Skip to content

restart restore reports success and clears the snapshot when a listed session no longer exists #426

Backlog

Description

@KooshaPari

kcode restart restore reports a clean success and then clears the snapshot even when a listed session does not exist. The window it creates is dead and never reports, so nothing in the herd shows the failure and the snapshot that could have been retried is gone.

Reproduce

Snapshot listing one session id that is not in the store:

{"version":1,"created_at":"2026-11-28T10:58:30Z","auto_restore_on_next_start":true,
 "sessions":[{"session_id":"session_missing_0000000000000_deadbeefdeadbeef",
              "display_name":"stage51 missing","working_dir":"<dir>","is_selfdev":false}]}

Then start plainly (kcode, no flags, with spawn_hook configured to hc run --bg --outlive-parent):

Found a reboot snapshot with auto-restore enabled. Restoring 1 jcode window(s)...
Restored 1 jcode window(s).
Cleared reboot snapshot after successful restore.

Parent exit is clean and the message says success. What the herd sees:

address  reported  identity  state     exit  title
t3w      False     ghostty   finished  1     (empty)

hc get t3w -> reported=False state=finished exit=1. After the run: snapshot file gone. Reproduced on kcode v0.93.0-k0.1.0-dev (1d42e78), and independently on the same flow in a probe home.

Same verbs without the hook (kcode restart restore) behave the same way: the restore is counted as success before anything checks that the session exists.

Why this is likely on a real reboot

The snapshot is written by restart save, which persists ids chosen at save time. Between the save and the next boot a session can be pruned by retention, removed by cleanup, or simply be a session that belongs to a different KCODE_HOME. Any of those turns a legitimate snapshot into a "restored 1 window(s)" that produced nothing.

Suggested shape of a fix

  • Resolve every listed session id before printing success and before clearing the file. A missing id should be surfaced, not swallowed.
  • Do not clear the snapshot unless the restored window count matches what was attempted; otherwise keep the file (or rewrite it with the ids that were restored) so a retry is possible.
  • The child should exit non-zero and report, so a monitoring layer can see the failure instead of a silent dead terminal.

Related, different trigger: #424 (a redirected store gives the same dead-child signature because hc run cannot carry the client's KCODE_HOME; workaround documented there). This issue is about validation and snapshot lifetime, and it bites default-store users too.

Activity

  1. added
    bug
    kilo-triaged
    on Nov 28, 2026
  2. KooshaPari commented on Nov 28, 2026

    @KooshaPari
    OwnerAuthor

    Contrast from the same session, so the difference is explicit.

    A snapshot whose sessions all resolve (kcode restart restore, 2 sessions):

    Restored 2 jcode window(s).
    Cleared reboot snapshot after successful restore.
    

    both children reported=True identity=ghostty state=live at t+8s and t+16s, each with its own title rendered.

    A snapshot naming one session that no longer exists (this issue):

    Restored 1 jcode window(s).
    Cleared reboot snapshot after successful restore.
    

    child reported=False state=finished exit=1, empty title, snapshot gone.

    So the restore count is reported from the snapshot's contents, not from what actually came up, and the snapshot is cleared on the same branch in both cases. Suggested fix direction (details in the issue body): resolve the ids first, report restored/skipped(missing) separately, and only clear the snapshot when every entry resolved - otherwise rewrite it with the unresolved entries so one more attempt is possible.

    Reachable on a normal reboot without any unusual setup: any saved session that was pruned, deleted, or belongs to a different home produces exactly this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugkilo-triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions