Skip to content

fix(orchestration): hold the mailbox pointer while the composer has an unsent draft - #33429

Merged
nwparker merged 7 commits into
mainfrom
nwparker/agint-26992
Oct 25, 2026
Merged

nwparker merged 7 commits into
mainfrom
nwparker/agint-26992

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​94 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45

ELI5

When a coordinator agent gets orchestration mail, Orca types "You have N orchestration message(s)…" into its terminal and presses Enter. If you were halfway through typing your own prompt there, Orca typed on top of it and the Enter sent your half-written prompt with the nudge glued on. Now Orca waits while the agent's input box shows unsent text. Once you send or clear it, the nudge arrives on the next check. The wait has a limit: it ends 10 minutes after your last keystroke, so a draft you walked away from (or a misread screen) can't hold mail forever.

Root cause

isAgentSettledForDelivery (the single gate in front of OrchestrationMailboxPointerDelivery.deliver) only checked agent idleness and, since #33366, an open Claude dialog. Nothing checked the composer, so an idle Claude/Codex pane with a typed draft passed the gate and got pointer + \r.

What changed (reuse, no new subsystem)

  • terminal-wait-settlements.ts: the existing hold predicate that fix(orchestration): hold mailbox pointers while the agent shows an open dialog (#21745) #33366 added (open dialog → refuse and recheck at 2s instead of 20 Hz) now also holds while the live screen model shows a composer draft. It reads the draft with the existing detectTerminalComposerDraft (src/shared/terminal-composer-draft.ts, the same reader the terminal projection uses). It only holds when the last driving (user/client) input is within USER_INPUT_HOLD_CAP_MS (10 min, renamed from CLAUDE_DIALOG_HOLD_CAP_MS since both holds share it), so the hold is bounded. TerminalRunFactsRegister gained readLastDrivingInputAt, so Orca's own launch writes (prefilled startup drafts, launch follow-ups) never hold its own mail.
  • Orca's own orchestration writes (mailbox pointer mailbox-pointer-pty-write.ts, dispatch preamble preamble.ts, external-message turns send-agent-turn.ts, Claude agent-teams tmux dispatcher) now use a new TerminalInputKind 'orchestration'. Every former === 'driving' consumer in main (run facts, terminal-use listeners, Claude input evidence, remote-desktop floor) treats it as driving via isDrivingInputKind. Only the hold clock ignores it. The value never leaves the main process: renderer, IPC and RPC inputs keep their existing kinds.
  • terminal-composer-draft.ts: Codex before 0.152 shows a rotating dim placeholder (codex-rs/tui/src/chatwidget.rs PLACEHOLDERS/SIDE_PLACEHOLDERS, removed in Use consistent TUI input placeholders openai/codex#37360). The reader's rawAfterCursor fallback read these as drafts. They're now stock placeholders. A real codex 0.137.0 frame (__fixtures__/codex-0-137-0-rotating-placeholder.txt) previously read {text:"Explain this codebase"} and now reads null.
  • Only the commit-to-type gate changes. The delayed-Enter path (mailbox-pointer-submit.ts) still uses isPtyAwaitingUserInput alone, so Orca's own pointer text sitting in the composer never blocks its own Enter.
  • The same gate fronts every runtime mailbox delivery edge (title idle, neutral-title restore, session graph), so all of them hold the same way.

Compared with #27195 (input-byte draft tracking in TerminalRunFactsRegister, +242): this change reads the draft from the screen model with the existing reader and plugs into the existing #33366 hold. That makes it about 20 non-test lines, with no new state machine for keystrokes, Shift+Enter, kitty Enter, or bracketed paste. Backspacing to empty is handled exactly, because the screen shows an empty composer.

Agent evidence (upstream)

Captured real PTY bytes from Claude Code 2.1.310 and codex (installed CLIs, 120x40 and 80x24) at an empty composer and after typing please refactor the auth mod. Fed through HeadlessEmulator + detectTerminalComposerDraft:

  • Claude empty → null (the Try "…" placeholder is excluded); Claude draft → {text:"please refactor the auth mod", promptGlyph:"❯"}
  • Codex empty → null (Ask Codex to do anything is excluded); Codex draft → {text:"please refactor the auth mod", promptGlyph:"›"}

Verification

  • Repro on main, real Claude bytes through the real runtime delivery path (scratch test using orchestration-mailbox-notification-test-harness, not checked in): with the Claude 2.1.310 draft screen, main writes ["\nYou have 1 orchestration message. Run orca-dev orchestration check --run ….\n", "\r"], which submits the draft. With this branch it writes []. With the empty-composer capture, both deliver normally.
  • Regression test added to orchestration-open-dialog-delivery-hold.test.ts. A draft holds the pointer, and it delivers after the draft is sent, or after the cap when the draft is abandoned. It fails on main.
  • pnpm tc:node; pnpm test over src/main/runtime/orchestration*, terminal/, claude-*, tui-idle*: 2211 passed. The only failures are 3 in orchestration-cli-subprocess.test.ts (built-CLI subprocess timeouts), which fail identically on main in this worktree. check:code-quality:changed is clean.
  • I couldn't do a full Electron run: the dev renderer in this nested worktree fails tsconfig resolution (unrelated to this change).

Risk

Fixes #26992. Supersedes #27195 (credit: @Hotragn, co-author).

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent 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: d24c0e4a-f520-419f-8daf-6cf1ebacabdf
Commits

Reviewing files that changed from the base of the PR and between c0f953a and 1d10733.

Files selected for processing: 1
  • config/flaky-test-pattern-baseline.txt
Files with no reviewable changes: 1
  • config/flaky-test-pattern-baseline.txt

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

Delivery settlement now holds orchestration messages while a PTY has a user-input dialog or a recent composer draft. Draft detection requires recent literal driving input, whole-screen state, and a detected draft on the cursor line. Orchestration writes are tracked separately from literal user-driving input. Tests cover draft detection and delivery after a draft is sent or the hold cap expires.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to 1d107

A mailbox nudge may still be delivered while a draft is present. Resolve the timestamp-loss path before merging, and confirm whether the stock-phrase case is reachable in a live pane.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning [#26992] requires that the coordinator nudge waits or is not written while the pane input buffer is non-empty. isPtyHoldingDelivery holds a detected draft only while `Date.now() - lastInputAt <= USE… Keep mailbox delivery from writing the pointer or \\r while a recognized composer draft remains visible, including after USER_INPUT_HOLD_CAP_MS. Update the regression test so an unchanged visible draft does not receive the nudge after th…
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 18 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: delaying mailbox-pointer delivery when the composer contains an unsent draft.
Description check Passed The description thoroughly covers the user impact, root cause, implementation, linked issue, testing, risks, limitations, and platform considerations. It omits the template's Visual Proof section and …
Out of Scope Changes check Passed The reviewed changes stay connected to [#26992] and its draft-protection behavior. The delivery hold, composer detection, Codex placeholder handling, orchestration input classification, hold-clock tra…
Full details: Description check

Explanation

The description thoroughly covers the user impact, root cause, implementation, linked issue, testing, risks, limitations, and platform considerations. It omits the template's Visual Proof section and several checklist sections, but the core required information is present, so the description is mostly complete.

Full details: Out of Scope Changes check

Explanation

The reviewed changes stay connected to [#26992] and its draft-protection behavior. The delivery hold, composer detection, Codex placeholder handling, orchestration input classification, hold-clock tracking, call-site updates, fixtures, and regression tests support draft detection or preserve existing delivery behavior. No unrelated change is demonstrated by the available whole-PR summary or focused source review.

Full details: Linked Issues check

Explanation

[#26992] requires that the coordinator nudge waits or is not written while the pane input buffer is non-empty. isPtyHoldingDelivery holds a detected draft only while Date.now() - lastInputAt &lt;= USER_INPUT_HOLD_CAP_MS. After the 10-minute cap, the delivery gate can write the pointer and \r while the draft remains visible. The regression test explicitly covers abandoned past the cap and expects delivery. This leaves the issue's core failure possible.

Resolution

Keep mailbox delivery from writing the pointer or \r while a recognized composer draft remains visible, including after USER_INPUT_HOLD_CAP_MS. Update the regression test so an unchanged visible draft does not receive the nudge after the cap. Preserve a separate bounded retry mechanism only if it cannot submit the draft.

  • 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
nwparker force-pushed the nwparker/agint-26992 branch from 7085c8b to 0f3c09e Compare October 25, 2026 06:35

@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: 2


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: 5d7a6af5-baf6-4076-b70f-4c885c747c3a
Commits

Reviewing files that changed from the base of the PR and between 7085c8b198d2ca7ac9dd29ccc49383d21f8ab40c and ea88febea31762253aca9368b021bc21513c1090.

Files selected for processing: 17
  • src/main/daemon/terminal-cursor-line-context.test.ts
  • src/main/ipc/pty/runtime/operations.ts
  • src/main/runtime/__fixtures__/codex-0-137-0-rotating-placeholder.meta.json
  • src/main/runtime/__fixtures__/codex-0-137-0-rotating-placeholder.txt
  • src/main/runtime/claude-agent-teams-tmux-dispatcher.ts
  • src/main/runtime/claude-open-dialog-hold.test.ts
  • src/main/runtime/claude-open-dialog-hold.ts
  • src/main/runtime/orchestration-open-dialog-delivery-hold.test.ts
  • src/main/runtime/orchestration/mailbox-pointer-pty-write.ts
  • src/main/runtime/orchestration/preamble.ts
  • src/main/runtime/orchestration/send-agent-turn.ts
  • src/main/runtime/terminal-run-facts-input.test.ts
  • src/main/runtime/terminal-run-facts.ts
  • src/main/runtime/terminal/layout/terminal-input-floor.ts
  • src/main/runtime/terminal/wait/terminal-wait-settlements.ts
  • src/shared/terminal-composer-draft.ts
  • src/shared/terminal-input-kind.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@@ -89,6 +90,7 @@ export class TerminalRunFactsRegister {
origin === 'reattach' && (incarnationId === null || !previous?.incarnationId)
if (!sameProcess) {
this.lastInputAtByPtyId.delete(commit.id)
this.lastDrivingInputAtByPtyId.delete(commit.id)

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.

Major · Functional Correctness · Heavy lift

Preserve literal-driving input recorded before the spawn commit.

If a user types after reserveSpawnCommit but before recordSpawnCommit, recordInput records the draft timestamp and pending first-input evidence. This deletion discards the draft timestamp while the pending first-input evidence survives. isPtyHoldingDelivery then cannot hold a visible unsent draft, so a mailbox pointer can submit it. Track the pending literal-driving timestamp by incarnation and carry it into the new process record.

text === 'Ask Codex to do anything' ||
text === 'Ask a follow-up question'
)
return /^Try\s+["\u201C]/.test(text) || STOCK_PLACEHOLDERS.has(text)

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.

Major · Functional Correctness · Quick win

🔎 Supported by static analysis

Script executed:

# Read the full target module with line numbers; confirm the snippet's lines and the set contents.
test -f src/shared/terminal-composer-draft.ts && cat -n src/shared/terminal-composer-draft.ts
# Locate other definitions or references of the relevant helpers across the source tree.
rg -n -F -e 'STOCK_PLACEHOLDERS' -e 'isStockPlaceholder' -e 'getCursorLineContext' -e 'detectTerminalComposerDraft' -- src/ || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 13709


Stop treating typed text as a stock placeholder.

isStockPlaceholder matches the cursor suffix against the stock set without checking whether that text is dim or typed. If a user types Explain this codebase and moves the cursor to the start of the phrase, the suffix equals that exact stock string. The check then clears the suffix. With nothing before the cursor, the composer text is empty, and detectTerminalComposerDraft returns null. Callers that treat null as "no draft" can then deliver into a pane that holds unsent user text.

The trigger is narrow. It needs the cursor before the phrase and an exact match of the full suffix. The /^Try\s+["\u201C]/ branch has the same gap.

Apply the placeholder rule only to dim suffix text, and keep undimmed suffix text as draft content. Add a regression case with the cursor at the start of a typed stock phrase.

nwparker and others added 5 commits October 25, 2026 00:21
…n unsent draft (#26992)

The coordinator nudge plus its Enter was typed onto the user's half-written
prompt and submitted it. Delivery now also holds while the pane's composer
shows a draft (read with the existing terminal-composer-draft reader), on the
same settled-for-delivery gate and 2s recheck as the open-dialog hold. The hold
lapses 10 minutes after the last input so an abandoned or misread draft cannot
strand mail.

Co-authored-by: Hotragn Pettugani <103170876+Hotragn@users.noreply.github.com>
…otating placeholders

- Hold clock reads driving input only, so Orca's own launch writes and
  prefilled drafts never hold its own mail.
- Codex < 0.152 rotating placeholders (codex-rs/tui/src/chatwidget.rs
  PLACEHOLDERS / SIDE_PLACEHOLDERS) are stock placeholders, not drafts;
  covered by a real codex 0.137.0 frame.
- Rename the shared cap to USER_INPUT_HOLD_CAP_MS.

Co-authored-by: Hotragn Pettugani <103170876+Hotragn@users.noreply.github.com>
…he draft-hold clock

Mailbox pointers, dispatch preambles, external-message turns and the Claude
agent-teams tmux dispatcher now write with inputKind 'orchestration', which is
treated as driving input everywhere (run facts, terminal-use listeners, Claude
input evidence, remote-desktop floor) except the user-input hold clock.

Co-authored-by: Hotragn Pettugani <103170876+Hotragn@users.noreply.github.com>
…ration input

Co-authored-by: Hotragn Pettugani <103170876+Hotragn@users.noreply.github.com>
…mposer

Co-authored-by: Hotragn Pettugani <103170876+Hotragn@users.noreply.github.com>
@nwparker
nwparker force-pushed the nwparker/agint-26992 branch from 6cb0e65 to c0f953a Compare October 25, 2026 07:24
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.

[Bug]: Coordinator nudge is typed over the user's unsent draft and submits it

1 participant