Skip to content

fix: finish admitted terminal prompts after sender disconnects - #34373

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/sta-12291-send-enter
Oct 27, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/sta-12291-send-enter

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​240 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​229
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​178 $\color{#cf222e}{\Huge{\mathbf{−}}}$​91 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​87

The problem

orca terminal send --text … --enter pastes a prompt into a Claude Code or Codex terminal, then presses Enter a moment later. If the script running that command was stopped or killed in between, Orca also cancelled the Enter, so the prompt sat unsent in the agent's input box. In the reported case one draft sat for 23 minutes until someone pressed Enter and submitted a stale message.

What this PR changes

  • Once Orca has accepted the paste, it still presses Enter even if the sending script is gone, so the prompt is submitted.
  • If the script goes away before the paste is accepted, nothing is typed.
  • Orca's own Cancel (for example cancelling a conversation) still stops the Enter.

How it works: Orca now treats "the sender stopped listening" and "someone asked to cancel" as different things. Losing the sender only stops Orca reporting back to it; only a real cancel, the terminal restarting or switching to a different process, or a permission change stops the remaining typing. No new saved data or message types.

What stays the same

  • After the first Enter, a gone sender still stops Orca retrying Enter and watching the turn, as before.
  • Intended: Ctrl-C typed into the agent's terminal behaves as today: the agent clears its input box, and Orca's later Enter lands on an empty box and submits nothing. Orca's "interrupt terminal" commands still just send keys and don't cancel a send in progress. This keeps behavior identical to main.
  • Temporary: input from two senders mixing in one terminal, and plain shells or agents Orca can't recognize, are left for follow-up, tracked in fix(terminal): one send owns the terminal's input until its last byte #26676.

How it was tested

  • Real Claude Opus 5.5 and Codex on macOS, with terminals opened on main and carried through an upgrade to this branch.
  • Script killed right after the paste: on main both agents kept an unsent draft; on this branch each got exactly one Enter and replied.
  • Orca Cancel right after the paste: no Enter for over 12 seconds, and both terminals then answered a new prompt normally.
  • Ctrl-C before the Enter: input box cleared, no stray prompt submitted. Normal typing, replies and working-to-done status also worked.
  • Automated tests cover disconnects before and after the paste over a real socket, cancel paths and terminal restarts; Windows and paired remote setups are covered by tests only. CI is green. QA ran on 9c08485.

Tracked in STA-12291.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 27, 2026 13:15
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

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: 7fd358b1-56e2-4b57-9ec9-fbb1500ab178
Commits

Reviewing files that changed from the base of the PR and between 980bf30 and 9c08485.

Files selected for processing: 1
  • src/main/runtime/rpc/terminal-agent-prompt-socket.test.ts

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

Walkthrough

The changes separate observation signals from delivery cancellation for terminal agent prompts. The write path adds checks for request state, PTY generation and targeting, process incarnation, expected binding, and PTY stop state. PTY lifecycle signals and launched-agent write guards now track lifecycle and foreground state. Tests cover cancellation, process changes, submission behavior, restored panes, and socket interactions.

Priority: Normal

Merge Risk: Minimal · up to 9c084

No merge-blocking issue is established; the change is ready for normal checks.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description clearly explains the problem, changes, scope, rationale, and testing. It does not follow the required template fully: it lacks an actual linked issue in the Fixes # field, required v… Add a linked issue using the Fixes #... format, add before/after visual proof or state N/A with a reason, and complete the missing template sections. Add the AI Disclosure section if the author is an outside contributor or used AI assis…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: admitted terminal prompts finish after the sender disconnects.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 15 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The description clearly explains the problem, changes, scope, rationale, and testing. It does not follow the required template fully: it lacks an actual linked issue in the Fixes # field, required visual proof or an explicit N/A explanation, and the Review, Agent skill upstream boundary, Notes, and Checklist sections.

Resolution

Add a linked issue using the Fixes #... format, add before/after visual proof or state N/A with a reason, and complete the missing template sections. Add the AI Disclosure section if the author is an outside contributor or used AI assistance.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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: 2


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: 7f595392-3080-49a5-8c99-3988180ca564
Commits

Reviewing files that changed from the base of the PR and between c903d30 and 980bf30.

Files selected for processing: 15
  • src/main/runtime/agent-prompt-permission-wait.test.ts
  • src/main/runtime/agent-prompt-submission-runtime-hook-and-generation.test.ts
  • src/main/runtime/agent-prompt-submission-runtime-test-fixture.ts
  • src/main/runtime/launched-agent-write-guard.test.ts
  • src/main/runtime/launched-agent-write-guard.ts
  • src/main/runtime/restored-pane-start-cli-handles.test.ts
  • src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
  • src/main/runtime/rpc/terminal-agent-prompt-socket.test.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/terminal/input/agent-prompt-signals.ts
  • src/main/runtime/terminal/input/terminal-agent-prompt-submit.ts
  • src/main/runtime/terminal/input/terminal-agent-prompt.ts
  • src/main/runtime/terminal/input/terminal-input-dispatch.ts
  • src/main/runtime/terminal/output/terminal-output-generation.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

A sending CLI could disconnect after its prompt reached the terminal agent’s composer but before the delayed Enter. The host treated that disconnect as cancellation and left an unsent draft. This PR separates observation from the host operation: an admitted prompt now completes through its first Enter even when its sender disappears. Explicit operation cancellation, generation retirement, exact PTY/known-incarnation checks and permission checks still stop further bytes; the prompt FIFO remains intact.

The full review loop finished in two rounds, with no remaining proven production findings. The target-input bridge, byte classifier and input subscriptions were removed; their framing and scaling findings disappear with that code. The retained fixes clean up a foreground guard even when cancellation wins its pending probe and allow null-to-known incarnation enrichment while still rejecting known replacement. The deciding session confirmed the bridge-free design and explicit-cancellation paths before the fresh round. The final reference and performance passes agreed. Final price: 262 production / 258 test lines changed, within the 400-line production allowance.

Intended, main parity: target-typed Ctrl-C follows the existing input path and the agent’s own composer handling. In the real run both agents cleared their composer before the delayed Enter and submitted no stray prompt. Standalone terminal interrupt APIs still send keys; they do not cancel a separate host operation. After the first Enter, observer loss still stops held-submit retries and observation, as on main; actual-source main/branch traces refuted the proposed retry regression.

Temporary: raw cross-writer interleave and the plain/shell or unproven-agent fallback remain tracked in #26676. No new saved field or wire operation was added. Retained paired-host coverage is compositional: an executed private joined WebSocket-close→writer→receipt-replay proof passed, but its additional regression was not retained under the test-line allowance.

Verification: focused named Vitest runs passed through tc-gate (115-test initial set, 92-test final affected set, 35 explicit-cancellation/consumer tests, 12 tests for the consumer follow-up, and two socket tests after the test-only CI correction). Normal implementation hooks passed. Main was synced once without conflicts in 980bf30; the final test-only correction is 9c08485. All PR and auxiliary WSL checks are green on that head.

The targeted qa-gate/qa-drive run passed on M4Air with actual Claude Opus 5.5 and Codex GPT-6.1-Sol, using terminals and exact PTYs carried through a graceful upgrade from main. Main left both pasted prompts unsent after sender death; the branch issued exactly one Enter and obtained a real reply for each. Actual Orca conversation Cancel after paste prevented Enter for over 12 seconds, and both same-agent terminals subsequently replied to recovery prompts. Target Ctrl-C left no stray submitted prompt. Ordinary rendered typing and CLI Enter produced real replies and working→done status. Status transitions are recorded; no busy-state screenshot is claimed. This is local macOS real-agent coverage; paired/Windows behavior is covered by tests, and no remote/mobile or unrelated lifecycle run is claimed. The QA apps and their 62 recorded process identities were stopped; the QA slot was released.

For Brennan’s review

Whole-window screenshots from the actual runs:

Flow Claude Codex
Main: sender dies; draft remains main-claude-sender.png main-codex-sender.png
Branch: sender dies; one submission and reply branch-claude-sender.png branch-codex-sender.png
Branch: explicit Orca Cancel; no Enter branch-claude-explicit-cancel.png branch-codex-explicit-cancel.png
Branch: same terminal recovers after Cancel branch-claude-cancel-recovery.png branch-codex-cancel-recovery.png
Branch: target Ctrl-C; no stray prompt branch-claude-target-ctrlc.png branch-codex-target-ctrlc.png
Branch: ordinary input and reply branch-claude-ordinary.png branch-codex-ordinary.png

Three places where the ownership boundary matters:

@brennanb2025
brennanb2025 merged commit b46fb04 into main Oct 27, 2026
54 of 55 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.

1 participant