Skip to content

fix(terminal): settle codex readiness from the composer when the startup header leaves the tail - #23313

Closed
eatmoreduck wants to merge 3 commits into
stablyai:mainfrom
eatmoreduck:fix/codex-composer-readiness-23241
Closed

eatmoreduck wants to merge 3 commits into
stablyai:mainfrom
eatmoreduck:fix/codex-composer-readiness-23241

Conversation

@eatmoreduck

@eatmoreduck eatmoreduck commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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 reports failedStage: 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: new isCodexComposerPromptPreview — 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 (mirrors isMuseReadyPromptPreview).
  • tui-idle-evidence.ts: new tier-1b lane hasQuietCodexReadyPrompt, 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 for quiescenceMs, and only after the fresh first-party working-status veto. readCodexReadyBodyEvidence joins TuiIdleSatisfactionInput and 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

findCodexReadyPromptIndex requires the startup header (OpenAI Codex + model: + directory:) to still be inside the retained tail. That header is a one-shot paint: --model/--effort are passed as -c overrides, 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 in codex-readiness-transcripts.test.ts), the post-turn case in that report is exactly codex-busy-turn-ended.txt (also pinned settling), and step 4 (two identical read --screen frames 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

  • I manually tested these changes locally — the full worker-start E2E was not reproduced locally (needs an orchestration run + codex); verification is unit-level with real-stream grounding below.
  • Automated tests added/updated, or explained why not below

Written red first (the codex-lane assertions fail against unfixed main):

  1. isCodexComposerPromptPreview accepts 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;
  2. hasQuietCodexReadyPrompt settles only for known codex panes, holds streaming panes and clock-less records to the quiescence demand;
  3. isTuiIdleSatisfied codex 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 view footer — 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.ts over the six affected suites: 99 tests pass. pnpm typecheck and 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

  • 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

No UI strings, no IPC/protocol changes, RuntimeTerminalWaitBlockedReason untouched. The lane can only fire for panes Orca itself identified as codex and only after the stream has been quiet for quiescenceMs, so its worst case is today's behavior (run to timeout).

Checklist

…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.
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e9799051-87c0-4c44-8119-b0978d79e893

📥 Commits

Reviewing files that changed from the base of the PR and between ab37b55 and 25e0e22.

📒 Files selected for processing (1)
  • src/main/runtime/codex-readiness-transcripts.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/codex-readiness-transcripts.test.ts

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


📝 Walkthrough

Walkthrough

The 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 25e0e

No concrete issue introduced by this change remains established. The trust-dialog behavior remains unverified against the PR base.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to ab37b

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

  • Medium · reliability · inferred: A retained composer from an earlier turn can satisfy a later wait after output goes quiet if no later interrupt marker survives and first-party working status is absent or no longer fresh. This can prematurely advance the worker-readiness transition.
Security review details

Security Blast Radius

  • inferred — The new readiness path is limited by the implemented Codex-pane identity check, but a false settlement can affect both leaf and PTY waits for such panes. The evidence does not establish a broader service or tenant exposure.

Security Findings and Attack Paths

  • inferred — Retained terminal text can outlive a turn, while output quiescence measures silence rather than completion. This supports a conditional premature-readiness path, not a verified attacker-controlled exploit or privilege gain.

Trust Boundaries and Controls

  • observed — The matcher rejects a composer followed by an interrupt-status marker, the idle predicate rejects fresh working status before considering the quiet-composer lane, and runtime polls resolve actionable blocked prompts before idle satisfaction. These controls do not bind a retained composer to the current turn.

Hardening Proposals

  • proposed — Bind composer evidence to the current turn or wait rather than relying on retained text and silence alone, and exercise the live wait path with a capture whose startup header has left the retained tail.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 8 files. 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 main change: using the Codex composer to settle readiness after the startup header leaves the retained terminal tail.
Description check ✅ Passed The description covers the required user impact, changes, rationale, linked issues, visual proof, testing, AI disclosure, scope notes, and checklist context. The Review heading and several checklist i…
Linked Issues check ✅ Passed The PR implements the readiness and idle objectives in [#23241] and [#23212]. isCodexComposerPromptPreview recognizes a retained Codex composer after the startup header is evicted. It rejects an act…
Out of Scope Changes check ✅ Passed The changed source, tests, and Codex transcript fixtures support the linked readiness and tui-idle objectives. The trust-dialog fixture and blocked-signal tests support correct interaction with exis…
  • Fix all pre-merge checks with AI

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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: f9465eff-e3cf-4fd1-9e38-ec657fefb8e3

📥 Commits

Reviewing files that changed from the base of the PR and between 3eb1ade and 9b43c27.

📒 Files selected for processing (7)
  • src/main/runtime/orca-runtime-resolve-exit-waiters.ts
  • src/main/runtime/runtime-terminal-idle-polls.ts
  • src/main/runtime/runtime-terminal-wait.ts
  • src/main/runtime/terminal-wait-detection.test.ts
  • src/main/runtime/terminal-wait-detection.ts
  • src/main/runtime/tui-idle-evidence.test.ts
  • 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; 7 remain after this review.

@pullfrog pullfrog 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.

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 persistent ask codex to do anything placeholder with the same blocked-signal ordering rule as the Muse ready prompt.
  • Tier-1b lane hasQuietCodexReadyPrompt (src/main/runtime/tui-idle-evidence.ts:179) — strict agent === 'codex' scope, composer body evidence, non-null lastOutputAt, and a quiescenceMs (3000 ms) quiet window; ranked after the first-party working-status veto and before hasSustainedTitleIdle.
  • 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 and isTuiIdleSatisfied integration in tui-idle-evidence.test.ts; 69 tests pass locally.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/runtime/tui-idle-evidence.ts Resolved
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.
@eatmoreduck

Copy link
Copy Markdown
Contributor Author

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 tui.animations off, so a mid-turn stall can no longer look quiet — the lane no longer leans on animation cadence at all. To your framing: the gate is no longer load-bearing on its own; quiescence stays as the second layer.

Pinned both directions on real captures recorded with capture-agent-pty-transcript.mjs (__fixtures__/codex-busy-mid-turn.txt refuses — the placeholder genuinely sits between two "esc to interrupt" paints, including codex's own "interupt" typo — and codex-busy-turn-ended.txt settles). Also took the Muse parity for findDismissedStartupModalIndex so a dismissed dialog with an evicted header reads as dismissed.

Separate observation from the same capture session, not part of this PR: on the committed codex-trust-dialog.txt bytes, the live tui-idle wait path settles instead of resolving agent-trust-workspace — codex paints the dialog word-by-word with CSI row positioning, and the retained tail fragments the sentinel phrases. Looks like a real detection gap for codex trust dialogs (quiet timeouts where a blocked reason would be far more actionable); happy to file it as its own issue.

@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.

🧹 Nitpick comments (1)
src/main/runtime/codex-readiness-transcripts.test.ts (1)

42-65: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Force the live tests onto the Codex composer lane.

Both live waits receive the full fixtures, which retain OpenAI Codex. RuntimeTerminalWait can therefore settle through isKnownReadyPromptPreview before it calls the Codex composer callback. Replacing readCodexReadyBodyEvidence with 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b43c27 and ab37b55.

📒 Files selected for processing (12)
  • src/main/runtime/__fixtures__/codex-busy-mid-turn.meta.json
  • src/main/runtime/__fixtures__/codex-busy-mid-turn.txt
  • src/main/runtime/__fixtures__/codex-busy-turn-ended.meta.json
  • src/main/runtime/__fixtures__/codex-busy-turn-ended.txt
  • src/main/runtime/__fixtures__/codex-idle-composer.meta.json
  • src/main/runtime/__fixtures__/codex-idle-composer.txt
  • src/main/runtime/__fixtures__/codex-trust-dialog.meta.json
  • src/main/runtime/__fixtures__/codex-trust-dialog.txt
  • src/main/runtime/codex-readiness-transcripts.test.ts
  • src/main/runtime/terminal-wait-detection.test.ts
  • src/main/runtime/terminal-wait-detection.ts
  • src/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.

@pullfrog pullfrog 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.

✅ 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-stripped esc to interrupt status 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 findDismissedStartupModalIndex with the codex composer index (Muse parity), so a dialog that survives only in scrollback above the composer no longer reads as actionable, and wired readCodexReadyBodyEvidence at 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ 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-stripped esc to interrupt status paint appears after the newest composer paint, so the lane no longer depends on codex's animation cadence.
  • findDismissedStartupModalIndex now 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 (detectTerminalWaitBlockedReason returns null).
  • Committed real captures — codex-idle-composer, codex-busy-mid-turn, codex-busy-turn-ended, codex-trust-dialog with 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.

Pullfrog  | View workflow run | Using 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.
@eatmoreduck

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant