Skip to content

fix(pi): hold worker mail while a Pi editor has an unsent draft - #45907

Merged
nwparker merged 1 commit into
stablyai:mainfrom
wuhaoyujerry:wuhaoyujerry/verify-pi-draft-hold
Nov 20, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
wuhaoyujerry:wuhaoyujerry/verify-pi-draft-hold

Conversation

@wuhaoyujerry

@wuhaoyujerry wuhaoyujerry commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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.ts render/createScrollBorder and custom-editor.ts renderTopBorder). 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.

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.ts covers:

    • The 3 recorded screens.
    • 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)

Copilot AI balanced review requested due to automatic review settings November 20, 2026 20:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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: Passed 4

Check name Status Explanation
Linked Issues check Passed 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 Passed 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 Passed 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 Passed 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.ts hasComposerDraft 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.

Share

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: d0fd3335-58bb-4cd6-b089-74f5a92f9b70
Commits

Reviewing files that changed from the base of the PR and between 2ac5398 and 88c2f48.

Files selected for processing: 3

  • src/main/daemon/emulation/testing/pi-composer-draft.test.ts
  • src/main/daemon/emulation/testing/serialize-grid-transcript-replay.test.ts
  • src/shared/terminal/input/pi-composer.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.

@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: f02aa3c4-fe3f-4def-a1da-848b46756643
Commits

Reviewing files that changed from the base of the PR and between 370c1ff and 9042011.

Files selected for processing: 9

  • src/main/daemon/emulation/testing/pi-composer-draft.test.ts
  • src/main/runtime/__fixtures__/pi-1-6-composer-draft-wrapped.meta.json
  • src/main/runtime/__fixtures__/pi-1-6-composer-draft-wrapped.txt
  • src/main/runtime/__fixtures__/pi-1-6-composer-draft.meta.json
  • src/main/runtime/__fixtures__/pi-1-6-composer-draft.txt
  • src/main/runtime/__fixtures__/pi-1-6-composer-empty.meta.json
  • src/main/runtime/__fixtures__/pi-1-6-composer-empty.txt
  • src/main/runtime/terminal/wait/terminal-wait-settlements.ts
  • src/shared/terminal/input/pi-composer.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.

* Pi's editor rules. Callers check that Pi is the pane's agent. */
export function piComposerHoldsDraft(context: TerminalCursorContext): boolean {
const cursorIndex = context.rows.length - 1
if (cursorIndex < 0 || PI_EDITOR_RULE.test(context.rows[cursorIndex] ?? '')) {

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

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.

Fixes stablyai#45901

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the wuhaoyujerry/verify-pi-draft-hold branch from 2ac5398 to 88c2f48 Compare November 20, 2026 21:55
@nwparker 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
@nwparker
nwparker merged commit 55fb22f into stablyai:main Nov 20, 2026
72 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.

[Bug]: Worker mail submits a half-typed prompt in a Pi coordinator terminal

3 participants