Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

Agent Focus: checkpoint Restore blanks the session and hangs (root cause + partial patch)

Open lpaiu-cs opened this issue 4 months ago • 4 comments

[!NOTE] Body corrected after tracing the code path and finding logs of the incident. My first version claimed the restore is a session fork and that it never reached the agent. Both were wrong: it is _kiro/checkpoint/revertMultiple, and it succeeded. The failure is in the Agent Focus renderer, after the agent returned success. Details in the correction comment below.

Before opening, please confirm:

Operating System

Windows 11 Home N 25H2 (build 26200)

Kiro Version

1.0.242 (kiro.kiro-agent extension 1.0.428)

Bug Description

Clicking Restore next to a checkpoint in a chat while in Agent Focus wipes the session list for that project — every session under the project disappears from the list, not just the one being restored. The chat area then shows a spinner that never resolves and eventually gives up on its own, with no error text anywhere.

Nothing is actually lost. Toggling the same window to IDE mode shows the session with its full history, and work continues normally from there. The session files on disk are untouched and the agent keeps serving them the whole time (log evidence below). So this is an Agent Focus UI failure, not session loss — but from the user's side it looks exactly like every session in the project was deleted.

This was reported before as #8556 against 0.11.133 and closed as stale, with a request to open a new issue if it still reproduces on the current version. It does, on 1.0.242. Related UX request: #7683.

Steps to Reproduce

  1. In Agent Focus, open a project that has several sessions (3 in my case), including one long session (~700 messages, 52 checkpoint snapshots).
  2. Open the long session and scroll back to an earlier checkpoint. (Restore is disabled while the agent is working, so stop the turn first if one is running.)
  3. Click Restore next to that checkpoint, then confirm.
  4. The project's session list goes empty in Agent Focus, and the chat shows a spinner that never completes. After a while it stops by itself; no error message is displayed.
  5. Toggle the window to IDE mode (top-right) — the session and its full history are present and usable.

Expected Behavior

Restore should revert the files and the conversation to the checkpoint, leave the project's other sessions in the list untouched, and either complete or fail with a visible error. A restore should never blank the session list, and the same state should be visible in Agent Focus and IDE mode.

Conversation ID

sess_11069357-5470-4ab6-b8a6-759cd4def0c6 (occurred 2026-07-31, 10:30:05 UTC)

Additional Context

Both round trips succeeded — the data was there and on time

Owning window's agent log (~/.kiro/logs/20260731T101245471/kiro.log, UTC):

10:29:59.403 [info]  [KiroAgent] ACP session/cancel sessionId=sess_11069357-…
10:29:59.407 [error] [str_replace] Stream error: type=StreamError message=Operation was aborted by user or system
10:30:04.855 [info]  [SessionPersistence] Loaded session sess_11069357-… (697 messages)
10:30:04.856 [warn]  [checkpoint-revert] No pre-snapshot found for …\CPdStateWorldmap.cpp (replace), skipping
10:30:05.112 [info]  [KiroAgent] Reverted session sess_11069357-… to message fc61c953-…: 4 files restored, 4 total
10:30:05.115 [info]  [KiroAgent] ACP session/load sessionId=sess_11069357-…
10:30:05.211 [info]  [KiroAgent] ACP session/load complete sessionId=sess_11069357-… messages=698

The revert restored 4 files in 250 ms and the webview's follow-up reload completed in 96 ms with 698 messages. The session listing was also served continuously — [SessionPersistence] Listed 3 session(s) for workspace 6377419eee432f48, 1930 lines between 10:12:45Z and 10:56:42Z, never fewer than 3 — spanning the whole period during which Agent Focus showed an empty list. Session files on disk are untouched (messages.jsonl is append-only; the revert appended a marker, 697 -> 698).

Where it breaks: the renderer, after success

Confirm handler in the chat webview (packages/kiro-ui-agent-chat, shared bundle):

