Skip to content

fix: deliver orchestration pointers to idle headless PTYs - #33230

Closed
Fede654 wants to merge 2 commits into
stablyai:mainfrom
Fede654:Fede654/fix-headless-mailbox-pointer
Closed

Fede654 wants to merge 2 commits into
stablyai:mainfrom
Fede654:Fede654/fix-headless-mailbox-pointer

Conversation

@Fede654

@Fede654 Fede654 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

ELI5

On a headless Orca server, a coordinator could be idle with new orchestration mail and never receive the prompt to check its inbox. The server kept the message, so someone had to notice it or the coordinator had to poll. With this change, the connected terminal receives the pointer when it is idle, including after it finishes a turn.

What Changed

orca serve publishes an empty renderer graph, yet the pointer delivery path required a renderer leaf. The runtime now uses a live PTY record as a parked mailbox leaf when no graph leaf exists. It reads the PTY's observed agent title and idle evidence, resolves the terminal handle for pointer submission, and offers pending mail on a working-to-idle transition. Existing graph leaves remain authoritative. Headless regressions cover arrival while idle, mail held until idle, and the delivery guards.

Why

The PTY already has the connected pane identity, title and process incarnation used later in pointer submission. Reusing those records addresses the missing headless target without creating another mailbox or changing the wire protocol. PR #8057 independently proposes a background-PTY fallback and idle-edge tests; this work credits that approach and adds controlled real-PTY headless validation. The fix retains the existing settled-idle and pointer submission checks.

Linked Issue

Fixes #33228

Visual Proof

This behavior is terminal input, so the fake-agent stdin ledger is the direct before/after proof. Both arms ran on the same Linux headless hub with the same frozen harness (SHA-256 a3571c645b0dc0140aed93fe615e62beb48967e8c1c800cb1d8c9c839ea14a52), distinct disposable profiles, and no real model account.

Before, unpatched 265f143ab8d769139c108d1648af66eae1187a81:

already idle:        status sent → no stdin; pointer=false, Enter=false
working then idle:   status sent while working → no stdin → Codex done → no stdin
isolated DB:         both messages unread; delivered_at=NULL; pointer_enter_pending=0

After, audited d3b5d08e88a726ea8f9faac4e4b5d0392a74f298:

18:25:09.279  "\nYou have 1 orchestration message. Run `orca orchestration check --run run_…`.\n"
18:25:09.781  "\r"
18:25:11.384  "\nYou have 1 orchestration message. Run `orca orchestration check --run run_…`.\n"
18:25:11.884  "\r"

The first pointer followed mail sent while idle. The second followed a live Codex working → Codex done transition; the ledger stayed unchanged while working. Both fixed DB rows acquired settled delivered_at timestamps and remained unread because the harness did not run check.

Testing

  • Manually tested the exact baseline and fixed commits in separate real-PTY headless Linux orcad processes.
  • Automated empty-graph regressions added and run by the implementation worker.

Local build from immutable source archives: pnpm install --frozen-lockfile, ORCA_BACKGROUND_LAUNCH=1 pnpm build:cli, ORCA_BACKGROUND_LAUNCH=1 pnpm build:mobile-web, ORCA_BACKGROUND_LAUNCH=1 pnpm build:orcad. Baseline orcad 0.1.0+9e1634c6008e; fixed orcad 0.1.0+aa9a66ee374a. Each built package included orcad/ and its sibling pinned runtimes/ Node.

The hub test ran /tmp/orca-orchestration-audit/hub-validation/mailbox-live-smoke.mjs once per arm with red or green, under systemd-run --scope --uid=orca -p MemoryMax=1536M -p CPUQuota=100% -p TasksMax=128 and ORCA_REQUIRE_CGROUP_CAP=1 ORCA_BACKGROUND_LAUNCH=1. It verified the cap, used a loopback port and fresh HOME/profile/workspace/Run, and stopped each case's server, daemon and PTY. Full commands, artifact hashes, sanitized ledgers and isolated DB summary are in the validation handoff report. Production remained active on port 6768 with the same PID and bundle hashes before and after. The harness verified its own and server cgroup, but did not record separate daemon/agent cgroup membership, an isolated-port-close check, or an empty-scope query; it did record case-owned process cleanup as empty.

