Skip to content

fix(terminal): size the pre-Enter wait to what the host actually ingests (#15925) - #16586

Merged
nwparker merged 3 commits into
mainfrom
nwparker/win-15925-conpty-ingest-bound
Aug 26, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/win-15925-conpty-ingest-bound

Conversation

@nwparker

@nwparker nwparker commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​479 $\color{#cf222e}{\Huge{\mathbf{−}}}$​31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​448
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158 $\color{#cf222e}{\Huge{\mathbf{−}}}$​36 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122

ELI5

When Orca pastes a long prompt into a terminal on Windows, the text takes time to actually arrive — the longer the prompt, the longer it takes. Orca used to wait a fixed 1.5 seconds and then press Enter, which was far too long for a short prompt and, on a big one, meant Enter reached the agent while the paste was still being delivered. The text is never lost or scrambled — the terminal writes bytes strictly in order — but the agent gets Enter with no breathing room, so it can submit an empty box and then watch your prompt appear underneath, unsent. Now Orca works out how long that particular paste needs based on its size and the machine it is going to, and waits for that instead. Short prompts submit roughly three times faster; long ones keep the same quiet gap before Enter that macOS and Linux have always had.

What Changed

src/shared/agent-prompt-injection.ts

  • Replaced the flat AGENT_PROMPT_SUBMIT_DELAY_MS constant (500 ms / 1500 ms on Windows, frozen from the importing process's process.platform) with getTerminalPasteIngestMs(platform, byteLength) — a size-proportional lower bound on when a paste can have reached the child — and getAgentPromptSubmitDelayMs(platform, byteLength) = 500 ms settle + that bound, uncapped.
  • WINDOWS_CONPTY_INGEST_BYTES_PER_MS = 64 (1.5x the slower of two measured host slopes); non-Windows keeps a 3x-margin 4096 B/ms rate that costs 0 ms at real prompt sizes.

src/main/runtime/orca-runtime.ts

  • The rate is resolved per-pty from the host that owns the pty transport (getPtyWriteHostPlatform), not the client and not the command's OS. A WSL pane on Windows still pays ConPTY, because local-pty-provider.ts:625 spawns wsl.exe behind the Windows pseudoconsole; an SSH pane follows the relay's reported remotePlatform.
  • Three call sites now use it: the open-loop fallback wait, the claude/codex render gate (its 1500 ms quiet window can no longer start before the ingest bound elapses, and its 8 s hard cap now sits on top of the bound rather than standing in for it), and the plain terminal.send suffix path, which previously had an undocumented flat 500 ms with no platform check at all.
  • Inter-chunk setTimeout(0) → setImmediate in the terminal input chunk loop.

Fix round (commit 9b7edafac28), on top of the original commit:

  • Render-gate hard cap double-counted the ingest window. armHardTimer() runs twice — at arm() and again when the show-cursor marker arrives — and each arming re-added the full pasteIngestMs, while the ingest clock runs once from gate construction. Now the deadline is captured absolutely (ingestDeadlineAt = Date.now() + pasteIngestMs) and both call sites arm with AGENT_PROMPT_RENDER_TIMEOUT_MS + Math.max(0, ingestDeadlineAt - Date.now()). Worst case for a 1 MB prompt on a never-quiet pane drops from ~34 s back to the intended ~24 s.
  • The scaled suffix wait is now abortable. signal is threaded terminal-send-method.ts → sendTerminal → writeTerminalAction → waitForAgentPromptDelay, matching what sendTerminalAgentPrompt already did. A 16 MB payload's wait is ~262 s, far past the CLI's 60 s request budget; before this an abandoned request still wrote \r at the end.
  • Elegance: dropped a dead isWslHookRelayConnectionId(connectionId) clause from getPtyWriteHostPlatform (a pty record's connectionId is only ever an SSH target id; wsl: ids are stamped on hook envelopes only), and removed two action.text! non-null assertions by hoisting a narrowed text.
  • Three new regression tests, each verified to fail against the pre-fix arithmetic, plus a correction to this PR's own render-gate cap test, which had encoded the double-count.

No new commits landed in this review round; the branch head is still 9b7edafac28. What changed is the analysis below.

Why

AGENT_PROMPT_SUBMIT_DELAY_MS was a constant modelling a size-proportional cost, so it was wrong in both directions. It was also computed from the importing process's process.platform at module load, so a macOS client driving a Windows host got the macOS value.

ConPTY paste ingest re-measured on a second real Windows 11 host (Node 24.18.0, the repo's patched node-pty, useConptyDll: true, 16 KiB chunks, raw-mode child; metric = first pasted byte written → child observes ESC[201~; 6 iterations per size, first discarded, p50):

bytes host A (issue) host B (this PR)
2,000 14 ms 25 ms
8,000 60 ms 89 ms
40,000 347 ms 440 ms
80,000 804 ms 858 ms
160,000 1,662 ms 1,499 ms
320,000 3,342 ms 2,969 ms

Linear on both, slopes 0.0104 and 0.0092 ms/byte (96.2 and 108.5 B/ms) — ~40% host-to-host spread, in both directions, which is why 64 B/ms is deliberately 1.5x the slower slope rather than a tight fit.

  • Too slow for the common case: a 2–8 KB prompt needs 14–89 ms and was charged 1500 ms.
  • Too short at the top end — a live correctness bug, but not the one the old description named. The old body said Enter could truncate or split the paste. That is wrong and is corrected here: node-pty's write queue is ordered and the \r is always appended after ESC[201~, so no byte is ever lost, dropped, or reordered. What the flat 1500 ms actually destroyed is the settle gap. Host B took 1,499 ms of ingest at 160 KB against a 1,500 ms constant, so the \r sat behind still-queued paste bytes and reached the child ~1 ms after paste-end — and is provably early beyond that, up to the 16 MB TERMINAL_INPUT_MAX_BYTES ceiling. An agent that attaches the pasted block asynchronously then processes Enter against pre-paste composer state: it submits an empty or previous-turn prompt, and the pasted text lands afterwards, sitting unsent in the box. Silent, and recoverable by pressing Enter again — but an automated caller has no one to press it and gets agent_prompt_stalled.

Resulting Windows waits: 2 KB 532 ms (was 1500) · 8 KB 626 ms (was 1500) · 160 KB 3000 ms (was 1500, measured 1499–1662) · 320 KB 5500 ms (measured 2969–3342).

The setTimeout(0) → setImmediate swap is separate: it cost a full ~15 ms Windows timer tick per 16 KiB chunk (~0.95 s/MB). It was not flow control — at 16 KiB/~15 ms it paces ~1.07 MB/s, 11x above ConPTY's ~96 KB/s drain, so the in-flight buffer grew regardless and TERMINAL_INPUT_MAX_BYTES bounds it identically either way. The event-loop yield it did provide (abort/permission/data callbacks between chunks) is preserved.

AGENT_PROMPT_RENDER_QUIET_MS is deliberately unchanged at 1500: nothing measured here describes post-paste redraw cadence, and shortening it risks submitting mid-redraw.

Risk & Trade-offs

Merge risk: Low-medium. The change touches every agent-prompt paste on every platform, and its central number (64 B/ms) is still fitted to two Windows hosts — but this round replaced the hand-wave with arithmetic, and the arithmetic says the failure mode is a silent, self-recoverable empty submit that needs an order-of-magnitude slowdown to reach ordinary prompts.

The grade was revisited, not carried over, and it did not move — for two offsetting reasons. It went down because the break condition is now derived rather than guessed, and because the derivation shows the ≥64 B/ms case is behaviourally identical to what macOS and Linux already ship (see below). It went up because the failure the PR actually prevents turned out to be a silent wrong-state submit rather than the visible corruption the old body claimed, and because the primary UI flow is still on the old flat delay (now #16680).

What the break condition actually is

The 500 ms settle term is not margin — it cancels. The gap the child sees between paste-end and \r is (500 + N/64) − N/R, so keeping the same flat 500 ms gap that non-Windows has always shipped requires R ≥ 64 B/ms independent of payload size. Host A measured 96.2 B/ms, so the entire budget is 96.2/64 = 1.503x. That is the whole safety story; there is no size at which the 500 ms buys extra room.

Two regimes follow:

  • Under ~16 KB (nearly all real prompts). The gap only reaches zero if the host is roughly an order of magnitude slower than measured — 4.5x at 16 KB, ~25x at 2 KB. Effectively unbreakable.
  • Above ~100 KB. The 1.5x is the entire budget. A host 2x slower than host A regresses at ~97 KB.

The only plausible source of a 2–3x factor is CPU contention (a busy build, a thermally throttled laptop). Two candidates were checked and ruled out: RDP is irrelevant because the ConPTY here is headless with no attached console window, and AV hooks file I/O, not named-pipe reads.

The strongest argument for the number

At R ≥ 64 B/ms the formula reduces the Windows large-paste case to exactly the macOS/Linux case: a flat 500 ms gap between paste-end and Enter. That configuration ships to the entire non-Windows fleet today and has produced no reports of this failure. That is empirical validation on a large population — a much better warrant than "1.5x of two hosts", which is how the previous version of this section justified it.

What could go wrong

  • A slow Windows host still gets Enter pressed too early, truncating or splitting a long prompt. Measured and re-characterised. Nothing truncates or splits — writes are ordered. The real risk is the settle gap reaching zero, which requires R < 64 B/ms: a 1.503x slowdown from host A, reachable only above ~100 KB, and needing ~10x at ordinary prompt sizes. Consequence if it happens: the agent submits an empty or previous-turn composer and the prompt lands unsent below it. Silent for a human (fixed by pressing Enter), agent_prompt_stalled for an automated caller. Still no telemetry to observe the field distribution; the tests pin the floor against regression only.
  • Long Windows prompts feel slow before they submit. A 320 KB prompt now waits ~5.5 s and a 1 MB prompt on a claude/codex pane waits ~18 s before Enter, against a flat 1.5 s before. This is intended and bounded (the render gate caps at ingest + 8 s), but a user pasting a very large prompt will notice the pane sitting still and may assume it hung. Certain to happen, by design; would surface as "Orca is stuck after I pasted".
  • The renderer's two-phase paste path is untouched, and its caller is the primary UI flow. agent-paste-draft.ts:214 and active-agent-note-send.ts:217 write Enter a flat POST_PASTE_SUBMIT_DELAY_MS = 50 after the paste, and because that Enter is a text-less terminal.send it picks up no ingest bound at all. The caller is the startup draft prompt — the way most prompts actually reach an agent — so this PR does not mean "large prompts are fixed". Pre-existing, deliberately out of scope, now filed as Renderer paste-then-Enter still uses a flat 50ms delay, so the startup draft prompt can submit empty on Windows #16680.
  • getPtyWriteHostPlatform falls back to process.platform when the pty record is missing. A macOS client driving a Windows host in that window would compute the non-Windows rate and effectively wait 0 ms of ingest. No case was constructed where a writable leaf has no record, so this is unhardened rather than known-broken; if it happened it would look identical to the pre-PR bug on that one send.
  • The setTimeout(0) -> setImmediate swap changes chunk pacing. It removes ~15 ms of Windows timer sleep per 16 KiB chunk. It was never flow control (it paced 11x above ConPTY's drain rate, and TERMINAL_INPUT_MAX_BYTES bounds the buffer identically either way), and it makes real ingest faster than the numbers the bound was fitted to, so the safety margin grows. Self-correcting in the direction that matters.

What a user gets in exchange

Ordinary prompts submit about 3x faster on Windows: a 2 KB prompt waits 532 ms instead of 1500 ms, an 8 KB prompt 626 ms instead of 1500 ms. Large prompts get back the 500 ms settle gap they had lost — host B measured 1,499 ms of ingest at 160 KB against the old 1,500 ms constant, i.e. Enter was reaching the child ~1 ms after paste-end and provably before it above that, up to the 16 MB input ceiling, which is how an agent ends up submitting an empty composer with the prompt sitting under it. Two paths the linked issue never mentioned (the claude/codex render gate and the plain terminal.send suffix, which had an undocumented flat 500 ms with no platform check) are now covered too, and the rate is resolved from the host that actually owns the pty — so a macOS client driving a Windows or WSL pane no longer gets the macOS value.

Alternatives considered and rejected

  • Closed-loop waiting on a render acknowledgement — ruled out, not overlooked. AGENT_PROMPT_RENDER_MARKER is ESC[?25h (show cursor), an artifact of how claude and codex repaint, not a paste acknowledgement. For an agent that never hides the cursor, canSettle never flips and the gate falls through to its 8 s timeout — turning today's 626 ms wait into a flat 8 s. A genuine closed loop needs a ConPTY drain signal, which node-pty does not expose on Windows.
  • Adaptive calibration — rejected because it adapts in the wrong direction. You would calibrate on an idle machine and paste during a build, i.e. measure fast and then run slow: it underestimates exactly when the margin is needed.

Trade-offs accepted

  • Worst-case latency is deliberately worse. Big Windows prompts now wait seconds to tens of seconds instead of 1.5 s. That is the cost of correctness; there is no way to submit sooner than the bytes arrive.
  • No telemetry was added to observe real ingest slopes in the field, so the 1.503x budget cannot be validated or tightened without another manual measurement round.
  • The two renderer flat delays are left broken, and they sit on the primary UI flow. Scope was narrowed to the main-process paths; follow-up filed as Renderer paste-then-Enter still uses a flat 50ms delay, so the startup draft prompt can submit empty on Windows #16680 for agent-paste-draft.ts:214 and active-agent-note-send.ts:217.
  • AGENT_PROMPT_RENDER_QUIET_MS stays at 1500 ms, unmeasured. Nothing here describes post-paste redraw cadence, and shortening it on a guess risks submitting mid-redraw — so the 1500 ms is still being paid on top of the ingest bound.
  • A reviewer cleanup was declined: the local yieldBetweenTerminalInputChunks() wrapper stays instead of the repo's node:timers/promises setImmediate idiom, because the promises binding cannot be patched by vi.useFakeTimers() and four tests fail with the swap. A comment records why; the small inconsistency with orchestration.ts and friends is accepted.
  • Not exercised end-to-end on Windows. The measurements were taken by hand on two Windows 11 hosts, but the shipped code path was verified only by the automated suite on macOS with fake timers.

How to back it out

Clean revert. No persisted state, no schema or wire fields, no stream opcodes, no migration — the change is timing constants and call-site arithmetic, so reverting restores the previous flat delays immediately with no cleanup.

Linked Issue

Fixes #15925.

This closes the root cause the issue names, and additionally covers two paths the issue did not (the claude/codex render gate and the plain terminal.send suffix). It does not cover the two renderer-side flat delays described under Review below — those are tracked separately as #16680, and because their caller is the startup draft prompt, merging this PR should not be read as "large prompts are fixed".

Visual Proof

N/A — this is a main-process timing change with no rendered output; the only user-visible difference is how long Orca waits before pressing Enter, which produces no UI a screenshot can distinguish.

Testing

From the fix round (real output, clean worktree on the branch head 9b7edafac28):

$ pnpm tc
EXIT=0

$ pnpm test src/main/runtime src/shared/agent-prompt-injection.test.ts
 Test Files  454 passed | 1 skipped (455)
      Tests  5374 passed | 9 skipped (5383)
   Duration  85.42s

$ npx oxlint src/main/runtime/orca-runtime.ts src/main/runtime/orca-runtime.test.ts \
    src/main/runtime/agent-prompt-submission-windows-submit-delay.test.ts \
    src/main/runtime/rpc/methods/terminal/terminal-send-method.ts \
    src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
exit=0  (no diagnostics)

Non-vacuity checks (fixes reverted, new tests kept):

x caps a never-quiet pane at one ingest window past the render timeout
x abandons the scaled suffix wait when the request is aborted
  Tests  2 failed | 12 passed (14)
x forwards the request signal to a plain send so an abandoned call stops before Enter
  Tests  1 failed | 2 passed (3)

Independently re-run by the reviewer on a clean checkout of the branch before the fix round (454 files / 5371 tests green at that point); check:max-lines-ratchet OK. The three tests above were added after that run.

Hardware measurement (this round, no code change): ConPTY ingest re-run on a second real Windows 11 host — host B in the table above, 6 iterations per size at 2 KB / 8 KB / 40 KB / 80 KB / 160 KB / 320 KB, first discarded, p50 reported. Linear fit on both hosts; slopes 96.2 B/ms (A) and 108.5 B/ms (B). From those, the break condition was derived rather than asserted: the settle gap is (500 + N/64) − N/R, which is size-independent and requires R ≥ 64 B/ms, giving a 1.503x budget against host A. The empty-submit failure mode was confirmed by inspection of node-pty's ordered write queue (\r always appended after ESC[201~), which is what disproved the earlier truncation claim.

Coverage added by the branch: \r is not written before 3,342 ms at 320 KB; a mid-ingest render marker cannot settle the gate early; a never-quiet pane is capped at exactly one ingest window past the render timeout; an aborted sendTerminal writes no Enter; a WSL pane on Windows still pays ConPTY; both SSH directions. Shared-module table tests are pinned to the slower of the two measured hosts at each size, so a future slope reduction cannot silently reopen the bug.

Not covered by any test: the settle-gap failure itself (it needs a real slow ConPTY, not fake timers), and the renderer two-phase path, which is out of scope and tracked in #16680.

Preserved unchanged: abort/request_aborted, terminal_handle_stale generation checks, agent_prompt_blocked escalation, the bracketed-paste-end recovery write, and serializeAgentPromptSubmission.

  • I manually tested these changes locally — partially. The ConPTY ingest measurements above were taken by hand on two real Windows 11 hosts, but the shipped code path was not exercised end-to-end in the app on Windows; verification of the fix itself is the automated suite on macOS with fake timers.
  • Automated tests added/updated, or explained why not below

Review

Credit

No community PR credit is owed on this one, and that is a checked result rather than an omission: gh pr list --repo stablyai/orca --search "15925 in:body" --state all returns exactly one PR — this one. No other contributor filed an overlapping or adjacent fix, so nothing here was inherited from anyone else's work.

Corrected claims from earlier versions of this body

  1. "The ingest bound backs every pre-Enter wait." False, removed earlier, and still false. Two renderer-side waits are untouched:

    • src/renderer/src/lib/agent-paste-draft.ts:214 waits a flat POST_PASTE_SUBMIT_DELAY_MS = 50 (defined at :36) between the bracketed paste and a separate Enter-only write.
    • src/renderer/src/lib/active-agent-note-send.ts:217 does the same in the guarded two-phase send.

    Neither picks up the new runtime bound, because the Enter arrives as a text-less terminal.send: hasText is false at orca-runtime.ts:19706, so writeTerminalAction inserts no delay at all. AGENT_DRAFT_PASTE_MAX_BYTES is 16 MB (agent-draft-paste-content.ts:20). The caller is the startup draft prompt, i.e. the primary UI flow. Pre-existing, out of scope here, filed as Renderer paste-then-Enter still uses a flat 50ms delay, so the startup draft prompt can submit empty on Windows #16680.

  2. "Enter lands mid-paste, so the prompt is truncated or split across two turns." False — corrected in place above. node-pty's write queue is ordered and \r is appended after ESC[201~, so nothing is truncated, dropped, or reordered. The real defect is that the settle gap collapses to zero: the \r sits behind queued bytes and reaches the child immediately at paste-end, so an agent that attaches the paste asynchronously evaluates Enter against pre-paste state and submits an empty or previous-turn composer, with the pasted text landing afterwards, unsent. Silent and human-recoverable; agent_prompt_stalled for automated callers.

  3. "The 500 ms settle plus 1.5x of two hosts is the margin." Misleading. The 500 ms cancels out of the gap equation and buys nothing; the entire budget is the 1.503x in the rate constant. The real warrant for 64 B/ms is that at R ≥ 64 the Windows case becomes byte-for-byte the macOS/Linux case, which the whole non-Windows fleet already runs without reports.

Declined during the fix round

The reviewer proposed replacing the local yieldBetweenTerminalInputChunks() wrapper with the repo's established import { setImmediate as yieldToEventLoop } from 'node:timers/promises' idiom (-5 lines, matches orchestration.ts:3 and others). Declined, with an experiment. vi.useFakeTimers() intercepts the global setImmediate but cannot patch the binding inside node:timers/promises; a throwaway probe confirmed the global resolves under advanceTimersByTimeAsync while the timers/promises one waits on the real event loop. With the swap applied, four of this PR's tests failed — a 320 KB paste needs ~20 sequential chunk yields, and a chain of pure-microtask awaits never reaches the libuv check phase, so the paste never completed on the fake clock. The existing importers of that idiom are not exercised under fake timers, so the precedent does not transfer. The wrapper stays, with one added comment line recording why the global is required here.

Residual risk

  • Calibration rests on two hosts that disagree ~40%, and the budget is 1.503x. Now quantified rather than asserted: R ≥ 64 B/ms is required at every size, so a host 1.503x slower than host A loses the settle gap — but only above ~100 KB (a 2x-slower host regresses at ~97 KB), and ordinary prompts need ~10x. CPU contention is the only plausible route there; RDP does not apply (headless ConPTY) and AV hooks file I/O, not named-pipe reads. The tests pin the floor so a regression is caught; a slower real-world host is not covered.
  • The failure mode is silent. If the gap does collapse, the user sees an empty submit followed by their prompt appearing unsent — not an error. Automated callers surface it as agent_prompt_stalled.
  • Worst-case latency grows materially for large Windows prompts. The minimum pre-Enter wait on a claude/codex pane is now ingest + 1500 ms (~18 s for a 1 MB prompt), capped at ingest + 8 s. Intentional, but no telemetry was added to observe the distribution in the field.
  • The primary UI flow is still unfixed (Renderer paste-then-Enter still uses a flat 50ms delay, so the startup draft prompt can submit empty on Windows #16680): the startup draft prompt reaches the terminal through the renderer's flat 50 ms two-phase path.
  • getPtyWriteHostPlatform falls back to process.platform when ptysById has no record for the ptyId. parseAppSshPtyId(ptyId) would recover an SSH pane in that window, but no case was constructed where a writable leaf has no record — this is hardening not done, not a known defect.
  • The setImmediate swap removes ~15 ms/chunk of Windows timer sleep that was inside the measured baseline, so real ingest is now faster than the numbers the bound was fitted to. Margin grows, not shrinks.
  • No wire, schema, persisted-state, settings, or provider-specific surface is touched: no new RPC fields, no stream opcodes, no Git invocations, so remote wire compatibility, rollback, and GitHub/GitLab neutrality are not at risk. Removing the module-scope AGENT_PROMPT_SUBMIT_DELAY_MS from a src/shared module is a small improvement for non-Node bundles; grep across src/, mobile/ and docs/ confirms the only remaining importers of the changed exports are orca-runtime.ts and tests.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: no new surface. Cross-platform: the whole point — rate follows the pty transport host (win32/WSL-behind-ConPTY/SSH remotePlatform), non-Windows keeps a 3x-margin rate that is 0 ms at real prompt sizes. Remote SSH: covered in both directions by tests. Mobile: untouched. Backwards compatibility: no persisted or wire state. Performance: 2–8 KB Windows prompts submit ~3x faster; large prompts intentionally wait longer because they have to.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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
  • pnpm tc, pnpm test src/main/runtime src/shared/agent-prompt-injection.test.ts, and oxlint pass locally; full pnpm build left to CI

The Windows agent-prompt submit delay was a flat 1_500 ms frozen from the
client's process.platform at import. Measured on two real Win11 hosts, ConPTY
ingests a bracketed paste linearly at ~0.009-0.010 ms/byte, so the constant was
both far too long for a 2-8 KB prompt (14-89 ms of real cost) and too short past
~145 KB — at 160 KB one host took 1_499 ms, meaning Enter landed mid-paste,
exactly the corruption the delay exists to prevent, up to the 16 MB input ceiling.

Replace it with getTerminalPasteIngestMs(platform, byteLength) and derive every
pre-Enter wait from it:

- open-loop fallback = 500 ms settle + ingest bound, uncapped
- claude/codex render gate cannot start its quiet window before the ingest bound
  elapses (an agent that repaints mid-ingest could otherwise satisfy
  marker-then-quiet while ConPTY was still feeding the paste), and its 8 s hard
  cap now sits on top of the ingest bound instead of standing in for it
- the plain terminal.send suffix path, which had an undocumented flat 500 ms

The rate follows the host that owns the pty transport, not the client: a WSL pane
is spawned as wsl.exe behind the Windows pseudoconsole so it still pays ConPTY,
while an SSH pane follows the relay's reported remotePlatform.

Also swap the inter-chunk setTimeout(0) for setImmediate. It cost a full ~15 ms
Windows timer tick per 16 KiB chunk (~0.95 s/MB) while pacing ~1.07 MB/s — 11x
above ConPTY's drain rate — so it never provided backpressure; the event-loop
yield it did provide is preserved.
The render gate's hard cap is armed twice -- once at arm() and again when the
show-cursor marker arrives -- but it re-added the whole ingest window each time
while the ingest clock itself runs once from gate construction. A marker seen
mid-ingest pushed the cap out by a second full ingest term (~34 s instead of
~24 s for a 1 MB prompt on ConPTY). Capture the ingest deadline absolutely and
arm with what is left of it.

Also thread the request AbortSignal through terminal.send so the now
payload-scaled suffix wait can be cancelled: at 16 MB it runs ~262 s, well past
the CLI's 60 s request budget, and previously nothing stopped the eventual Enter.

Cleanups: a pty record's connectionId is only ever an SSH target id, so the
wsl: relay-id guard in getPtyWriteHostPlatform was dead; and hoisting
action.text removes both non-null assertions in writeTerminalAction.
@coderabbitai

coderabbitai Bot commented Aug 26, 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: c3a24e79-749c-4844-a129-06b5a089f8e1

📥 Commits

Reviewing files that changed from the base of the PR and between 0096e47 and 6ee3856.

📒 Files selected for processing (8)
  • src/main/runtime/agent-prompt-submission-runtime.test.ts
  • src/main/runtime/agent-prompt-submission-windows-submit-delay.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
  • src/shared/agent-prompt-injection.test.ts
  • src/shared/agent-prompt-injection.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/main/runtime/agent-prompt-submission-runtime.test.ts
  • src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
  • src/main/runtime/rpc/terminal-agent-prompt-send.test.ts
  • src/shared/agent-prompt-injection.test.ts
  • src/shared/agent-prompt-injection.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/agent-prompt-submission-windows-submit-delay.test.ts
  • src/main/runtime/orca-runtime.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Terminal submission delays now scale with UTF-8 payload size and PTY host platform. Terminal sends resolve remote host platforms, yield between chunks with setImmediate, and support abort signals. Agent prompt rendering waits for paste ingestion before quiet or hard settlement timers. RPC handling forwards request signals to terminal sends. Tests cover platform differences, large payloads, remote hosts, render settlement, cancellation, and invalid timing inputs.

Merge Risk: ⚪ Minimal · up to 6ee38

This change adjusts terminal prompt submission timing and cancellation handling; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 6 files. (2 skipped: 2… 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 primary change: sizing the terminal pre-Enter wait based on host ingestion speed.
Description check ✅ Passed The description is complete and directly matches the template. It explains the change and rationale, links issue #15925, documents visual proof as not applicable, lists testing and platform coverage, …
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: Description check

Explanation

The description is complete and directly matches the template. It explains the change and rationale, links issue #15925, documents visual proof as not applicable, lists testing and platform coverage, records known limitations, and completes the checklist.

Full details: Docstring Coverage

Explanation

Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 6 files. (2 skipped: 2 too large.)

  • Fix all pre-merge checks with AI
✨ 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 commented Aug 26, 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.

@nwparker
nwparker merged commit 08a447d into main Aug 26, 2026
99 of 101 checks passed
@nwparker
nwparker deleted the nwparker/win-15925-conpty-ingest-bound branch August 26, 2026 23:30
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…sts (stablyai#15925) (stablyai#16586)

* fix(terminal): size the pre-Enter wait to what the host actually ingests

The Windows agent-prompt submit delay was a flat 1_500 ms frozen from the
client's process.platform at import. Measured on two real Win11 hosts, ConPTY
ingests a bracketed paste linearly at ~0.009-0.010 ms/byte, so the constant was
both far too long for a 2-8 KB prompt (14-89 ms of real cost) and too short past
~145 KB — at 160 KB one host took 1_499 ms, meaning Enter landed mid-paste,
exactly the corruption the delay exists to prevent, up to the 16 MB input ceiling.

Replace it with getTerminalPasteIngestMs(platform, byteLength) and derive every
pre-Enter wait from it:

- open-loop fallback = 500 ms settle + ingest bound, uncapped
- claude/codex render gate cannot start its quiet window before the ingest bound
  elapses (an agent that repaints mid-ingest could otherwise satisfy
  marker-then-quiet while ConPTY was still feeding the paste), and its 8 s hard
  cap now sits on top of the ingest bound instead of standing in for it
- the plain terminal.send suffix path, which had an undocumented flat 500 ms

The rate follows the host that owns the pty transport, not the client: a WSL pane
is spawned as wsl.exe behind the Windows pseudoconsole so it still pays ConPTY,
while an SSH pane follows the relay's reported remotePlatform.

Also swap the inter-chunk setTimeout(0) for setImmediate. It cost a full ~15 ms
Windows timer tick per 16 KiB chunk (~0.95 s/MB) while pacing ~1.07 MB/s — 11x
above ConPTY's drain rate — so it never provided backpressure; the event-loop
yield it did provide is preserved.

* fix(terminal): stop double-charging paste ingest in the render gate

The render gate's hard cap is armed twice -- once at arm() and again when the
show-cursor marker arrives -- but it re-added the whole ingest window each time
while the ingest clock itself runs once from gate construction. A marker seen
mid-ingest pushed the cap out by a second full ingest term (~34 s instead of
~24 s for a 1 MB prompt on ConPTY). Capture the ingest deadline absolutely and
arm with what is left of it.

Also thread the request AbortSignal through terminal.send so the now
payload-scaled suffix wait can be cancelled: at 16 MB it runs ~262 s, well past
the CLI's 60 s request budget, and previously nothing stopped the eventual Enter.

Cleanups: a pty record's connectionId is only ever an SSH target id, so the
wsl: relay-id guard in getPtyWriteHostPlatform was dead; and hoisting
action.text removes both non-null assertions in writeTerminalAction.
rahuljangirworks pushed a commit to rahuljangirworks/veer that referenced this pull request Aug 27, 2026
…sts (stablyai#15925) (stablyai#16586)

* fix(terminal): size the pre-Enter wait to what the host actually ingests

The Windows agent-prompt submit delay was a flat 1_500 ms frozen from the
client's process.platform at import. Measured on two real Win11 hosts, ConPTY
ingests a bracketed paste linearly at ~0.009-0.010 ms/byte, so the constant was
both far too long for a 2-8 KB prompt (14-89 ms of real cost) and too short past
~145 KB — at 160 KB one host took 1_499 ms, meaning Enter landed mid-paste,
exactly the corruption the delay exists to prevent, up to the 16 MB input ceiling.

Replace it with getTerminalPasteIngestMs(platform, byteLength) and derive every
pre-Enter wait from it:

- open-loop fallback = 500 ms settle + ingest bound, uncapped
- claude/codex render gate cannot start its quiet window before the ingest bound
  elapses (an agent that repaints mid-ingest could otherwise satisfy
  marker-then-quiet while ConPTY was still feeding the paste), and its 8 s hard
  cap now sits on top of the ingest bound instead of standing in for it
- the plain terminal.send suffix path, which had an undocumented flat 500 ms

The rate follows the host that owns the pty transport, not the client: a WSL pane
is spawned as wsl.exe behind the Windows pseudoconsole so it still pays ConPTY,
while an SSH pane follows the relay's reported remotePlatform.

Also swap the inter-chunk setTimeout(0) for setImmediate. It cost a full ~15 ms
Windows timer tick per 16 KiB chunk (~0.95 s/MB) while pacing ~1.07 MB/s — 11x
above ConPTY's drain rate — so it never provided backpressure; the event-loop
yield it did provide is preserved.

* fix(terminal): stop double-charging paste ingest in the render gate

The render gate's hard cap is armed twice -- once at arm() and again when the
show-cursor marker arrives -- but it re-added the whole ingest window each time
while the ingest clock itself runs once from gate construction. A marker seen
mid-ingest pushed the cap out by a second full ingest term (~34 s instead of
~24 s for a 1 MB prompt on ConPTY). Capture the ingest deadline absolutely and
arm with what is left of it.

Also thread the request AbortSignal through terminal.send so the now
payload-scaled suffix wait can be cancelled: at 16 MB it runs ~262 s, well past
the CLI's 60 s request budget, and previously nothing stopped the eventual Enter.

Cleanups: a pty record's connectionId is only ever an SSH target id, so the
wsl: relay-id guard in getPtyWriteHostPlatform was dead; and hoisting
action.text removes both non-null assertions in writeTerminalAction.
luisgonzaleznf added a commit to luisgonzaleznf/orca that referenced this pull request Aug 27, 2026
Keep the pending-draft check ahead of the paste-ingest sizing (stablyai#16586)
that now feeds createAgentPromptRenderGate.

Co-Authored-By: Claude Fable 5 <[email protected]>
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 28, 2026
…sts (stablyai#15925) (stablyai#16586)

* fix(terminal): size the pre-Enter wait to what the host actually ingests

The Windows agent-prompt submit delay was a flat 1_500 ms frozen from the
client's process.platform at import. Measured on two real Win11 hosts, ConPTY
ingests a bracketed paste linearly at ~0.009-0.010 ms/byte, so the constant was
both far too long for a 2-8 KB prompt (14-89 ms of real cost) and too short past
~145 KB — at 160 KB one host took 1_499 ms, meaning Enter landed mid-paste,
exactly the corruption the delay exists to prevent, up to the 16 MB input ceiling.

Replace it with getTerminalPasteIngestMs(platform, byteLength) and derive every
pre-Enter wait from it:

- open-loop fallback = 500 ms settle + ingest bound, uncapped
- claude/codex render gate cannot start its quiet window before the ingest bound
  elapses (an agent that repaints mid-ingest could otherwise satisfy
  marker-then-quiet while ConPTY was still feeding the paste), and its 8 s hard
  cap now sits on top of the ingest bound instead of standing in for it
- the plain terminal.send suffix path, which had an undocumented flat 500 ms

The rate follows the host that owns the pty transport, not the client: a WSL pane
is spawned as wsl.exe behind the Windows pseudoconsole so it still pays ConPTY,
while an SSH pane follows the relay's reported remotePlatform.

Also swap the inter-chunk setTimeout(0) for setImmediate. It cost a full ~15 ms
Windows timer tick per 16 KiB chunk (~0.95 s/MB) while pacing ~1.07 MB/s — 11x
above ConPTY's drain rate — so it never provided backpressure; the event-loop
yield it did provide is preserved.

* fix(terminal): stop double-charging paste ingest in the render gate

The render gate's hard cap is armed twice -- once at arm() and again when the
show-cursor marker arrives -- but it re-added the whole ingest window each time
while the ingest clock itself runs once from gate construction. A marker seen
mid-ingest pushed the cap out by a second full ingest term (~34 s instead of
~24 s for a 1 MB prompt on ConPTY). Capture the ingest deadline absolutely and
arm with what is left of it.

Also thread the request AbortSignal through terminal.send so the now
payload-scaled suffix wait can be cancelled: at 16 MB it runs ~262 s, well past
the CLI's 60 s request budget, and previously nothing stopped the eventual Enter.

Cleanups: a pty record's connectionId is only ever an SSH target id, so the
wsl: relay-id guard in getPtyWriteHostPlatform was dead; and hoisting
action.text removes both non-null assertions in writeTerminalAction.

(cherry picked from commit 08a447d)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…sts (stablyai#15925) (stablyai#16586)

* fix(terminal): size the pre-Enter wait to what the host actually ingests

The Windows agent-prompt submit delay was a flat 1_500 ms frozen from the
client's process.platform at import. Measured on two real Win11 hosts, ConPTY
ingests a bracketed paste linearly at ~0.009-0.010 ms/byte, so the constant was
both far too long for a 2-8 KB prompt (14-89 ms of real cost) and too short past
~145 KB — at 160 KB one host took 1_499 ms, meaning Enter landed mid-paste,
exactly the corruption the delay exists to prevent, up to the 16 MB input ceiling.

Replace it with getTerminalPasteIngestMs(platform, byteLength) and derive every
pre-Enter wait from it:

- open-loop fallback = 500 ms settle + ingest bound, uncapped
- claude/codex render gate cannot start its quiet window before the ingest bound
  elapses (an agent that repaints mid-ingest could otherwise satisfy
  marker-then-quiet while ConPTY was still feeding the paste), and its 8 s hard
  cap now sits on top of the ingest bound instead of standing in for it
- the plain terminal.send suffix path, which had an undocumented flat 500 ms

The rate follows the host that owns the pty transport, not the client: a WSL pane
is spawned as wsl.exe behind the Windows pseudoconsole so it still pays ConPTY,
while an SSH pane follows the relay's reported remotePlatform.

Also swap the inter-chunk setTimeout(0) for setImmediate. It cost a full ~15 ms
Windows timer tick per 16 KiB chunk (~0.95 s/MB) while pacing ~1.07 MB/s — 11x
above ConPTY's drain rate — so it never provided backpressure; the event-loop
yield it did provide is preserved.

* fix(terminal): stop double-charging paste ingest in the render gate

The render gate's hard cap is armed twice -- once at arm() and again when the
show-cursor marker arrives -- but it re-added the whole ingest window each time
while the ingest clock itself runs once from gate construction. A marker seen
mid-ingest pushed the cap out by a second full ingest term (~34 s instead of
~24 s for a 1 MB prompt on ConPTY). Capture the ingest deadline absolutely and
arm with what is left of it.

Also thread the request AbortSignal through terminal.send so the now
payload-scaled suffix wait can be cancelled: at 16 MB it runs ~262 s, well past
the CLI's 60 s request budget, and previously nothing stopped the eventual Enter.

Cleanups: a pty record's connectionId is only ever an SSH target id, so the
wsl: relay-id guard in getPtyWriteHostPlatform was dead; and hoisting
action.text removes both non-null assertions in writeTerminalAction.
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.

Windows agent-prompt submit burns ~1.45s of dead time per send, and the 1500ms constant is too short above ~145KB

1 participant