const H = await d("revertMultiple", { sessionId: c, messageId: e });
if (H.success) {
  r();                                  // clearSessionForReload()  <-- UI emptied here
  const $ = await d("loadSession", c);   // refill
  … setConfigOptions / setContextUsageConfig / setAvailableAgents …
  o();                                  // completeCheckpointRevert()  <-- spinner ends here
} else {
  x(H.error ?? "Revert failed");
}
  1. Clear-before-reload with no rollback. The store is emptied first and refilled second, so anything that goes wrong in between leaves the session visually empty with nothing to restore it from.
  2. Failures are silent by construction. The catch path does x(err) and o(). o() is completeCheckpointRevert, which dismisses the checkpoint-revert panel — and v.error renders only inside that panel (.kiro-checkpoint-revert-error). So the error text is written to a component that the same handler unmounts. Agent-side rejections (SessionNotFound, "Cannot revert while the agent is still running", "A revert is already in progress for this session") can never reach the user.
  3. The spinner is React.useTransition's isPending, with no timeout or failure state, so if the awaited work never settles it spins indefinitely.

Related hazard in the same flow (not the cause here)

In Agent Focus the target agent is resolved from a module-level mutable global:

// src/extension/agent-chat/active-window-state.ts
function getActiveWindowId() { return activeWindowId; }
function setActiveWindowId(windowId) { activeWindowId = windowId; }
var activeWindowId;

getKiroClient() looks up pool.getClientForWindow(getActiveWindowId()) and silently falls back to the Agent Focus window's own agent when that misses — an agent that holds no state for the session. activeWindowId is assigned only by the kiroAgent.sessions.switch command, so it goes stale when a project window is closed and reopened with a new id and port. _revertMultiple and loadSession pass no window id, unlike resolvePermissionRequest and resolveUserInput, which route explicitly by pending.windowId through the same pool. In IDE mode there is a single local client, so this hazard does not exist there.

Remaining gap

The blanked session content is explained above. I could not verify why the project's whole session list empties: the Agent Focus window writes no logs at all (its logs/<session>/window*/ directory is empty, while project windows have renderer.log and exthost/kiro.kiroAgent/Kiro Logs.log), and nothing on the renderer's revert path is logged. Logging on the revert request/reload and log output from the Agent Focus window would make this diagnosable from a user's report.

Also worth a look

[checkpoint-revert] No pre-snapshot found for …\CPdStateWorldmap.cpp (replace), skipping — the revert silently skipped a file it could not restore while reporting "4 files restored, 4 total". A partial revert should say so in the UI.

Suggested fix

  • Do not clear the store until the reload has data, or keep a snapshot and restore it if the reload fails.
  • Surface failures where they are visible instead of dismissing the panel that displays them in the same step.
  • Give the pending transition a timeout and a failure state so the spinner cannot run forever.
  • Route session-scoped calls by the session's owning window id rather than a mutable global, and fail loudly rather than falling back to the local client.
  • Report skipped files from a partial revert.

Happy to test a build, capture more logs, or run a specific repro.

lpaiu-cs avatar Jul 31 '26 10:07 lpaiu-cs

Thanks for filing this detailed report, including the reproduction steps and the context from the earlier issue! We can see that restoring a checkpoint in Agent Focus is blanking the session list and hanging, even though the underlying data remains intact. A maintainer will take a look at this shortly. We appreciate you helping us track this down — the thorough write-up really helps! 🙏

github-actions[bot] avatar Jul 31 '26 10:07 github-actions[bot]

Correction and root cause

I traced the actual code path and found logs of the incident on my machine. Two claims in my original report were wrong — corrected below, and the issue body has been edited accordingly.

What I got wrong

  1. Checkpoint Restore is not a session fork. It is _kiro/checkpoint/revertMultiple -> KiroAgent.handleRevertToMessage(), an in-place revert. session/fork / createdReason: "rewind" belongs to a different path, so my "no fork request in the logs" evidence was searching for the wrong thing, and the forkSession workspace-bucket hazard I raised does not apply here.
  2. The restore did reach the agent, and it succeeded. I had grepped for fork/rewind rather than for the revert's own log line.

What actually happened

From the owning window's agent log (~/.kiro/logs/20260731T101245471/kiro.log, UTC):