The final read-only auditor ran ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/runtime/orchestration-headless-mailbox-pointer.test.ts: 10/10 passed. The implementer reported 80 related tests, pnpm tc:node, and the changed-file quality gate passing; the exact related-test command and quality output were not preserved in this handoff. The fake agent proves pointer bytes and Enter reached a real PTY. It does not prove a real model consumes the prompt; macOS, Windows, SSH execution and mixed-version peers were not exercised.

AI Disclosure

GPT-6 Sol (medium) Codex workers implemented and audited the fix. A Codex validation worker built both artifacts and ran the isolated real-PTY before/after test; the final read-only auditor independently reran the focused suite.

Review

Agent skill upstream boundary

  • Not applicable; this change copies no upstream skill-installer source.

Notes

The execution host owns the PTY and status evidence. The change adds no RPC fields or stream opcodes. It keeps platform-dependent behavior within the existing runtime path and does not assume a Git worktree; the live harness used a disposable Git worktree, while the implementation also accepts parked PTY identities. No production service, profile, inspector or mail was modified during validation. The experimental ORCA_LAYOUT_OWNER_IS_MAIN path is still unable to reconstruct a parked leaf for a main-owned pane with no graph leaf, because that mode removes the PTY's copied tab/pane fields. This was already broken in the baseline; the switch is off in shipped builds. The final read-only audit found no actionable issue on the shipped path.

Checklist

  • This PR is small and focused
  • I explained the user-facing before/after, mechanism, and why
  • Before/after terminal proof included above
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered
  • Full repository lint, test and build gates pass or CI will cover them (10 focused tests, 80 related tests, pnpm tc:node, changed-file quality checks and local orcad builds passed as described above)

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The runtime can resolve orchestration mailbox leaves and terminal handles for eligible parked PTYs when no live graph leaf exists. Mailbox callbacks, idle-edge delivery, and delivery-settlement checks use these lookups. New tests cover pointer delivery and retry behavior across headless PTY states.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to d3b5d

