Repository navigation
fix(orchestration): point idle headless terminals at their mail - #33258
Conversation
A headless orca serve publishes no window leaves, so the mailbox lookups (getLiveLeafForHandle, leaves, handleByLeafKey, the title idle edge) found no target and the pointer never reached a live coordinator. When no window publishes a terminal's pane, its connected PTY record now stands in as the mailbox target, built from the runtime's existing PTY-lane lookups. A window leaf stays authoritative, and the idle and settled gates are unchanged. Fixes #33228 Co-authored-by: Fede654 <[email protected]>
Walkthrough
Priority: Severity of issue fixed: Medium Merge Risk:
|
A window host's missing leaf means a reload, crash or unmounted pane, so the lane must not type there. It now runs only under ready headless graph authority, keeps assertGraphReady, and defers to any leaf that holds the PTY. The parked submit target reuses the same PTY leaf builder. Co-authored-by: Fede654 <[email protected]>
… pane A retained predecessor and its replacement can both be connected at the same recorded pane; the lane now finds no owner then, so mail waits for an explicit check instead of reaching the wrong process. Co-authored-by: Fede654 <[email protected]>
The headless lane now also refuses a pane a window retracted before it closed, and the delayed Enter re-runs the same owner check, so a claimant that appears after the pointer is typed withholds the submit. Co-authored-by: Fede654 <[email protected]>
… flowing Restoring headless authority clears handle records the PTY lane still owns; mailbox handle checks now re-issue them under headless authority, as other PTY-owned handle reads do. Co-authored-by: Fede654 <[email protected]>
# Conflicts: # src/main/runtime/terminal/wait/terminal-wait-settlements.ts
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3d74d568-7934-4dba-bb5d-3e4d3ff8b3f3
Files selected for processing: 10-
src/main/runtime/construction/runtime-construction-services.tssrc/main/runtime/construction/runtime-service-state.tssrc/main/runtime/orchestration-headless-mailbox-pointer.test.tssrc/main/runtime/orchestration-mailbox-notification-test-harness.tssrc/main/runtime/orchestration/pty-mailbox-leaf.tssrc/main/runtime/orchestration/terminal-authority/write-orchestration-pointer-pty.tssrc/main/runtime/orchestration/terminal-pane-mail-routing.tssrc/main/runtime/terminal/output/terminal-title-observation.tssrc/main/runtime/terminal/query/pty-terminal-summary.tssrc/main/runtime/terminal/wait/terminal-wait-settlements.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
-
| ? pty?.connected && | ||
| pane?.tabId === stagedLeaf.tabId && | ||
| isTerminalLeafId(stagedLeaf.leafId) && | ||
| pane.paneKey === makePaneKey(stagedLeaf.tabId, stagedLeaf.leafId) | ||
| ? { | ||
| ...stagedLeaf, | ||
| writable: true, | ||
| lastAgentStatus: pty.lastAgentStatus, | ||
| lastAgentStatusObservedLive: pty.lastAgentStatusObservedLive, | ||
| lastOscTitle: pty.lastOscTitle | ||
| } | ||
| pane.paneKey === makePaneKey(stagedLeaf.tabId, stagedLeaf.leafId) && | ||
| // Re-checked at Enter: a second claimant may have appeared since the pointer was staged. | ||
| this.headlessMailboxLaneAdmitsPty(pty) | ||
| ? { ...stagedLeaf, ...ptyMailboxLeaf(stagedLeaf, pty) } | ||
| : null | ||
| : currentLeaf.ptyId === ptyId | ||
| ? currentLeaf |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
sed -n '1,135p' src/main/runtime/orchestration/terminal-authority/write-orchestration-pointer-pty.ts sed -n '1,225p' src/main/runtime/orchestration/mailbox-pointer-stage.ts sed -n '1,145p' src/main/runtime/orchestration/mailbox-pointer-submit.ts git diff 7dfae5e1d6e9e7f4aff93311744d4dddcd582928 1c7576ed2f906fa2dd3cd5804d13ed8b1bf4d5e4 -- src/main/runtime/orchestration/terminal-authority/write-orchestration-pointer-pty.ts src/main/runtime/terminal/query/pty-terminal-summary.ts
Repository: stablyai/orca
Length of output: 25713
Script executed:
set -o pipefail printf '%s\n' '--- symbol usages ---' rg -n -F --glob '*.ts' \ -e 'headlessMailboxLaneAdmitsPty' \ -e 'resolveOrchestrationPointerSubmitTarget' \ -e 'getPtyLaneMailboxTargetForPty' \ -e 'stageOrchestrationMailboxPointer' \ -e 'OrchestrationMailboxDeliveryFlight' \ src/main/runtime src/main/runtime/orchestration || test "$?" -eq 1 printf '%s\n' '--- changed and related tests ---' rg -n -F --glob '*.test.ts' \ -e 'parked' \ -e 'promotion' \ -e 'window' \ -e 'headlessMailboxLaneAdmitsPty' \ -e 'resolveSubmitTarget' \ src/main/runtime/orchestration src/main/runtime/session-graph || test "$?" -eq 1 printf '%s\n' '--- runtime subclasses ---' rg -n -F --glob '*.ts' \ -e 'extends OrcaRuntimeWithWriteOrchestrationPointerPty' \ -e 'protected headlessMailboxLaneAdmitsPty' \ src/main/runtime || test "$?" -eq 1
Repository: stablyai/orca
Length of output: 17313
Script executed:
rg -n -F --glob '*.ts' -e 'headlessMailboxLaneAdmitsPty' -e 'resolveOrchestrationPointerSubmitTarget' -e 'getPtyLaneMailboxTargetForPty' -e 'OrchestrationMailboxDeliveryFlight' src/main/runtime/orchestration src/main/runtime || test "$?" -eq 1
Repository: stablyai/orca
Length of output: 6150
Script executed:
set -o pipefail printf '%s\n' '--- pty summary target selection ---' sed -n '120,215p' src/main/runtime/terminal/query/pty-terminal-summary.ts printf '%s\n' '--- mailbox delivery binding ---' sed -n '110,175p' src/main/runtime/orchestration/mailbox-pointer-delivery.ts sed -n '250,280p' src/main/runtime/construction/runtime-service-state.ts printf '%s\n' '--- target and flight contracts ---' sed -n '1,90p' src/main/runtime/orchestration/mailbox-pointer-submit.ts sed -n '1,75p' src/main/runtime/orchestration/mailbox-pointer-state.ts sed -n '1,130p' src/main/runtime/orchestration/mailbox-owner.ts printf '%s\n' '--- concrete target fixtures ---' sed -n '1,75p' src/main/runtime/orchestration/mailbox-pointer-stage.test.ts sed -n '120,180p' src/main/runtime/orchestration/mailbox-pointer-submit.test.ts sed -n '260,320p' src/main/runtime/orchestration/mailbox-pointer-submit.test.ts
Repository: stablyai/orca
Length of output: 24443
Reject parked targets outside the ready headless lane.
The mailbox delivery path only returns a parked target from getPtyLaneMailboxTarget, which already requires ready headless authority. Desktop parked delivery does not depend on off-lane admission.
The current negated predicate lets a headless-staged flight pass after window promotion and graph reload. Delayed submission can then send '\r' to the promoted desktop PTY.
Suggested fix
- return !this.servesHeadlessMailboxLane() || this.getPtyLaneMailboxTargetForPty(pty) !== null
+ return this.servesHeadlessMailboxLane() && this.getPtyLaneMailboxTargetForPty(pty) !== null
ELI5
When a worker sends mail to a coordinator agent, Orca types a short note into the coordinator's terminal ("You have 1 orchestration message. Run
orca orchestration check"). On a headlessorca servethat note never arrived, because Orca only looked for terminals that a desktop window was showing, and a headless server has no window. This change lets Orca find the terminal directly.What Changed
orca serve, Run mail was stored but the coordinator never got the pointer. That was true whether the mail arrived while the agent was idle or while it was working and the agent went idle afterwards. Users had to pollorca orchestration check.Mechanism: the mailbox code found its target pane only through window-published leaves (
getLiveLeafForHandle,leaves,handleByLeafKey, and the title idle edge'sgetLeavesForPty). A headless server publishes none, sogetLiveLeafForHandlethrewterminal_handle_stale, the pointer path swallowed it, and the idle edge had nothing to visit. Under ready headless graph authority, a connected PTY's recorded pane now stands in as the mailbox target. One owner check (getPtyLaneMailboxTargetForPtyinpty-terminal-summary.ts) decides it, and it is used by every step:The check admits a PTY only when all of these hold:
The idle and settled gates are unchanged. A cancelled desktop promotion clears handle records the PTY still owns, so the mailbox handle check re-issues them under headless authority, as other PTY-owned handle reads already do.
Why
This fixes the actual cause, the window-only target lookup, rather than adding a second delivery path. The contributor PR #33230 (by @Fede654) had the same idea, and it was right: a connected PTY is the target when no window leaf exists. But it built a separate set of "parked leaf" helpers (+503 lines), including a scan of every PTY per lookup and a change to how retries stop that the window path doesn't share. This PR routes the same idea through the PTY-lane lookups the runtime already uses for
terminal wait, rename and activation, with one owner check and one gate and retry policy shared with the window path. I also compared it with the background-PTY fallback in #8057.Thanks to @Fede654 for the very detailed report and live before/after in #33228, which pinned the cause (
terminal_handle_stalewith zero leaves). They are credited as co-author on the commit.Linked Issue
Fixes #33228
Visual Proof
N/A. There is no UI change; the effect is keystrokes written into a headless terminal. The live run below shows the stdin ledger.
Testing
New
src/main/runtime/orchestration-headless-mailbox-pointer.test.ts, run against true headless graph authority. Each case fails without the fix it covers:Live, on macOS: I built
orcadfrom origin/main and from this branch and ran each headless with isolated HOME and userData on a loopback port. The fake agent ran in a real PTY created byorca terminal create, showedCodex working/Codex donetitles and recorded every stdin chunk. The coordinator was bound withorchestration run-create --from, and mail was sent withorchestration send --to run:<id> --type status.\rabout 500 ms later; working, nothing while working, then the pointer once idle.Related runtime suites, single worker: orchestration/, terminal/, mailbox, tui-idle and delivery tests, 172 of 173 files passed. The one failure was
terminal/surface/pty-pane-copy-census.test.ts, which runs out of heap on this machine on origin/main as well.The full static job ran locally (all steps), and
smoke:orcad-terminalpassed.Not verified: Linux and Windows hosts, and a real model acting on the pointer.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Codex and an independent review found several fail-closed gaps over the rounds:
All are fixed, each with a test, and they now meet in the one owner check above. Codex is clean on the current head against the pinned base 0302e0a.
ref-oss check (after round 3): remote terminal servers address server-initiated input by the terminal process's own identity, and treat UI ownership as advisory. That matches this design. The PTY record and its process incarnation are the identity, and the pane binding is only trusted when unambiguous. A redesign that routes Run mail by coordinator handle instead of pane would touch the whole mailbox subsystem and is out of scope, so the approach did not change.
Agent skill upstream boundary
Notes
orcad, and old clients are unaffected.terminal-agent-status-and-submission.ts) still iterates window leaves only.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)