You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(sleep): resume an idle agent whose hook row is gone from its saved checkpoint - #42391
When you put a workspace to sleep, Orca writes down which agent conversation each terminal was running, so it can bring that conversation back when you open the tab again. For an agent that had been sitting idle for a long time, Orca no longer had a fresh status for it and wrote nothing down. On wake, that terminal came back as an empty shell and the conversation was gone from the tab.
Now, when the fresh status is missing, Orca uses the checkpoint it had already saved for that terminal, as long as the checkpoint clearly belongs to that terminal and that agent.
What Changed
Before: a Claude (or other resumable agent) pane that had been idle long enough for its hook-status row to disappear was skipped by Sleep. Waking the workspace and opening the tab started a plain shell instead of claude --resume <id>.
After: the same pane is recorded by Sleep and resumes its conversation when its tab is opened, like any other slept agent pane.
Mechanism: when main runs the sleep, captureWorktreeSleepResumeRecords builds one worktree-sleep record per pane from that pane's hook-status row. With no row, it skipped the pane (if (!row) continue). The window does not collect records itself when main runs the sleep, so it took main's empty answer. The only remaining handle was the pane's saved origin: 'live' checkpoint, and live checkpoints are consumed only by cold restore, not by wake.
With this change, when the row is missing, main reads the pane's saved record from the workspace session and turns it into a normal sleep record, but only if all of these hold:
it is a live checkpoint (sleep and quit records are already durable and kept as they are),
it belongs to the worktree being slept,
its agent is a resumable TUI agent and a resume command exists for its provider session,
the agent main knows the PTY runs (getPaneTerminalAgent: launch, foreground, or launch command) does not name a different agent. It is read when the checkpoint is read, after the pane's presence probe, the same way the hook rows are read.
The saved record is read through the resume-record queue (inResumeRecordOrder), like readSavedResumeSource. So a checkpoint write from a hook status accepted before the sleep lands first, and the sleep cannot turn the older checkpoint into its record.
The record is built through the same code as the hook-row path: state: 'done', origin: 'worktree-sleep', restoreOnTabOpenOnly: true, a fresh capturedAt, the same local-connection-id rule, and the launch recipe only through launchStatement, so a custom binary/args are kept only when main still holds that launch. A pane the hook store proved exited is still retired first, before any fallback.
The row-to-source logic moved into worktree-sleep-resume-source.ts, so the hook-row path and the saved-checkpoint path share one record builder.
Why
The window's own sleep path (collectSleepingAgentSessionRecordsForWorktree with manual-worktree-sleep) already promotes a saved live checkpoint when the pane has no live status. Main-run sleep lost that behaviour, so the fix gives main the same fallback.
Alternatives considered:
Have the window collect its own records again when main runs the sleep and merge them. That brings back two writers for one sleep, which main-owned sleep was built to avoid. It also would not help a sleep started from the phone or CLI with no window open.
Keep the hook row alive longer. The row can go away for many reasons (expiry, restart, lost hook connection). The checkpoint already exists for this purpose and is the more durable source.
Treat a missing row as "agent gone" and retire the record. That is today's data loss made explicit. A missing row is not evidence that the agent left; only the hook store's exit proof is, and that path is unchanged.
N/A: no UI change. The visible effect is that the woken tab runs --resume instead of a plain shell; the unit test covers the record that decides this.
Testing
Added src/main/runtime/terminal/stop/worktree-sleep-resume-records.test.ts. Its first case (a pane with no hook row and a saved live Claude checkpoint is recorded as a tab-open resume) fails without this change. The other cases pin what must not be resumed: a checkpoint for another worktree, a checkpoint naming another agent than the pane runs, a quit record, a pane the hook store proved exited, and a pane with no saved checkpoint. One more case checks the pane's agent after the presence probe, not before it.
Added src/main/runtime/terminal/stop/worktree-sleep-resume-recording.test.ts. It runs a real sleepTerminalsForWorktree while a hook status's checkpoint write is still queued and the status's row is gone. The sleep records the newer conversation. Without the queued read it records the older checkpoint.
Ran the src/main/runtime/terminal/stop tests, src/main/runtime/workspaces/sleep, src/main/runtime/construction/orca-runtime.test.ts, src/renderer/src/lib/agent-session/resume, src/renderer/src/store/terminals/sleep and the manual-sleep capture test, plus pnpm tc and the changed-code quality check.
Found on Linux: a Claude pane idle for days, its hook row gone, a saved origin: 'live' checkpoint with a provider session id in sleepingAgentSessionsByPaneKey. Sleep wrote no record and wake spawned a plain shell.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
The riskiest part: a stale live checkpoint whose agent exited without the hook store noticing (for example, across an app restart) now becomes a sleep record. Opening that tab after wake would then run --resume for the old conversation instead of a plain shell. This matches what the window's own sleep path already does with the same checkpoint. The guard against a contradicting known pane agent and the unchanged exit-proof retire path keep the case narrow.
No saved-data format change: the record has the same shape as every other worktree-sleep record. SSH/remote panes keep their connection id exactly as on the hook-row path. A plain revert backs this out.
Level: Low
AI Disclosure
Written with Claude Code (Claude Opus 5.5); the diagnosis, change and tests were reviewed by the author.
Review
Cross-platform: no platform-specific code; pure record logic in main.
SSH/remote: the connection id follows the same local-relay rule as the hook-row path; panes on a paired server are still recorded by that server's own main.
Agents/integrations: any resumable TUI agent; the resume command must exist for the saved provider session.
Mobile: a phone-started sleep runs through main, so it gets the same fix; records stay tab-open-only, so a phone wake does not respawn every tab.
Performance: one in-memory session lookup per pane without a hook row, only during sleep. It waits only for resume-record writes already queued.
Security: no new inputs; the saved record was already written by Orca.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
No actionable comments were generated in the recent review.
Walkthrough
Capture uses a pane’s hook row when available. If no hook row exists, it can use a saved checkpoint that matches the worktree and current pane agent. The runtime supplies current pane agents and reads saved records through the worktree’s resolved session host after earlier queued writes. Added tests cover accepted and rejected checkpoints, exited agents, missing checkpoints, and write ordering.
Severity of issue fixed: Medium
Merge Risk: Low · up to b7a07
Idle agents whose hook row has expired should now resume from their saved checkpoint after workspace sleep and wake. A pane whose checkpoint sits on a different session partition than the worktree's main one can still restart as a plain shell. This is a narrow remaining gap with a safe fallback, so merging carries low risk.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: sleep resumes an idle agent whose hook row is gone by falling back to its saved checkpoint. It uses the fix(sleep) convention and matches the objectives and changeset.
Description check
The description follows the template closely. It covers ELI5, What Changed, Why with alternatives, Linked Issue (Fixes #42542), Visual Proof (N/A with reason), Testing, Risk with level and revert path…
Linked Issues check
[#42542] The issue requires that Sleep record an idle Claude Code pane whose hook-status row is gone, so that wake resumes it with claude --resume <id> instead of a plain shell. At the reviewed head…
Out of Scope Changes check
All changed areas connect to the #42542 objective. worktree-sleep-resume-records.ts gains the checkpoint fallback. worktree-sleep-resume-source.ts holds the shared record-source logic for the hook…
Full details: Description check
Explanation
The description follows the template closely. It covers ELI5, What Changed, Why with alternatives, Linked Issue (Fixes #42542), Visual Proof (N/A with reason), Testing, Risk with level and revert path, AI Disclosure, Review, the upstream boundary checkbox, and the checklist. The manual testing box is unchecked and the lint/typecheck/test/build checkbox is unchecked, which the template allows when CI covers them.
Full details: Linked Issues check
Explanation
[#42542] The issue requires that Sleep record an idle Claude Code pane whose hook-status row is gone, so that wake resumes it with claude --resume <id> instead of a plain shell. At the reviewed head, captureWorktreeSleepResumeRecords in worktree-sleep-resume-records.ts no longer skips a pane when row is missing. It calls savedCheckpointResumeSource(await args.readSavedRecord(paneKey), args.worktreeId, args.agentOfPty(ptyId)). savedCheckpointResumeSource in worktree-sleep-resume-source.ts accepts a record only when it has origin: 'live', matches the worktree, names a resumable TUI agent, has a provider session with a resume argv, and does not conflict with the agent main knows the PTY runs. An accepted source produces a worktree-sleep record with state: 'done' and restoreOnTabOpenOnly: true, the same shape as the hook-row path. The exit-proof retirement via checkAgentPresence(paneKey, 0) runs before the fallback and is unchanged. The fallback therefore covers the reported case. Unit tests in worktree-sleep-resume-records.test.ts and the queued-write test in worktree-sleep-resume-recording.test.ts are described in the PR. I did not run them. The issue states no further acceptance criteria. No coding requirement remains unmet.
Full details: Out of Scope Changes check
Explanation
All changed areas connect to the #42542 objective. worktree-sleep-resume-records.ts gains the checkpoint fallback. worktree-sleep-resume-source.ts holds the shared record-source logic for the hook-row and checkpoint paths. This extraction is a refactor that supports the fallback, and the PR states that the hook-row path keeps its behavior. worktree-sleep-resume-recording.ts reads the saved record through the resume-record queue so that a queued checkpoint write lands first. This supports the correctness of the fallback. The two test files cover the new behavior. The PR does not change the file format, UI, or unrelated subsystems. No demonstrated unrelated change was found.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Read the agent after each presence probe.
agentByPtyId snapshots each PTY's agent before captureWorktreeSleepResumeRecords awaits checkAgentPresence. A PTY without a launch agent can change its foregroundAgent during that await. The fallback then compares a saved checkpoint with the earlier value and can reject a current checkpoint. No resume record is captured, and the pane restores as a plain shell.
Pass a getter so the agent is read at the point of comparison:
--- a/src/main/runtime/terminal/stop/worktree-sleep-resume-records.ts+++ b/src/main/runtime/terminal/stop/worktree-sleep-resume-records.ts
@@
- /** The agent main knows each PTY runs; a saved checkpoint naming another one is stale. */- agentByPtyId: ReadonlyMap<string, TerminalAgent | null>+ /** The agent main knows the PTY runs when the checkpoint is read; a checkpoint naming another one is stale. */+ agentOfPty: (ptyId: string) => TerminalAgent | null
@@
args.readSavedRecord(paneKey),
args.worktreeId,
- args.agentByPtyId.get(ptyId) ?? null+ args.agentOfPty(ptyId)
)
Update any other caller or test that passes agentByPtyId, including the new worktree-sleep-resume-records.test.ts coverage, to supply agentOfPty.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Quick win
Look up the saved record in the pane's tab partitions as well as the routed host.
writeHookStatusResume stores checkpoints on the partition that owns the pane's tab, while readSavedRecord reads only the worktree's routed host. When a tab is split across partitions, the checkpoint can sit on a partition the reader does not check. The capture then finds no record and skips the resume. The reader should check the tab-owning partitions and keep the routed host, which holds the records written at sleep time.
Suggested fix
--- "a/src/main/runtime/terminal/stop/worktree-sleep-resume-recording.ts"+++ "b/src/main/runtime/terminal/stop/worktree-sleep-resume-recording.ts"@@ -103,13 +103,23 @@
[...ptyIds].map((ptyId) => [ptyId, this.getPaneTerminalAgent(ptyId)])
),
readRows: () => this.getAgentProviderSessionSnapshotFn?.() ?? [],
readSavedRecord: (paneKey) => {
// Why try: an unresolvable workspace has no saved record, and must not fail the sleep.
- const hostId = this.tryGetWorkspaceSessionHostIdForWorktree(worktreeId)- return hostId- ? this.store?.getWorkspaceSession?.(hostId)?.sleepingAgentSessionsByPaneKey?.[paneKey]- : undefined+ const tabId = parsePaneKey(paneKey)?.tabId+ const routedHostId = this.tryGetWorkspaceSessionHostIdForWorktree(worktreeId)+ const hostIds = new Set([+ ...(tabId ? this.getWorkspaceSessionHostIdsForTab(worktreeId, tabId) : []),+ ...(routedHostId ? [routedHostId] : [])+ ])+ for (const hostId of hostIds) {+ const record =+ this.store?.getWorkspaceSession?.(hostId)?.sleepingAgentSessionsByPaneKey?.[paneKey]+ if (record) {+ return record+ }+ }+ return undefined
},
checkAgentPresence: this.checkHookAgentPresenceFn,
capturedAt: Date.now()
}),
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
Read the saved checkpoint in resume-record queue order.
readSavedRecord reads sleepingAgentSessionsByPaneKey directly. It does not use inResumeRecordOrder, which the adjacent readSavedResumeSource uses. Sleep awaits capture before stopping PTYs, and nothing drains the queue first.
When a pane has a queued hook write B and no hook row at readRows(), capture can read the older checkpoint A. Persist then runs after B and sets the pane's sleeping record to the captured A. B's effect on that record is lost. Wake can then resume the older checkpoint.
Read the saved checkpoint through inResumeRecordOrder, as readSavedResumeSource does. The read then runs after queued writes that were accepted before the sleep. Because readSavedRecord is currently synchronous, the callback and capture's readSavedRecord type need to become asynchronous.
…nd wake (stablyai#43529)
* fix(agent-hooks): record the exit when a hookless agent quits to its shell
A Codex resumed by a wake sends no hooks while idle, so the shell-confirmed
reconcile kept its resume row without exit evidence and the next sleep
captured it again. Derive the ended presence from the pane's row (the shape
sleep settle already builds), and let a later Orca launch forget an exit
that predates it.
* fix(agent-hooks): keep shell-return exits to process-less rows
A row with a proved process gets its exit from the presence probe, and a
same-session relaunch replaces an ended resume row.
* test: type the provider session in the hookless quit test
* Keep pane conversation identity through sleep and wake
Co-authored-by: d.bondarev <d.bondarev@crm-onebox.com>
* Read canonical pane identity and preserve saved turn verdicts
* Retire exited pane recovery before exit evidence expires
* Complete canonical sleep settlement and skip empty recovery edits
* Keep wake continuity scoped to resume boundaries and satisfy source gates
* fix(agent-hooks): record the exit when main sees the launched agent's command finish
QA showed main's own command-finished retirement clears a hookless Codex's
row before the renderer's shell-return reconcile lands, so neither recorded
an exit. Pass confirmedExit through that path (command finish only, not PTY
exit).
* Spy on durable mutations in the exit performance contract
* Exercise Interrupted through an idle wake and second sleep
* Scope sleep notification assertions to the sleep transition
* test: expect the confirmed-exit flag on launch retirement
* Preserve saved turn verdicts and keep sleep replay out of completion delivery
* Supply renderer history when checking recovered completion eligibility
* fix(agent-hooks): don't treat a suspended launch as an exit
A Ctrl-Z'd agent finishes its shell command with a stop status while its
process lives on; only record the exit for other statuses. Drop the
renderer reconcile's confirmedExit, whose message can't tell a suspend.
* fix(agent-hooks): keep a suspended agent's launch held
A Ctrl-Z stop status isn't the launch command finishing, so don't retire the
launch for it; the agent's real finish after fg then still records the exit.
* Revert "fix(agent-hooks): keep a suspended agent's launch held"
This reverts commit 03ac47c.
* Run the sleep runtime integration on the native test worker
* Preserve recovered turns on wake and avoid resuming shared agent processes
* Keep accepted turns through startup restatements and separate sleep from quit
* Follow the process observation module moved on main
* Keep status ingestion within the module size gate
* Replace accepted rows when observing a surviving tmux host
* Consult pane ownership before the hook-row restore fallback
* Keep accepted turns and process ownership through startup reports
* Keep shared conversation ownership through both sleep cleanup paths
* Record a shell-confirmed agent exit only for pane-owned processes, proven end to end
Carries stablyai#42922's command-finished exit evidence through the pane identity owner.
* Type the proving test's fixtures
* Preserve stopped agent recovery and detached shared ownership
* Retire quit agent recovery without conflating shell foreground and exit
* Route quiet shell confirmation through the current launch owner
* Keep suspended Codex recovery through listings and release detached tmux conversations
A listing re-mints a restored surface's receipt after Ctrl-Z already retired its launch, so the next
unrelated command read as the agent's exit. Only a launch no finish has retired names one now.
A tmux client's detach left only the pane's saved checkpoint, which sleep re-promoted as pane-owned
and woke as a duplicate resume; the shared conversation now releases that checkpoint when its client
leaves the pane.
* Release tmux-hosted checkpoints after a restart and leave verifiable owners to their own exit
After a restart the tmux row is gone until the inner agent hooks again, so a sleep read the saved
checkpoint as the pane's own; the pane's tmux client now releases it. A stopped hooked agent's
shell foreground no longer clears its live row, since its process answers for its exit.
* Prove unmarked exits with the host's shell-alone check and retire shared and SSH recovery on every path
The daemon's child check reads the foreground name, so a stopped hookless agent looked exited; the
host's shell-alone proof rejects stopped jobs, and an unknown (reattached) launch may use it while a
gone launch stays refused. The unmarked-exit path releases a shared conversation's checkpoint like
the other two. Retirements pinned to the pane's exact record or turn clear SSH claims too. Pane
clears look up their one remembered status instead of scanning all of them.
* Let a verifiable owner's presence probe answer a quiet shell
A hooked agent that quit without a session end kept its live row on main until something probed it;
the shell's foreground now triggers that probe, which retires an exited owner and keeps a stopped one.
* Keep Windows unmarked quits provable and probe tmux-shown checkpoints only at sleep capture
The daemon's shell proof follows prompt marks that cmd and Git Bash often lack; Windows shells stop
no jobs, so a childless shell foreground suffices there. The rowless tmux checkpoint probe ran on
every fleet presence read; only a sleep capture asks for it now.
* Prove Windows unmarked quits from the host's job census
The Windows fallback read the same agent-name signal that asked for the proof; a decision-time
inspection's child census is independent evidence. Ordinary presence reads now provably skip the
sleep-capture tmux probe.
* Pin the Windows exit proof to an explicit child census
Per the council ruling (A): an older daemon's answer without a census, or a census that still finds
a child, never proves the agent ended.
* Refuse a running background job as exit proof on the local shell check
Council follow-up: Ctrl-Z then bg leaves the agent running beside a foreground shell; the exit proof
now also requires no live descendant of that shell, leaving ordinary foreground reads unchanged.
* Mark a tmux-hosted conversation shared from its own hook
A Claude inside tmux posts ordinary pane hook rows, and the only shared marker came from a sleep-time
probe of the pane's foreground, which a detached client no longer shows; each wake then resumed a
duplicate beside the live tmux agent. A hook carrying a real tmux pane (not Orca's inherited one)
now marks its conversation shared at admission, so detach and sleep release it.
* Fix gate findings: pin test clock, drop renderer-clearing tests the main owner replaced
The worktree sleep recording regression test comes from stablyai#42391.
Co-authored-by: d.bondarev <d.bondarev@crm-onebox.com>
* Retire an exited record without copying the session; probe tmux hosts only at sleep capture
A confirmed exit deep-cloned the whole host session twice to delete one saved record; it now patches that record and rolls back only it. Ordinary presence reads (fleet snapshots, holder checks) no longer run tmux-host discovery for row-present panes.
* Keep the legacy tmux sleep test's harness beside it after main removed the hook-root suites
* Retire an exited record through the store's single-record retirement and the coalesced save
The keyed patch still reordered every workspace's rows and forced an immediate whole-domain durable write per exit. The store now drops just that record without topology work, and the ordinary debounced save persists it, so a burst of exits shares one save, as the window's own record clearing did.
* Place the saved-resume retirement store test above the comment it displaced
* Format the sleep handoff tests after main's directory move
* Close new-vs-main gaps: tmux proofs, shared read budget, sleep verdicts, resume-only status, release cutoff, quit capture, notification and replay guards
* Fix new-test types; forward the shell-alone proof option through the degraded daemon provider
* End a resumed Claude's startup window at its SessionStart; swallow only Claude's startup OSC work
* Revert "End a resumed Claude's startup window at its SessionStart; swallow only Claude's startup OSC work"
This reverts commit a8e5278.
* End a resumed agent's startup window at the user's first submission; narrow the no-process tmux proof to agents; queue tmux reads behind hook admission
* Let a sleep replay carry a finished main agent's completion
* Record a submitted line for every pane so remote panes end a resumed agent's startup too
* Count only Enter as a submission, prune it with the pane, and refuse unreadable jobs as tmux proof
* Keep paste framing across writes and drop submission marks of closed panes
* Forget a closed tab's submission marks with its other pane caches
* Judge a submission from the write alone and bound remembered submissions
* Count an Enter in merged keystroke writes
* Show terminal work after a wake as main does: drop the startup swallow and its submission tracking, and skip the cancel latch on a resumed row
* fix(sleep): keep main's behavior for six review findings
A restated done keeps its turn only when it ends no other turn; a tmux
release keeps a checkpoint saved during its probe; quit capture leaves
saved live checkpoints as main does; only an attached tmux client hosts a
pane; sleep no longer cancels an already finished main agent.
* fix(sleep): count tmux's unambiguous attach prefixes as attaching
* fix(sleep): read grouped tmux flags when proving an attached client
* perf(sleep): index each PTY inventory snapshot once for per-pane lookups
* fix(sleep): a foreground tmux server is no attached client; index inventory only for repeated lookups
* fix(sleep): repeat one pane's inventory lookup from memory; -V/-h are no attached client
* fix(sleep): index the PTY inventory only as far as lookups scan; new-session -d attaches nothing
* fix(sleep): only a tmux client's harmless flags may precede an attaching command
* perf(sleep): keep main's inventory lookups; index only for sleep capture's tmux probe
* refactor(sleep): record tmux/shared topology when the hook row is written
A conversation a tmux or shared server keeps alive now carries sharedHost on
its status, and no live checkpoint is written for it, so a restart cannot
resume it beside its server. Codex hooks report their tmux pane like Claude's.
This replaces the sleep-time tmux process probe and its release paths.
* fix(sleep): an SSH pane's returning shell retires its record, as on main
Main's shell-alone proof covers local panes only; for a remote pane the window
clears the record when its shell comes back, except for the sleep's own kill.
* fix(sleep): prove an agent's exit from the PTY's root shell in a fresh process table
A daemon answers shell ownership from prompt marks and dropped the
no-live-descendants request, so a job left behind the prompt could pass as an
exit. POSIX exit proof now reads the root shell's tree directly for local and
daemon PTYs alike; the option no longer crosses the provider contract.
* fix(sleep): a command mark ends a process-less agent only on the host's shell-alone word
A shell nested inside a live Codex inherits Orca's prompt marks, so its 133;D
alone could retire the conversation. The exit is now recorded only once the
host confirms the pane's shell holds its PTY alone.
* test: name the session cast in the SSH shell-return test
* fix(sleep): persist shared topology, prove exits from login-rooted PTYs, and let a later mark end an agent a nested mark kept
- Persist sharedHost with the hook row and restore it on hydration, so a tmux-hosted
conversation still gets no checkpoint after a restart.
- Stamp the tmux pane Orca itself runs in as ORCA_INHERITED_TMUX so hook scripts don't
report it as a tmux started in the pane.
- Find the PTY's shell beneath a macOS /usr/bin/login root and read one process table
per proof; drop the background-job gate.
- When a nested shell's command mark leaves the agent alive, the next mark re-checks
the shell alone instead of finding no launch to retire.
* fix(sleep): prove unseen agent exits per pane without rescanning, and keep main's word where no host proof exists
- Track panes whose process-less agent may have ended unseen (a nested shell's mark or a
job stop) in one tracker: a mark re-proves, one proof per pane at a time, a mark during
it asks for one more, and a stale proof can't re-add a cleared pane.
- Ctrl-Z, fg, then /quit ends the conversation again.
- Remote and Windows panes give no shell proof, so a command mark ends the agent as on main.
- Only a stopped agent blocks the proof; a stopped editor from before the launch doesn't.
- Cache each PTY's root PID per incarnation instead of listing every terminal per proof.
* fix(sleep): prove the quit of an agent typed at the prompt, and keep proving when a row changes mid-proof
- A command mark with no launch held now arms a pane whose live process-less identity no
retirement armed (an agent typed at the prompt), so its /quit retires the record.
- A row replaced while a proof runs may be the same conversation's; keep tracking instead of
treating it as settled.
* perf(sleep): read an exit proof's root PID from its PTY alone, not every terminal
The local provider builds rows only for the requested PTYs, and the proof's root lookup uses
the daemon's targeted owner read; neither reads a PTY's absence as its end.
* fix(sleep): read hydrated sharedHost through a type guard; expect jobStopped in the authority spec
* perf(sleep): keep each live PTY's root PID until its teardown instead of a bounded cache
An exit proof pays one inventory per PTY incarnation at most; cycling more PTYs than a cache
held no longer re-reads the whole daemon session list.
* fix(sleep): only the pane's own stopped agent keeps its exit unproven
Another agent suspended earlier in the same shell no longer blocks the proof, so quitting the
agent after it still retires its record.
* perf(sleep): take an exit proof's root PID from the PID its PTY published at spawn
Main already keeps each local PTY's spawn PID; only a host that published none falls back to
the targeted inventory, so proofs no longer move the daemon's session list.
* fix(sleep): a proof doesn't count once input reached the PTY, and launchless marks read only indexed pane keys
- Typing (say `codex resume <id>`) while a shell-alone proof runs voids that proof; the next
mark proves again.
- A command mark with no launch held reads the PTY's recorded pane key and its indexed leaves,
never a main-owned layout's pane search.
* perf(sleep): a PTY whose host published no PID pays one root inventory per incarnation
The answer, a root or none, lasts until the PTY's teardown, so repeated proofs on such a PTY
don't re-read the daemon's sessions.
* refactor(sleep): a command mark asks the host whether the agent ended, whatever its exit status
Drop the 145..150 'job stopped' reading of OSC 133;D statuses. Every mark now starts the
existing proof: a process-less agent's shell-alone check refuses a stopped (Ctrl-Z) agent and
confirms a real exit at once; an agent with a local process keeps its identity for its presence
probe to decide. Hosts with no proof (remote, Windows) keep main's rule that the mark ends it.
* fix(sleep): sleep reads the quit its exit proof is still deciding; plain shells skip the saved-record read; tmux stays shared
- Sleep capture's presence check waits for a pane's in-flight shell-alone proof, so a quit
just before sleep is retired instead of saved.
- A launchless command mark on a pane with no hook row and no tracked proof returns before
reading saved records, which can search every repo in main-owned layouts.
- An unverified writer no longer strips a tmux host's shared topology.
* fix(sleep): CLI and mobile input void a running exit proof; sleep waits only for the proof in flight; proofs read the pane's PTY from the spawn index
- The input fence also reads the runtime's input facts, which CLI and mobile writes update.
- Sleep capture waits for a pane's running proof, not queued re-proofs, so marks arriving
faster than proofs can't hold a sleep back.
- A proof resolves the pane's PTY from the spawn-time index before searching the runtime's
panes, as ownsProcess does.
* fix(sleep): a WSL or SSH agent's command mark ends it as on main
Only a hook row the presence probe can reach (connectionId null) keeps its identity for the
probe; WSL and SSH rows have no probe, so their mark retires them.
* perf(sleep): a quit checkpoint reads terminal identity once for all saved panes
Each saved pane's live-terminal check shares one identity read context instead of scanning
every leaf and PTY per pane.
* fix(sleep): query replies don't void exit proofs; launchless marks arm only provable panes; a Claude continuation stays shared
- The input fence reads the runtime's input facts alone, which skip a terminal's automatic
query replies (a prompt's cursor-position request no longer voids every proof).
- A launchless mark arms only a local POSIX pane; on SSH, WSL and Windows, main ends no agent
at such a mark and neither does this.
- Following a Claude session continuation keeps a tmux host's shared topology.
* fix(sleep): a trusted WSL or SSH command mark retires the agent's checkpoint too
The presence probe can't reach a WSL or SSH process, so the mark that ends such an agent also
records its exit instead of leaving the saved checkpoint to be resumed.
* fix(sleep): a sleep re-proves a tracked pane once; quit checkpoints reuse one identity read for launch lookups
- A sleep capture runs one fresh shell-alone proof for a pane still tracked, so a quit whose
last proof was voided by typed input is retired instead of resumed.
- The quit checkpoint's launch lookups reuse its shared identity read context.
* fix(sleep): only a sleep capture re-proves a tracked pane, and it waits for a re-proof already queued
Other presence readers (resume ownership, federation snapshots) await only a running proof, so
polling them starts no process-table reads. A sleep also awaits a quit's re-proof queued behind a
nested mark's proof.
* perf(sleep): a sleep settles all panes' exit proofs together and resolves its saved-record host once
* fix(sleep): the pane's agent still running in the background keeps its exit unproven
* fix(sleep): settle proofs only when the hook server is wired
* perf(sleep): a capture that read no saved record says so, so identity doesn't route the read again
* perf(sleep): a quit's exit proof reads the launch through the pane's indexed PTY; retiring an exit routes its host once
* perf(terminal): an exit confirmation reuses its presence check's pane keys for suspension
* perf(sleep): materialization passes its absent record; an agent that gains a verifiable process drops its shell-proof retry
* perf(sleep): spawn, exit and reconcile callbacks check their row and stop gates before reading a saved record
* perf(sleep): a proven quiet exit reuses its pre-proof identity; row-only reads pass an absent record
* fix(sleep): a mark on a restored surface whose launch already finished goes to the shell-alone proof, so a typed agent's quit retires it
* fix(hooks): a Codex Stop read from its transcript keeps the tmux host's shared topology
* fix(sleep): a typed agent's quit on Windows or WSL retires its record, as main's returning shell did
* perf(sleep): a tracked pane whose agent became shared or ended drops its shell-proof retry
* fix(sleep): a quiet shell's return proves a typed agent's exit without a held launch
* perf(sleep): a quiet shell's return skips the proof for an ended agent or one a command mark is already proving
* perf(sleep): one quiet exit reported by both renderer callbacks runs one proof
* fix(sleep): a live process whose argv the host couldn't read keeps an agent's exit unproven
* perf(sleep): cold root-PID lookups started together share one owner inventory
* perf(sleep): a batch of cold root-PID lookups indexes its shared reply once
* fix(sleep): a quiet return defers to a running mark proof, a second exit report reruns once, and an unreadable argv blocks only as the agent
* perf(sleep): a host that published no shell PID gives no proof, so no exit proof inventories a daemon
* fix(sleep): the window learns a tmux-hosted conversation is shared, so it writes no checkpoint for it
* fix(sleep): an identity-only status of a tmux-hosted conversation leaves no window checkpoint
* fix(sleep): an ended agent's retained identity reaches the window no more, so a quit isn't checkpointed again on restart
* test(sleep): the woken terminal holds the pane's layout, as the window saves it
* fix(sleep): only a slept pane's record lists its agent; a live checkpoint is recovery, not a running agent
* refactor(sleep): one serialized executionHost field records who runs a conversation, replacing the binding symbol and the persisted sharedHost flag
* fix(sleep): a resumed turn takes its host from the resuming hook, so a tmux row resumed in the pane keeps its checkpoint
* fix(sleep): a resumed turn keeps the host when the hook reuses the row's own binding
* refactor(sleep): one name for who runs a conversation; the window and pane identity read executionHost
* fix(sleep): a typed WSL agent's mark ends it again; only a process main can probe excuses the shell proof
* fix(sleep): a slept conversation with no turn yet stays slept across an app restart
---------
Co-authored-by: d.bondarev <d.bondarev@crm-onebox.com>
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When you put a workspace to sleep, Orca writes down which agent conversation each terminal was running, so it can bring that conversation back when you open the tab again. For an agent that had been sitting idle for a long time, Orca no longer had a fresh status for it and wrote nothing down. On wake, that terminal came back as an empty shell and the conversation was gone from the tab.
Now, when the fresh status is missing, Orca uses the checkpoint it had already saved for that terminal, as long as the checkpoint clearly belongs to that terminal and that agent.
What Changed
Before: a Claude (or other resumable agent) pane that had been idle long enough for its hook-status row to disappear was skipped by Sleep. Waking the workspace and opening the tab started a plain shell instead of
claude --resume <id>.After: the same pane is recorded by Sleep and resumes its conversation when its tab is opened, like any other slept agent pane.
Mechanism: when main runs the sleep,
captureWorktreeSleepResumeRecordsbuilds oneworktree-sleeprecord per pane from that pane's hook-status row. With no row, it skipped the pane (if (!row) continue). The window does not collect records itself when main runs the sleep, so it took main's empty answer. The only remaining handle was the pane's savedorigin: 'live'checkpoint, and live checkpoints are consumed only by cold restore, not by wake.With this change, when the row is missing, main reads the pane's saved record from the workspace session and turns it into a normal sleep record, but only if all of these hold:
livecheckpoint (sleep and quit records are already durable and kept as they are),getPaneTerminalAgent: launch, foreground, or launch command) does not name a different agent. It is read when the checkpoint is read, after the pane's presence probe, the same way the hook rows are read.The saved record is read through the resume-record queue (
inResumeRecordOrder), likereadSavedResumeSource. So a checkpoint write from a hook status accepted before the sleep lands first, and the sleep cannot turn the older checkpoint into its record.The record is built through the same code as the hook-row path:
state: 'done',origin: 'worktree-sleep',restoreOnTabOpenOnly: true, a freshcapturedAt, the same local-connection-id rule, and the launch recipe only throughlaunchStatement, so a custom binary/args are kept only when main still holds that launch. A pane the hook store proved exited is still retired first, before any fallback.The row-to-source logic moved into
worktree-sleep-resume-source.ts, so the hook-row path and the saved-checkpoint path share one record builder.Why
The window's own sleep path (
collectSleepingAgentSessionRecordsForWorktreewithmanual-worktree-sleep) already promotes a saved live checkpoint when the pane has no live status. Main-run sleep lost that behaviour, so the fix gives main the same fallback.Alternatives considered:
Linked Issue
Fixes #42542
Visual Proof
N/A: no UI change. The visible effect is that the woken tab runs
--resumeinstead of a plain shell; the unit test covers the record that decides this.Testing
Added
src/main/runtime/terminal/stop/worktree-sleep-resume-records.test.ts. Its first case (a pane with no hook row and a saved live Claude checkpoint is recorded as a tab-open resume) fails without this change. The other cases pin what must not be resumed: a checkpoint for another worktree, a checkpoint naming another agent than the pane runs, a quit record, a pane the hook store proved exited, and a pane with no saved checkpoint. One more case checks the pane's agent after the presence probe, not before it.Added
src/main/runtime/terminal/stop/worktree-sleep-resume-recording.test.ts. It runs a realsleepTerminalsForWorktreewhile a hook status's checkpoint write is still queued and the status's row is gone. The sleep records the newer conversation. Without the queued read it records the older checkpoint.Ran the
src/main/runtime/terminal/stoptests,src/main/runtime/workspaces/sleep,src/main/runtime/construction/orca-runtime.test.ts,src/renderer/src/lib/agent-session/resume,src/renderer/src/store/terminals/sleepand the manual-sleep capture test, pluspnpm tcand the changed-code quality check.Found on Linux: a Claude pane idle for days, its hook row gone, a saved
origin: 'live'checkpoint with a provider session id insleepingAgentSessionsByPaneKey. Sleep wrote no record and wake spawned a plain shell.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
The riskiest part: a stale live checkpoint whose agent exited without the hook store noticing (for example, across an app restart) now becomes a sleep record. Opening that tab after wake would then run
--resumefor the old conversation instead of a plain shell. This matches what the window's own sleep path already does with the same checkpoint. The guard against a contradicting known pane agent and the unchanged exit-proof retire path keep the case narrow.No saved-data format change: the record has the same shape as every other
worktree-sleeprecord. SSH/remote panes keep their connection id exactly as on the hook-row path. A plain revert backs this out.Level: Low
AI Disclosure
Written with Claude Code (Claude Opus 5.5); the diagnosis, change and tests were reviewed by the author.
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code