Skip to content

fix(orchestration): wake slept coordinators for waiting mail - #41746

Draft
brennanb2025 wants to merge 106 commits into
brennanb2025/orchestration-mail-holesfrom
brennanb2025/omh-slept-coordinator-wake
Draft

brennanb2025 wants to merge 106 commits into
brennanb2025/orchestration-mail-holesfrom
brennanb2025/omh-slept-coordinator-wake

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What broke

With Agent sleep turned on (experimental, off by default), Orca can put a coordinator agent to sleep while its workers are still running, because the coordinator itself has no open task. When a worker then finished and sent its result, the mail just sat there. Nothing woke the coordinator, the workspace showed no unread bell, and the sender wasn't told. The mail arrived only when someone happened to open that workspace.

Reproduced on main (macOS, Claude coordinator, Agent sleep after 1 minute): the coordinator slept, the worker's worker_done sat unread for 4 minutes with no bell or notice, and it was delivered the moment the workspace was opened.

Why

Mail delivery only types into a terminal that is running. A slept pane has no running terminal, so delivery returned without doing anything, and the only things that wake a slept pane are opening its workspace or a phone action.

What changes

  • When a coordinator or worker that Agent sleep put to sleep has unread mail waiting, Orca wakes just that pane (resuming its saved conversation the same way opening the workspace does) and the mail is delivered normally once the agent is back. Only mail sent to a run or task mailbox does this; empty mailboxes never wake anything.
  • Panes the user put to sleep by hand are not woken. Their mail waits, the workspace shows the unread bell, and the sender's receipt says how to resume the agent.
  • A wake waits for a sleep that is still finishing, and bursts of mail cause one wake per pane.
  • If a wake fails (the agent can't resume, the host is down), the mail stays unread, the bell stays on, and Orca tries again on the next app start, window ready, host reconnect, or new mail. It never retries in a loop.
  • If the agent fails to resume and leaves a plain shell behind, Orca keeps track that the mail is still owed instead of forgetting it, never types into that shell, and the receipt tells the user to re-run the agent in that terminal. Starting the agent again in that shell automatically is left for a follow-up (see Limits).

Checks

  • Tests run the production wake decision: only the right pane wakes for waiting mail; manual sleep holds with the right receipt and bell; a sleep finishing after mail arrived still wakes; a successful wake whose mail stays unread doesn't wake again for the same mail; a failed wake retries on reconnect; a failed resume that leaves a shell keeps the obligation, tells the user to re-run the agent, and never types into it.
  • pnpm tc:node, pnpm tc:web, lint, format, code-quality gate.

Limits

  • TEMPORARY: a remote coordinator slept by a client that then disconnects still waits until the workspace is opened (no host-side resume yet). Tracked in Linear STA-15080.
  • TEMPORARY: after a failed resume leaves a plain shell, Orca doesn't restart the agent in it automatically; the user re-runs it from the receipt's instructions. Doing that safely needs the host to block typing into that shell first. Tracked in Linear STA-15118.
  • On Windows, WSL and SSH terminals, a resume shows the held wording until Orca confirms the agent is running.
  • Terminals without Orca's shell integration (and some right after a restart) can't prove a failed attempt has ended, so Orca holds the mail and asks the user to re-run the agent rather than guessing.
  • Native chat panes use their own delivery and aren't affected.

Stacked on #41701 (mail held when the agent isn't in the foreground). Reimplements the mechanism from #18731 on current code; that PR will be closed when this lands.

Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​973 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​973
Prod 60 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2167 $\color{#cf222e}{\Huge{\mathbf{−}}}$​178 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1989

brennanb2025 and others added 28 commits November 15, 2026 17:26
…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.
…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
brennanb2025 added a commit that referenced this pull request Nov 19, 2026
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.
… read; fence retirement across every root lookup; stopped one-shots don't count
@brennanb2025
brennanb2025 force-pushed the brennanb2025/omh-slept-coordinator-wake branch from 0de3f03 to b0d8086 Compare November 19, 2026 21:08
brennanb2025 added a commit that referenced this pull request Nov 19, 2026
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.
…ected agent is stopped behind it; exclude codex exec and versioned one-shots; fence retirement per lookup
…th one indexed query, not its whole Run history
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.
admitFailedMailWake ran every ownership and shell check and then always returned
false, so a failed mail wake was never retried automatically. Remove it, its
retry admission module, the retryMailWake trigger and port, and the shell
occupancy probe it alone used. Recovery stays explicit.
…once

A targeted wake reaches a mounted pane through its wake listener, which only
resumed a target armed when the agent's process exited. Remounted tabs and panes
woken before had none, and mounting an already-mounted tab starts nothing, so
those panes never got a process. A wake aimed at a mounted pane now resumes it
from its slept-agent record when it has no live process, and the background wake
mounts the tab only when no mounted pane took the wake.

A pane that types its startup command also handed the resume command to the
spawn, so main's shell-ready submission and the renderer's typed copy could
interleave in the shell. The typed copy is now the only writer for those panes.
…ange

Drop the mutation-scope crawl that guessed which mailboxes a database change
touched. Any traffic/topology/records notice (and a consuming mail read) now
coalesces into one pass that re-runs the indexed owner query for each sleeping
pane plus already-tracked mailboxes.
…wake

The mail wake used to rewrite the sleep record to a tab-open-only quit
bookmark before launching, which blocked the mounted-pane wake. The wake
claim now sits beside the unchanged record; a pending claim is never read
as a finished sleep that may retire the pane.
…ion database

Main now claims a wake attempt in the orchestration database before asking
the window to resume a slept pane, stamps the process the wake launched,
and deletes the row when the agent confirms or nothing is owed. The sleep
record no longer carries custody, so the window's custody guards, settle
notices and refusal restores go away. A claim that never launched is
dropped when the database opens, so the next mail edge can wake the pane.
The window still performs the resume until main owns pane layout (STA-15080).
… tried wakes

Mail traffic refreshes only the mailboxes it names; ownership changes still
re-derive every sleeping pane. A retained or failed wake no longer asks the
window to prepare again until an availability edge. Unchanged session
writes skip the record inventory, and the wake queue drains lazily.
…tempts

A launched wake now also confirms when its pane's foreground process is the
agent, for agents that report nothing until their first turn. An attempt
whose process is gone is released and its mail stays queued. A refused
prepare counts as a failed wake. Consumption and named record notices
refresh only their mailboxes, the record index skips non-sleeping records
without allocating, invocation watches and the held-worktree bell update
only when they changed, and waking receipts skip the workspace-name lookup.
…e orphans

Main's attempt id now travels with the wake request and becomes the resumed
agent's launch token, so main stamps exactly the process its wake started.
Once the window has restored its panes, a launched attempt whose process is
missing or replaced is released and its mail stays queued. Invocation
watches are released per settled token, foreground probes skip hosts that
cannot prove an agent, the record index compares fields instead of
serializing them, and unnamed ownership changes share one full pass per
second.
…turn's checkpoint

A done checkpoint for the same conversation replaced the Agent Sleep record
with a live one, so mail for the slept coordinator never woke it.
…tokens

The command-finished scanner now advances an offset and stops its ST search
at the next escape, so a burst of BEL-terminated markers is read once. The
window forgets a mail wake's launch token when that wake never reached the
pane.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/omh-slept-coordinator-wake branch from b0d8086 to 9598ee9 Compare November 19, 2026 22:42
@brennanb2025
brennanb2025 force-pushed the brennanb2025/orchestration-mail-holes branch from a09a5ad to 48c3eed Compare November 19, 2026 22:55
brennanb2025 added a commit that referenced this pull request Nov 25, 2026
* fix(orchestration): resume a slept agent when mail waits for it (from #41746)

* fix(orchestration): slept agents look idle to orchestration and wake in place

Ported onto main from brennanb2025/agent-sleep-orchestration (8f63a47..fd32c2e),
with the mail-read listener that re-checks sleeping-mail wakes.

* test(agent-sleep): a message wake resumes a remounted slept pane instead of reattaching its stopped session

* fix(orchestration): keep the sleeping-mail wake scoped, honest and quiet

- A pane the user put to sleep with Workspace Sleep is no longer listed or read as a live,
  writable agent; only Agent Sleep's stops answer as idle.
- Mail to a Run coordinator whose pane moved to another tab before it slept now finds the
  pane by its leaf and wakes it.
- A crew change that names Dispatches or parties refreshes only those mailboxes and panes
  instead of re-deriving every sleeper.
- When main refuses Agent Sleep because mail is waiting, the renderer asks again after a
  doubling delay (up to 16 minutes) and no longer reports sleeping-mail availability.

* fix(orchestration): drive the sleeping-mail pass from waiting mail

- A pass that re-checks every sleeper now starts from the mailboxes that hold deliverable mail,
  so its work no longer grows with sleeping panes or their old Runs, and a direct message to a
  slept agent's own handle is found again once the window restores.
- The sleeping-mail and slept-wait listeners register as idle, so crew writes keep skipping
  their names comparison; slept waits re-check only on terminal identity changes.
- A mail wake's launch id is read rather than taken, so a startup built as a probe leaves the
  real launch under main's attempt id.

* fix(orchestration): reopen slept workers' follow-ups as Orca's own, and bound mail discovery

- A follow-up to an Orca-created worker whose agent Agent Sleep stopped reopens its conversation
  in a terminal Orca owns, so auto-close and worker-stop keep working; messages, terminal send
  and worker-start --terminal still wake a slept agent in place.
- A change that names nothing no longer re-checks sleeping mail; arriving or rerouted mail
  requests its own mailbox's wake and availability edges re-check everything.
- A pane's owned-mailbox discovery checks for mail inside one statement per owner kind instead
  of one query per old Run.

* test(orchestration): read the correlated inbox check's plan

* fix(orchestration): keep slept-worker release as on main, and bound sleeping-mail work by sleepers

- Worker release, observation and follow-up placement treat a slept worker as main does; the
  in-place follow-up work moves to brennanb2025/agent-sleep-worker-followup. Slept agents still
  list as idle and wake in place on messages, terminal send and worker-start --terminal.
- The full sleeping-mail re-check on window, host and SSH availability walks each sleeping pane's
  own inboxes, never the database's old undelivered mail.
- A pane re-check includes the direct mailbox of the handle its sleep record saved, so a message
  sent while the agent was going to sleep wakes it once the record reaches main.
- Crew changes are watched only while some agent sleeps, so crew writes keep their shortcut when
  nobody is listening.

* test(orchestration): count sleeping-mail work after the restore repoint

* fix(orchestration): name a slept pane by its handle, and leave Workspace Sleep's exit waits settled

- Pane lookup (Copy Terminal ID, resolvePane) returns a slept pane's parked handle, which input
  wakes, instead of a synthetic handle for its stopped process.
- A process the user's own Workspace Sleep stops is known as such at the stop, so an exit wait on
  it settles as before rather than waiting on as for an Agent-slept agent.

* fix(orchestration): bound sleeping-mail work by what is asleep and what changed

- Re-checks no longer walk every Run a sleeping coordinator pane created: Run and Dispatch mail
  reaches a sleeper on arrival, and after a restart through the restored-mail repoint. Owner
  history is re-walked only for the few panes holding a wake attempt, so its custody settles.
- A change that names nothing re-checks only the mailboxes already owed to sleepers.
- Failed wakes retry when a host becomes connected, not on every repeated status broadcast, and
  that retry no longer re-sends an unchanged held set.
- With nobody asleep, a mail read skips finding its mailboxes and a send skips the sleeping-mail
  hold lookup.
- A parked handle still names its stopped process, so worker-read of a finished worker whose pane
  sleeps keeps reading its output.

* test(orchestration): mail reads with nobody asleep do no sleeping-mail lookups

* fix(orchestration): wake before dispatch injection, read a mailbox owner once, batch host edges; drop an unrelated lockfile change

* fix(orchestration): slept handles stay bound to their stopped process; a reused slept worker keeps Orca's custody

Agent Sleep no longer parks a slept pane's handle: it stays on the stopped
process, so its identity, output and liveness verdict keep answering for the
idle agent, and the resume takes the handle over. worker-start --terminal on a
slept Orca-owned worker carries the stopped process's custody to the resumed
one. The dispatch --inject wake moves to the follow-up branch.

* fix(orchestration): a resumed slept pane keeps its handle when its own status row lands first; restore the store fixture main's test cut removed

Drop the renderer remount-wake test whose fixtures main removed; QA covers that path.

* fix(orchestration): slept handles answer pane operations; a sleep published late still wakes for its Run mail; host edges re-check only tracked wakes

- show/focus/rename/close accept a slept pane's handle while it names its stopped process
- a sleep record reaching main after its Run or Dispatch mail re-checks the mailboxes the pane owns once
- a runtime environment becoming available retries failed and tracked wakes only, as SSH edges do
- carrying a slept handle across a pane move looks its leaf up by id instead of scanning the graph

* fix(orchestration): re-check sleep eligibility after main's admission; keep a slept pane's archive; trim repeated sleeping-mail work

- a pane the user returns to while main admits its sleep stays awake
- the exited-terminal archive bound skips stopped processes that open slept panes still name
- a host edge re-sends the held set only when it changed; a pane's sleep notice retries only its own failed wake
- a publication pass reads each owed mailbox once instead of again for its wake request

* fix(orchestration): a reused slept agent wakes before a worker start reads its process

Federated worker starts on an explicit terminal now resume a slept agent before
readiness, so the attachment names the woken process and its reports are accepted.

* fix(orchestration): address review threads on slept-agent wakes

- a shared wake's failure is observed even when the first caller already aborted, and an aborted first caller starts no wake
- a corrupt stored mail-wake row is dropped instead of stopping the load
- a request queued behind a refused wake waits for the same availability edge
- touched mailboxes are read once for both the sleeping-mail publish and stale-card cleanup
- a cursor read of a slept agent keeps the stream's own (possibly empty) page
- a finished turn keeps the Agent Sleep record but takes its changed effort, permission mode and launch config
- a cancelled OSC 133 sequence breaks marker adjacency

* fix(orchestration): page a slept agent's output from the pane's kept copy again

The stopped process's buffers are emptied at exit, so a cursor read from them always came back empty.

* fix(orchestration): a resumed slept agent keeps its handle's line cursors; query replies never wake it

- the resumed process continues the slept handle's line count, so a cursor read before the sleep still reaches the resumed output instead of silently skipping it
- a terminal's query reply to a slept agent is refused without waking it, as on a disconnected pane

* fix(orchestration): continue a slept handle's cursors from its stopped process's final line count

A released transcript zeroes the stopped process's count and the sleep's graph sync resets the pane's copy, so keep the count the transcript reached and use it for slept reads and for the resumed process.

* fix(orchestration): continue a slept handle's cursors when the resumed spawn takes the handle

The resumed spawn binds the slept handle before the graph sync, so the line-count carry runs where a process first takes over a stopped process's handle (once), with the graph sync as a fallback. Slept reads and the carry share one count, and an empty preview no longer reads as a line.

* fix(orchestration): declare the handle line-cursor carry for the slept-handle layer

* test(orchestration): a woken slept agent answers as slept again after its second sleep

* fix(orchestration): a woken worker's first process never takes its handle back

Orchestration finds a worker by the process it launched. After a slept worker's resume took over its
handle, re-issuing a handle for that stopped first process pointed the worker's handle back at it, so
after the next sleep the worker read as exited and its second wake started nothing. A stopped process
whose successor holds its handle now answers to that handle without repointing it.

* test(orchestration): the first-process lookup leaves a re-slept worker's handle alone on both bind orders

* fix(orchestration): evicting a woken agent's first process keeps the handle its resume holds

The stopped first process still aliases the handle its resumed successor took over. Dropping that
record (the disconnected-record archive) removed the handle with it; now only the alias goes.

* test(orchestration): model the minted first-process handle in the eviction test

* test(orchestration): evict the first process after the woken agent sleeps again

* perf(orchestration): bound slept-agent wait, held-set and sleep re-check work

Identity writes re-check only the slept-agent waits on the handles they touch,
held-set publishes coalesce to one full set per tick, and the re-check before a
pane sleeps plans only that pane.

* fix(orchestration): slept-agent waits re-check once a reloaded window graph is ready

* perf(orchestration): graph syncs re-check slept waits only after a pane leaves, held mail sends changes, and the sleep re-check reads one pane

Title-only window graph publications check no pending slept-agent wait; only a
dropped leaf or a reload's ready edge re-checks them. After a window's first
full held-workspace set, main sends only the workspaces that joined or left,
and the sidebar notifies just those cards. The re-check before a pane sleeps
collects host evidence and binding ages for that pane alone.

* fix(orchestration): a cancelled window reload resends the whole sleeping-mail workspace set

* test(orchestration): drop a reload test that passes without its fix

* perf(orchestration): a dropped pane re-checks only its own slept waits, and the sleep re-check reads one tab

Pending slept-agent waits are indexed by pane leaf as well as handle, so closing
an unrelated pane checks none of them. The one-pane re-check before sleep finds
its tab through an index shared across a drain, and owner resolution lists a
workspace's PTYs only when two hosts publish it.

* fix(orchestration): a slept pane keeps its handle when a renderer reload re-issued its stopped process

* fix(orchestration): slept-agent waits stop listening once the last one times out or is cancelled

* fix(orchestration): a reload neither ends a slept pane's exit wait nor renames a pane that slept again

A waited slept pane counts as closed only once its saved sleep record is gone,
so a reloading window that publishes its panes late leaves the wait pending;
the record's removal re-checks that pane's waits. A slept pane reclaims its
saved handle when the record holding it names no live process, which covers a
second reload after the pane woke and slept again.

* fix(orchestration): a slept pane's exit wait reads only its saved sleep record, not a mail wake's custody

* fix(orchestration): a window that (re)subscribes to sleeping-mail changes asks for the whole set

* perf(orchestration): waited panes find their leaf through an index, and ambiguous-owner sleep checks share one PTY walk

* fix(orchestration): the waited-pane leaf index is held weakly by its graph map

* fix(orchestration): a sleeping-mail change the window dropped makes the next send the whole set, and a finished page load resends it

* perf(orchestration): route renderer replies by request id, look up waking panes, settle an ambiguous owner once, and build nothing for a window that refused sleeping-mail

Each renderer reply goes straight to its request through one listener per
reply channel. A pane being woken is a keyed lookup. An ambiguous workspace
owner is settled once per PTY list. After a window refuses a sleeping-mail
send, nothing more is built until it asks for the whole set.

* perf(agent-sleep): a pane wake reaches only its own mounted tab

Mounted terminal tabs register as wake owners by workspace and by tab, so a
targeted wake calls one owner and a workspace wake calls that workspace's tabs,
instead of every mounted tab filtering a window-wide event.

* perf(agent-sleep): post-resume alias cleanup reads one conversation's records, and workspace snapshots rebuild on read

* fix(agent-sleep): a slept agent whose tab isn't mounted answers by its saved handle to list, show, send, waits and wake

* fix(agent-sleep): a slept handle is awake only once its record names the resumed process

* fix(agent-sleep): a launch-config refresh of a sleep record keeps the handle the pane slept under

* perf(agent-sleep): a pane's last sleep check reads only its tab's foreground time, and the host-connect reader keeps only connected hosts

* perf(agent-sleep): a pane's last sleep check reads only its own drivers and input stamp, and a removed host's cached sleep records go

* fix(agent-sleep): a sleeper whose host was removed and came back still counts as an arrival, so its owned mail is read

* perf(agent-sleep): a pane's last sleep check reads only its own process's driver, and session-tab changes build no scope with nobody listening

* perf(agent-sleep): a pane's last sleep check asks attention for and plans over only its own process, not its tab's split or the whole workspace

* perf(agent-sleep): sleep admission reads only a pane's newest Run and its Runs with mail, the last sleep check survives sibling edits without reindexing, held-mail receipts read one catalog row, scoped terminal lists read one workspace's sleepers, and unnamed crew changes re-check owed mail once a second

* test(agent-sleep): bind the real Run reads before counting them

* fix(agent-sleep): a sleep check still finds its tab after the coordinator restarts or its cached positions overflow

* perf(agent-sleep): sleep admission and wake re-checks find a pane's Runs from mail awaiting delivery, a pane's retry, a PTY exit, a targeted wake, a handle-scoped list and an unmounted act read only their own target, the final check keeps its owner, and session writes that change no sleeper list no hosts

* test(agent-sleep): the saved hosts include the written one

* fix(agent-sleep): a slept pane's stopped process survives archive pruning whichever binding names it, and a removed host with no sleepers keeps no cached input

* perf(agent-sleep): Run mail checks probe the pane's own Runs again, not every queued Run message; a pane-keyed mail index is the follow-up

* fix(agent-sleep): a woken Claude agent resumes on the model it was launched with

* fix(agent-sleep): a woken Claude agent resumes on the model it last reported, falling back to its launch model

* revert(agent-sleep): resume no longer saves Claude's launch model; Claude restores the conversation's own model, which a saved flag would override

* fix(agent-sleep): a resumed agent starts with its update screen off, so a woken Codex can't take Orca's first Enter as 'Update now'

* chore(agent-sleep): keep the window lifecycle under the line limit after main's growth

This branch has not been deployed

No deployments
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