Skip to content

feat(resume): auto-resume an agent session after a host restart - #6

Merged
kiwidream merged 10 commits into
swaplabs/mainfrom
swaplabs/auto-resume-sessions
Sep 23, 2026
Merged

kiwidream merged 10 commits into
swaplabs/mainfrom
swaplabs/auto-resume-sessions

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 23, 2026 •

Copy link
Copy Markdown

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. installAgentResumeRecovery registered its pane handler with session.transport as owner, but read that value eagerly at install time — and it runs before installPtyInputRecovery assigns the transport. The owner was captured as undefined, so getAgentResumePaneHandler never 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 real connectPanePty ordering.

A notice row 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\repo and a transcript reporting /home/me/repo are 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-sessions and in PR #2, which stays open against its own base for review of that history.

Verification, stated honestly

pnpm tc clean, npx oxlint clean, 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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

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>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high · 🟡 3 medium

💬 Inline comments (2)

📍 Outside the diff (2)

  • 🟠 Runtime leg rebuild drops appliedSessionDepth (runtime-session-scanner.ts:158–162) — withRuntimeExecutionHost rebuilds the parsed runtime-host result field by field and omits appliedSessionDepth, so a runtime host that correctly reported 'unlimited' has that field stripped on the client side (src/main/ai-vault/runtime-session-scanner.ts:158).
  • 🟡 SSH fallback-crawl leg never reports its depth (ssh-session-list.ts:135–144) — scanRemoteAiVaultSessions returns { sessions, issues, scannedAt } with no appliedSessionDepth, and scanOneSshHost spreads that fallback result unchanged (src/main/ai-vault/ssh-session-list.ts:135) even though this client itself ran the crawl under the requested bound.
🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Reserved session leaks if the respawn fails (agent-resume-recovery-install.ts:87) — resumeWithCandidate reserves the session id (src/renderer/src/components/terminal-pane/pty-connection/agent-resume-recovery-install.ts:87) and then fire-and-forgets the spawn via void session.startFreshColdRestoreAgentResume(startup), discarding the promise.

Reviewed commit: 0cdebd9

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T19:37:47.545043Z 6d2a5fe New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand to see previous review

Adds appliedSessionDepth scan-depth wire metadata to the AI Vault and a new agent auto-resume chooser, but two host legs fail to report the depth they applied.

…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>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

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

@kiwidream

Copy link
Copy Markdown
Author

Two of the five fixed in 02c0d49a46; three still open and noted below.

Scan depth (P1) — wider than the line the bot named. withRuntimeExecutionHost dropping appliedSessionDepth was real, but enumerating the builders rather than patching that one turned up a second: scanRemoteAiVaultSessions never set the field at all, which is the SSH path. So the coverage check was refusing on every runtime environment and every SSH target — the hosts this feature exists for — not just on old ones. It fails safe to a plain shell, which is the pre-feature behaviour, so nothing looked broken.

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 (expected undefined to be 'unlimited').

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 sync:localization-runtime-catalog (there is a test that enforces that catalog stays in sync).

Still open, not yet fixed:

  • Retry recovery after agent-status hydration (P1)
  • Tab moves focus off the listbox, leaving the resume keys dead (medium)
  • Dispose releases a reservation while a resume spawn is in flight (medium)

Verification. pnpm tc clean, oxlint clean, changed-code quality gate 0 new findings across 94 files. Targeted suites pass. Eight failures in session-scanner-opencode-sqlite-open, session-scanner-service-search and -search-roots are pre-existing — I confirmed the identical eight on a clean baseline with my changes stashed. Still no test exercises a real host restart.

luxor-code-review[bot]
luxor-code-review Bot previously approved these changes Sep 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (2)

Reviewed commit: aca2fdf

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +124 to +126
session.agentResumeRecoveryStatusUnsubscribe?.()
session.agentResumeRecoveryStatusUnsubscribe = null
void session.attemptAgentResumeRecovery?.()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment on lines +87 to +101
!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
}
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@luxor-code-review
luxor-code-review Bot dismissed their stale review September 23, 2026 18:52

