Skip to content

fix(terminal): settle CLI prompts for Claude and Codex - #14608

Merged
Jinwoo-H merged 3 commits into
mainfrom
bug-strange-behavior-i-think-when-using-orchestr
Aug 15, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
bug-strange-behavior-i-think-when-using-orchestr

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 +707 −1 +706
Prod 4 +231 −37 +194

Summary

  • mark non-empty CLI terminal send --text ... --enter calls as optional agent-prompt intent
  • use bracketed-paste settlement only when a fresh foreground-process read positively identifies Claude or Codex
  • keep the exact legacy direct-send path for shells, stale agent metadata over a returned shell, OpenCode, every other agent, text-only input, bare Enter, interrupts, mobile input, and query replies
  • avoid the 6.5-second wrapper retry loop during speculative CLI classification
  • preserve mixed-version behavior: old hosts strip the optional intent and retain current timing

Fixes #14347
Fixes #14525
Tracks STA-4328

Root cause

The generic CLI path pastes text, waits a fixed 500 ms on POSIX (1.5 s on Windows), then sends Enter. Slow or busy composers can still be processing the paste, so Enter is consumed before submission is ready and the completed prompt remains in the composer.

The generic writer is byte-identical across the inspected 1.4.170–1.4.183 release range, so no recent Orca source first-bad boundary was found. This is a latent timing race that became more visible with long handoff prompts and TUI/runtime timing changes.

Narrow fix

For freshly identified Claude and Codex terminals only, the owning runtime:

  1. sends one sanitized bracketed-paste frame;
  2. waits for the observed post-paste show-cursor marker;
  3. waits for 1.5 seconds of render quiescence;
  4. sends exactly one Enter, with an 8-second fallback window.

Unknown, wrapper-only, stale, and non-target identities fail open to the pre-existing direct behavior. OpenCode was deliberately removed from this PR after review because its existing startup-ready cursor signal is not proof of a post-paste render marker.

Validation

  • rebased onto current origin/main (931cb037c5)
  • focused CLI/RPC/runtime suite: 1,201 passed, 1 existing skip
  • pnpm typecheck:node
  • pnpm typecheck:cli
  • changed-file standard and type-aware lint
  • reliability manifest: 85 gates valid
  • deterministic source-built macOS public CLI → RPC → runtime → real PTY delayed-composer E2E passed with zero premature Enter and no rescue send
  • physical Windows source-built Electron/CLI/ConPTY journey passed twice for the same delayed Codex oracle
  • real Claude 2.1.233 source-built public-CLI test submitted a ~23 KB prompt and produced the exact requested assistant reply without manual Enter
  • three fresh OpenCode agents reviewed routing safety, timer behavior, and coverage; their stale-identity finding was reproduced and fixed, scratch/doc issues were cleaned up, and their OpenCode-evidence concern caused OpenCode to be excluded

Risk and tradeoffs

  • Claude/Codex sends that previously happened to work after 500 ms may now take about 1.5 seconds after the marker. A missing marker falls back after 8 seconds; a very late marker receives a fresh bounded settlement window, so pathological total latency can approach 16 seconds.
  • If fresh foreground identity cannot be proven, Orca preserves the old behavior. That minimizes regression risk but means an unusually wrapped fresh Claude/Codex process can retain the old race.
  • OpenCode and all other agents are intentionally unchanged and remain follow-up work once their post-paste settlement signals are independently validated.
  • No required RPC field, stream opcode, or protocol-version change is introduced.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 051cf911-934c-4991-939c-03b4ba9bfffa

📥 Commits

Reviewing files that changed from the base of the PR and between 931cb03 and 9a25596.

📒 Files selected for processing (9)
  • config/reliability-gates.jsonc
  • src/cli/handlers/terminal.test.ts
  • src/cli/handlers/terminal.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
  • tests/e2e/terminal-send-agent-prompt-submit.spec.ts
  • tests/tools/repro-terminal-send-submit.mjs
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/cli/handlers/terminal.ts
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/cli/handlers/terminal.test.ts
  • config/reliability-gates.jsonc
  • tests/tools/repro-terminal-send-submit.mjs
  • src/main/runtime/orca-runtime.ts

