Skip to content

fix(orchestration): hold mailbox pointers while the agent shows an open dialog (#21745) - #26928

Closed
yasyf wants to merge 2 commits into
stablyai:mainfrom
yasyf:fix/mailbox-hold-on-blocked-prompt
Closed

yasyf wants to merge 2 commits into
stablyai:mainfrom
yasyf:fix/mailbox-hold-on-blocked-prompt

Conversation

@yasyf

@yasyf yasyf commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

ELI5

When Claude Code stops to ask the user a question, its terminal title still says it is at rest. If orchestration mail arrived at that moment, Orca typed "You have N orchestration messages..." into the pane and pressed Enter half a second later. That Enter answered the question with whichever option was highlighted. With this change, Orca waits until the question is gone before it types anything or presses Enter.

What Changed

  • Before: Orca checked whether a pane was ready for mail by reading its title and screen. Claude keeps its ✳ rest title while an AskUserQuestion, permission, or plan-approval dialog is open, and Orca has no screen rule for that dialog, so the pane counted as idle. Delivery typed the mail pointer, and the delayed Enter only checked that the title still read idle or working. In our own Claude coordinator session, two heartbeat deliveries landed within a second of two question answers, and both answers were the first option.
  • After: Orca checks the pane's newest hook row before it types the pointer. Claude reports these dialogs through its hooks (PreToolUse for AskUserQuestion, PermissionRequest for permissions and plan approval), and both arrive as waiting. While the row reads waiting or blocked, the gate refuses and re-arms its existing recheck. The delayed Enter rechecks the same row. If a dialog opened after the pointer was typed, the Enter is deferred to the next idle edge, where it is rechecked before it is sent.
  • Mechanism:
    1. isPtyAwaitingUserInput(ptyId) reads the pane's newest live hook row, joined on its pane keys and terminal handles. Rows from before a respawn are ignored, and there is no age bound: an unanswered question posts no further hooks, so a 30-minute freshness cutoff would let mail answer a question left open that long.
    2. isAgentSettledForDelivery refuses while that check holds.
    3. submitOrchestrationMailboxPointer takes the check as a new dependency and sends the deferred Enter down the same deferFlightUntilIdle path that a neutral title already uses.
    4. selectFreshExplicitAgentStatusRow and the new selectNewestExplicitAgentStatusRow share one selector. The fresh one keeps its 30-minute bound, so the tui-idle hook lane is unchanged.

Why

Mail typed into an open dialog is worse than late mail. It picks an answer nobody gave and the pointer itself is lost. The hook row is the only signal Orca has for these dialogs. A screen anchor would need a captured transcript for each dialog shape, and the title cannot help because Claude keeps it at rest.

#21880 fixes the same issue with the same signal. The main difference is what happens when a dialog opens between the pointer write and the Enter. #21880 settles the pointer as delivered and sends no Enter, which leaves the text in the composer and marks the mail read. This PR keeps the flight and defers the Enter to the next idle edge, so the pointer is submitted once the dialog closes.

Two smaller differences: #21880 polls a parked pane every 1 s, while this PR keeps the existing quiescence recheck (about 3 s). #21880 also holds on a cached AskUserQuestion tool name or interactivePrompt field, while this PR reads only waiting/blocked. Either PR closes the issue, and maintainers should pick whichever fits better.

Linked Issue

Fixes #21745

Visual Proof

N/A. Nothing visible changes. The fix only stops keystrokes from reaching an open dialog, and a runtime test covers that path, listed below.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Two new tests, both run locally on macOS (vitest run), both green:

  • src/main/runtime/orchestration-open-dialog-delivery-hold.test.ts: a Claude pane with a ✳ title and a waiting hook row gets mail. Nothing is written for 10 s. After the row turns done, the pointer and one Enter are written. A second case uses a row older than 30 minutes and holds the same way. With the gate removed, both cases fail.
  • src/main/runtime/orchestration/mailbox-pointer-submit.test.ts, "holds the Enter while a dialog is open and submits once the agent is idle again": the Enter is deferred while the dialog is open, deferred again on an idle edge that comes while it is still open, and sent exactly once after it closes.

Also run: mailbox-pointer-stage.test.ts and tui-idle-hook-lane.test.ts (unchanged behavior), plus oxlint and oxfmt on the changed files. The full suite, typecheck, and build are left to CI.

Accepted risk: if a waiting row is never followed by another hook, mail stays held until the next hook or a respawn, as when the dialog is dismissed in a way that posts nothing. Claude's answer keystroke already clears a question's row, and the next turn's hooks clear the rest. Holding mail is the safe side of that trade.

AI Disclosure

Written with Claude (Opus 5.5) in Claude Code, reviewed by the author.

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-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

The check reads the hook rows the runtime already has, so SSH and WSL panes work the same way as local ones. No wire or protocol change.

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)

