Repository navigation
fix(agent-prompt): send Codex's retry Enter for a just-launched worker's brief - #23044
brennanb2025 wants to merge 9 commits into
Conversation
…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.
…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.
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 reviewThe 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:
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:
Live QA (remote Mac, real Codex CLI 0.157.1, a fresh profile and home per round, dummy key, unreachable model endpoint)
PR head, direct terminal (brief submitted once; the model call then fails by design): 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): ValidationTargeted vitest for every changed or pinning file (retry runtime, worker-start contract, federation, prompt budget, and 35 related files): all pass. Known limits and open questions
|
|
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. |



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.launchinto a reused terminal, and mobile sends.agent.launchinto 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-agentsubmitRetryDelayMssetting (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: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
--terminalworker 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:
Known limits:
--terminalworker that happens to reach a Codex that booted moments ago is not covered, same as in the app window.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
Automated, run locally (targeted vitest by file, oxlint and
check:code-quality:changedon the changed files,pnpm tc:node):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.terminal send-style queued send each get exactly one Enter.--terminalworker gets exactly one Enter.pnpm tc:nodepasses. Fullpnpm tcand 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
docs/reference/agent-skill-sharing-upstream-boundary.mdand 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)