📝 Walkthrough

Walkthrough

The CLI now marks text-plus-Enter sends as agent prompts. The terminal RPC routes eligible sends for running agents through sendTerminalAgentPrompt and preserves direct input for other cases. Runtime gate creation supports all configured TUI agents, using render markers or output quiescence before submission. Tests, an end-to-end fixture, a reproduction script, and reliability gates validate delayed submission and paste behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses the Codex issues but leaves cursor-agent on the legacy path, so the linked cursor-agent requirement is not met. Extend settled prompt submission to cursor-agent, or document and link a follow-up issue explaining why cursor-agent is intentionally deferred.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The runtime, RPC, reliability gates, tests, and reproduction tooling directly support the linked terminal prompt submission objectives.
Title check ✅ Passed The title clearly identifies the main change: settling CLI prompts for Claude and Codex.
Description check ✅ Passed The description covers the change, rationale, linked issues, scope, risks, compatibility, and extensive validation details.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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: 3

🧹 Nitpick comments (6)
src/cli/handlers/terminal.test.ts (1)

97-137: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the interrupt exclusion. Neither test exercises text plus Enter plus interrupt. This branch must remain direct terminal input.

  • src/cli/handlers/terminal.test.ts#L97-L137: Add a --text plus --enter plus --interrupt case. Assert that the payload omits agentPrompt.
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts#L53-L86: Add an agentPrompt: true request with interrupt: true. Assert that it calls sendTerminal and does not call sendTerminalAgentPrompt.

The PR objective requires interrupts to retain direct terminal input.

tests/e2e/terminal-send-agent-prompt-submit.spec.ts (1)

14-14: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Reuse fixtureScript instead of recomputing the script path.

Line 14 already resolves the repro script path. Line 55 rebuilds the same path from repoRoot. Two sources for one path can drift.

♻️ Proposed refactor
-        path.join(repoRoot, 'tests', 'tools', 'repro-terminal-send-submit.mjs'),
+        fixtureScript,

Also applies to: 52-67

tests/tools/repro-terminal-send-submit.mjs (2)

270-270: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Write a report when the fake agent times out.

The timeout handler exits with code 8 and writes nothing. The parent then throws fake agent did not write a report, and the recorded prematureEnters and paste-framing data are lost. That data identifies the failure mode this tool exists to diagnose.

♻️ Proposed refactor
-  const timeout = setTimeout(() => process.exit(8), timeoutMs)
+  const timeout = setTimeout(() => {
+    void writeFile(
+      reportPath,
+      JSON.stringify(
+        {
+          contractOk: false,
+          submitted: false,
+          timedOut: true,
+          prematureEnters,
+          pasteFramingRequired,
+          hasBracketedPasteFrame: input.includes(BEGIN) && input.includes(END),
+          markerReceived: input.includes(marker),
+          receivedBytes: Buffer.byteLength(input, 'utf8')
+        },
+        null,
+        2
+      )
+    ).finally(() => process.exit(8))
+  }, timeoutMs)

42-74: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Bound runCommand with a manual timeout.

callOrca passes no timeout, so a hung orca process can block direct runs. Use setTimeout to kill the child and reject the promise. Clear the timer when the child exits.

src/main/runtime/orca-runtime.test.ts (1)

16730-16738: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Check carriage returns across complete writes.

The 1,500 ms AGENT_PROMPT_RENDER_QUIET_MS window makes the current timer sequence valid. Assert over writes.join(''), or count carriage returns across all writes, so an embedded '\r' cannot bypass the test.

config/reliability-gates.jsonc (1)

8656-8659: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add the CLI build step to the Windows command.