yasyf added 2 commits October 9, 2026 10:46
…en dialog

Claude keeps its rest title (`✳ ...`) while an AskUserQuestion, permission, or
plan-approval dialog is open, so the mailbox delivery gate read the pane as
idle and typed the pointer plus a delayed Enter into the dialog. The Enter
picked the dialog's first option.

Delivery now reads the pane's hook row: while the agent's hooks report a wait
(`waiting`/`blocked`), the pre-write gate refuses and re-arms its recheck, and
the delayed Enter is deferred until the next idle edge, where it rechecks.
An unanswered question posts no further hooks, so the 30-minute freshness
bound on the hook turn reader would have let mail answer a question left
open longer than that. The hold now reads the pane's newest live hook row
with no age bound, retired only by a newer row or a respawn.
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

The runtime selects explicit hook-status rows and checks whether the newest row indicates that a PTY is waiting for user input. Mailbox-pointer submission now defers when that check is true, and delivery settlement also rejects a leaf whose PTY is waiting. Tests cover open Claude questions, deferred submission, and submission after the question closes.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to c852e

Mail delivery could remain queued after a respawn if an old prompt status is replayed. The timestamp check should be corrected before merge if that replay path is supported.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 11 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: holding orchestration mailbox pointers while an agent dialog is open.
Description check Passed The description is complete and matches the repository template. It explains the user impact, implementation, rationale, linked issue, testing, risks, compatibility considerations, and checklist statu…
Linked Issues check Passed Issue #21745 requires mailbox delivery to hold while a Claude dialog is open and to prevent the delayed Enter from answering it. The PR joins live hook rows by pane keys and terminal handles, ignores …
Out of Scope Changes check Passed The changes remain connected to issue #21745. Runtime changes provide and wire the dialog gate. Selector changes support newest-row and existing fresh-row behavior. Test-harness, fixture, and test cha…


  • Fix all pre-merge checks with AI
  • 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.

@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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68e0ff54-7d5b-46ad-8a77-76668604010d
📥 Commits

Reviewing files that changed from the base of the PR and between 077b62d and c852e65.

📒 Files selected for processing (11)
  • src/main/runtime/orca-runtime-resolve-authoritative-terminal-wait-permission.ts
  • src/main/runtime/orca-runtime-resolve-exit-waiters.ts
  • src/main/runtime/orca-runtime-stop-requested-pty-ids.ts
  • src/main/runtime/orchestration-mailbox-notification-test-harness.ts
  • src/main/runtime/orchestration-open-dialog-delivery-hold.test.ts
  • src/main/runtime/orchestration/mailbox-pointer-delivery-contract.ts
  • src/main/runtime/orchestration/mailbox-pointer-stage.test.ts
  • src/main/runtime/orchestration/mailbox-pointer-stage.ts
  • src/main/runtime/orchestration/mailbox-pointer-submit.test.ts
  • src/main/runtime/orchestration/mailbox-pointer-submit.ts
  • src/main/runtime/runtime-hook-agent-row-selection.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.

const row = join ? selectNewestExplicitAgentStatusRow(join) : null
return (
row !== null &&
row.receivedAt >= (this.agentPromptExplicitStatusFloorByPtyId.get(ptyId) ?? -1) &&

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect the respawn-floor assignment and relay replay's row provenance.
rg -n -C 4 'agentPromptExplicitStatusFloorByPtyId|evidenceObservedAt|restoredUnconfirmed' src/main/runtime src/main/agent-hooks src/shared

Repository: stablyai/orca

Length of output: 42563


🏁 Script executed:

set -e
printf '%s\n' '--- target resolver ---'
nl -ba src/main/runtime/orca-runtime-resolve-authoritative-terminal-wait-permission.ts | sed -n '95,155p'
printf '%s\n' '--- floor assignment ---'
rg -n -C 12 -F -- 'agentPromptExplicitStatusFloorByPtyId' src/main/runtime
printf '%s\n' '--- status application ---'
nl -ba src/main/agent-hooks/server-status-application.ts | sed -n '135,205p'
printf '%s\n' '--- row source projection ---'
nl -ba src/main/runtime/runtime-worktree-pty-agent-sources.ts | sed -n '1,75p'
printf '%s\n' '--- newest-row and join references ---'
rg -n -C 8 'selectNewestExplicitAgentStatusRow|isPtyAwaitingUserInput|hookRows' src/main/runtime/orca-runtime-resolve-authoritative-terminal-wait-permission.ts src/main/runtime

Repository: stablyai/orca

Length of output: 42767


🏁 Script executed:

echo waiting for the previously requested focused source inspection

Repository: stablyai/orca

Length of output: 214


🏁 Script executed:

set -e
printf '%s\n' '--- newest explicit row selector ---'
nl -ba src/main/runtime/runtime-hook-agent-row-selection.ts | sed -n '1,82p'
printf '%s\n' '--- focused tui-idle scenarios ---'
rg -n -C 8 'prior-process|respawn|launchToken|waiting|blocked' src/main/runtime/tui-idle-hook-lane.test.ts
printf '%s\n' '--- replay stamping implementation candidates ---'
rg -n -C 8 'evidenceObservedAt|receivedAt.*now|isReplay|replay' src/main/agent-hooks src/shared | head -240

Repository: stablyai/orca

Length of output: 34755


🏁 Script executed:

set -e
rg -n -F -- 'resolveEvidenceObservedAt' src
rg -n -F -- 'ingestRemote' src/main/agent-hooks src/shared
rg -n -F -- 'isReplay' src/main/agent-hooks src/shared | head -120

Repository: stablyai/orca

Length of output: 39053


Reject pre-respawn prompt evidence at the PTY floor.

selectNewestExplicitAgentStatusRow accepts old live rows and orders them by receivedAt. Replay can restamp receivedAt while preserving an earlier evidenceObservedAt. The current check can therefore accept a pre-respawn waiting or blocked row and keep mail parked.

Compare row.evidenceObservedAt ?? row.receivedAt with the floor, or match the row to the current launch identity.

Suggested timestamp fix
--- "a/src/main/runtime/orca-runtime-resolve-authoritative-terminal-wait-permission.ts"
+++ "b/src/main/runtime/orca-runtime-resolve-authoritative-terminal-wait-permission.ts"
@@ -127,7 +127,8 @@
     const row = join ? selectNewestExplicitAgentStatusRow(join) : null
     return (
       row !== null &&
-      row.receivedAt >= (this.agentPromptExplicitStatusFloorByPtyId.get(ptyId) ?? -1) &&
+      (row.evidenceObservedAt ?? row.receivedAt) >=
+        (this.agentPromptExplicitStatusFloorByPtyId.get(ptyId) ?? -1) &&
       (row.state === 'waiting' || row.state === 'blocked')
     )
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
row.receivedAt >= (this.agentPromptExplicitStatusFloorByPtyId.get(ptyId) ?? -1) &&
(row.evidenceObservedAt ?? row.receivedAt) >=
(this.agentPromptExplicitStatusFloorByPtyId.get(ptyId) ?? -1) &&

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @yasyf! Your approach landed via #33366 (your commits kept, plus Co-authored-by on the squash), with a bounded hold: it holds only while Claude's dialog is on screen (or a fresh waiting row when the screen can't be read), capped at 10 min, so an Esc-dismissed question can't hold mail forever. Closing as superseded.

nwparker added a commit that referenced this pull request Oct 25, 2026
…en dialog (#21745) (#33366)

Orchestration mailbox pointers (typing and the delayed Enter) are held while a Claude pane shows an open dialog (AskUserQuestion / permission / plan approval chrome on screen, or a fresh waiting row when the screen can't be read), capped at 10 minutes, so mail no longer answers the dialog. Recheck backs off to 2s while held. Fixes #21745. Supersedes #26928, #21880.

Co-authored-by: yasyf <[email protected]>
@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]: orchestration mail pointer answers a Claude AskUserQuestion — the delayed Enter selects the highlighted option while the pane reads as idle

2 participants