10:29:59.403 [info]  [KiroAgent] ACP session/cancel sessionId=sess_11069357-…
10:29:59.407 [error] [str_replace] Stream error: type=StreamError message=Operation was aborted by user or system
10:30:04.855 [info]  [SessionPersistence] Loaded session sess_11069357-… (697 messages)
10:30:04.856 [warn]  [checkpoint-revert] No pre-snapshot found for …\CPdStateWorldmap.cpp (replace), skipping
10:30:05.112 [info]  [KiroAgent] Reverted session sess_11069357-… to message fc61c953-…: 4 files restored, 4 total
10:30:05.115 [info]  [KiroAgent] ACP session/load sessionId=sess_11069357-…
10:30:05.211 [info]  [KiroAgent] ACP session/load complete sessionId=sess_11069357-… messages=698

(I had to stop the running turn first, since Restore is disabled while the agent is active.)

Both round trips landed on the correct agent and returned success: the revert restored 4 files in 250 ms, and the webview's follow-up reload completed in 96 ms with 698 messages. Meanwhile the session listing kept being served once per second throughout (Listed 3 session(s) for workspace 6377419eee432f48, 1930 lines from 10:12 to 10:56).

So every piece of data the UI needed was available and delivered on time. The failure is entirely in the Agent Focus renderer, after both calls succeeded.

Why the UI ends up blank and stuck

The confirm handler in the chat webview (packages/kiro-ui-agent-chat, shared bundle) does this:

const H = await d("revertMultiple", { sessionId: c, messageId: e });
if (H.success) {
  r();                                  // clearSessionForReload()  <-- UI is emptied here
  const $ = await d("loadSession", c);   // refill
  … setConfigOptions / setContextUsageConfig / setAvailableAgents …
  o();                                  // completeCheckpointRevert()  <-- spinner ends here
} else {
  x(H.error ?? "Revert failed");
}

Three problems compound:

  1. Clear-before-reload with no rollback. The store is emptied first and refilled second. Anything that goes wrong in between — including a reload whose replayed history never lands in the webview — leaves the session visually empty with nothing to restore it from.
  2. The error is written to a component the same handler unmounts. The catch path is x(err) and o(). o() is completeCheckpointRevert, which dismisses the checkpoint-revert panel, and v.error is only rendered inside that panel (.kiro-checkpoint-revert-error). Every failure in this flow is therefore silent — which matches what I saw: no message at all, just a spinner.
  3. The spinner is React.useTransition's isPending, so if the awaited work never settles the spinner never stops, and there is no timeout or fallback on this path.

Agent-side, handleRevertToMessage can reject with SessionNotFound, "Cannot revert while the agent is still running", or "A revert is already in progress for this session." None of those can reach the user because of (2).

Why IDE mode is unaffected — and a related hazard

In a project window there is one local agent client, so the request cannot be misrouted. In Agent Focus the target agent is resolved from a module-level mutable global:

// src/extension/agent-chat/active-window-state.ts
function getActiveWindowId() { return activeWindowId; }
function setActiveWindowId(windowId) { activeWindowId = windowId; }
var activeWindowId;

getKiroClient() looks up pool.getClientForWindow(getActiveWindowId()) and, when that misses, silently falls back to the Agent Focus window's own agent, which holds no state for the session. activeWindowId is only assigned by the kiroAgent.sessions.switch command, so it goes stale whenever a project window is closed and reopened with a new id and port. _revertMultiple and loadSession pass no window id, unlike resolvePermissionRequest and resolveUserInput, which route explicitly by pending.windowId through the same pool.

That did not cause this incident (the logs show correct routing), but it is the same class of failure reachable from the same code, and combined with (1) and (2) it would be silent.

Remaining gap

I can explain the blanked session content. The user-visible symptom also included the project's whole session list going empty, and I could not verify that part: the standalone/Agent Focus window writes no logs at all (its logs/<session>/window*/ directory is empty, while regular project windows have renderer.log and exthost/kiro.kiroAgent/Kiro Logs.log). Nothing on the revert path in the renderer is logged either. Some logging around the revert request/response and its reload, and log output from the Agent Focus window, would make this diagnosable from a user's bug report.

Also worth a look

[checkpoint-revert] No pre-snapshot found for …\CPdStateWorldmap.cpp (replace), skipping — the revert silently skipped a file it could not restore while reporting "4 files restored, 4 total". A revert that cannot fully revert should say so in the UI.

