Agent Focus: Projects list is lost after force quit and never restored on launch (root cause + patch)
Before opening, please confirm:
- [x] I have searched for duplicate or closed issues
Operating System
Windows 11 Home N 25H2 (build 26200) — also reproduced on macOS
Kiro Version
1.0.242
Bug Description
In Agent Focus, the Projects list is lost after an abnormal exit (force quit from Task Manager, renderer/main process kill, power loss). On relaunch, Agent Focus comes up with no working projects and every folder has to be re-added by hand through Open folder, one at a time. Seen on both Windows and macOS.
Two variants show up on relaunch: sometimes the Projects list is empty immediately, and sometimes the saved projects appear as loading (spinner) cards that never resolve and then clear out after a while, leaving the list empty.
The sessions themselves are fine: as soon as a folder is re-added, that project's session history is back, so nothing is actually lost except the project list. With 6-8 projects open this turns every unclean shutdown into several minutes of re-adding folders, and it is easy to forget one and lose track of the work in it.
Digging into the shipped 1.0.242 bundle, this does not look like a flush/timing problem. The saved project list is (1) only written for projects that are currently in the background (headless) state, (2) deleted from disk at the moment it is read on startup, and (3) never used to actually reopen the projects. Details and code references below.
Steps to Reproduce
- Launch Kiro and switch to Agent Focus.
- Add several project folders (Open folder). Each one opens as a background (headless) window and appears in the Projects list.
- Optionally bring one project to the foreground (the "return to IDE" / reveal path) so it is no longer headless.
- Force quit Kiro: Windows Task Manager -> End task on the Kiro processes (Force Quit on macOS; a power loss or a renderer crash has the same effect). Do not use File -> Exit.
- Relaunch Kiro (Agent Focus).
- The Projects list comes up empty — either immediately, or after showing loading (spinner) cards that never resolve and then disappear. Any project that was in the foreground in step 3 is gone even after a clean exit.
- Re-add one folder via Open folder -> the project comes back with its session history intact.
Expected Behavior
Agent Focus should come back with the same set of projects it had before, including after a crash or force quit:
- the project list should survive an unclean exit,
- projects should be reopened (or at least be one click away) on the next launch instead of having to be re-picked from a folder dialog,
- a project should not drop out of the list just because its window was in the foreground when Kiro exited.
Conversation ID
No response
Additional Context
Where the state lives
%APPDATA%\Kiro\User\globalStorage\storage.json, key agentFocus.headlessProjects:
"agentFocus.headlessProjects": [
{ "type": "folder", "path": "<project-a>", "label": "<project-a>", "folderPaths": ["<project-a>"] },
{ "type": "folder", "path": "<project-b>", "label": "<project-b>", "folderPaths": ["<project-b>"] }
]
Three problems in agentRegistryMainService (resources/app/out/main.js, 1.0.242)
-
The persist function only walks the headless window set, and clears the key when that set is empty:
// for each window id in <headless set>: if it has an openedWorkspace, push {type, path, label, folderPaths} e.length > 0 ? this.r.setItem(Do.m, e) : this.r.removeItem(Do.m) // Do.m === "agentFocus.headlessProjects"revealHeadlessWindow()removes the window from that set and immediately re-persists, so revealing a project drops it from the saved list. If every project happens to be revealed, the key is deleted outright. I can see this in my ownstorage.json: one project I had brought to the foreground is present inwindowsStateandbackupWorkspaces.foldersbut missing fromagentFocus.headlessProjects. -
The read is destructive:
async getSavedHeadlessProjects(){ const e = this.r.getItem(Do.m); this.r.removeItem(Do.m); ... }The list is consumed on read, so between startup and the next successful persist there is nothing on disk. A crash or force quit in that window loses the whole list permanently, and it also means the list cannot be recovered by simply restarting again.
-
Nothing in the main process reopens the saved projects.
agentFocus.headlessProjectshas exactly one reader, the Agent Focus contribution inresources/app/out/vs/workbench/workbench.desktop.main.js:this.mb.getSavedHeadlessProjects().then(V => { for (const z of V) { /* ...derive label/folderPaths... */ this.Q?.showLoadingProject(Y, Z) } this.uc() })Compare the manual Open folder path, which shows the same placeholder and then actually opens the folders:
this.Q?.showLoadingProject(s, t); this.uc(); await this.mb.openWorkspaceFolders(t, !0) === void 0 ? (this.Q?.removeLoadingProject(s), this.uc()) : ...The restore path has no
openWorkspaceFolderscall, so saved projects only ever render as spinner placeholders that never resolve, and since the key was already deleted they are gone on the next launch.markWindowHeadlessis only called from the "send window to background" confirmation flow, so windows restored by the normal window-restore path are not re-registered as Agent Focus projects either.
Log evidence (%APPDATA%\Kiro\logs\<session>\main.log, project names abbreviated)
Previous session held six background projects, then quit through the Agent Focus close path:
19:01:52 [info] [AgentRegistry] Standalone window closed
19:02:21 [info] [AgentRegistry] Only headless windows remain after AFM closed, quitting
Next launch restored no project windows at all; the Projects list had to be rebuilt manually, one folder dialog at a time (~30 s apart), and one project from the previous session was never recovered:
19:02:30 [info] [AgentRegistry] Standalone window opened: 1
19:02:40 [info] [AgentRegistry] Opened headless workspace window 2 with 1 folder(s)
19:03:08 [info] [AgentRegistry] Opened headless workspace window 3 with 1 folder(s)
19:03:43 [info] [AgentRegistry] Opened headless workspace window 4 with 1 folder(s)
19:03:51 [info] [AgentRegistry] Opened headless workspace window 5 with 1 folder(s)
19:04:15 [info] [AgentRegistry] Opened headless workspace window 6 with 1 folder(s)
19:04:35 [info] [AgentRegistry] Opened headless workspace window 7 with 1 folder(s)
Suggested direction
- Persist the Agent Focus project set independently of window visibility (include revealed projects), keyed by path.
- Treat the stored list as durable state: keep it on read and only overwrite it after the restore has been applied, instead of
removeItemup front. - In the restore path, reopen the saved projects the way the manual flow does (
openWorkspaceFolders(paths, true)), or make the placeholder cards clickable so one click restores a project. - A "Recent projects" entry in the Agent Focus project dropdown would also make this recoverable when persistence fails for any other reason.
Happy to test a build or provide more logs.
Thanks for opening this issue and for the thorough investigation into the root cause — the detail about the project list only being written for headless windows and then deleted on read is really helpful! We understand how frustrating it must be to re-add multiple project folders after every unclean shutdown. A maintainer will review this shortly. We appreciate you taking the time to reproduce this across both Windows and macOS — reports like this make Kiro better for everyone! 🙌
Patch for this issue
Patch + apply/revert script for the shipped 1.0.242 bundles: https://gist.github.com/lpaiu-cs/3c0a1eb8ebb4f1864def3a93c315769d
Three hunks, matching the three problems in the report:
-
out/main.js, persist function — walk every window that registered an agent endpoint, not only the ones currently in the headless set, and never delete the stored key:// before for(const i of this.c){if(i===this.j)continue; … e.length>0?this.r.setItem(Do.m,e):this.r.removeItem(Do.m) // after const _p10592=new Set([...this.c,...this.b.keys()]); for(const i of _p10592){if(i===this.j||i===this.h)continue; … e.length>0&&this.r.setItem(Do.m,e)this.bis exactly the set of Agent Focus projects regardless of visibility. The orchestrator (this.j) and the standalone window (this.h) are excluded; the standalone window is empty and would have been dropped by the existingopenedWorkspacecheck anyway. -
out/main.js,getSavedHeadlessProjects()— stop consuming the list on read (drop theremoveItem), so it is still on disk if the next persist never happens. -
out/vs/workbench/workbench.desktop.main.js, restore path — actually reopen the saved projects, the way the manual Open folder path does:// before .then(V=>{ for(const z of V){ … this.Q?.showLoadingProject(Y,Z) } this.uc() }) // after .then(async V=>{ …same cards, collected as {label,paths}… const open = new Set(folder paths of all non-standalone, non-orchestrator windows); for (const p of saved) if (!p.paths.every(x => open.has(x))) await this.mb.openWorkspaceFolders(p.paths, true); // === undefined -> removeLoadingProject })Sequential, and it skips any project whose folders are already open in another window so a restore cannot duplicate windows.
One deliberate trade-off in hunk 1: since the stored list is never deleted, closing the last project leaves the previous entry behind and it reappears once on the next launch. Losing the whole list on an unclean exit seemed clearly worse, and telling "the user closed everything" apart from "we happen to see nothing right now" needs an explicit close signal — a larger change than a bundle patch should make.
Verification status
Static verification passes: each anchor occurs exactly once before the patch and the patched form exactly once after, the replacement snippets parse in isolation, and node --check passes on both patched bundles. The script refuses to write unless every anchor matches exactly once, backs the originals up first, and writes through a temp file + rename.
Runtime verification is still pending — it needs a force-quit/relaunch cycle on the patched build. I will follow up here with the result rather than claim it now.
Thanks for raising this. The Agent Focus projects list is lost after an abnormal exit because the state file is only flushed on clean shutdown. A force quit or crash skips the flush, leaving an empty state on relaunch. Marking this as a bug to investigate further.
Thanks for raising this. The Agent Focus projects list being lost after a force quit is a real data loss issue — the list of opened workspaces relies on VS Code's in-memory window state which is not safely flushed on abnormal exit, so it's never restored on next launch. Marking this as a bug to investigate further.