Skip to content

fix(orchestration): hold the mailbox nudge while the composer has a draft - #27195

Closed
Hotragn wants to merge 3 commits into
stablyai:mainfrom
Hotragn:fix/orchestration-nudge-waits-for-draft
Closed

Hotragn wants to merge 3 commits into
stablyai:mainfrom
Hotragn:fix/orchestration-nudge-waits-for-draft

Conversation

@Hotragn

@Hotragn Hotragn commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

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 message in that same box, Orca typed on top of it and the Enter sent your unfinished message, with the nudge glued to the end. Now Orca waits: while you have unsent text in the box, it doesn't type the nudge. Once you send your message (or clear it with Ctrl+C), the nudge comes at the next chance, and no mail is lost.

What Changed

  • Before: the only checks before typing the nudge are whether the agent is idle, whether a waiter is holding the mailbox, and the in-flight bookkeeping. Nothing looks at whether the composer holds text. The idle check passes as soon as the agent finishes its turn, even while you are typing, so the nudge and its Enter land on your draft.
  • After:
    • TerminalRunFactsRegister.recordInput, which both write paths already call for every byte going to a PTY, now also tracks per PTY whether text was typed or pasted since the last Enter.
    • The rules:
      • printable text, or anything inside a bracketed paste, starts a draft;
      • a bare \r, kitty's ESC[13u Enter, or Ctrl+C ends it;
      • Shift+Enter (ESC CR / ESC[13;2u), arrows, Esc, Alt+key, Tab, Backspace, focus reports and terminal replies leave it as it was;
      • it resets when a new process replaces the pane.
    • OrchestrationMailboxPointerDelivery.deliver checks this right before it would type a new pointer. If there is a draft, it types nothing. The mail stays unread in the DB, so the idle edge after you send, or the next message, offers it again. orca orchestration check still returns it at any time.
    • Orca's own pointer bytes don't count as a draft: writeOrchestrationPointerPty saves the draft state before its write and restores it right after. Input is recorded synchronously inside that write, so the restore can't undo a keystroke.
  • I put the check after the in-flight Enter, flight, watermark and crash-resume handling, so pointers Orca already typed finish the way they do today. Only the decision to start a new pointer changes.

Why

The issue lists three options: skip the nudge while the box has text, a setting to turn the nudge off (#26767), or deliver it outside the input line. I went with the first. It fixes the actual damage (your message sent half-written) without making anyone change settings, and it keeps the nudge for people who rely on it.

I track input bytes instead of reading the screen. Orca already sees every byte going into the PTY, and screen rules differ for every agent and break when an agent changes its prompt.

Each rule above is there to avoid a specific mistake:

Known limit: if you type and then delete everything with Backspace, Orca can't prove the box is empty, so the nudge waits until your next Enter or the next message. Waiting a little longer is the safe side here.

The 500 ms gap between the pointer text and its Enter is a separate race: you start typing exactly then. #26928 is already changing that Enter path (mailbox-pointer-submit.ts), so I left it alone to stay out of that PR's way. This change only touches one wiring line next to it.

Linked Issue

Fixes #26992

Visual Proof

N/A. No UI changes: the difference is that Orca no longer types into the terminal while a draft is there. The tests below cover it.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • terminal-run-facts.test.ts:

    • a draft lives until Enter, kitty Enter or Ctrl+C;
    • Shift+Enter, newlines in a bracketed paste split across writes, terminal replies and focus reports keep it;
    • Esc, arrows, SS3, Alt+key, Backspace and Tab don't start one;
    • a new process or delete drops it.
  • mailbox-pointer-stage.test.ts: with a draft, deliver writes nothing and reserves nothing. Once the draft is sent, the same mail is pointed. I checked that this test fails with the gate removed.

  • terminal-run-facts-input.test.ts: through the real runtime write funnel, Orca's own pointer write leaves no draft and keeps a user's draft. I checked that this test fails without the save/restore.

  • pnpm tc:node, oxlint, oxfmt and pnpm run check:code-quality:changed pass. I also ran every suite under src/main/runtime and src/main/ipc/pty (1,248 files, 12,725 tests): all pass on macOS.

I did not run a live Claude Code coordinator for this; the tests drive the delivery and write funnel directly.

AI Disclosure

I used Claude Code (Claude Opus 5.5) to trace the delivery path and the input write funnel, and to draft the change and tests. I chose where the gate goes, reworked the rules after spotting the Esc and Cursor cases, and reviewed every line.

Review

My review of the change, with the agent's help:

  • Cross-platform: byte-level rules that are the same on macOS, Linux and Windows. Windows input-record newlines (ESC CR, ESC[13;2u) count as newlines, not sends.
  • SSH / remote: the register and the delivery both live on the execution host. Input from the desktop, mobile or a paired client reaches that host's write funnel, so the host that decides to type the nudge is the one that saw the draft.
  • Agents:
    • the rules are agent-neutral, and Cursor's no-Enter pointer is unaffected;
    • a create-time draft Orca leaves in the composer counts as a draft, which is right: the nudge's Enter would have sent it too.
  • Performance: one pass over each input chunk, and one small map entry per PTY, cleared with the PTY.
  • Security: no new inputs or IPC. It only decides not to write.
  • Mobile / compatibility: no wire or RPC change, so older and newer peers are unaffected.

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

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)

…raft

Orca typed "You have N orchestration message(s)..." and Enter into a
coordinator pane even when the user had unsent text in the agent's input
box, so the Enter sent their half-written message with the nudge on the end.

The run-facts register already sees every byte written to a PTY. It now
also tracks whether text was typed or pasted since the last Enter or
Ctrl+C. Delivery checks that before typing a new pointer and leaves the
mail unread for the next idle edge or message. Orca's own pointer bytes
stay out of that state.

Fixes stablyai#26992
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Terminal input now updates per-PTY composer draft state. Mailbox pointer delivery skips targets with unsubmitted input, leaving messages unread for a later attempt. Pointer writes save and restore the draft state, including when a write throws. Tests cover draft tracking, delivery deferral, and retry after the draft is cleared.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to cb8b6

A coordinator message may remain unread after the user submits or cancels a draft, until another delivery event occurs. Add a post-input retry before merging, or explicitly accept that delay.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: delaying mailbox nudges while the composer contains a draft.
Description check Passed The description is complete and follows the repository template. It explains the user impact, implementation, rationale, linked issue, lack of visual changes, tests, AI disclosure, compatibility consi…
Linked Issues check Passed The changes satisfy the coding objective in [#26992]. TerminalRunFactsRegister tracks per-PTY draft state for typed and pasted input, clears it on Enter, kitty Enter, or Ctrl+C, and resets it for a …
Out of Scope Changes check Passed The changes are limited to draft tracking, pointer-delivery gating, pointer-write state preservation, required runtime wiring, and focused tests. These changes directly support [#26992]. The diff does…
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ea262129-f9b4-4c4d-86af-0f4210457d83
📥 Commits

Reviewing files that changed from the base of the PR and between cbeb703 and 3c240e2.

📒 Files selected for processing (8)
  • src/main/runtime/orca-runtime-stop-requested-pty-ids.ts
  • src/main/runtime/orca-runtime-write-orchestration-pointer-pty.ts
  • src/main/runtime/orchestration/mailbox-pointer-delivery-contract.ts
  • src/main/runtime/orchestration/mailbox-pointer-delivery.ts
  • src/main/runtime/orchestration/mailbox-pointer-stage.test.ts
  • src/main/runtime/terminal-run-facts-input.test.ts
  • src/main/runtime/terminal-run-facts.test.ts
  • src/main/runtime/terminal-run-facts.ts

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

Comment thread src/main/runtime/terminal-run-facts.ts Resolved
Comment thread src/main/runtime/terminal-run-facts.ts Resolved

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Retry pending delivery after the draft is cleared. · mailbox-pointer-delivery.ts:121-124

src/main/runtime/orchestration/mailbox-pointer-delivery.ts:121-124
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Retry pending delivery after the draft is cleared.

When OrchestrationMailboxPointerDelivery.deliver returns at mailbox-pointer-delivery.ts:121-124, it leaves the message unread. Enter and Ctrl+C clear the tracked draft, but the input paths only record the input and write it to the PTY. They do not request mailbox delivery.

The settlement timer does not cover this case. It is armed only when the settlement check rejects delivery, while the draft gate returns before that check. An already-idle coordinator can therefore keep the message unread until another delivery event occurs.

Add a retry after an accepted user input that clears the draft. Keep the draft check in OrchestrationMailboxPointerDelivery.deliver, so the retry cannot write into an active draft.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fccb642e-1ea6-4879-b3f6-f19c73f46668
📥 Commits

Reviewing files that changed from the base of the PR and between 3c240e2 and cb8b6f2.

📒 Files selected for processing (2)
  • src/main/runtime/terminal-run-facts.test.ts
  • src/main/runtime/terminal-run-facts.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/runtime/terminal-run-facts.test.ts
  • src/main/runtime/terminal-run-facts.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.

…udge-waits-for-draft

# Conflicts:
#	src/main/runtime/terminal-run-facts.ts
nwparker added a commit that referenced this pull request Oct 25, 2026
…n unsent draft (#33429)

Hold the orchestration mailbox pointer (and coordinator nudges) while the agent's composer has an unsent draft, so Orca never submits over what the user is typing.

Fixes #26992
Supersedes #27195

Co-authored-by: Hotragn <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor

Thanks @Hotragn! The fix landed in #33429 (merged, with your co-author credit), rebased onto the current mailbox-pointer and composer-draft code. Closing this one in favor of it.

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

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

2 participants