Repository navigation
fix(terminal): settle codex readiness from the composer when the startup header leaves the tail - #23313
fix(terminal): settle codex readiness from the composer when the startup header leaves the tail#23313eatmoreduck wants to merge 3 commits into
Conversation
…tup header leaves the tail Codex's startup header is a one-shot paint. Startup warnings or the intro animation can push it out of the retained tail before the composer settles, and then the tier-1 body check (OpenAI Codex + model: + directory:) never fires again: known-agent panes have no quiet-foreground fallback (stablyai#9976), so worker-start waits on agent_readiness until timeout while Codex sits idle at its prompt (stablyai#23241). Add a tier-1b lane shaped like the Muse one: for panes Orca knows are codex, the repainted composer placeholder (Ask Codex to do anything) counts as readiness evidence once the stream has gone quiet, with the same blocked-signal interplay as the header check. Scoping to known codex panes keeps another agent's scrollback quoting codex from settling its own wait, and the quiescence demand keeps a streaming turn from satisfying.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change adds Codex composer prompt detection and quiet-output evidence to TUI idle evaluation. Runtime terminal wait, polling, and exit-waiter paths provide the detection callback for both leaf and PTY checks. Tests cover composer recognition, blocked-dialog placement, pane identity, output quiet time, and first-party working-status vetoes. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No concrete issue introduced by this change remains established. The trust-dialog behavior remains unverified against the PR base. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The change can recover workers that are ready but no longer show their startup information. A quiet worker may also be mistaken for ready if an earlier prompt remains visible after activity indicators disappear. The evidence does not establish how often that condition occurs. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f9465eff-e3cf-4fd1-9e38-ec657fefb8e3
📒 Files selected for processing (7)
src/main/runtime/orca-runtime-resolve-exit-waiters.tssrc/main/runtime/runtime-terminal-idle-polls.tssrc/main/runtime/runtime-terminal-wait.tssrc/main/runtime/terminal-wait-detection.test.tssrc/main/runtime/terminal-wait-detection.tssrc/main/runtime/tui-idle-evidence.test.tssrc/main/runtime/tui-idle-evidence.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
Important
The new codex composer lane is only as safe as codex's repaint cadence. Codex paints the composer placeholder during a working turn (its set_task_running clears prompt suggestions, not the placeholder), and the frequent status-row / title-spinner repaints that keep the stream busy are gated on tui.animations (default on, but off under OS reduced-motion). With animations off, a >3s silent stall mid-turn satisfies the quiescence gate and settles a busy pane — the #6011 class, not the "worst case is today's behavior (run to timeout)" the PR describes. Details inline.
Reviewed changes
isCodexComposerPromptPreview(src/main/runtime/terminal-wait-detection.ts:74) — matches the persistentask codex to do anythingplaceholder with the same blocked-signal ordering rule as the Muse ready prompt.- Tier-1b lane
hasQuietCodexReadyPrompt(src/main/runtime/tui-idle-evidence.ts:179) — strictagent === 'codex'scope, composer body evidence, non-nulllastOutputAt, and aquiescenceMs(3000 ms) quiet window; ranked after the first-party working-status veto and beforehasSustainedTitleIdle. - New required input field
readCodexReadyBodyEvidence— wired at all six satisfaction sites (runtime-terminal-wait.ts×2,runtime-terminal-idle-polls.ts×2,orca-runtime-resolve-exit-waiters.ts×2); the required field makes the compiler enforce completeness. - Tests — composer accept / refuse / blocked-below / dismissed-above in
terminal-wait-detection.test.ts, lane helpers andisTuiIdleSatisfiedintegration intui-idle-evidence.test.ts; 69 tests pass locally.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Review follow-ups on stablyai#23313: the composer placeholder is also painted while a turn runs, and with tui.animations off a mid-turn stall would otherwise look quiet, so quiescence was the lane's only mid-turn guard. The lane now refuses when a turn's own status line (esc to interrupt) paints after the newest composer, ANSI-stripped because codex fragments the phrase with SGR spans; that paint survives in the retained tail regardless of animation settings. Also give the composer the Muse parity in findDismissedStartupModalIndex (a composer painted after a dialog proves the dialog was dismissed), and pin the whole lane to captured codex transcripts recorded with capture-agent-pty-transcript.mjs: idle composer, mid-turn, turn-ended, and the folder trust dialog.
|
Thanks @pullfrog — real gap, fixed in ab37b55. The lane now refuses whenever a turn's own status line ("… • esc to interrupt") appears after the newest composer paint, ANSI-stripped because codex paints the phrase with SGR spans inside it. That status paint survives in the retained tail even with Pinned both directions on real captures recorded with Separate observation from the same capture session, not part of this PR: on the committed |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/codex-readiness-transcripts.test.ts (1)
42-65: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winForce the live tests onto the Codex composer lane.
Both live waits receive the full fixtures, which retain
OpenAI Codex.RuntimeTerminalWaitcan therefore settle throughisKnownReadyPromptPreviewbefore it calls the Codex composer callback. ReplacingreadCodexReadyBodyEvidencewith a no-op would not change these test results. The direct matcher tests do not cover this runtime wiring.Insert enough terminal output before the final composer paint to evict the startup header while retaining the composer bytes.
Suggested fix
import { createTranscriptPane } from './agent-transcript-pane-test-harness' +import { MAX_TAIL_LINES } from './terminal-tail-limits' ... function transcript(name: string): string { return readFileSync(join(FIXTURE_DIR, `${name}.txt`), 'utf8') } +function transcriptWithEvictedStartupHeader(name: string): string { + const data = transcript(name) + const composer = 'Ask Codex to do anything' + const composerIndex = data.lastIndexOf(composer) + if (composerIndex === -1) { + throw new Error(`fixture ${name} has no composer`) + } + return `${data.slice(0, composerIndex)}${'\n'.repeat(MAX_TAIL_LINES + 1)}${data.slice(composerIndex)}` +} + describe('codex readiness from captured terminal bytes', () => { ... - data: transcript('codex-idle-composer') + data: transcriptWithEvictedStartupHeader('codex-idle-composer') ... - data: transcript('codex-busy-turn-ended') + data: transcriptWithEvictedStartupHeader('codex-busy-turn-ended')
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 107795b2-a5e4-41e6-9438-9d0caafb4ab2
📒 Files selected for processing (12)
src/main/runtime/__fixtures__/codex-busy-mid-turn.meta.jsonsrc/main/runtime/__fixtures__/codex-busy-mid-turn.txtsrc/main/runtime/__fixtures__/codex-busy-turn-ended.meta.jsonsrc/main/runtime/__fixtures__/codex-busy-turn-ended.txtsrc/main/runtime/__fixtures__/codex-idle-composer.meta.jsonsrc/main/runtime/__fixtures__/codex-idle-composer.txtsrc/main/runtime/__fixtures__/codex-trust-dialog.meta.jsonsrc/main/runtime/__fixtures__/codex-trust-dialog.txtsrc/main/runtime/codex-readiness-transcripts.test.tssrc/main/runtime/terminal-wait-detection.test.tssrc/main/runtime/terminal-wait-detection.tssrc/main/runtime/tui-idle-evidence.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/runtime/tui-idle-evidence.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the previous pullfrog review (9b43c277), which resolves all three prior concerns.
- Committed real codex PTY captures —
codex-idle-composer,codex-busy-mid-turn,codex-busy-turn-ended,codex-trust-dialog— with meta sidecars, recorded via the transcript-capture reference. - Added a mid-turn veto to
isCodexComposerPromptPreview: it refuses the composer when an ANSI-strippedesc to interruptstatus paint appears after the newest composer paint, so the lane no longer relies on codex's animation cadence. - Added
codex-readiness-transcripts.test.ts, pinning the matcher verdicts on the captured bytes (idle and turn-ended accept, busy-mid-turn refuse). - Extended
findDismissedStartupModalIndexwith the codex composer index (Muse parity), so a dialog that survives only in scrollback above the composer no longer reads as actionable, and wiredreadCodexReadyBodyEvidenceat all six satisfaction sites so the immediate check and the polls agree.
The new parity test asserts the wait-path verdict (detectTerminalWaitBlockedReason returns null), so the dismissal rule is covered at the level the composer lane actually consumes it. The trust-dialog observation raised separately is out of scope for this PR — it looks worth filing as its own issue.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (9b43c277), which addresses all three concerns raised there.
- Mid-turn veto in
isCodexComposerPromptPreview— refuses the composer whenever an ANSI-strippedesc to interruptstatus paint appears after the newest composer paint, so the lane no longer depends on codex's animation cadence. findDismissedStartupModalIndexnow includes the codex composer — Muse parity, so a trust dialog surviving only in scrollback above the composer stops reading as actionable; the new test asserts the wait-path verdict (detectTerminalWaitBlockedReasonreturnsnull).- Committed real captures —
codex-idle-composer,codex-busy-mid-turn,codex-busy-turn-ended,codex-trust-dialogwith meta sidecars. codex-readiness-transcripts.test.ts— pins the matcher verdicts on the captured bytes (idle and turn-ended accept, mid-turn refuse), resolving the synthetic-fixture concern.
Verification: replaying the mid-turn capture through the runtime tail pipeline (normalizeTerminalChunk → appendNormalizedToTailBuffer → buildTerminalWaitText) yields isCodexComposerPromptPreview(...) === false, so the veto is effective on the buffer the runtime actually feeds, not just raw bytes. Codex's StatusIndicator schedules a frame whenever the turn timer is running (every 1 s with tui.animations disabled) and renders Working (0s • esc to interrupt) in that mode (codex-rs/tui/src/status_indicator_widget.rs), so the veto holds under reduced motion. The busy/turn-ended/lane suites pass locally.
The author's documented residual — a mid-turn composer repaint that does not re-emit the status line after it could clear the veto — is not observed in the captures and is called out in the matcher comment.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…repro screens The idle and turn-ended captures in this suite are the exact screen states the stablyai#23212 report describes (idle Codex tab timing out on tui-idle, and the same after a completed turn), so the live-pipeline settle tests replay them.
|
Closing — the fix has landed via #23475, which reads Codex readiness from the live screen rather than the retained tail, and covers both halves this PR targeted (worker-start readiness and the tui-idle hang). The captured-transcript approach converged on the same conclusion that the composer state is the evidence to trust; the live-screen source is the sturdier place to read it from. Thanks @AmethystLiang for the thorough treatment. |

ELI5
When Orca starts a Codex worker with
--model/--effort, Codex ends up sitting idle at its prompt but Orca never notices, waits out the readiness timeout, and reportsfailedStage: agent_readiness— three of those and the task circuit-breaks. This PR gives the readiness check a second, continuously repainted signal (Codex's composer line) so it still recognizes "Codex is ready" after Codex's one-shot startup header has scrolled out of the buffer Orca reads.What Changed
terminal-wait-detection.ts: newisCodexComposerPromptPreview— recognizes Codex's composer placeholder ("Ask Codex to do anything") without requiring the startup header, with the same blocked-signal interplay as the existing header check (mirrorsisMuseReadyPromptPreview).tui-idle-evidence.ts: new tier-1b lanehasQuietCodexReadyPrompt, ranked exactly like the Muse lane: scoped to panes Orca itself knows are codex (launch agent or foreground agent), believed only once the stream has gone quiet forquiescenceMs, and only after the fresh first-party working-status veto.readCodexReadyBodyEvidencejoinsTuiIdleSatisfactionInputand is supplied at every satisfaction site (immediate check ×2, idle polls ×2, exit-waiter fallback ×2) so the immediate check and the poll agree about the same pane.Why
findCodexReadyPromptIndexrequires the startup header (OpenAI Codex+model:+directory:) to still be inside the retained tail. That header is a one-shot paint:--model/--effortare passed as-coverrides, which makes Codex print a startup warning, and warnings or the intro animation push the header out of the bounded tail before the composer settles. A known-agent pane deliberately has no quiet-foreground fallback (#9976), and Codex offers no idle OSC title at startup, so the wait can only run to its timeout — this matches both reporters' mechanism analysis on #23241 (A/B with and without warnings, plus the Ctrl+L redraw datapoint). The composer placeholder is repainted for the life of the pane, so it survives everything that evicts the header.The Muse lane is the existing precedent for exactly this shape — an agent whose readiness cannot be read off titles — including its two guards: agent scoping (another agent's scrollback quoting codex must not settle its own wait) and the quiescence demand (a streaming turn never satisfies).
Linked Issue
Fixes #23241 — the reported readiness timeout is the header-eviction failure this lane repairs; the issue's other suggestion (pass model/effort without forcing embedded mode) would remove one common trigger and remains a possible follow-up, but the symptom is covered.
Fixes #23212 — that report is the same lane end to end: step 1 is Codex idle at the "› Ask Codex to do anything" prompt (exactly
__fixtures__/codex-idle-composer.txt, which settles over the live wait pipeline incodex-readiness-transcripts.test.ts), the post-turn case in that report is exactlycodex-busy-turn-ended.txt(also pinned settling), and step 4 (two identicalread --screenframes 3s apart) confirms the stream is quiet, which is the lane's quiescence gate.Visual Proof
N/A — detection logic only, no new pixels.
Testing
Written red first (the codex-lane assertions fail against unfixed main):
isCodexComposerPromptPreviewaccepts a real idle tail shape (composer + status + warning footer) with no header present, refuses a tail that never painted the composer, refuses the composer once a blocked dialog opens below it, and accepts it when a dismissed dialog survives only in scrollback above;hasQuietCodexReadyPromptsettles only for known codex panes, holds streaming panes and clock-less records to the quiescence demand;isTuiIdleSatisfiedcodex lane settles a header-less codex pane, a fresh first-party working status still vetoes it, and another agent quoting the composer does not settle.Real-stream grounding: captured genuine codex TUI output (codex-cli 0.156.1, macOS, real PTY) for the idle composer — placeholder, model/cwd status line,
⚠ 1 warning · f2 to viewfooter — and used those shapes in the fixtures. The reporter ran 0.157.0; the placeholder string is codex's standing composer copy.pnpm vitest run --config config/vitest.config.tsover the six affected suites: 99 tests pass.pnpm typecheckand the changed-code quality gate pass locally.AI Disclosure
Developed with the GLM coding agent (Zhipu), supervised by the human contributor: the contributor picked the issue, captured the real codex terminal streams used as fixtures, and reviewed the diff and the red/green run; the agent wrote the change and the tests.
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
No UI strings, no IPC/protocol changes,
RuntimeTerminalWaitBlockedReasonuntouched. The lane can only fire for panes Orca itself identified as codex and only after the stream has been quiet forquiescenceMs, so its worst case is today's behavior (run to timeout).Checklist