You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(pi): hold worker mail while a Pi editor has an unsent draft - #45907
When you type a message into Pi but have not pressed Enter yet, Orca could deliver a worker's mail into that same box and press Enter for it, sending your half-written message. Orca now notices that Pi's box has text in it and waits until it is empty before delivering mail.
What Changed
Before: in a Pi coordinator terminal, a worker's orchestration send typed Orca's mail note and Enter into Pi's editor even while the user had an unsent draft there, so the half-typed prompt was submitted together with the note.
After: mail delivery holds while Pi's editor contains a draft, the same way it already does for Claude, Codex and OpenCode.
Mechanism:hasComposerDraft in src/main/runtime/terminal/wait/terminal-wait-settlements.ts only had a layout reader for OpenCode. Every other agent went to readTerminalComposerTypedText, which looks for a prompt glyph (❯/›/»). Pi draws no glyph, so its drafts were never detected. Pi panes now use a new piComposerHoldsDraft reader (src/shared/terminal/input/pi-composer.ts). The editor is the rows between two full-width ─ rules, and any non-blank row between them counts as a draft. Text that Pi draws inside a rule, such as the ↑/↓ N more scroll markers and the working, retry or compaction status in the top rule, is still recognized as a rule. Pi shows no placeholder text, so a blank editor reads as empty.
Why
This follows the existing OpenCode pattern: each prompt-less agent gets its own layout reader, and routing is by the pane's agent. I checked the layout against Pi's source (packages/tui/src/components/editor.tsrender/createScrollBorder and custom-editor.tsrenderTopBorder). The rule check uses plain string tests, not a regex, for two reasons:
esbuild keeps ─ inside regex literals, which would break the ASCII-only orcad bundle.
The contributor's original regex backtracked quadratically on rows that start with ─ (about 700 ms per call in an adversarial case). This check is linear.
Out of scope: OMP, and Pi setups whose extensions replace the editor layout (custom editors), keep the generic reader. They behave the same as on main, so mail can still be typed over a draft there. Fixing those needs a different detector.
N/A. Nothing changes in Orca's UI. The fix changes when mail is typed into a Pi terminal. That behavior is covered by recorded Pi 1.6.0 terminal screens (empty editor, one-line draft, wrapped draft), replayed through the headless terminal emulator in the tests.
Testing
Reproduced the bug on main by replaying the recorded Pi 1.6.0 screens through HeadlessEmulator.getCursorLineContext(). The generic reader returns no draft for the draft and wrapped-draft screens, which is the bug, and the Pi reader holds for both. The empty screen does not hold either way.
Synthetic cases taken from Pi's render code: scroll markers, a draft under the working status, a narrow spinner, and text only below the cursor.
Cases that must let mail through: no rule above or below the cursor, the cursor on a rule, an empty editor while Pi works, and an empty editor under an earlier chat rule.
A routing test: a pi pane holds on the draft screen and a claude pane does not. Renaming the agent === 'pi' branch makes it fail.
serialize-grid-transcript-replay.test.ts: added the new captures' I2 counts to KNOWN_PREEXISTING_I2_FAILURES with a comment naming the cells. These are existing serializer limitations; this PR does not touch the serializer.
pty-transcript-secret-scan.test.mjs passes (156 tests), including the new transcripts.
src/shared/terminal/input and src/main/runtime/terminal/wait pass, except one failure: terminal-creation-and-readiness-part-06.spec.ts fails the same way on main.
oxlint, oxfmt, the anti-slop and code-quality oxlint configs, ast-grep and the changed-code quality gate report 0 findings.
Platforms: macOS (unit and replay tests). The reader is pure string logic with no platform-specific paths.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Perf: the reader runs only when mail is delivered or rechecked. It is not on the keystroke, terminal-stream or polling path, and it adds no I/O, timers or subprocesses. Node, per call:
Case
Time per call
Typical 30-row screen
0.06 us (the generic reader it replaces for Pi panes: about 0.2 to 0.6 us)
Adversarial, no rules (1000 rows above and 1000 below, 500 columns)
13 us
Adversarial, all spaces between rules
623 us
Adversarial, rule-prefixed rows
15 us
All cases are O(rows) and far below 16 ms.
Risk
The riskiest part is reading Pi's screen wrong:
False hold: a selector that draws its own ─ borders could read as a draft. Mail then waits, which is safer than typing into a selector, and the existing user-input hold cap limits the wait.
Missed hold: a draft row made only of ─ characters, or a pane narrower than about 13 columns, can be missed. That is the same as main.
Only Pi panes take the new path. Other agents are unchanged. Back out with a plain revert.
Level: Low
Notes
Original fix by @wuhaoyujerry in #45907. Their authorship is kept on the commit. I replaced their rule regex with a linear check that keeps the bundle ASCII-only, added a routing test, and registered the serializer replay counts.
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.
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)
I stated the risk: what could break, for whom, and how to back it out
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)
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
No actionable comments were generated in the recent review.
Walkthrough
The changes add piComposerHoldsDraft to detect non-whitespace text between Pi editor rules. Terminal wait checks now use this helper for Pi panes. New tests cover recorded empty, draft, and wrapped-draft screens, plus synthetic cursor contexts and transcript-pane routing.
Severity of issue fixed: Medium
Merge Risk: Moderate · up to 88c2f
This change makes worker mail wait while a Pi coordinator terminal holds an unsent draft, which fixes the main reported case. A draft made of rule characters, or text above a rule-like line in the editor, can still be missed, so mail may be delivered into text the user has not sent. This is an edge case with a clear fix. It should be resolved or knowingly accepted before merge.
Pre-merge checks: 4
Check name
Status
Explanation
Linked Issues check
Directly linked issue #45901 requires that worker mail wait while a Pi coordinator terminal holds unsent typed text. At the reviewed head, src/shared/terminal/input/pi-composer.ts defines `piCompose…
Out of Scope Changes check
The changes support the Pi draft-hold objective of #45901. The changed set includes the new piComposerHoldsDraft helper, its Pi-only call in hasComposerDraft (verified at head), a Pi composer test…
Title check
The title names the primary change: Pi worker mail is held while a Pi editor has an unsent draft. The raw summary shows the Pi composer draft reader (piComposerHoldsDraft) and its routing in hasCompos…
Description check
The description follows the repository template closely. It has ELI5, What Changed (before/after and mechanism), Why (including alternatives and why the regex was replaced), a linked issue (Fixes #459…
Full details: Linked Issues check
Explanation
Directly linked issue #45901 requires that worker mail wait while a Pi coordinator terminal holds unsent typed text. At the reviewed head, src/shared/terminal/input/pi-composer.ts defines piComposerHoldsDraft. It finds the cursor row's nearest editor rule above the cursor and a rule below it, then returns true when a non-blank typed row lies between them. isPiEditorRule accepts any row that starts and ends with ─, which covers plain rules, scrolled ↑ N more / ↓ N more rules, and working-status rules. It returns false when the cursor sits on a rule, when a rule is missing, or when the editor is empty. At head, src/main/runtime/terminal/wait/terminal-wait-settlements.tshasComposerDraft routes panes whose agent is pi to piComposerHoldsDraft, and other panes keep the OpenCode and generic paths. ptyDeliveryHold uses hasComposerDraft, so a Pi draft produces the existing draft hold. This meets the #45901 expected behavior. The test file pi-composer-draft.test.ts and the recorded fixtures were not inspected because the diff tool was unavailable for the whole-PR diff. The author-reported test results are therefore not independently verified.
Full details: Out of Scope Changes check
Explanation
The changes support the Pi draft-hold objective of #45901. The changed set includes the new piComposerHoldsDraft helper, its Pi-only call in hasComposerDraft (verified at head), a Pi composer test file, Pi 1.6.0 fixture text and metadata files, and an update to the KNOWN_PREEXISTING_I2_FAILURES baseline in the serializer replay test. Fixtures, tests, and the baseline entry support the Pi draft behavior and do not add unrelated product behavior. The OpenCode and generic reader paths are unchanged at the call site. Limits: the whole-PR diff was unavailable, so I could not confirm the full changed-file list at head against the merge base. I did not inspect the test or fixture contents.
Full details: Title check
Explanation
The title names the primary change: Pi worker mail is held while a Pi editor has an unsent draft. The raw summary shows the Pi composer draft reader (piComposerHoldsDraft) and its routing in hasComposerDraft, which matches the title. The title uses the conventional fix(scope) form and is specific enough for a teammate scanning history.
Full details: Description check
Explanation
The description follows the repository template closely. It has ELI5, What Changed (before/after and mechanism), Why (including alternatives and why the regex was replaced), a linked issue (Fixes #45901), Visual Proof marked N/A with a reason, Testing with platforms and results, Risk with level and back-out plan, the AI Disclosure section left empty as the template allows, the upstream boundary checkbox, and a checklist. The description is detailed and matches the change. Minor gaps: the 'pnpm lint/typecheck/test/build' checklist item is unchecked, and the 'Review' heading is empty. Neither is critical.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Functional Correctness · Heavy lift
Distinguish editor borders from rule-shaped draft text.
If the user types ─── as an unsent draft, Line 11 returns false even when genuine editor borders surround that row. ptyDeliveryHold then sees no draft, so mail can submit the unsent text.
The upward search has the same ambiguity. With editable rows important instructions, ───, and an empty cursor row, it treats the editable separator as the top border and excludes the instructions.
Identify structural borders without treating editable rule-shaped rows as borders. Add regression cases for both inputs. Preserve the empty-editor and ordinary-text cases.
Pi's editor draws no prompt glyph, so the generic composer reader never
saw a typed draft and mail delivery typed its note and Enter over it,
submitting the half-typed prompt. Pi panes are now read by their editor
rules (the full-width `─` lines above and below the editor), allowing the
scroll markers and working status Pi draws inside those rules. The check
uses no regex so the orcad bundle stays ASCII-only and the scan is linear.
Adds recorded Pi 1.6 empty, draft and wrapped-draft screens, a routing
test, and their serializer replay counts.
Fixesstablyai#45901
Co-authored-by: Neil <[email protected]>
nwparker
changed the title
fix(pi): hold worker mail while a Pi terminal has an unsent draft
fix(pi): hold worker mail while a Pi editor has an unsent draft
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When you type a message into Pi but have not pressed Enter yet, Orca could deliver a worker's mail into that same box and press Enter for it, sending your half-written message. Orca now notices that Pi's box has text in it and waits until it is empty before delivering mail.
What Changed
orchestration sendtyped Orca's mail note and Enter into Pi's editor even while the user had an unsent draft there, so the half-typed prompt was submitted together with the note.hasComposerDraftinsrc/main/runtime/terminal/wait/terminal-wait-settlements.tsonly had a layout reader for OpenCode. Every other agent went toreadTerminalComposerTypedText, which looks for a prompt glyph (❯/›/»). Pi draws no glyph, so its drafts were never detected. Pi panes now use a newpiComposerHoldsDraftreader (src/shared/terminal/input/pi-composer.ts). The editor is the rows between two full-width─rules, and any non-blank row between them counts as a draft. Text that Pi draws inside a rule, such as the↑/↓ N morescroll markers and the working, retry or compaction status in the top rule, is still recognized as a rule. Pi shows no placeholder text, so a blank editor reads as empty.Why
This follows the existing OpenCode pattern: each prompt-less agent gets its own layout reader, and routing is by the pane's agent. I checked the layout against Pi's source (
packages/tui/src/components/editor.tsrender/createScrollBorderandcustom-editor.tsrenderTopBorder). The rule check uses plain string tests, not a regex, for two reasons:─inside regex literals, which would break the ASCII-only orcad bundle.─(about 700 ms per call in an adversarial case). This check is linear.Out of scope: OMP, and Pi setups whose extensions replace the editor layout (custom editors), keep the generic reader. They behave the same as on main, so mail can still be typed over a draft there. Fixing those needs a different detector.
Linked Issue
Fixes #45901
Visual Proof
N/A. Nothing changes in Orca's UI. The fix changes when mail is typed into a Pi terminal. That behavior is covered by recorded Pi 1.6.0 terminal screens (empty editor, one-line draft, wrapped draft), replayed through the headless terminal emulator in the tests.
Testing
Reproduced the bug on main by replaying the recorded Pi 1.6.0 screens through
HeadlessEmulator.getCursorLineContext(). The generic reader returns no draft for the draft and wrapped-draft screens, which is the bug, and the Pi reader holds for both. The empty screen does not hold either way.src/main/daemon/emulation/testing/pi-composer-draft.test.tscovers:pipane holds on the draft screen and aclaudepane does not. Renaming theagent === 'pi'branch makes it fail.serialize-grid-transcript-replay.test.ts: added the new captures' I2 counts toKNOWN_PREEXISTING_I2_FAILURESwith a comment naming the cells. These are existing serializer limitations; this PR does not touch the serializer.pty-transcript-secret-scan.test.mjspasses (156 tests), including the new transcripts.src/shared/terminal/inputandsrc/main/runtime/terminal/waitpass, except one failure:terminal-creation-and-readiness-part-06.spec.tsfails the same way on main.oxlint, oxfmt, the anti-slop and code-quality oxlint configs, ast-grep and the changed-code quality gate report 0 findings.
Platforms: macOS (unit and replay tests). The reader is pure string logic with no platform-specific paths.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Perf: the reader runs only when mail is delivered or rechecked. It is not on the keystroke, terminal-stream or polling path, and it adds no I/O, timers or subprocesses. Node, per call:
All cases are O(rows) and far below 16 ms.
Risk
The riskiest part is reading Pi's screen wrong:
─borders could read as a draft. Mail then waits, which is safer than typing into a selector, and the existing user-input hold cap limits the wait.─characters, or a pane narrower than about 13 columns, can be missed. That is the same as main.Only Pi panes take the new path. Other agents are unchanged. Back out with a plain revert.
Level: Low
Notes
Original fix by @wuhaoyujerry in #45907. Their authorship is kept on the commit. I replaced their rule regex with a linear check that keeps the bundle ASCII-only, added a routing test, and registered the serializer replay counts.
Agent skill upstream boundary
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)