Skip to content

fix(agent-prompt): send Codex's retry Enter for a just-launched worker's brief - #23044

Closed
brennanb2025 wants to merge 9 commits into
mainfrom
brennanb2025/fix-codex-first-launch-lost-enter
Closed

brennanb2025 wants to merge 9 commits into
mainfrom
brennanb2025/fix-codex-first-launch-lost-enter

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​350 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​329
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​101 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88

ELI5

When Orca hands a task to a brand-new Codex worker, it pastes the task into Codex and presses Enter. Right after Codex starts up, it briefly ignores Enter, so the task can sit in Codex's input box unsent and the worker never begins. Orca's app window already handles this for the first prompt it types into a Codex it just started, by pressing Enter a second time about a second later. This PR makes Orca's background (host) path do the same, for the same case only.

What Changed

Before: when orchestration started a Codex worker, the host launched Codex, waited for its screen to settle, pasted the brief and pressed Enter once. On a slow first launch that Enter could be lost: the pane showed "[Pasted Content N chars]" unsent and the worker never started.

After: when the host delivers the first prompt to a Codex it just launched in that terminal, it presses Enter once more 1.2 s after the first Enter, the same retry the app window has sent for Codex launch prompts since #16689. If the first Enter worked, the second one lands on Codex's empty input box and does nothing. The brief is still pasted exactly once.

Scope: only orchestration worker-start (local and on a connected worker server) gets the retry, and only when it created the worker's terminal and so just launched the agent. Everything that sends to an agent that was already running sends one Enter, exactly as on main: orca terminal send, orchestration dispatch --inject, coordinator auto-dispatch, worker-start with --terminal, agent.launch into a reused terminal, and mobile sends. agent.launch into a new terminal does not need it: a Codex launch prompt rides Codex's command line and is never pasted.

Mechanism: the host prompt writer (writeTerminalAgentPrompt) takes a new caller-set send option, promptTarget: 'just-launched-agent', read on the queued send path worker-start uses (the strictly verified path is main's code unchanged). Only when it is set does the writer read the per-agent submitRetryDelayMs setting (only Codex has one) that until now only the app window read, wait that long after the first Enter and write one more Enter (agent-prompt-submit-retry.ts). It is caller intent, not stored state: the caller already knows whether it created the terminal. Details:

  • It runs inside the same per-terminal submission queue as the paste and the first Enter, so another host prompt to that terminal cannot slip in between the two Enters.
  • It runs before turn-start observation and does not depend on the caller's observation window, so it also happens on worker-start, which never waits for a turn start inside the send (its window is 0).
  • Right before writing, it re-runs the checks the first Enter passed: the request was not cancelled, the terminal was not replaced, the caller's own write check, and no permission prompt is showing. If any check refuses, the retry is skipped silently and the send still reports the first Enter as accepted.
  • The "input accepted" receipt checkpoint is still recorded right after the first Enter, before the 1.2 s wait, and the turn-start baseline is still taken before the first Enter, so a turn started only by the retry Enter is observed as started.
  • If the terminal is replaced during the retry wait, the send returns "input accepted" and leaves the verdict to the turn-start observation stage, as it already did for a replacement right after the send. Without this, a replacement in the new 1.2 s window would have failed a worker whose brief was already delivered. Sends without the retry keep main's handling.

Worker-start budget: the task-spec size limit is derived so that a worst-case Windows paste plus turn observation fits in worker-start's fixed 50 s reply window. The limit now also reserves the 1.2 s retry, which lowers the maximum task spec from 1,214,464 to 1,137,664 bytes. Nothing else about the reply window changes, so older CLIs keep working unchanged.

Dispatch contract (#19423): the worker-start contract test pinned exactly one Enter for a dispatch, to forbid pasting or submitting the brief a second time after six Codex workers wedged. A bare second Enter is not a resend, so the contract now pins: the brief is pasted exactly once, a worker-start that created the terminal gives Codex exactly two Enters, and a --terminal worker gets exactly one. A new case shows that when only the first Enter is swallowed, the retry starts the turn and the worker settles ready. When every Enter is swallowed, the worker still settles "outcome unknown" with its capability kept and nothing torn down, exactly as before.

Why

Codex discarding Enter for a short window after its input box first appears is already measured in this repo (#16689: roughly 75-150 ms, wider with prompt size and machine load, and a redundant Enter is a no-op after a successful submit). #16689 added the retry only in the app window and only for launch prompts, because at the time host sends only reached an agent that was already running. Orchestration worker-start breaks that assumption: it sends to a Codex that has just booted.

Why this over the alternatives:

  • Retry on every host-sent Codex prompt (an earlier version of this PR): a follow-up to a Codex that is mid-turn could have its extra Enter land on an approval prompt that opened in the 1.2 s gap, or pick the highlighted entry of a slash-command picker. A running agent is past the startup window, so it gets nothing from the retry. Matching the app window's launch-only scope removes that risk.
  • An acceptance-only turn-start rule with a conditional retry (an earlier version of this PR): the retry lived inside the verifier's polling loop, and orchestration dispatch never runs that loop (0 observation window), so it never fired on the path this bug is about. The rule also treated every Codex that Orca launched as hook-reporting, so a Codex with hooks off would never be reported as started. And which signal produced the one false "turn started" we saw was never verified, so a rule change for it is held until a captured trace names it.
  • A conditional retry ("only if no turn start yet"): it would depend on the same turn-start evidence that is suspected of being wrong in the reported case. An unconditional retry is what the app window sends for launch prompts, and it is harmless after a successful submit.
  • Deciding "just launched" from stored terminal state (for example a first-prompt flag per process): it would be a second copy of a fact every caller already has, and it would also fire for a re-dispatch to a worker that has been idle for an hour. The caller that created the terminal is the one that knows.
  • Passing the brief on Codex's command line instead of pasting it: the brief contains the worker's dispatch capability, which would then be readable in the process list, and Windows caps command lines far below the allowed brief size.

Known limits:

  • If a lost Enter also survives the second Enter, the worker still settles "outcome unknown" after 30 s, as on main.
  • A re-dispatch or --terminal worker that happens to reach a Codex that booted moments ago is not covered, same as in the app window.
  • The false "turn started" signal from the single local repro is not addressed by this PR, and its cause is unverified.
  • Text a user types into a just-created worker pane within 1.2 s of the brief can be submitted by the retry Enter, the same exposure the app window has for launch prompts. A permission prompt that opens within 1.2 s of a worker's first prompt is only caught if Codex has reported it by then.

Linked Issue

No tracking issue. Found during orchestration QA of Codex workers on a fresh profile.

Visual Proof

N/A: no UI change. The difference is whether a Codex worker's pasted brief gets submitted, which shows up in the terminal and the worker-start result.

Testing

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

Automated, run locally (targeted vitest by file, oxlint and check:code-quality:changed on the changed files, pnpm tc:node):

  • Host-writer tests on the real dispatch options (acceptQueued, 0 observation window) with the just-launched option: the retry Enter goes out exactly 1.2 s after the first Enter and before the send returns; a turn started only by the retry Enter is reported as started; a non-Codex agent gets exactly one Enter; the retry is skipped when the request is cancelled, the terminal is replaced, the caller's write check refuses, or a permission prompt opens after the first Enter, and each of those keeps the "input accepted" receipt.
  • Without the option, a Codex dispatch and a terminal send-style queued send each get exactly one Enter.
  • Worker-start contract: the brief is pasted once; a created-terminal worker gets exactly two Enters (first Enter swallowed -> the retry starts the turn and the worker settles ready; every Enter swallowed -> "outcome unknown" with the capability kept, as before); a --terminal worker gets exactly one Enter.
  • Federated worker start passes the just-launched option when it created the terminal.
  • The existing prompt-receipt, hook and runtime composer-settle tests pass unchanged from main.
  • Ablations: turning the retry off in the writer turns 8 tests red (4 host-writer, 4 contract); not passing the option from worker-start turns 4 contract tests red; not passing it from federated worker start turns its test red; retrying regardless of the option turns 7 tests red (the one-Enter cases above and existing receipt and hook tests that pin one Enter).
  • Related suites by file (agent prompt runtime and verifier, worker-start, federation, agent launch, dispatch, terminal send and receipts, coordinator dispatch, the runtime aggregate, and the app window's own retry test): all pass.
  • pnpm tc:node passes. Full pnpm tc and the full test suite were not run locally (machine under heavy load); CI covers them.

Live QA is pending on a remote Mac (fresh profile, real Codex, under load). Nothing was run live on this branch yet.

Review

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

SSH: the prompt writer runs on the host that owns the terminal, and for an SSH terminal it writes both Enters through the relay; a 1.2 s gap is far above relay jitter. Windows (ConPTY) and WSL: the retry is the same carriage return as the first Enter, sent after the existing paste-ingest wait. Mixed versions: the new option is set and read inside the host that runs worker-start, from facts it already has (whether it created the terminal); no RPC parameter, stream frame or stored data changes. An older host sends one Enter as today; a newer host retries for the terminals it created whatever the client version. Performance: one timer and one extra write per just-launched Codex worker; other sends and other agents are unchanged.

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)

…ched turn started

A first Codex launch could leave a pasted worker brief unsubmitted while orchestration
recorded the turn as started. The host wrote one Enter where the renderer writes two, and
the verifier counted any working signal after the baseline as a turn, including Codex's
startup spinner title.

The hook store now records the main agent's own prompt submission (with Codex's turn id)
as a live-only acceptance fact. For a Codex process Orca launched with its hooks, the
verifier accepts only that fact; other panes keep the working-edge rules. The host sends
the agent's configured second Enter only while no turn start has been accepted.
The host retry Enter lived inside the verifier's poll loop, which never
runs on orchestration dispatch (zero observation window), and the
acceptance-only rule counted any Orca-launched Codex as hook-reporting,
so hooks-off panes could never settle a turn start. Which signal faked
the one observed turn start is still unverified, so the rule change is
held until a captured trace names it.
Codex discards Enter for a short, load-dependent window after its
composer first renders. The renderer already follows its first Enter
with one blind retry Enter for Codex, but the host writer did not,
because it assumed host sends only reach an already-running agent.
Worker start breaks that assumption: it launches Codex, waits for the
TUI to idle, then pastes the brief through the host writer.

The host writer now waits submitRetryDelayMs after the first Enter and
writes one more Enter inside the same per-terminal submission, before
turn observation, so it runs on every dispatch path. It re-runs the
first Enter's guards (abort, PTY generation, caller write guard,
permission) and skips silently if any refuses. The worker-start prompt
budget reserves the retry delay, and the dispatch contract now pins one
paste and exactly two Enters for Codex.
Codex prompts sent through the host writer now get one retry Enter, so
tests that counted a single Enter for Codex expect two, and a fixture
that started a hook turn on every Enter now starts one only when a
pasted draft is waiting, as Codex does.
@brennanb2025 brennanb2025 changed the title fix(agent-prompt): only Codex's own prompt acceptance proves a dispatched turn started fix(agent-prompt): send Codex's retry Enter when the host pastes a prompt Sep 26, 2026
…agent's first prompt

The retry covers Codex's cold-boot Enter gate, which only the first prompt
into an agent Orca just launched can hit. Callers now say so with
`promptTarget: 'just-launched-agent'`: worker-start and federated
worker-start when they created the terminal, and agent.launch when it
created the terminal. `terminal send`, dispatch --inject, coordinator
dispatch, `--terminal` workers and reused launch terminals send one Enter,
as on main. Restores the prompt tests that no longer see a retry.
… send

Only worker-start marks a prompt as going to a just-launched agent, and it
always sends queued, so the retry now sits in the queued path alone and the
strict path is main's code unchanged. agent.launch no longer passes the
option: a Codex launch prompt always rides the command line, and no agent
that takes its launch prompt through the terminal has a retry delay.
@brennanb2025 brennanb2025 changed the title fix(agent-prompt): send Codex's retry Enter when the host pastes a prompt fix(agent-prompt): send Codex's retry Enter for a just-launched worker's brief Sep 26, 2026
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status (head 408cae0)

Verdict: code review clean after 6 review loops; still a draft. Live QA shows no regression on the real path, but it has not yet shown the retry rescuing a lost Enter.

What changed during review

The first version of this PR added a rule that only Codex's own prompt-submit hook proves a turn started, plus a conditional second Enter inside the submission check. Review found three problems with it:

  • The second Enter never fired on the path the bug is about: orchestration dispatch runs the check with a zero-length window, so the retry loop never ran.
  • The new rule was switched on by the launch token, which Orca mints for every launched agent, so a Codex worker whose hooks are off or not delivering would always settle as "outcome unknown".
  • The new status-row field, receipt field and Codex turn-id plumbing were not justified by evidence: which signal faked the one false "turn started" is still unverified.

That design was replaced by a smaller one. It reuses the retry the app window has sent since #16689, where Codex was measured to discard Enter for a short, load-dependent window after its input box first renders:

  • Worker-start is launching Codex into a terminal it just created (locally or on a connected Orca server). In that case the host's queued prompt writer sends one more Enter submitRetryDelayMs (1.2 s) after the first.
  • Before that Enter it re-checks cancellation, terminal generation, the write guard and whether a permission prompt is showing.
  • Every other send — terminal send, re-dispatch, --terminal workers, coordinator dispatch, mobile — runs main's code with one Enter.
  • fix(orchestration): worker-start settles readiness on observed turn start, not write acceptance #19423's contract test now pins a single paste and two Enters, and still guards against a false "ready".

Live QA (remote Mac, real Codex CLI 0.157.1, a fresh profile and home per round, dummy key, unreachable model endpoint)

  • Direct terminal, both arms: the brief was submitted exactly once and settled ready with the turn observed. Codex's session file has one user message, so there is no double submission.
  • Lost Enter, not reproduced faithfully: the rig put a small byte-forwarding terminal proxy in front of Codex to drop the first Enter on purpose. Through that proxy Codex ignored every Enter on both arms, even with nothing dropped and even a manual Enter minutes later, so those rounds say nothing either way. The proxy logs do show the PR sending the second Enter 1199–1237 ms after the first, only for a worker in a terminal worker-start created, and a terminal send getting one Enter.
  • Unit coverage of the rescue: a first-Enter-swallowed contract test settles ready only because of the retry. Removing the retry turns 8 tests red.

PR head, direct terminal (brief submitted once; the model call then fails by design):
pr-direct-crop.jpg

main, same scenario:
main-direct-crop.jpg

PR head through the proxy rig, pasted brief left unsent. This comes from the rig, not the product (the same happens on main with no Enter dropped):
pr-s1-39-b.jpg

Validation

Targeted vitest for every changed or pinning file (retry runtime, worker-start contract, federation, prompt budget, and 35 related files): all pass. pnpm tc:node passes locally. oxlint and the changed-lines code-quality gate are clean. Ablations turn the retry and option tests red. CI: typecheck, verify, static analysis, packaging and persistence pass, and 6 of the 8 test shards are still running.

Known limits and open questions

  • The lost Enter itself has still only been seen once, in one local round. That the retry rescues it rests on the fix(agents): submit-retry Enter for codex composer #16689 measurements and the unit tests, not on a live before/after.
  • The single false "turn started" from that round is not addressed, and its cause is unverified.
  • A re-dispatch or --terminal send that reaches a Codex that booted moments earlier gets no retry, the same as the app window's own rule.
  • Worker-start into a created Codex terminal returns about 1.2 s later. The maximum worker-start task spec drops from 1,214,464 to 1,137,664 bytes for all agents, to keep the retry inside the 50 s reply window.
  • Not live-tested: SSH remotes, Windows ConPTY, WSL.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: the root cause is Codex 0.157's first-launch daemon start, which pauses input and flushes anything typed meanwhile, plus Orca declaring Codex ready on its provisional startup screen. A retry Enter doesn't remove that (it failed 2 of 2 in measurement). Follow-ups: a readiness fix that works on Codex 0.157 and 0.158, and delivering the first worker brief at Codex startup with a confirmed-acceptance turn check.

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