build:cli exists and installs the development CLI. The Windows command should prepare the source-built CLI before running Playwright, as the macOS command does.

Proposed change
-        "pnpm.cmd exec playwright test tests/e2e/terminal-send-agent-prompt-submit.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1",
+        "pnpm.cmd run build:cli && pnpm.cmd exec playwright test tests/e2e/terminal-send-agent-prompt-submit.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1",

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6d70d886-4610-4cd0-8fdc-6eef07e3b955

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb8836 and fd5332e.

📒 Files selected for processing (9)
  • config/reliability-gates.jsonc
  • src/cli/handlers/terminal.test.ts
  • src/cli/handlers/terminal.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
  • tests/e2e/terminal-send-agent-prompt-submit.spec.ts
  • tests/tools/repro-terminal-send-submit.mjs

Comment thread config/reliability-gates.jsonc Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved
@Jinwoo-H
Jinwoo-H force-pushed the bug-strange-behavior-i-think-when-using-orchestr branch from fd5332e to 11e42fa Compare August 15, 2026 00:02
@Jinwoo-H Jinwoo-H changed the title fix(cli): settle agent prompts before terminal submit fix(terminal): settle prompt submission for every agent Aug 15, 2026

@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

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)

17610-17619: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Represent the prompt render-marker policy in configuration. claude uses --prefill and codex uses codex-composer-prompt, so these checks are intentional but separate from draftPasteReadySignal; an explicit field would prevent future drift.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ea6d5838-6073-43e5-8338-f4c757780b50

📥 Commits

Reviewing files that changed from the base of the PR and between fd5332e and 11e42fa.

📒 Files selected for processing (5)
  • config/reliability-gates.jsonc
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
  • src/main/runtime/rpc/methods/terminal.ts

Comment thread config/reliability-gates.jsonc Outdated
"https://github.com/stablyai/orca/issues/14525"
],
"invariant": "A public CLI send containing non-empty text plus Enter and no interrupt identifies agent-prompt intent. The owning runtime uses bracketed-paste and settled submit only when the exact target is a running recognized agent on a desktop call; shells, text-only input, bare Enter, interrupts, mobile input, query replies, and older clients keep the direct terminal contract.",
"oracle": "Launch a bare fake Codex through the real Electron PTY and delay its composer render for 1,200 ms, beyond the legacy generic 500 ms gap. Send a 557-byte prompt with the public CLI and require the marker, zero premature Enter, no rescue Enter, and one submission. POSIX child stdin must retain one bracketed-paste frame; Windows ConPTY consumes that control frame, so runtime tests require the frame at the PTY write boundary while the Windows child requires the exact prompt. The same harness against the installed pre-fix runtime must record one premature Enter and require one bare rescue Enter. Focused units require CLI intent only for text plus Enter, settled routing after recognized-agent confirmation, every configured TUI agent to wait for output quiescence, unidentified fresh prompts to wait 1.5 seconds, wrapper foregrounds to avoid speculative polling, and byte-for-byte direct fallback for a non-agent target.",

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Reconcile the prompt byte counts.

Line 8871 states a "557-byte prompt". Line 8928 states "all 567 prompt bytes". Both describe the same fake-Codex payload. Correct the wrong value, or state why the counts differ (for example, framing bytes).

Also applies to: 8928-8928

@Jinwoo-H
Jinwoo-H force-pushed the bug-strange-behavior-i-think-when-using-orchestr branch from 11e42fa to 9a25596 Compare August 15, 2026 10:35
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Jinwoo-H Jinwoo-H changed the title fix(terminal): settle prompt submission for every agent fix(terminal): settle CLI prompts for Claude and Codex Aug 15, 2026
@Jinwoo-H
Jinwoo-H merged commit d2ffe1f into main Aug 15, 2026
99 of 101 checks passed
@Jinwoo-H
Jinwoo-H deleted the bug-strange-behavior-i-think-when-using-orchestr branch August 15, 2026 22:45
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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

1 participant