Skip to content

fix(orchestration): point idle headless terminals at their mail - #33258

Merged
nwparker merged 6 commits into
mainfrom
nwparker/headless-mail-pointer
Oct 25, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/headless-mail-pointer

Conversation

@nwparker

@nwparker nwparker commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​191 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​191
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​172 $\color{#cf222e}{\Huge{\mathbf{−}}}$​27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145

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 headless orca serve that 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

  • Before: on a headless 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 poll orca orchestration check.
  • After: the pointer and its Enter reach the idle coordinator in both cases. Mail that arrives while the agent is working still waits until it goes idle.

Mechanism: the mailbox code found its target pane only through window-published leaves (getLiveLeafForHandle, leaves, handleByLeafKey, and the title idle edge's getLeavesForPty). A headless server publishes none, so getLiveLeafForHandle threw terminal_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 (getPtyLaneMailboxTargetForPty in pty-terminal-summary.ts) decides it, and it is used by every step:

  • target lookup by handle and by pane, wired into the mailbox owner, pointer delivery and notifications;
  • the settled-to-type gate and its quiet-time recheck;
  • the title idle edge for a PTY with no window leaf;
  • the delayed Enter, re-checked through the parked submit target, which now reuses the same PTY leaf builder.

The check admits a PTY only when all of these hold:

  • the host is a ready headless graph, not a window whose graph is empty, reloading, crashed or unavailable, so those keep failing closed;
  • no window leaf holds that pane or that PTY;
  • it is the only live PTY claiming the pane;
  • its pane was not retracted by a window before it closed.

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_stale with 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:

    • delivery: an already idle coordinator gets the pointer and Enter; mail that arrives while working is pointed at on the working-to-idle edge; a name-only idle title waits for the quiet-time recheck; delivery still works after a cancelled desktop promotion;
    • fail-closed controls: no typing on a window host whose graph is empty or unavailable; no typing while two live PTYs claim the pane; no Enter when a second claimant appears after the pointer is typed; no typing into a pane a serve window retracted before it closed.
  • Live, on macOS: I built orcad from 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 by orca terminal create, showed Codex working/Codex done titles and recorded every stdin chunk. The coordinator was bound with orchestration run-create --from, and mail was sent with orchestration send --to run:<id> --type status.

    • origin/main: already idle, no pointer; working then idle, no pointer; the ledger stayed empty.
    • this branch: already idle, pointer then \r about 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-terminal passed.

  • 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:

  • the lane also fired on window hosts with an empty or unavailable graph;
  • two live PTYs could claim one pane;
  • a second claimant could appear between the pointer and its Enter;
  • a pane a window had retracted could be revived;
  • a cancelled promotion dropped handle records the lane still needed.

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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Desktop is unchanged. The lane runs only under ready headless graph authority, so a window host's unmounted, reloading or crashed panes still get no pointer until a leaf exists.
  • SSH and mixed versions: there are no wire or protocol changes. This is host-local logic, so it ships with the host's orcad, and old clients are unaffected.
  • Folder workspaces are unaffected (the lookup is by pane and PTY, not by git).
  • Out of scope: the disproved-agent-exit restore edge (terminal-agent-status-and-submission.ts) still iterates window leaves only.

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)
  • 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)

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]>
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds PTY-backed mailbox targets for connected terminals without graph leaves in the ready headless runtime. Mailbox routing, pointer delivery, idle-edge detection, and settlement checks use these targets when graph leaves are unavailable. Tests cover mail arriving while idle, mail arriving while working and then becoming idle, delayed delivery for a name-only pane, and cases involving competing PTYs or unavailable window graphs.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to 1c757

Changing from headless to a window during the pointer delay can send an unintended Enter to the terminal. Fix the admission check before merging if this transition must remain fail-closed.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: routing orchestration mail pointers to idle headless terminals.
Description check Passed The description follows the required template and provides a clear user-facing explanation, implementation details, rationale, linked issue, testing evidence, limitations, and completed checklist item…
Linked Issues check Passed Issue #33228 requires pointer delivery to a connected PTY when a ready headless graph has no window leaf. getPtyLaneMailboxTargetForPty implements this path and keeps a graph leaf authoritative. It …
Out of Scope Changes check Passed The production changes support issue #33228 by sharing PTY-lane target resolution across mailbox lookup, pointer delivery, idle-edge handling, settlement, and delayed Enter. The new PTY leaf helper, s…
Full details: Description check

Explanation

The description follows the required template and provides a clear user-facing explanation, implementation details, rationale, linked issue, testing evidence, limitations, and completed checklist items.

Full details: Linked Issues check

Explanation

Issue #33228 requires pointer delivery to a connected PTY when a ready headless graph has no window leaf. getPtyLaneMailboxTargetForPty implements this path and keeps a graph leaf authoritative. It fails closed for non-ready window graphs, pane retraction, multiple PTY claimants, and invalid handles. Mailbox lookup, idle-edge delivery, settlement recheck, and delayed Enter use the shared target checks. The added tests cover idle mail, working-to-idle mail, quiet-time gating, and the reported fail-closed cases. The existing idle and submission gates remain in use.

Full details: Out of Scope Changes check

Explanation

The production changes support issue #33228 by sharing PTY-lane target resolution across mailbox lookup, pointer delivery, idle-edge handling, settlement, and delayed Enter. The new PTY leaf helper, service declarations, test harness option, and focused test suite support or verify that implementation. No unrelated change is demonstrated by the whole-PR summary.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

nwparker and others added 5 commits October 24, 2026 14:22
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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Commits

Reviewing files that changed from the base of the PR and between c59c24c and 1c7576e.

Files selected for processing: 10
  • src/main/runtime/construction/runtime-construction-services.ts
  • src/main/runtime/construction/runtime-service-state.ts
  • src/main/runtime/orchestration-headless-mailbox-pointer.test.ts
  • src/main/runtime/orchestration-mailbox-notification-test-harness.ts
  • src/main/runtime/orchestration/pty-mailbox-leaf.ts
  • src/main/runtime/orchestration/terminal-authority/write-orchestration-pointer-pty.ts
  • src/main/runtime/orchestration/terminal-pane-mail-routing.ts
  • src/main/runtime/terminal/output/terminal-title-observation.ts
  • src/main/runtime/terminal/query/pty-terminal-summary.ts
  • src/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.

Comment on lines 60 to 69
? 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

🔎 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

@nwparker
nwparker merged commit 843e502 into main Oct 25, 2026
40 checks passed
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.

Headless orca serve stores orchestration mail but never sends the idle pointer

1 participant