A newer Tenki review found issues on this pull request.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +61 to +63
if (resolveAgentResumePaneLiveness(state, rowPaneKey) !== 'exited') {
claimed.add(entry.providerSession.id)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

kiwidream and others added 2 commits September 23, 2026 14:54
…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>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

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 appliedSessionDepth signal threaded through the AI Vault scan pipeline with i18n for six locales.

Reviewed commit: de775c3

luxor-code-review[bot]
luxor-code-review Bot previously approved these changes Sep 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +50 to +52
{panes.map((pane) => (
<AgentResumeChooserPortal key={pane.id} paneKey={makePaneKey(tabId, pane.leafId)} />
))}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (1)

📍 Outside the diff (1)

  • 🟡 Uncapped issue merge trips overflow detection (session-list-results.ts:94) — mergeAiVaultListResults concatenates every leg's issues with no cap (issues.push(...result.issues)), but the renderer treats a list at AI_VAULT_SCAN_ISSUE_LIMIT as proof that issues were dropped (src/renderer/src/lib/agent-resume-candidate-source.ts:131).
🧹 Nitpicks (3) — 🟢 3 low
  • 🟢 Absent-owner test assertion always passes (pty-connection-agent-resume-handler-ownership.test.ts:127) — The test leaves no handler registered under an absent owner asserts getAgentResumePaneHandler(paneKey, undefined) is undefined (src/renderer/src/components/terminal-pane/pty-connection-agent-resume-handler-ownership.test.ts:136), but the lookup short-circuits on a falsy owner and returns undefined unconditionally (src/renderer/src/lib/agent-resume-pane-handlers.ts:49).
  • 🟢 Korean chooser title leaves terminal untranslated (ko.json:15011) — The Korean chooser title reads "이 terminal에서 어떤 세션을 재개할까요?" — the English word left inline (src/renderer/src/i18n/locales/ko.json:15011).
  • 🟢 Parity test skips all age subkeys (agent-resume-chooser-locales.test.ts:44) — The new parity test asserts every chooser key per locale, but its KEYS list contains only label/title/help/dismiss and never descends into age (src/renderer/src/i18n/agent-resume-chooser-locales.test.ts:15).

Reviewed commit: 8b14831

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +94 to +102
const spawned = Promise.resolve(session.startFreshColdRestoreAgentResume(startup)).catch(
() => undefined
)
session.agentResumeSpawnInFlight = spawned
void spawned.finally(() => {
if (session.agentResumeSpawnInFlight === spawned) {
session.agentResumeSpawnInFlight = null
}
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@luxor-code-review
luxor-code-review Bot dismissed their stale review September 23, 2026 19:13

A newer Tenki review found issues on this pull request.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Korean title leaves terminal untranslated (ko.json:15011) — The ko translation of the chooser title reads "이 terminal에서 어떤 세션을 재개할까요?", leaving the English word terminal untranslated mid-sentence (src/renderer/src/i18n/locales/ko.json:15011).

Reviewed commit: 72faa3f

@kiwidream

Copy link
Copy Markdown
Author

72faa3f656 fixes the resolver P1. The Windows SSH shell P1 I am deferring, with the reason below.

"Honor the pane's restored provider session identity" — fixed. The recovery path passed only paneAgent, so a pane whose own conversation was short lost it to the substance floor while an unrelated substantial transcript survived as sole candidate and resumed automatically. 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 substance only decides between transcripts not already known to be this pane's. Test verified to fail without the fix (it resumes the rival).

"Propagate the Windows SSH host's shell family" — correct, and deferred. The analysis holds: hostPlatform fixes the OS, resolveLocalWindowsAgentStartupShell deliberately returns undefined for remote targets, and resolveStartupShell then defaults every Windows command to PowerShell quoting. A Windows SSH host running cmd or Git Bash still gets a command its shell rejects.

What stops it being a review-round fix: no such signal exists anywhere today. AiVaultSession carries executionHostPlatform but nothing carries a shell — I grepped the shared types and there is no executionHostShell or equivalent. Supplying one means a new host-reported field crossing the remote boundary, which under docs/reference/remote-wire-compatibility.md is a new optional field that older hosts will not send, so the renderer needs a defined behaviour for its absence — and "absent" is exactly the case that is wrong today. That is a design decision about what to do when the host will not say, not a line to change.

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>

@luxor-code-review luxor-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds an agent-resume feature: AI Vault session scanning gains an appliedSessionDepth attestation, and the renderer gains a blocking resume chooser with candidate resolution, session reservations/claims, and PTY-connection recovery wiring.

Comment on lines +94 to +103
const spawned = Promise.resolve(session.startFreshColdRestoreAgentResume(startup)).catch(
() => undefined
)
session.agentResumeSpawnInFlight = spawned
void spawned.finally(() => {
if (session.agentResumeSpawnInFlight === spawned) {
session.agentResumeSpawnInFlight = null
}
})
return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant