Skip to content

fix(agent-prompt): press Enter again while a Windows Codex composer still holds a dispatch - #33295

Merged
nwparker merged 6 commits into
mainfrom
nwparker/agint-11343
Oct 25, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/agint-11343

Conversation

@nwparker

@nwparker nwparker commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​265 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​255
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​219 $\color{#cf222e}{\Huge{\mathbf{−}}}$​32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​187

ELI5

On Windows, Codex reads a paste one key at a time, and on a slow machine that takes a while. For a ~10 KB task it took about 20 seconds. Orca pressed Enter after well under a second. That Enter reached Codex while it was still reading the paste, so Codex treated it as a newline inside the paste. The task then sat in the composer as [Pasted Content N chars] and never ran. After the first Enter, Orca now checks the composer. If no turn has started and the composer still holds a draft, Orca presses Enter again. It keeps checking for a window sized to the paste.

Root cause

The issue title is out of date. On main, the paste and the Enter already go out as separate writes (terminal-agent-prompt.ts), except for OMP. What fails now is the timing of that one Enter.

  • Codex's TUI on Windows gets no bracketed-paste event. The paste arrives as a stream of KeyCode::Char/KeyCode::Enter events, and PasteBurst treats an Enter during an active burst, or within 120 ms of its last key, as a newline inside the paste instead of a submit:
  • The timing uses the moment Codex processes each event, and Orca's Enter is queued behind the whole paste in the console input buffer. So an Enter written before Codex has read every pasted key is always handled immediately after the last pasted key, which means a newline. Waiting longer before that single Enter does not help unless the wait is longer than Codex's read time. Orca's wait is sized to ConPTY ingest (64 B/ms), which is far faster than Codex reading key events.
  • This also explains the earlier negative result in the issue thread (a quiet-window gate before Enter). Codex stays silent while it buffers a burst, so a quiet screen does not mean the paste has been read.
  • An existing one-shot retry Enter for Codex (submitRetryDelayMs, STA-5379) only ran on the composerReady launch path. Dispatch preambles, dispatch --inject, worker-start and agent-prompt terminal.send never got it.

What changed

  • resubmitHeldAgentPrompt (new terminal-agent-prompt-resubmit.ts, replacing resubmitAgentPromptAfterRetryDelay) runs after the first Enter for agents with submitRetryDelayMs (codex, qwen-code):
    • Windows input-record agents only (getAgentPromptHeldSubmitBudgetMs > 0: a Windows write host and windowsInputRecordPasteNewline, so Codex): every submitRetryDelayMs it waits for a turn start. Turn-start evidence comes from verifyAgentPromptSubmission: lifecycle or hook, never output bytes. If no turn has started, it presses Enter again only while the composer draft is this prompt (isHeldAgentPromptDraft). That means one of two things. Codex's [Pasted Content N chars] placeholders appear with nothing else beside them, and their sum lies between the prompt's length and that length plus 2 per LF, plus 1 per absorbed Enter, plus 8. That bound was measured: a 10,312-char prompt with 142 LFs showed 10,597. Or the visible text matches the prompt. A rotating placeholder such as Explain this codebase, a question overlay, the user's own text (alone or typed beside the held paste), and an unrelated paste never get an Enter. After beforeWrite, the turn start, permission, held deadline and draft match are all checked again, right before the write. Once the prompt is gone after a gated retry, it stops. The window is 3 ms/char, capped at AGENT_PROMPT_EFFECT_TIMEOUT_MS minus twice the paste's ingest floor. So the render gate (≤ 8 s + ingest), ingest itself and this wait add up to ≤ 38 s of delivery.
  • worker-start shortens its turn-start observation to whatever is left of its 50 s client grace after delivery (min(30 s, 50 s − delivery)). The RPC can no longer time out because of a held wait. A delivery under 20 s, which is every case today, keeps the full 30 s.
    • Everywhere else, main's behaviour is unchanged. There is no new wait. The only change: a composerReady launch's one blind retry is now skipped once the first Enter started a turn.
    • The blind launch retry is tracked apart from the gated retries, so a large Windows fresh-launch prompt can still be rescued after it.
  • No new IPC or protocol. The change runs on whichever host owns the PTY.

How verified

Real Codex CLI 0.162.1 on a low-spec Windows 11 host (win-lowspec, Orca 1.4.205 as the PTY host), driven from the Orca CLI. Codex was given a throwaway CODEX_HOME with a dummy API key, so a submit shows up as a turn that ends in 401.

  • Repro on the real dispatch path: a fresh Codex worker, then orca orchestration dispatch --inject of a 5.5 KB spec (10,597 chars with the preamble). Dispatch returned ok in ~1.3 s. The composer still held [Pasted Content 10597 chars] 40 s later, in 3/3 fresh-worker trials.
  • Codex read time: about 2 ms/char on this host. A raw bracketed paste took 5.1 s (1,849 chars), 10.4 s (4,587) and 21.1 s (9,249) to show its placeholder. An Enter sent 11 s into the 9,249-char paste was absorbed: the draft showed 9,250 chars, one more than the paste.
  • This PR's strategy on the same path (rule ported to the CLI, since the patched build can't run on that host): after the real dispatch --inject, press Enter again only while the composer shows a draft, every 1.2 s. In 4/4 trials there was exactly one extra Enter, about 20-21 s after dispatch, when the placeholder appeared. It submitted the full task every time. Alternating old/new trials: old 2/2 held, new 4/4 submitted. After the final review: 2/2 more real dispatches with the bounded rule were each rescued by one Enter (~22 s). A real held [Pasted Content 10597 chars] with the user's also fix the readme typo typed beside it resolved to no Enter. After the review redesign: 2/2 real dispatches matched [Pasted Content 10597 chars] against the prompt and were rescued with one Enter (~25 s). A worker with an empty composer and one holding the user's own text (also fix the readme typo) both resolved to no Enter.
  • Tests:
    • The bounded match table: measured count, split placeholders, user text beside the paste, an oversized or undersized paste, a rotating placeholder.
    • The retry is decided again after a write guard during which the user types or the held window runs out: no Enter.
    • worker-start observes only the time left of its grace after a 40 s delivery.
    • A real Codex frame (bold glyph, dim rotating placeholder, model footer) through the real headless reader. The reader reports it as a draft, and no extra Enter is sent.
    • New regression test: a Windows Codex dispatch whose first Enter is absorbed gets exactly one more Enter, and gets none when the composer is empty.
    • The launch retry test now also checks that the retry is skipped once a turn started.
    • pnpm tc:node, pnpm run check:code-quality:changed, and pnpm test on the runtime and orchestration suites all pass (2125 passed). The two orca-runtime.test.ts folder-import failures also happen without this change: they come from the macOS /private/var tmp path.

