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
Don't type orchestration mail into the shell an agent exited to - #51165
When one agent sends another agent mail, Orca types a short notice into the receiving agent's terminal and presses Enter. If that agent had just quit back to its shell, Orca could still think it was there and type the notice into the shell instead. The shell then ran the command inside the notice, which marked the mail as read, so the mail was lost. Now Orca checks that the agent itself is in front before typing, and keeps the mail waiting if a shell is.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$143
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$143
Prod
6
$\color{#1a7f37}{\Huge{\mathbf{+}}}$157
$\color{#cf222e}{\Huge{\mathbf{−}}}$39
$\color{#1a7f37}{\Huge{\mathbf{+}}}$118
What Changed
Before: for about a minute after an agent exited (for example /exit in Claude), its terminal still counted as "agent idle". Mail sent in that window was typed into the shell. In zsh the notice's backticked orca orchestration check ran, consumed the mail, and printed zsh: command not found: You. The send receipt gave no warning.
After: mail waits, unread, while a shell is in front of an agent's terminal. It is delivered when an agent is back at its prompt in that terminal (its next status change). A paused agent behind another program was already held correctly and is unchanged.
Mechanism: delivery already runs one async check right before typing (that the terminal still exists). That same step now also reads which process is in front of the terminal, using the existing reader that worker start uses. A shell verdict holds the mail. Three guards keep the hold safe:
A delivery that arrives while a check is in flight (for example the agent coming back) makes a shell verdict check again instead of dropping that delivery.
The check records which agent process it read; if the terminal's process changed before typing, delivery checks again instead of typing.
Where the foreground can't be read per terminal (Windows, older daemons, hosts that can't tell), nothing is held, the same as before.
Why
The agent status that delivery trusted is built from hooks and titles, and those outlive the agent's exit. The process in front of the terminal is the direct signal, and it's read once per delivery, only when there is mail to type. A larger rework of mail holding (#41701) is mostly superseded by changes already on main; reproducing on main showed this exited-agent case was the one still losing mail.
Linked Issue
N/A (maintainer).
Visual Proof
N/A for UI: no visual change. Terminal evidence of the bug on main, macOS, real Claude, after /exit:
❯ You have 1 orchestration message. Run `orca orchestration check --terminal term_…`.
zsh: command not found: You
The mail was then marked handled although no agent read it.
Testing
Reproduced on main with real Claude and Codex on macOS. Held correctly on main: an agent paused with Ctrl-Z behind vim or at a bare shell, including under heavy CPU load. Lost on main: an agent that had exited.
mailbox-delivery-target.test.ts: a shell in front holds the mail; the agent in front delivers it; a delivery that joined an in-flight check gets checked again rather than dropped.
pnpm check:changed passes (Linux).
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
Performance
One foreground read per mail delivery to a recognized terminal agent, only when there is unread mail to type: one per-terminal daemon request on local macOS/Linux (normally one terminal-scoped process read), one shell-alone request on Windows, the existing per-terminal path on SSH. No polling, no idle work, and nothing that scales with the number of workspaces or terminals; daemons that would need a full session inventory skip the read. Delivery waits for that read before typing.
Risk
Level: Low
Riskiest part: a held message waits for the agent's next status change. If an agent came back without one, its mail would wait for orca orchestration check or the next status change instead of being typed. Unknown or unreadable foregrounds never hold. Plain revert.
AI Disclosure
Review
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-platform 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)
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)
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.
No actionable comments were generated in the recent review.
Walkthrough
Mailbox delivery now checks foreground-shell state as well as PTY absence when a probe is available. Runtime workspace inspection supplies probes for supported TUI agents. Delivery groups deferred messages by PTY and uses probe results to hold, discard, or redeliver them. Redelivery can request another terminal probe. Tests cover shell-in-front, agent-in-front, and a later delivery that arrives during a shell read.
Merge Risk: Low · up to 379d5
Mail is now held when a shell is in front of an exited agent and delivered when the agent returns. One narrow timing case remains: if the agent exits right after a re-check that a later delivery joined, the notice could still be typed into the shell. This is not worse than before the change, and the risk is low.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: orchestration mail is no longer typed into a shell after an agent exits. The raw summary shows the change adds a foreground-shell probe that holds mail while a shell i…
Description check
The description follows the template closely. It has the ELI5, What Changed (before and after), Why, Visual Proof, Testing, Performance, Risk with a level and revert method, and the checklist. The Lin…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: orchestration mail is no longer typed into a shell after an agent exits. The raw summary shows the change adds a foreground-shell probe that holds mail while a shell is in front of the agent's terminal. The title is specific and matches the changeset.
Full details: Description check
Explanation
The description follows the template closely. It has the ELI5, What Changed (before and after), Why, Visual Proof, Testing, Performance, Risk with a level and revert method, and the checklist. The Linked Issue section says N/A (maintainer), which the template allows for maintainers. The AI Disclosure and Review sections are left empty. The template says to skip AI Disclosure for internal team members, so that is acceptable. The description gives the mechanism, the guards, and the risks in detail. The Visual Proof section gives terminal evidence, which fits a behavior change. Some items remain open, such as the Testing claim that the new tests fail without the change. The reviewer should confirm that claim.
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; 0 remain after this review.
144-147: Minor · Functional Correctness · Poor tradeoff
Stale-proof check misses an agent exit that keeps the PTY incarnation.
After the foreground probe reads false, the timer decides stale from shellInFront and the PTY incarnationId. If the agent exits in the interval before typing, and the PTY keeps the same incarnation, stale stays false. redeliverAfterProbe then delivers with skipTerminalProbe: true, so no foreground read occurs. The commit gate checks agent status, and the method comment at lines 93-95 says status can outlive the exit. The submit path checks the handle and processIncarnation only. The pointer can then be typed into a shell that is in front.
The window is the interval between the probe result and typing. Impact is limited to an exit inside that interval. A probe that reads a shell in front still holds the mail correctly.
The identity behind this check is scoped to the PTY. workspace-foreground-inspection.ts:57 returns this.ptysById.get(ptyId)?.incarnationId. The doc comment on foregroundShellProbe says "agent process incarnation". The code and the comment disagree. An agent-scoped identity is the contract the doc describes, and it is the identity needed to detect this exit.
Require that an agent exit invalidates a pending foreground proof before the pointer is typed. The mechanism is open. It can be an agent-scoped identity or an exit-triggered invalidation. Re-reading the foreground inside the timer narrows the window but does not close it, because the read is asynchronous and leaves a gap before typing.
Align the doc comment and the implementation so both describe the same identity.
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: ca45a446-adef-448b-9b2b-37833af91399
Commits
Reviewing files that changed from the base of the PR and between d4ed6c2 and 867e235.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Status: proposed for closing (not reproducible on current main)
Head 867e235: pnpm check:changed and CI pass. A regression audit (3 issues) and a code review (1 issue, 2 minor) were fixed in this head, and the reviewer agreed. Performance check: one per-terminal foreground read per notice typed; no idle work; nothing that grows with workspaces or terminals.
QA on Linux (1,902 workspaces, real Claude and Codex, under load and across a graceful restart) and on macOS with zsh: with this PR, mail sent right after an agent exits is held and delivered exactly once when the agent returns. No regressions.
The bug reproduced once on an older main, but 10 attempts on this PR's merge-base 0cc007946ba (Claude hooks on and off, with and without Ctrl-Z/vim/fg before /exit, send 0.35–4 s after the prompt returned) never typed mail into the shell. Main already refuses to type when the agent's live status has cleared, and in every attempt it cleared within about 1 s of exit.
Why keep it: on an older main this bug typed a mail notice into a live shell. That is worse than losing the mail, and ten clean runs on a newer main don't prove the window is gone.
No later fix: nothing merged in between touches the agent's live-status clearing or the gate that decides whether to type.
How it closes the window: this PR checks which process is actually in front of the terminal at the moment of typing, so it closes the window whatever let the stale status through.
Fixed in review: the regression audit's 3 issues and the code review's 3. The reviewer agreed with the fixes.
Performance: one per-terminal foreground read per notice typed. No idle work, and nothing that scales with workspaces or terminals.
QA on Linux: 1,902 workspaces, real Claude and Codex, under load and across a graceful restart. With this PR, mail sent to an agent that just exited is held and delivered exactly once when it returns.
QA on macOS (zsh): the same, plus an agent paused with Ctrl-Z, with or without vim. No regressions.
The blinded regression audit raised three P2s on this head. After it was shown the trade-off behind each:
One foreground read per typed notice: no longer blocks. The read is coalesced per terminal and scales with mail volume. Its cost is justified by keeping a shell from running the notice and consuming the mail.
Mail held during Ctrl-Z stays unread after fg until the next status change: no longer blocks. Main behaves identically (shown in QA on the base build), and it is tracked separately.
A forced re-read ignores deliveries that join it:still blocks, in the auditor's view. This is the residual of capping re-reads at one per batch, so that a steady stream of deliveries is still typed. If the agent exits right after that second read, while its status is stale, the whole deferred batch can be typed into the shell. Under review.
Head 379d5db. Main was merged in once, with no conflicts. pnpm check:changed passes. A regression audit, a code review and an automated review were all run, and every finding was fixed except the one below.
Accepted residual (Brennan: "Accept, finish it").
The audit's concern: sometimes mail arrives while Orca is checking whether the agent is in front, so a second check is made. That second check is final, so a steady stream of mail can't make Orca re-check forever. If the agent exits right after that final check, while its status still looks current, the waiting notices can still be typed into the shell.
The other side: closing that gap brings back the endless re-check, where steady mail is never typed. A fixed cap only moves the gap to the last check. The gap is one check long, and it only opens after new mail has already forced a re-check. Main types with no check at all.
The audit's verdict: with this risk accepted, it rates the change safe.
QA evidence:
Linux: 1,902 workspaces, real Claude and Codex, under load and across a graceful restart.
macOS with zsh: including an agent paused with Ctrl-Z, with and without vim.
Result: mail sent to an agent that has just exited is held, nothing is typed into the shell, and it is delivered exactly once when the agent returns. No regressions against main. This was run on 867e235. The later commits change only the timing of the foreground check, and unit tests cover them: deliveries joining a check, a steady stream, an agent returning during a check, and reserved types.
Perf: one per-terminal foreground read per typed notice, plus at most one more when deliveries join the check. No idle work, and nothing that grows with workspaces or terminals.
Perf waiver (Brennan): "Accept, finish it" (2026-11-28), for the accepted residual above (not a performance failure). #51165 (comment)
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 one agent sends another agent mail, Orca types a short notice into the receiving agent's terminal and presses Enter. If that agent had just quit back to its shell, Orca could still think it was there and type the notice into the shell instead. The shell then ran the command inside the notice, which marked the mail as read, so the mail was lost. Now Orca checks that the agent itself is in front before typing, and keeps the mail waiting if a shell is.
What Changed
Before: for about a minute after an agent exited (for example
/exitin Claude), its terminal still counted as "agent idle". Mail sent in that window was typed into the shell. In zsh the notice's backtickedorca orchestration checkran, consumed the mail, and printedzsh: command not found: You. The send receipt gave no warning.After: mail waits, unread, while a shell is in front of an agent's terminal. It is delivered when an agent is back at its prompt in that terminal (its next status change). A paused agent behind another program was already held correctly and is unchanged.
Mechanism: delivery already runs one async check right before typing (that the terminal still exists). That same step now also reads which process is in front of the terminal, using the existing reader that worker start uses. A shell verdict holds the mail. Three guards keep the hold safe:
Why
The agent status that delivery trusted is built from hooks and titles, and those outlive the agent's exit. The process in front of the terminal is the direct signal, and it's read once per delivery, only when there is mail to type. A larger rework of mail holding (#41701) is mostly superseded by changes already on main; reproducing on main showed this exited-agent case was the one still losing mail.
Linked Issue
N/A (maintainer).
Visual Proof
N/A for UI: no visual change. Terminal evidence of the bug on main, macOS, real Claude, after
/exit:The mail was then marked handled although no agent read it.
Testing
Reproduced on main with real Claude and Codex on macOS. Held correctly on main: an agent paused with Ctrl-Z behind vim or at a bare shell, including under heavy CPU load. Lost on main: an agent that had exited.
mailbox-delivery-target.test.ts: a shell in front holds the mail; the agent in front delivers it; a delivery that joined an in-flight check gets checked again rather than dropped.pnpm check:changedpasses (Linux).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
Performance
One foreground read per mail delivery to a recognized terminal agent, only when there is unread mail to type: one per-terminal daemon request on local macOS/Linux (normally one terminal-scoped process read), one shell-alone request on Windows, the existing per-terminal path on SSH. No polling, no idle work, and nothing that scales with the number of workspaces or terminals; daemons that would need a full session inventory skip the read. Delivery waits for that read before typing.
Risk
Level: Low
Riskiest part: a held message waits for the agent's next status change. If an agent came back without one, its mail would wait for
orca orchestration checkor the next status change instead of being typed. Unknown or unreadable foregrounds never hold. Plain revert.AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)