Suggested fix

  • Do not clear the store until the reload has data; or keep a snapshot and restore it if the reload fails.
  • Surface failures where they are visible: keep the panel (or use a notification) when x(err) is set, instead of dismissing it in the same step.
  • Add a timeout/failure state to the pending transition so the spinner cannot run forever.
  • Route session-scoped calls by the session's owning window id rather than a mutable global, and fail loudly instead of falling back to the local client when the pool lookup misses.
  • Report skipped files from a partial revert.

Tested on Kiro IDE 1.0.242 / kiro.kiro-agent 1.0.428, Windows 11. Happy to run a specific repro or provide fuller logs.

lpaiu-cs avatar Jul 31 '26 11:07 lpaiu-cs

Partial patch for this issue

Patch + apply/revert script for the shipped 1.0.242 chat bundle: https://gist.github.com/lpaiu-cs/3c0a1eb8ebb4f1864def3a93c315769d

Target is extensions/kiro.kiro-agent/packages/kiro-ui-agent-chat/dist/assets/mermaid-GHXKKRXX-zvWLQDG1.js — despite the name that file is the chat UI's shared app chunk, used by the session-view, standalone and session-manager entry points. The script locates it by content, since the hash in the filename changes between builds.

One store detail that sharpens the report: clearSessionForReload() resets the session slice to the empty state and sets isReloadingCheckpoint: true, and only completeCheckpointRevert() clears that flag. So a call that never settles leaves the overlay spinning on an already-emptied session — that is the endless spinner, and it is why the session looks deleted.

Hunk A — bound both calls, so the flow always settles:

const _to10593=(_pr,_ms,_lbl)=>Promise.race([_pr,new Promise((_res,_rej)=>
  setTimeout(()=>_rej(new Error(_lbl+" timed out after "+Math.round(_ms/1e3)+"s")),_ms))]);
H = await _to10593(d("revertMultiple",{sessionId:c,messageId:e}), 12e4, "Checkpoint restore");
$ = await _to10593(d("loadSession",c),                            12e4, "Session reload");

Hunk B — make the failure visible and recoverable. The catch keeps the inline error, raises a showMessage notification (the same channel the standalone compose path already uses for its own failures), and attempts one reload so the session is not left blank:

catch(H){ const $=H,_m10593=$ instanceof Error?$.message:"Revert failed. Please try again.";
  x(_m10593), o();
  try{ await d("showMessage",{type:"error",message:"Checkpoint restore failed: "+_m10593}) }catch{}
  try{ await d("loadSession",c) }catch{}
}

d and c are already in the enclosing scope, and both are covered transitively by the React Compiler memo cache through w, whose dependency list contains them.

What this patch deliberately does not fix

  • The store is still emptied before the reload delivers. The replayed history arrives as notifications during loadSession, so moving the clear after the await would wipe what just arrived. A proper fix snapshots the slice and restores it on failure, or defers the clear until the first replayed message lands. That is a design decision for the owning team rather than something a bundle patch should guess at.
  • Partial reverts stay silent ([checkpoint-revert] No pre-snapshot found for … skipping alongside 4 files restored, 4 total). Surfacing it needs the skipped list to come back through the API.
  • Cross-window routing still resolves the target agent from the mutable global activeWindowId and silently falls back to the Agent Focus window's own agent when the pool lookup misses. Routing by the session's owning window id is the real fix.

So this turns a silent, apparently-destructive failure into a bounded and visible one. It does not make the revert flow correct.

Verification status

Static verification passes: both anchors occur exactly once before and the patched forms exactly once after, the snippets parse in isolation, and node --check passes on the patched bundle. The script refuses to write unless the anchors match exactly once, backs up the original, and writes through a temp file + rename.

Runtime verification is still pending — it needs a restart plus a fresh Restore attempt on the patched build. I will follow up with the result rather than claim it now.

lpaiu-cs avatar Jul 31 '26 11:07 lpaiu-cs

Thanks for raising this, and for the detailed root cause trace and correction comment. The failure being isolated to the Agent Focus renderer (after the agent succeeds) narrows this down — the revert itself appears to work, but the UI might not be recovering from it correctly. The fact that switching to IDE mode shows everything intact suggests it's likely a rendering/state issue in the Agent Focus window rather than actual data loss. Marking as a bug.

AnilMaktala avatar Jul 31 '26 16:07 AnilMaktala