feat(sessions): restore agent sessions through one "after restart" model - #82
BIackFIame wants to merge 2 commits into
Conversation
|
One correction is needed before merging, based on static review of P2 — Reopen windows starts a fresh conversation but retains the previous conversation ID.
Until a lifecycle hook reports the new conversation ID, the card still points to its previous conversation. With lifecycle hooks disabled or unavailable, that stale ID can survive indefinitely. After the fresh process exits, choosing Continue can therefore resume the old conversation rather than the one that just ran. Switching the restore setting to Continue conversations can also persist the stale association for the next application restart. Please clear the previous Please extend the existing Reopen regression to cover the saved state as well as launch arguments:
The dependency on #80 looks consistent: #82 contains its exact commit, preserves Codex's exact-resume/picker behavior, and reads v1 I have not run the tests or reproduced this in the UI; the finding follows from the restore plan, session initialization, persistence, and Continue code paths. |
Builds on howdeploy#80 (teo-nex, "restore each Codex card to its own conversation"): its capture of the conversation id from authenticated lifecycle hooks, the validated id saved per card, `codex resume <id>`, the resume picker when no id is known and a plain restart forgetting the id are kept as they are. This extends the same exact resume to Claude Code (`claude --resume <id>`) and OpenCode (`opencode --session <id>`); the field is renamed from codexThreadId to threadId for that, with one per-provider check (canonical UUID for Codex and Claude, `ses_` id for OpenCode) shared by the hook client, the gateway, the store and the launch, and v1 records' codexThreadId still read. Settings → General now offers Don't save / Reopen windows / Continue conversations (settings v21; the old opt-in boolean migrates true→continue, false→off). Session records move to v2 (v1 stays readable): last state at quit or exit, the thread id, a per-card restore flag, and two validated opaque plugin slots (launch options and an environment ref, 4 KB each). No scrollback, prompts or secrets are saved. Restore puts parents before children, resumes a recorded conversation by id, and without one uses a "latest in this folder" flag only when that CLI has one card in the folder (otherwise it starts fresh with a note on the card; Codex opens its picker). Finished cards come back stopped with Restart / Continue (Continue resumes the card's own conversation), and a card whose environment is unavailable is held stopped with its reason instead of running locally. Cards get an options menu with "Don't restore this card". For plugins: the v2 record's two opaque slots are where later extension points keep per-card state across restarts. A launch contributor's chosen options are saved in `options[pluginId]` and an environment's ref in `environment`, both validated and capped at 4 KB, so a restored card can be prepared or placed again (or held stopped with a reason) without the core knowing what the values mean.
437f434 to
c1d603a
Compare
|
Thanks, confirmed and fixed in c1d603a. Root cause. The restore plan decided how a card starts, but not which conversation it stays tied to. Fix.
Regression. The Reopen test in
The plan test and the held-card test also check that stopped and held cards keep A. The new assertions fail on the previous commit. Other paths checked.
The stacked PRs #83–#88 are rebased onto this commit. Each is still one commit, and typecheck and the full test suite pass on every branch. |
|
Consolidated into #88 at the maintainer's request. Its branch already includes this implementation (the #81 authentication fix is incorporated through #87). Please continue all follow-up fixes and discussion in #88. Detailed changes-requested review: #88 (review) . Closing this superseded PR preserves its branch, commits and authorship; no code is being merged into main. |
Goal
Replace "Windows after restart" with one model: Don't save, Reopen windows or Continue conversations. Every card comes back to its own conversation, and later plugin extension points get a place to keep per-card state.
What changes
codex resume <id>and picker fallback, and extends the same exact resume to Claude Code (--resume <id>) and OpenCode (--session <id>). There is one per-provider id check (normalizeThreadId), used by the hook client, the gateway, the store and the launch.trueto continue andfalseto off. Session records are v2 and v1 stays readable. A record saves the last state, the thread id, a restore flag, and two validated opaque plugin slots (launch options and an environment ref, 4 KB each). It saves no scrollback, prompts or secrets.Extension point for plugins
The v2 slots (
options[pluginId],environment) are where #84 saves launch options and #85 saves environment refs, so a restored card can be prepared or placed again.Tests and checks
tests/session-restore-v2.test.mjsand the updated store, gateway and launch tests. Suite 894/894 and typecheck with a fake HOME.--resume <uuid>;--continue;Dependency
Stacked on #80 (teo-nex). Review only the top commit; the commit below it is #80. Note for #80: the field is renamed to
threadId, and v1codexThreadIdis still read.Used by canvastty-plugin-environments (restores worktree and container cards in place) and canvastty-plugin-accounts (saved account choice).