The change delivers orchestration pointers to idle headless PTYs in the shipped serve path. One narrow gap remains: a layout-owner-main build would not benefit from the parked-PTY fallback. This is low risk to merge, and the pane lookup can be aligned in a follow-up or before merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: delivering orchestration pointers to idle headless PTYs.
Description check Passed The description covers the required sections, explains the user-facing behavior and implementation, links issue #33228, provides terminal proof, documents testing and limitations, and completes the ch…
Linked Issues check Passed Issue #33228 is the only active direct target. Its coding requirements are: (1) a connected headless PTY must receive the orchestration pointer when Run mail arrives while it is idle; (2) the same mus…
Out of Scope Changes check Passed All changed areas support the issue objective of mailbox pointer delivery to headless PTYs: runtime-construction-services.ts (new protected accessors), runtime-service-state.ts (callbacks switched…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 6…
Full details: Description check

Explanation

The description covers the required sections, explains the user-facing behavior and implementation, links issue #33228, provides terminal proof, documents testing and limitations, and completes the checklist. The unchecked full-repository gate is explicitly explained with the tests and builds that passed.

Full details: Linked Issues check

Explanation

Issue #33228 is the only active direct target. Its coding requirements are: (1) a connected headless PTY must receive the orchestration pointer when Run mail arrives while it is idle; (2) the same must hold when it changes from working to idle; (3) a PTY is eligible only when no renderer graph leaf exists, and a real graph leaf stays authoritative; (4) the existing idle and pointer-submission gates still apply.

Evidence from the whole-PR summary:

  • Requirement 3: getParkedOrchestrationLeafForPty in terminal-title-observation.ts and pty-terminal-summary.ts builds a parked mailbox leaf from a live PTY only when its recorded tab and pane key parse to that tab and no live leaf occupies that pane. Live graph leaves are still checked first, and runtime-service-state.ts now routes lookups through the new accessors.
  • Requirement 1: the arrival path resolves the parked leaf and terminal handle, and submits the pointer through the existing path.
  • Requirement 2: idle-edge detection in title application (working to idle, or a changed title while idle) with no live leaves triggers delivery. terminal-wait-settlements.ts applies the same parked fallback to the delayed recheck and to isAgentSettledForDelivery.
  • Requirement 4: the summary states that the settled-idle and submission checks are kept. Parked lookups return null when the PTY incarnation or handle no longer matches.
  • Automated tests: orchestration-headless-mailbox-pointer.test.ts (+376 lines) covers arrival while idle, mail held until idle, idle-edge delivery, PTY incarnation replacement, Dispatch delivery, and pending mail after PTY exit or pane adoption. The PR reports a 10/10 pass for this file. I did not re-run it, so that result rests on the reported run.

No concrete unmet coding requirement is shown. Platform and real-model checks named in the PR (macOS, Windows, SSH, mixed-version peers, real model consumption) are outside the issue's Linux headless scope or are not coding requirements. Related issues #11787, #24932, #22115, and PR #8057 are context only. The known ORCA_LAYOUT_OWNER_IS_MAIN limitation predates this PR and is not a requirement of #33228.

Full details: Out of Scope Changes check

Explanation

All changed areas support the issue objective of mailbox pointer delivery to headless PTYs: runtime-construction-services.ts (new protected accessors), runtime-service-state.ts (callbacks switched to those accessors), terminal-title-observation.ts (parked-leaf lookup and idle-edge delivery), pty-terminal-summary.ts (parked PTY lookup and handle resolution with incarnation check), terminal-wait-settlements.ts (delayed recheck and settled-idle evidence for parked PTYs), and the new headless mailbox-pointer test file. The second commit, which stops parked-mailbox retries when ineligible, is a delivery guard in the same path and matches the issue's requirement that existing gates still apply. The summary shows no unrelated feature, RPC, protocol, or UI change. The PR description's validation artifacts and checklist are documentation, not code changes. The change set is small and focused.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 6 files.

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

@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.

🧹 Nitpick comments: 1
src/main/runtime/terminal/query/pty-terminal-summary.ts: 1

141-141: Trivial · Functional Correctness · Low value

Use paneOfPty when ORCA_LAYOUT_OWNER=main is enabled.

Layout-owner records omit tabId and paneKey, so this helper rejects their parked PTYs. The shipped orca serve path does not enable this mode, so this is not a current headless-serve blocker.

Suggested fix
-    if (!pty?.connected || !pty.tabId || !pty.paneKey) {
+    if (!pty?.connected) {
       return null
     }
-    const pane = parsePaneKey(pty.paneKey)
+    const recorded = this.paneOfPty(pty)
+    if (!recorded.tabId || !recorded.paneKey) {
+      return null
+    }
+    const pane = parsePaneKey(recorded.paneKey)
     if (
       !pane ||
-      pane.tabId !== pty.tabId ||
+      pane.tabId !== recorded.tabId ||
       this.leaves.has(this.getLeafKey(pane.tabId, pane.leafId))

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: 28bd503c-f4c5-4adc-aee1-15345ecfd796
Commits

Reviewing files that changed from the base of the PR and between 13db649 and d3b5d08.

Files selected for processing: 6
  • 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/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; 9 remain after this review.

@nwparker

Copy link
Copy Markdown
Contributor

Thank you @Fede654 for this PR, and for the careful report in #33228. Your diagnosis was exactly right: on a headless orca serve no window publishes leaves, so getLiveLeafForHandle threw terminal_handle_stale, the pointer path swallowed it, and the idle edge never reached the pane. Your before/after run on a real hub, with the stdin ledger, made the bug easy to trust and to reproduce.

We shipped the fix in #33258 and kept your design: a connected PTY becomes the mailbox target when no window publishes its pane, a real window leaf stays authoritative, and the existing idle and settled-to-type gates still decide when to type. We routed it through the PTY lookups the runtime already has (getLivePtyForHandle, getPtyRecordForPaneKey, the PTY idle evidence) instead of a separate set of parked-leaf helpers, behind one pane-owner check that only runs on a ready headless graph, so both lanes share one gate and one retry policy. Your idle-arrival, working-to-idle and quiet-recheck cases became our tests, and you're credited as co-author on the commit. Closing this in favour of #33258. Thanks again!

@nwparker nwparker closed this Oct 25, 2026
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

2 participants