Risk

  • Latency for busy or unobservable Windows Codex: if a turn start is never observed, the writer can wait up to the held window (≤ 30 s) before returning. The draft check still sends no stray Enter in that case. This happens when the agent was already working when the prompt was queued, when hooks are missing, or when the draft reader misses the layout. A dispatch --inject reply is late by that much, but stays inside its 60 s CLI timeout.
  • worker-start budget: delivery is now bounded at ≤ 38 s, and the turn-start observation is cut to the rest of the 50 s grace. A slow rescue can therefore leave less time to observe a late turn start. Such a start is still reported as unobserved/unverifiable, never as failed.
  • Layouts the draft reader misses: some Codex layouts aren't recognized by the draft reader, e.g. an extra ⚠ N warning footer row. The rescue doesn't fire there, which is today's behaviour.
  • Count drift: the placeholder count bound comes from one Codex version (0.162.1). If a future Codex counts a paste differently, the rescue fails safe: no Enter.
  • Very slow hosts: a host much slower than ~2 ms/char, with a large prompt, can outrun the cap.
  • Other platforms: non-Windows hosts are unchanged, except that a fresh launch's blind retry is skipped once a turn started.
  • Not covered: Claude on Windows ([Bug]: worker-start injected prompt lands as unsubmitted draft in Claude worker (packaged Windows), blocking unattended orchestration #14505) is a separate root cause. [Bug]:Orca pasted the preamble while Codex was still loading the MCP; the terminal recorded the text, but Codex did not submit it as a user message. #13439 is not claimed.

Fixes #11343

…till holds a dispatch

Codex on Windows reads a paste as console key events and takes an Enter that
reaches it before the last pasted key as a newline, so a large dispatch sat in
its composer as [Pasted Content N chars]. After the first Enter, agents with a
submit retry now press Enter again only while no turn has started and the
composer still shows a draft, for up to a paste-sized window on Windows.

Fixes #11343
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 38bb9e82-3582-4d67-aa74-071a9584701f
Commits

Reviewing files that changed from the base of the PR and between ffa04d6 and b857567.

Files selected for processing: 9
  • src/main/runtime/agent-prompt-submission-runtime.test.ts
  • src/main/runtime/orca-runtime-tests/agent-launch-prompt-submit.spec.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-start-readiness-settlement.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-start-readiness-settlement.ts
  • src/main/runtime/terminal/input/terminal-agent-prompt-resubmit.ts
  • src/main/runtime/terminal/input/terminal-agent-prompt.ts
  • src/main/runtime/windows-codex-held-prompt-resubmit.test.ts
  • src/shared/agent-prompt-injection.test.ts
  • src/shared/agent-prompt-injection.ts
Walkthrough

The prompt write path now uses a held-submit budget and a retry method that checks submission activity before sending Enter again. The budget applies to Windows TUI agents configured for input-record paste newlines and scales with prompt length up to a timeout cap. Tests cover large Windows Codex dispatches, agent-launch retry cases, and a zero-budget call.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to ffa04

A narrow process-switch race could send a retry Enter to the wrong terminal process. Add a generation check immediately before that write; otherwise the change is mergeable with bounded risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: retrying Enter for a Windows Codex composer that still holds a dispatch.
Linked Issues check Passed Issue #11343 requires a coding fix for large Windows Codex dispatch payloads that remain as [Pasted Content ...] after the first Enter. The shared agent-prompt flow sends the paste and submit separa…
Out of Scope Changes check Passed The production changes remain within issue #11343. They update agent-prompt submission, add the Windows Codex held-submit budget, preserve the OMP special case, and adjust the related retry tests. The…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 5 files.
Description check Passed The description is detailed and explains the problem, root cause, implementation, testing, risks, platform scope, and linked issue. It does not include several template headings, including Visual Proo…
Full details: Linked Issues check

Explanation

Issue #11343 requires a coding fix for large Windows Codex dispatch payloads that remain as [Pasted Content ...] after the first Enter. The shared agent-prompt flow sends the paste and submit separately for non-OMP agents, then calls resubmitHeldAgentPrompt. The retry waits for a turn start, reads the composer draft, and sends one or more standalone Enter events only while the draft remains. Windows Codex receives a paste-sized budget capped by AGENT_PROMPT_EFFECT_TIMEOUT_MS. The regression test covers both a retained [Pasted Content 9250 chars] draft and an empty composer. The implementation addresses the linked issue without re-sending the prompt.

Full details: Out of Scope Changes check

Explanation

The production changes remain within issue #11343. They update agent-prompt submission, add the Windows Codex held-submit budget, preserve the OMP special case, and adjust the related retry tests. The tests verify the retry count and the no-retry case after submission. No unrelated product area, protocol, or IPC change is shown.

Full details: Description check

Explanation

The description is detailed and explains the problem, root cause, implementation, testing, risks, platform scope, and linked issue. It does not include several template headings, including Visual Proof, Review, Agent skill upstream boundary, Notes, and Checklist, and it does not explicitly state whether AI disclosure applies. These omissions do not make the description largely incomplete.

Finishing Touches
📝 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: 1


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: e83e56e2-174d-4a76-aa9d-801d8cdc9fcc
Commits

Reviewing files that changed from the base of the PR and between 2aae457 and ffa04d6.

Files selected for processing: 5
  • src/main/runtime/agent-prompt-submission-runtime.test.ts
  • src/main/runtime/orca-runtime-tests/agent-launch-prompt-submit.spec.ts
  • src/main/runtime/terminal/input/terminal-agent-prompt-resubmit.ts
  • src/main/runtime/terminal/input/terminal-agent-prompt.ts
  • src/shared/agent-prompt-injection.ts

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

…showing this prompt

Review follow-up: the draft gate now matches the held prompt itself (Codex
paste placeholders summing to its length, or its text), so a rotating
placeholder, question overlay or the user's own draft never gets an Enter.
Turn start and permission are re-checked after the write guard. The gated
loop runs only for Windows input-record agents; elsewhere only the existing
launch retry remains, skipped once a turn started. The blind launch retry no
longer ends the Windows rescue early.
nwparker and others added 4 commits October 24, 2026 17:23
…side worker-start's grace

Re-review follow-up: a held placeholder must stand alone and its count fit
the prompt (measured +2 per LF, +1 per absorbed Enter), so text the user typed
or an unrelated paste is never submitted. The draft and the held deadline are
re-checked after the write guard, right before the retry Enter. The held wait
is capped against the paste's ingest, and worker-start shortens its turn
observation by any delivery that ran past its client grace.
The screen read can take seconds, so it now runs before the deadline and
turn-start checks, leaving nothing awaited between them and the retry Enter.
The wait between gated retries is clamped to the remaining held window.
…tail

A 32-char fragment from the middle of the prompt could be the user's own
text, and the rescue would submit it. A scrolled composer shows the
paste's end, so the tail still matches.
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]: dispatch --inject to Codex never submits large payloads — trailing Enter is concatenated into the bracketed-paste PTY write (v1.4.159)

1 participant