Repository navigation
feat(resume): auto-resume an agent session after a host restart - #6
Conversation
A pane that was running an agent comes back as that agent with its conversation, instead of as a bare shell the user has to re-attach by hand. A pure resolver decides which conversation a pane resumes; a candidate source and chooser surface present the options when more than one fits; per-pane gates decide when a shell may be replaced by a recovered session; and a recovery orchestrator drives it from the pane itself. Five rounds of review shaped it. The last found that the chooser had never worked: its handler was registered with `session.transport` read eagerly at install time, before `installPtyInputRecovery` assigns it, so the owner was captured as undefined and every interaction silently no-opped. Claims are now keyed by pane identity rather than raw session id, a scan reports whether it actually covered its scope instead of assuming it did, WSL UNC and Linux cwd forms are matched as the same path, and the chooser is localized. Squashed onto the integration branch. The eleven-commit history is preserved on kiwidream/auto-resume-sessions and in PR #2, which stays open against its own base for review of that history. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Review complete. 🟠 1 high · 🟡 3 medium 💬 Inline comments (2)
📍 Outside the diff (2)
🧹 Nitpicks (1) — 🟢 1 low
Reviewed commit: 0cdebd9 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0cdebd91df
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ages
Two review findings on the chooser and its scan-coverage check.
The coverage check refuses recovery when a host does not state
`appliedSessionDepth`, because silence cannot be told from a slice. Two scan
paths never stated it, so that refusal was firing on every remote host rather
than on old ones: `withRuntimeExecutionHost` rebuilt the result field by field
and dropped it, and `scanRemoteAiVaultSessions` never set it at all. Recovery
was therefore disabled for every runtime environment and every SSH target —
the hosts this feature exists for — and it failed silently to a plain shell,
which is the pre-feature behaviour, so nothing looked wrong.
The retagging rebuild now spreads instead of listing fields, so it cannot drop
what it does not know about, and the remote scanner echoes the bound it ran
under. Both are covered by tests that fail without the change.
The chooser's age column ("newest", "3h older", "unknown") was hard-coded
English inside a dialog round five had otherwise localized, so non-English
users read mixed-language decision metadata. Those labels now route through the
translator with counts, and the strings ship in all six locales. English
plural suffixes are regenerated into the runtime-required catalog by
sync:localization-runtime-catalog.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Review complete. No issues found — approved ✅. Adds an AI-vault session-depth plumbing for safe auto-resume decisions plus a blocking agent-resume chooser with per-pane reservations, claims, and i18n across all six locales; review found no blocking issues. Reviewed commit: 02c0d49 |
|
Two of the five fixed in Scan depth (P1) — wider than the line the bot named. The retagging rebuild now spreads instead of listing fields, so it cannot drop what it does not know about, and the remote scanner echoes the bound it ran under. Both covered by tests verified to fail without the change ( Credit to @sawfish-f6's review for pushing back on the single-line fix — the SSH half would have shipped otherwise. Age labels (P2). Routed through the translator with counts, shipped in all six locales, and the English plural suffixes regenerated into the runtime-required catalog via Still open, not yet fixed:
Verification. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02c0d49a46
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ervations The last three review findings on the chooser and pane recovery. A restored pane whose only pane-scoped evidence is the hook server's persisted status reached the agent gate before that status landed, returned without spending the attempt latch, and was never asked again: an already-visible pane gets no later visibility flip. It sat as a plain shell until the user switched away and back. A pane that declines for want of evidence now watches for it, through the same latch so a late arrival cannot double-run, and the watch is armed only by a pane that needs it rather than by every connection. Tab moved focus out of the chooser's listbox to the close and dismiss buttons, and every resume key stopped working while the selected row still looked active — a blocking dialog whose help text promises "press a number or Enter", with a dead keyboard and no cue that focus had moved. Tab is now held on the listbox; the rows were never tabbable, so no reachable stop is lost. Disposing a binding released its resume reservation unconditionally, including while the spawn that reservation authorized was still settling. A sibling pane scanning that window saw neither reservation nor claim and could respawn the same transcript — the fork the map exists to prevent. Release now waits for an in-flight spawn and re-reads the pane's owner when it lands, since a deferred release can arrive after a successor took the slot. Extracted to its own module rather than growing the dispose file past its line limit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
Reviewed commit: aca2fdf |
There was a problem hiding this comment.
Expand to see previous review
This PR threads an appliedSessionDepth signal through the AI Vault session-scan/cache/merge layers and adds a new renderer agent-resume recovery subsystem (chooser UI, reservations, claims, recovery install, and locale strings); two medium lifecycle findings were flagged in the recovery-install watcher.
| session.agentResumeRecoveryStatusUnsubscribe?.() | ||
| session.agentResumeRecoveryStatusUnsubscribe = null | ||
| void session.attemptAgentResumeRecovery?.() |
There was a problem hiding this comment.
🟡 bug · medium
Evidence watcher never re-arms after unspent refusal
The store subscription in watchForPaneAgentEvidence unsubscribes itself before invoking attemptAgentResumeRecovery (agent-resume-recovery-install.ts:124-126). When the attempt ends in an unspent refusal (scan-unverifiable) or throws, the latch resets at lines 196-198/202 but the watch is not re-armed: re-arming only happens in the !isResumableTuiAgent(paneAgent) branch, which is unreachable here because the watcher fired precisely because paneAgent became resumable. An already-visible restored pane has no later visibility flip and no further onPtySpawn, so despite the unspent latch it never retries and sits as a plain shell until the user manually switches tabs away and back, contradicting the contract stated in the comment at lines 111-112.
📋 Prompt for AI Agents
In src/renderer/src/components/terminal-pane/pty-connection/agent-resume-recovery-install.ts around lines 196-204, after resetting session.agentResumeRecoveryAttempted = false for the unspent scan-unverifiable refusal and inside the catch block, also call watchForPaneAgentEvidence() to re-arm the evidence watcher. Currently the one-shot subscription at lines 124-126 unsubscribes before invoking attemptAgentResumeRecovery, so an already-visible pane whose scan comes back unverifiable (or whose attempt throws) loses its only retry trigger for the life of the connection. The early return at lines 114-116 already guards against double subscription.
| !reserveAgentResumeSession(candidate.providerSession.id, session.cacheKey) | ||
| ) { | ||
| return false | ||
| } | ||
| // Held so disposal can tell "reserved, spawn still settling" from "reserved and claimed". | ||
| // Releasing in that window frees a transcript a sibling pane can then respawn. | ||
| const spawned = Promise.resolve(session.startFreshColdRestoreAgentResume(startup)).catch( | ||
| () => undefined | ||
| ) | ||
| session.agentResumeSpawnInFlight = spawned | ||
| void spawned.finally(() => { | ||
| if (session.agentResumeSpawnInFlight === spawned) { | ||
| session.agentResumeSpawnInFlight = null | ||
| } | ||
| }) |
There was a problem hiding this comment.
🟡 bug · medium
Failed respawn leaks the session reservation
resumeWithCandidate reserves the session synchronously at agent-resume-recovery-install.ts:87 and then starts the respawn whose rejection is swallowed by .catch(() => undefined) (lines 93-95), returning true regardless. Nothing releases the reservation when the spawn fails; the only release path is releaseAgentResumeReservationOnDispose, which runs at pane disposal, and the latch stays spent because the resume decision is not in UNSPENT_AGENT_RESUME_REFUSALS. The pane is left as a plain shell while the reservation map keeps the session marked as held, so every sibling pane's claimedProviderSessionIds excludes that transcript for the pane's remaining lifetime — one failed auto-resume permanently locks the session away from recovery in other panes.
📋 Prompt for AI Agents
In src/renderer/src/components/terminal-pane/pty-connection/agent-resume-recovery-install.ts around lines 87-101, when session.startFreshColdRestoreAgentResume(startup) rejects, release the reservation taken at line 87 (call the release helper in src/renderer/src/lib/agent-resume-reservation-release.ts targeted at candidate.providerSession.id / session.cacheKey) instead of swallowing the error with .catch(() => undefined), so a failed respawn does not leave the reservation map holding the session until pane disposal and block sibling panes from resuming it.
A newer Tenki review found issues on this pull request.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aca2fdf892
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (resolveAgentResumePaneLiveness(state, rowPaneKey) !== 'exited') { | ||
| claimed.add(entry.providerSession.id) | ||
| } |
There was a problem hiding this comment.
Scope provider-session claims to their host and agent
When two execution hosts—or two different agents—contain the same provider session ID, a live row on one is added as a claim against the other because only the raw ID is retained. This is reproducible with cloned runtime/SSH homes, where identical IDs name separate on-disk transcripts, and it disables recovery on the otherwise unrelated host. Build the claim identity from the execution host, agent, provider key/ID, and transcript path where required, rather than using providerSession.id globally.
AGENTS.md reference: AGENTS.md:L89-L91
Useful? React with 👍 / 👎.
…sted agent alone Two review findings, both P1. An SSH connection was read as evidence of Linux, so `buildCandidateResumeStartup` rebuilt every remote resume command with POSIX quoting. Windows SSH hosts are supported and their scan rows already report `executionHostPlatform`, so after a restart the generated command was invalid for the remote PowerShell or cmd shell. The candidate now carries the platform its host reported and the launch target prefers it; SSH remains the fallback only when the host said nothing. The field is required on the candidate so a future source cannot quietly omit it — absent means "the host did not say", not "assume Linux". A pane opened to run a specific command has a `launchAgent` naming what the user just asked to start, not a conversation that went missing. Recovery begins before that startup is delivered, and automatic delivery records no terminal input, so a scan finishing later could replace the requested agent with an older transcript. Such a pane no longer enters recovery, and the decision is latched so it still holds once the command has been delivered and cleared. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Review complete. No issues found — approved ✅. Adds an agent auto-resume feature — a resume chooser UI in terminal panes, PTY spawn interception and recovery wiring, session reservations/claims, and an Reviewed commit: de775c3 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de775c3afc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| {panes.map((pane) => ( | ||
| <AgentResumeChooserPortal key={pane.id} paneKey={makePaneKey(tabId, pane.leafId)} /> | ||
| ))} |
There was a problem hiding this comment.
Serialize resume dialogs for split panes
When two visible panes in the same split tab both resolve to multiple candidates after a restart, the visibility gate admits both and this map mounts two app-modal Radix dialogs simultaneously. Their overlays and focus traps stack, while neither dialog identifies its pane, so the user can interact with the wrong chooser and resume a conversation into the wrong terminal. Queue a single pending pane choice at a time, or otherwise scope the chooser to a clearly identified pane.
AGENTS.md reference: AGENTS.md:L1-L3
Useful? React with 👍 / 👎.
A status row exists only after a spawn, so the claim set was blind for the whole window between another pane queueing a cold restore and that restore starting. A recovering pane scanning inside it saw the session as free and could start a second agent on the same transcript — the fork the rule exists to prevent. A pane's own sleeping record names the session it intends to resume, so those records now join the claim set under the same identity and liveness rule: never a claim against the pane that owns the record, and a claim from any other pane this renderer has not positively lost. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Review complete. 🟡 2 medium 💬 Inline comments (1)
📍 Outside the diff (1)
🧹 Nitpicks (3) — 🟢 3 low
Reviewed commit: 8b14831 |
There was a problem hiding this comment.
Expand to see previous review
Adds an agent-resume chooser with session reservations/recovery in the terminal pane plus an appliedSessionDepth field for AI vault scan truncation reporting; overall solid, with a few reservation and scan-merge edge cases worth tightening.
| const spawned = Promise.resolve(session.startFreshColdRestoreAgentResume(startup)).catch( | ||
| () => undefined | ||
| ) | ||
| session.agentResumeSpawnInFlight = spawned | ||
| void spawned.finally(() => { | ||
| if (session.agentResumeSpawnInFlight === spawned) { | ||
| session.agentResumeSpawnInFlight = null | ||
| } | ||
| }) |
There was a problem hiding this comment.
🟡 bug · medium
Failed respawn leaves reservation held until dispose
resumeWithCandidate reserves the session at spawn time, and a rejected startFreshColdRestoreAgentResume is swallowed with .catch(() => undefined) which only clears agentResumeSpawnInFlight — never the reservation (src/renderer/src/components/terminal-pane/pty-connection/agent-resume-recovery-install.ts:94-102). The sole release path is releaseAgentResumeReservationOnDispose, so after a failed respawn the session id stays reserved for the life of the connection. Every other pane's agentResumeSessionsReservedElsewhere then reports it reserved, so the transcript cannot be recovered anywhere until this pane is disposed.
📋 Prompt for AI Agents
In src/renderer/src/components/terminal-pane/pty-connection/agent-resume-recovery-install.ts around lines 94-102, make the spawn settlement distinguish success from failure: capture the result of session.startFreshColdRestoreAgentResume(startup) instead of mapping rejection to undefined, and in the settlement handler call a release that removes only candidate.providerSession.id for session.cacheKey (add a targeted releaseAgentResumeSession(sessionId, paneKey) alongside releaseAgentResumeSessionsForPane in src/renderer/src/lib/agent-resume-session-reservations.ts) guarded by the same transport-ownership check used in agent-resume-reservation-release.ts, so a successor binding's reservation is never dropped. Keep the existing agentResumeSpawnInFlight identity check so a newer spawn's state is not cleared. Why: a failed spawn leaves no agent on the transcript, but the reservation currently blocks sibling panes from resuming it until the pane is disposed.
A newer Tenki review found issues on this pull request.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b14831602
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
When hook-server hydration restores this pane's status row with its exact provider session, the recovery path passed only the agent, so the resolver treated every same-agent transcript in the workspace as a contender. A pane whose own conversation was short lost it to the substance floor while an unrelated substantial transcript survived as the sole candidate and was resumed automatically — forking the wrong conversation, which is the one outcome this resolver exists to avoid. The pane's own provider session, read from the host-owned status store under its own pane key, now short-circuits the contest: identity settles it, and the substance and sole-candidate heuristics only decide between transcripts that are not already known to be this pane's. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
Reviewed commit: 72faa3f |
|
"Honor the pane's restored provider session identity" — fixed. The recovery path passed only "Propagate the Windows SSH host's shell family" — correct, and deferred. The analysis holds: What stops it being a review-round fix: no such signal exists anywhere today. I considered refusing to build a resume command for a remote win32 host whose shell is unknown, which matches this code's own "refuse rather than offer" rule. I did not do it: it would disable resume for every Windows SSH host including the PowerShell ones that work today, trading a narrow wrong-quoting bug for a broad loss of function. Filed as a follow-up rather than coded here. The scope regression this PR did fix — every SSH host being quoted for Linux regardless of OS — is the larger half. |
Found on PR #2 against the same code, never raised here. The plain shell this connection just spawned still owns the pane's stable key, so `startFreshColdRestoreAgentResume` reached `beginPtyIpcSpawn`, found that owner, and REATTACHED it instead of running the resume command. Recovery and every chooser selection reported success and closed the chooser over the same untouched shell. `reattach-result-handler` retires an adopted shell only for a passive sleeping-record restore, and this startup deliberately carries no record, so nothing retired it. The binding is now disconnected and cleared first, the way that passive path does it, before the replacement spawn. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
| const spawned = Promise.resolve(session.startFreshColdRestoreAgentResume(startup)).catch( | ||
| () => undefined | ||
| ) | ||
| session.agentResumeSpawnInFlight = spawned | ||
| void spawned.finally(() => { | ||
| if (session.agentResumeSpawnInFlight === spawned) { | ||
| session.agentResumeSpawnInFlight = null | ||
| } | ||
| }) | ||
| return true |
There was a problem hiding this comment.
🟡 bug · medium
Failed resume spawn leaks the reservation and strands the transcript
resumeWithCandidate reserves the session synchronously (reserveAgentResumeSession, agent-resume-recovery-install.ts:88) and then swallows every spawn failure (.catch(() => undefined), agent-resume-recovery-install.ts:94-96). When startFreshColdRestoreAgentResume fails, nothing releases the reservation, so agentResumeSessionsReservedElsewhere hides the session from every sibling pane's scan while this pane's one-shot latch is already spent and the chooser was cleared. The pane sits as a plain shell and the transcript cannot be auto-resumed anywhere until this pane is disposed — a transient spawn failure locks a live transcript out of recovery.
📋 Prompt for AI Agents
In src/renderer/src/components/terminal-pane/pty-connection/agent-resume-recovery-install.ts around lines 94-103, resumeWithCandidate reserves the provider session then calls session.startFreshColdRestoreAgentResume(startup), swallowing both null resolutions and rejections via .catch(() => undefined). Change the follow-up so a spawn that did not go live (resolved pty id is null, or the promise rejected) releases the just-created reservation — add a targeted releaseAgentResumeSession(sessionId, paneKey) in src/renderer/src/lib/agent-resume-session-reservations.ts rather than clearing the whole pane key, so a successor's reservation survives — and reset agentResumeRecoveryAttempted so the pane can re-attempt on the next reveal, mirroring the existing UNSPENT_AGENT_RESUME_REFUSALS handling at lines 210-212. Keep the reservation when the spawn succeeded.
Stacked on #5. Review that one first — this branch contains its commit, and GitHub will show only this feature's diff once #5 merges.
ELI5
Your remote dev machine reboots. A terminal that was running Claude comes back as a plain shell, and the conversation — still sitting on disk — is something you have to go and find. This makes the pane come back as the agent it was, with the conversation it had.
What changed
A pure resolver decides which conversation a pane resumes. A candidate source and a chooser surface present the options when more than one fits. Per-pane gates decide when a shell may be replaced by a recovered session, and a recovery orchestrator drives the whole thing from the pane itself rather than from a global sweep.
What five rounds of review changed
Worth reading, because the last round found the feature's main surface had never worked.
The chooser was inert.
installAgentResumeRecoveryregistered its pane handler withsession.transportas owner, but read that value eagerly at install time — and it runs beforeinstallPtyInputRecoveryassigns the transport. The owner was captured asundefined, sogetAgentResumePaneHandlernever matched and every chooser interaction (Enter, number key, click) silently did nothing. Only the automatic sole-candidate path ever functioned. Nothing caught it because no test exercised the realconnectPanePtyordering.A
noticerow meant the opposite of what earlier rounds assumed. It is emitted precisely when the issue array overflowed and failure rows were dropped, so a scan with hundreds of refusals shipped only the notice, the renderer saw zero failures, called the scan complete, and could auto-resume a surviving subset — forking the wrong transcript. A scan now reports whether it actually covered its scope.Claims are keyed by pane identity, not raw session id, so a
done-but-live pane cannot have its transcript adopted by another pane, and a recovering pane's own restored-unconfirmed row cannot claim against itself.WSL cwd forms are matched as one path. A workspace stored as
\\wsl.localhost\Ubuntu\home\me\repoand a transcript reporting/home/me/repoare the same place; they previously normalized apart, discarding every valid WSL candidate.The chooser is localized into es, fr, ja, ko and zh rather than falling back to inline English in a blocking dialog.
Why squashed here
The integration branch carries one commit per feature, matching how #1, #3 and #4 landed on it. The eleven-commit history is preserved on
kiwidream/auto-resume-sessionsand in PR #2, which stays open against its own base for review of that history.Verification, stated honestly
pnpm tcclean,npx oxlintclean, changed-code quality gate 0 new findings across 90 files.What has not happened: no test exercises a real host restart, which is this feature's entire premise. Five rounds of bot review and a large unit suite did not catch an inert chooser, so bot silence is weak evidence here. Treat this as reviewed, not verified.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.