jcode icon indicating copy to clipboard operation
jcode copied to clipboard

restart restore can resume stale agent/tool work without a new operator prompt

Open ianalitis opened this issue 3 months ago • 1 comments

Summary

jcode restart restore can bulk-open a stale snapshot and resume pending model/tool execution without a fresh operator submission.

This is a safety issue because a command that appears to restore windows can cause old agent turns to continue and invoke tools in multiple repositories.

Environment

  • macOS ARM64
  • Jcode v0.81.5-dev at 422da2bc0
  • Ghostty + fish
  • Long-lived Jcode server

Reproduction

  1. Have several connected sessions, including sessions with interrupted or pending turns.
  2. Run jcode restart save.
  3. Leave the snapshot for a substantial period.
  4. Run jcode restart restore.

Observed with a snapshot containing 13 sessions that was approximately 47 hours old:

  • All 13 sessions were launched immediately.
  • There was no age warning, session preview, count confirmation, dry run, or per-session selection.
  • The primary snapshot was cleared after the windows launched.
  • Two restored sessions appended new runtime activity without a new textual operator prompt after restore:
    • one emitted a batch tool call;
    • another emitted two swarm tool calls and then an implementation directive.
  • Their persisted transcripts began with empty user/tool-result entries immediately after restore, consistent with continuation of interrupted tool loops.

The remaining restored clients had to be terminated manually.

Expected behavior

Restart restoration should be passive:

  1. Show snapshot age, count, and session list before launching anything.
  2. Require explicit confirmation for stale or multi-session snapshots.
  3. Reattach UI surfaces without resuming model/tool execution.
  4. Require a fresh explicit operator submission before any restored session may invoke a provider or tool.
  5. Preserve the snapshot until restore is confirmed successful and safe.

At minimum, a snapshot this old or this large should not launch silently.

Source evidence

  • src/cli/commands/restart.rs:121-169
    • restores immediately;
    • has no preview or confirmation;
    • clears the snapshot after successful launch.
  • crates/jcode-app-core/src/restart_snapshot.rs:184-213
    • iterates every saved session;
    • calls spawn_resume_in_new_terminal_with_context for each session.
  • src/cli/commands/restart.rs:186-253
    • captures connected, non-crashed sessions;
    • snapshot entries do not record whether a turn or tool loop was in progress.

Suggested safety invariant

restart restore restores windows and attachments only. It must never create a provider request, continue an agent turn, or invoke a tool until the operator explicitly submits a new message in that restored session.

Minimal test coverage

  • A stale snapshot requires confirmation or an explicit --yes.
  • A multi-session snapshot exposes a preview before spawning.
  • Restoring a session with a pending tool continuation leaves it paused.
  • No provider/tool events occur until a new operator message is submitted.
  • Snapshot cleanup happens only after the selected launches complete.

No private prompts, credentials, or repository contents are included in this report.

ianalitis avatar Aug 31 '26 04:08 ianalitis

Additional source trace after independent review:

  • created_at is persisted but never checked before restoration (restart_snapshot.rs:10-16, 184-185).
  • The direct resume handler reconstructs history but is not itself the model-dispatch site.
  • Automatic provider/tool continuation exists in server startup recovery for eligible headless nonterminal swarm members. Active/pending and reload-interrupted sessions can be selected and continued with a generated continuation reminder and no fresh operator message (server.rs:341-347, 1048-1059, 1127-1138; client_session.rs:54-97). Existing tests intentionally cover this continuation (server/tests.rs:727-847).
  • Reload-recovery intent remains eligible for seven days (reload_recovery.rs:7).
  • Generic JSON recovery can restore a preceding .bak when the primary is malformed (jcode-storage/src/lib.rs:549-647), so age validation must apply to the exact recovered snapshot too.

This makes the required boundary clearer: reboot/window restoration must not implicitly authorize the separate headless/reload continuation mechanism. A restore context should suppress automatic continuation until a fresh operator submission, in addition to adding snapshot preview, confirmation, age checks, and noninteractive fail-closed behavior.

ianalitis avatar Aug 31 '26 04:08 ianalitis