Repository navigation
fix(agent-hooks): keep each pane's agent conversation through sleep and wake - #43529
Conversation
…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.
A row with a proved process gets its exit from the presence probe, and a same-session relaunch replaces an ended resume row.
Co-authored-by: d.bondarev <d.bondarev@crm-onebox.com>
…ke' into brennanb2025/sleep-pane-agent-identity # Conflicts: # src/main/agent-hooks/server/server-ingest-terminal.ts # src/main/agent-hooks/server/server-pane-sleep.ts # src/main/agent-hooks/server/testing/persistence/server-pane-sleep.test.ts
… 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).
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.
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.
This reverts commit 03ac47c.
…ke' into brennanb2025/sleep-pane-agent-identity
…it-after-wake # Conflicts: # src/main/runtime/terminal/surface/slept-pane-exit-status-main.test.ts
…ke' into brennanb2025/sleep-pane-agent-identity
…ne-agent-identity # Conflicts: # src/main/agent-hooks/server/testing/tmux/server-tmux-canonical.test.ts # src/main/runtime/terminal/surface/slept-pane-exit-status-main.test.ts
…oint is recovery, not a running agent
…a conversation, replacing the binding symbol and the persisted sharedHost flag
|
PERF PASS — no introduced P0/P1 performance blocker found. Fresh independent review of the full PR diff The changes after 750c77a add one sleep-record admission check to listing, and replace symbol/persisted-boolean topology with Work ledger: W=worktrees, R=repo/host-routing candidates, T=live terminals, A=hook rows, S=saved records in a host partition, Q=panes being captured, K=one PTY's bindings, L=legacy aliases, P=host processes, D=one root's descendants. Reference workload: W=750, R≈12, T≈300, A≈100; dimensions considered independently at 10×. S/P/D are variables, not claimed fleet caps. Unless stated otherwise, bookkeeping runs in Electron main; capture I/O is asynchronous, while projection, parsing, indexing and copies still consume main-thread CPU.
The additional host-wide proof is real work beyond main's renderer-only retirement. For P=2,000/20,000, an isolated eligible return pays one 2,000/20,000-row capture/index plus its D descendants. At one eligible return/s this means one capture/s and 2,000/20,000 indexed rows/s, not a timing claim. It does not mean each ordinary hook update or command mark visits 300/3,000 terminals. Separate process-less owners require separate descendant judgments to avoid retiring live/stopped agents; their concurrent host-table inputs share a capture. These necessary event-driven proofs have no extra fleet multiplier or autonomous polling loop. Per-capture spawn accounting: macOS normally uses 0 children through the native reader. Foreign unreadable argv can add one batched recovery ps under the existing burst-2 / one-per-2-s budget; native failure uses the existing fallback budget (burst 4, then one/s). A late failure can follow argv work, so this is not an unconditional one-child ceiling. Linux uses one ps, plus the existing Pre-existing costs kept separate from regressions: resume reads/hook-status writes already resolve the workspace-session host, potentially O(R), and real immutable saved-map edits already copy S references. With R≈12/120, a saved-only exit can pay one initial identity route and one retirement route; it does not route five times or route once per captured pane. The untouched Executed evidence on this head (no install, app build, typecheck, broad vitest or GUI run):
Recurring-class screen (matched and disproved unless otherwise stated):
Six-question disposition: (1) reviewed producer admission through renderer/store no-op handling; (2) reviewed ownership, consumers, capture/index sharing and per-pane retry bounds; (3) reviewed main-thread copies/parsing versus asynchronous capture and coalesced storage; (4) reviewed A/S/Q/T/P/D/R/L growth, freshness and retry progress; (5) reviewed source-level macOS/Linux/Windows/WSL/SSH/mobile/folder-workspace gates and spawn paths; (6) reviewed close/forget, entry/row/incarnation/input invalidation, bounded sleep waiting and IPC-map cleanup, with deterministic teardown counts. Validation limits: no live Linux/Windows/WSL/SSH capture, packaged-app CPU/heap/frame measurement, or rendered sleep/wake QA. This is a performance-count/source review, not a measured responsiveness or complete functional QA claim. No unresolved source-proven amplification is being deferred as a measurement gap. No code edited, committed or pushed. |
…a tmux row resumed in the pane keeps its checkpoint
|
PERF PASS — no introduced P0/P1 performance blocker found. Independent review of the complete PR diff from merge base The latest change ( Work ledger: W=worktrees, R=repositories, H=host partitions, T=live terminals, A=hook rows, S=saved records, Q=captured panes, K=bindings belonging to one PTY, L=legacy aliases, P=host processes, D=descendants of one root. Reference fleet: W=750, R≈12, T≈300, A≈100; each population considered separately at 10×. S, P, D, K and L are populations, not alleged fixed caps. Main-side projections/copies/parsing/indexing consume Electron-main CPU; asynchronous process/native/file capture is identified separately. Unless stated otherwise, rows below add zero subprocesses and zero process-table reads.
Price and host accounting. The new proof is real work beyond main's renderer-only retirement: at P=2,000/20,000, an isolated eligible return needs one 2,000/20,000-row capture/index plus D-local traversal. At one eligible return/s, that is one capture/s and 2,000/20,000 indexed rows/s, not a CPU-time claim. It is necessary evidence to avoid retiring a live/stopped process-less agent, shares its host input among concurrent owners, and introduces no autonomous polling or all-terminal multiplier. At 100/1,000 concurrent callers, the source-module count check below observed one capture per cohort. Ordinary status events/ordinary shell marks request zero of these new captures. On macOS the shell-tier reader avoids unused tty/start fields and normally captures natively with 0 children. Unreadable foreign argv can invoke one batched recovery ps, through the existing burst-2 / one-per-2-second budget. A native failure uses the existing fallback budget (burst 4 then one/second); failure after argv recovery can pay both stages, so an unconditional one-child maximum would be inaccurate. Linux uses one ps per capture plus existing Pre-existing scaling kept separate. Main already routes workspace-session reads and hook resume writes through repository/host selection (potential O(R), R≈12/120) and copies immutable S-record maps on real saved-state edits. An exit can pay one initial rowless identity route plus one retirement route per applicable alias, not five repeated routes; sleep resolves its host once for all Q panes. With S=300/3,000, a real saved deletion copies up to 300/3,000 references, absent deletion copies zero. Existing status writes/map edits and coalesced persistence already have this cost; this change removes renderer eager duplicate cleanup and avoids topology ordering. Existing alias scans and requested full listings are also pre-existing population paths. The untouched terminal-client-use caller can still perform its existing provider lookup before calling the changed shell-alone helper; this PR adds no caller to that fallback. These are not new fleet work on every status. Executed evidence on this head:
Recurring regression classes: matched and disproved by the ledger/counts: work before admission gates; per-row global derivation/hot rescans; subprocess per item/re-reading input; per-entity state surviving teardown; unbounded retries/queues; no-op store identity churn; whole-snapshot/publication or whole-file persistence amplification; synchronous main-thread I/O/eager startup imports; hidden/per-mounted-owner activity and fixed polls. No added streaming full-message reprocessing or shared-context fanout matched. Required fresh proof input is intentionally re-read after an eligible return; coalescing preserves that freshness rather than reusing an older answer. Six-question disposition: (1) reviewed admission through producer, projection, publication and renderer no-op guards; (2) reviewed pane/host ownership, recipients and sharing; (3) reviewed main-thread parsing/copies versus asynchronous capture and coalesced saves; (4) reviewed independent W/R/H/T/A/S/Q/K/L/P/D growth and retry progress; (5) reviewed local/daemon/macOS/Linux/Windows/WSL/SSH/mobile/folder routing in source; (6) reviewed close/forget, entry/row/PTY-incarnation/input invalidation, finite sleep wait and IPC-map cleanup, with teardown counts at N/10N. No confirmed new unnecessary population-scaled work remains. Limits: no packaged-app CPU/frame/heap profile, live Linux/Windows/WSL/SSH capture, or rendered sleep/wake QA. This grade is based on inspected source bounds and deterministic counts, not measured responsiveness or a claim of complete functional QA. |
… pane identity read executionHost
|
PERF PASS — no introduced P0/P1 performance blocker found. Reviewed the full PR diff from merge base The earlier late-completion failure is fenced by entry identity in Work ledger: W=worktrees, R=repos, H=host partitions, T=terminals, A=hook rows, S=saved records, Q=panes captured, K=bindings/leaves of one PTY, L=legacy aliases, P=host processes, D=one root's descendants. Reference fleet: W=750, R≈12, T≈300, A≈100; consider each independently at 10×. S/P/D/K/L are populations, not fixed caps. Projections, parsing, indexing and immutable copies run on Electron main or the renderer as identified; async capture does not make their CPU cost disappear. Unless explicitly stated, the following work adds zero subprocesses and zero process-table reads.
Process and scale accounting. The new proof is real work beyond main's renderer-only recovery retirement, and is necessary to distinguish a returning shell from an agent that is stopped, backgrounded or hosting a nested shell. At an illustrative P=2,000/20,000 processes and one eligible return/s, it requests one capture/s and indexes 2,000/20,000 rows/s, plus D-local work. Native formatting may sort P rows; this is a count/complexity statement, not a measured CPU-time claim. Ordinary shell marks and ordinary status updates request zero of these new shell proofs. At 100/1,000 concurrent fresh callers the executed reader harness produced one capture per cohort. It does not assert that callers arriving after capture start can reuse pre-request evidence.
Existing population costs, kept separate: repository/twin-host routing can be O(R), about 12/120 repo visits per route. A rowless quit can pay one initial identity route plus one retirement route per applicable alias; this no longer repeats the route five times, and matches main's existing per-hook/resume event routing class. A real saved deletion copies up to S references (illustratively 300/3,000), as existing immutable resume edits do; absent deletion copies zero. Alias collection is O(L), as on the existing exit-cleanup path. The unchanged Executed evidence on this head:
Recurring regression classes touched: matched and disproved by admission gates, keyed ownership and the bounds above: per-row global derivation/hot-path rescans; subprocess-per-item and re-reading unchanged input (fresh evidence is required after a return, coalesced before capture); no-op store identity churn; whole-snapshot/publication amplification; whole-file persistence/synchronous-main I/O; per-entity state outliving teardown; unbounded retry/queue admission; hidden/mounted-owner work and fixed polling; eager startup imports. Existing topology/save scheduling remains, and no SDK/heavy adapter was added to eager startup. No new whole-message streaming processing, broad selector or React effect matched. Six scan questions: (1) reviewed producer-to-publication skip gates, including rowless shells and renderer no-ops; (2) reviewed pane/host ownership, duplicate reports and snapshot sharing; (3) reviewed main/renderer CPU, native/subprocess capture and coalesced persistence; (4) reviewed independent W/R/H/T/A/S/Q/K/L/P/D growth and retry progress; (5) reviewed local/daemon, macOS/Linux, Windows/WSL, remote/mobile and folder paths in source, with platform mocks explicitly distinguished; (6) reviewed close/forget, row/input/PTY/launch invalidation, finite sleep waiting and IPC-map release, with N/10N teardown counts. No confirmed new unnecessary population-scaled repeated work remains. Limits: no packaged-app CPU/frame/heap profile, live Linux/Windows/WSL/SSH capture or rendered sleep/wake QA; this performance grade establishes inspected bounds and deterministic counts, not measured responsiveness or complete functional QA. The session-ownership invariant is that sleep retains the pane's accepted conversation while proven exit retires only that conversation's recovery; full rendered/provider correctness remains outside this requested performance-only pass. |
…in can probe excuses the shell proof
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.
|
PERF PASS — no introduced P0/P1 performance blocker found at efe23d7. Independent review of the full PR diff, merge base The change since bac860d is one keyed Work ledger. W=worktrees, R=repos, H=host partitions, T=terminals, A=hook rows, S=saved records, Q=panes being captured, K=one PTY's associated leaves/keys, L=legacy aliases, P=host process rows, D=one root's descendants. Reference fleet: W≥750, R≈12, T≈300, A≥100; consider each independently at 10×. Unless the table explicitly says otherwise, changed work requests zero process captures and zero subprocesses. These bounds describe work, not measured latency.
Process reads and spawns per proof. This PR intentionally adds fresh host evidence for process-less local exits: a returning shell alone cannot distinguish a stopped/backgrounded agent or its nested shell. That is necessary work for this behavior, not proof of zero added cost. At illustrative P=2,000/20,000 and one eligible return per second, the request bound is one capture/s with 2,000/20,000 index rows/s plus D-local work; native formatting can sort P rows. There is no T×P index rebuilding for a shared snapshot. Ordinary shell marks without identity/debt and ordinary status updates request zero of these new shell captures.
Pre-existing population work, distinguished from regressions: host/twin-repo resolution can visit R repos (about 12/120); a saved-only quiet exit can need its initial identity route and its retirement route per applicable alias. Main already routes per hook-resume write/read; the new retirement performs one route and reuses its saved answer. Alias collection is O(L), already present in exit cleanup. Real immutable recovery edits copy S references (illustratively 300/3,000); absent deletion copies zero and no extra topology sort occurs. The unchanged Executed evidence:
Recurring regression classes touched: matched and disproved by the gates/counts above: per-row global derivation and hot-path rescans; subprocess-per-item/repeated reads (fresh proof input is required and shared); no-op identity churn; publication/whole-snapshot amplification; whole-file persistence and synchronous main I/O; per-entity retention; unbounded retry/queue work; hidden/mounted-owner and fixed-cadence work; eager startup imports. No new broad keyed-map selector, React effect, or whole-message streaming transform matched. Meaningful lifecycle updates still use existing commits/saves; skip gates do not truncate required outputs. Six questions: (1) reviewed skip gates before identity/proof/payload work; (2) reviewed pane/PTY/host ownership and duplicate callbacks; (3) reviewed main/renderer CPU, native/child capture and coalesced storage; (4) checked W/R/H/T/A/S/Q/K/L/P/D growth and retry progress; (5) inspected macOS/Linux/Windows, local/daemon/WSL/SSH, mobile input and folder routing, distinguishing mocks from live evidence; (6) checked close/forget, stale row/input/PTY/launch results, finite sleep waiting, retry-entry identity and IPC-map final release, including N/10N counts. No confirmed unnecessary population-scaled repeated work remains. Limits: no packaged-app CPU/frame/heap measurement, live Linux/Windows/WSL/SSH capture, or rendered sleep/wake QA. This is a source/count performance grade, not measured responsiveness or complete functional QA. The relevant ownership invariant is that sleep retains each pane's accepted conversation while a proven exit retires that conversation's recovery. No code changes, installs, typechecks, broad tests, builds, commits, pushes or GUI actions; working tree remains clean. |
|
PERF PASS — #43529 at Independent full-diff review against merge base The PR does add necessary process observation on an actual process-less agent exit, where main previously accepted the returning shell without that proof. That is not constant in host process count. It is gated to an agent needing proof, coalesced across concurrent requests, and no longer multiplied by terminal inventories. I found no unnecessary new fleet scan per ordinary prompt, PTY chunk, hook status, or mounted pane. Cost notation: W = workspaces, R = repos, T = live terminals, A = hook rows, S = saved resume records in the relevant partition, Q = panes/keys in the affected capture, P = host processes, D = descendants of the particular PTY root, K = aliases/placements of that PTY, E = retained exit evidence. Reference sizing: W=750, R≈12, T≈300, A≈100; growth sizing multiplies each independently by 10. Bounds below are source counts, not measured latency.
Verification: four explicitly named Vitest files through Also executed a small isolated count harness through tc-gate, loading production The previously reported late-failure resurrection is therefore closed by both source identity guard and count evidence. The root-inventory regression is closed by source: the proof calls All six scan questions were assessed:
Touched regression classes: unused producer work / hot-path rescans — gated/indexed as above; subprocess-per-event/item / unchanged rereads — necessary fresh exit proof only, shared physical capture, no inventory; fixed polling / hidden-owner work — no new cadence, unresolved debt dormant; collection fanout / unbounded queues — Sets/maps, one pending bit, sleep requests share capture; entity state outliving owner — teardown plus late-result identity guard; publication/store churn / whole snapshots / whole-file rewrites — existing event fanout and coalesced persistence, one enum added, absent retirement is a no-op; sync main-thread I/O / startup imports — no added matching costly operation. Each matched class was checked and disproved as an introduced waste regression; none is a finding. Pre-existing population work remains visible: workspace host routing may inspect R repos/host partitions; main-window launch-context lookup already uses terminal identity resolution per status; reconciliation already visits alias state; status/resume writes already replace record maps, and dirty exit persistence serializes E retained exit records. This span does not introduce a higher-cadence fleet scan for those paths. Necessary new exit/sleep outputs use those existing owners. At 10× fleet those existing paths still scale; this PASS does not claim they are constant or benchmark them away. Limits: this is a source/count-based performance verdict. No packaged Electron frame/CPU/heap profile, real 1,000-terminal sleep, Windows/WSL/SSH runtime timing, or cold-start timing was collected. Native capture latency and actual per-host subtree sizes remain unmeasured; no millisecond/CPU claim is made. The recovery invariant being screened is that a physical sleep preserves the pane's conversation, while shared/ended identities do not launch another copy (#42542 / STA-15387). Full cross-platform correctness certification is outside this independent performance pass. |
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.
|
Review loop, final round (6f3a93f → 463ed3b). What changed. An external design review asked for a rework. The PR body has the current design and its known limits.
Repairs found by this round's reviewers (each with a test that fails when the fix is reverted):
Design choices kept (the PR body has details). Each alternative would regress current behavior:
Council re-check on 463ed3b (diff plus the regression notes, against the reference tools):
Verified.
Screenshots:
|
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.
Replays #41746 (brennanb2025/omh-slept-coordinator-wake @ b82ff2d) onto the into main's notifyAgentSessionStoreCacheChanges; cold-restore resume-record handler kept in pane-resume-record.ts with #43529's edits; mail-wake guard added to #43529's refused-resume predicate; new files moved to main's folders.




Problem
Sleeping a workspace could lose an idle conversation, hide its agent after another sleep, or replace an interrupted turn with a false completion during wake. And a Codex resumed by a wake, then quit with
/quit, came back ascodex resume <id>at the next wake instead of staying a shell.User-facing change
fgkeeps it resumable.Change
One owner for a pane's agent.
paneAgentIdentityanswers "which agent conversation is in this pane, and has it ended". It reads the pane's hook row in any at-rest shape, otherwise its saved conversation, minus an exit recorded since. It is a pure read. Sleep capture, the sleep gate, stopping protection, process listing, quit capture and restore all use it, and their separate live-row and placeholder filters are deleted.worktree pslists a saved record's agent only when the record is a sleep's; a live checkpoint is recovery, not a running agent.Who runs the conversation is recorded once, on the hook row.
executionHost: 'pane-owned' | 'shared' | 'unverifiable'is set when the hook row is written. A Claude or Codex hook reports the tmux pane it ran in; a PTY spawned while Orca itself runs inside tmux carriesORCA_INHERITED_TMUX, so a hook doesn't mistake Orca's own tmux pane for a host. OpenCode's own attach/serve evidence decides the rest. The field follows the conversation's binding, an unverified writer can't claimpane-owned, and onlysharedis persisted (a pane-owned claim is proven again by its next hook). The window receives the same field and writes no checkpoint for a shared conversation. This replaces the sleep-time tmux probe.Exit is proven by the host, not guessed from a mark. When a command finishes at the shell (OSC 133;D) in a pane whose agent has no process the presence probe can check, the agent ends only once the host proves the shell is alone: one fresh process table, the PTY's shell at or beneath its root (macOS roots at
/usr/bin/login), in the foreground, with no stopped or background job running the pane's own agent. If the proof fails (a shell nested in the live agent finished a command, or the agent is stopped with Ctrl-Z), the pane is tracked inunproven-agent-exits.tsand a later mark re-proves it, one proof per pane at a time. A proof doesn't count if input reached the PTY while it ran. An agent typed at the prompt (no launch held) is tracked the same way. A sleep settles every pane's pending proof together before it captures. Remote and Windows panes give no proof, so a mark ends the agent there, as on main; a hookless Windows quit is proven by the host's job census. A proven exit durably deletes the pane's saved sleep record, through the same session write path as every session save on main.This carries #42922's change (its commits are included), per the review council, and supersedes it. Tracked in #42542 and STA-15387. Carries the saved-conversation regression from #42391, with contributor credit in the commit.
Design choices kept, and why
A final design review proposed three alternatives. Each would add a regression, so they are not taken:
TMUX/TMUX_PANEfrom every PTY's environment instead of marking an inherited tmux. This changes the environment of every user who runs Orca inside tmux (their shells and tools would stop seeing the tmux they are actually in)./quitafterwards would never be proven.Known limits
bgstops itself on its next terminal read (SIGTTIN/SIGTTOU), so the proof sees it stopped and it stays resumable.TMUX, lacksORCA_INHERITED_TMUX, so a Codex in it can be treated as shared until that PTY ends.destroy-unattached(not the default) loses recovery: a shared host is never checkpointed.codexleft idle with no prompt is not seen until its first hook.No new regressions vs main
Every automated-review finding and every known limit was checked against main's code. Where the behavior was new with this PR, it is fixed here with a test.
worktree.ps/context) was hiddenfg/compactshows Done while compacting; a dismissed agent's sidebar row reads IdleValidation
pnpm check:changedon Linux through remote-check on each head.worktree pslisting./quit: stays a shell at every later wake and after restart. A nested shell command inside a live Codex doesn't end it; its real/quitafterwards does.+: sleep/wake resumes the same id with exact recall.fg, quit after wake, idle Claude with no hook row (STA-15387), mid-turn Interrupted. PASS.