Skip to content

fix(runtime): read Codex readiness from the live screen - #23475

Merged
Jinwoo-H merged 4 commits into
mainfrom
jinwoo/sta-8628-bug-worker-start-for-codex-times-out-at-agent_readiness-when
Sep 27, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
jinwoo/sta-8628-bug-worker-start-for-codex-times-out-at-agent_readiness-when

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​266 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​266
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​98 $\color{#cf222e}{\Huge{\mathbf{−}}}$​27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71

ELI5

Starting a Codex worker with a model and reasoning effort (worker-start --agent codex --model … --effort …) would hang until it gave up, even though Codex was sitting at its prompt ready for work. Orca was reading its own text notes of what Codex printed, and those notes came out garbled. Orca now looks at the actual terminal screen it already keeps, which shows the correct text.

What Changed

Before: worker-start for Codex with --model/--effort failed at agent_readiness with lastError: timeout. The Codex pane showed a ready prompt with a ⚠ 1 warning · f2 to view footer. Without those flags it worked.

After: the start settles once Codex has finished loading, and the task prompt is injected.

Mechanism:

  • Orca passes the effort as -c model_reasoning_effort=…. In Codex 0.157, any -c override makes Codex skip its new shared background server ("embedded mode") and show a startup warning (config_exclusion in codex-rs/tui/src/daemon_startup.rs).
  • The warning shifts the layout, and Codex redraws its header by rewriting only the characters that changed, jumping the cursor over the rest. Recorded bytes: ESC[5;3Hdir ESC[5;7Hctory:.
  • Orca's readiness check read a line-by-line text copy of the output that drops those cursor jumps, so it saw dirctory:. The Codex rule needs openai codex + model: + directory:, so it never matched.
  • Orca's main process already keeps a live screen emulator for every terminal, fed from the first byte. That screen shows the header correctly.

The change:

  • readLiveTerminalScreenLines(ptyId): a synchronous read of that live screen's visible rows (~0.1–0.2 ms, no daemon call). It returns null when the screen can't be trusted: no emulator, a partial copy restored from the provider, or a pending restore.
  • isKnownReadyPromptBody(waitText, agent, readScreenLines): today's text rules decide first. Only when they say "not ready", and only for panes known to be Codex (or unknown), it reads the screen: ready when the Codex header box shows model: and directory: and neither still says loading. Only the header box is parsed, so chat below it can't interfere. The screen can only add readiness, never take it away, so every verdict the text rules give today is kept.
  • All six tui-idle checkpoints (wait start, the existing 2 s poll, title-driven resolution, delivery settle) call this one function, so they can't disagree.
  • Unchanged: the text copy, blocked-prompt detection, polling cadence, and every other agent's rules.

Why

Why the screen, not a text-copy patch: the text copy is a scrollback list with no screen coordinates. Codex 0.157 draws full-screen with absolute cursor positioning, so teaching the text copy to follow it would mean writing a second emulator. The live emulator already exists.

Why the header rule plus "not loading", not the › input line: Codex keeps the › input line visible while working, so it would report "ready" mid-task. The header only drops loading once startup finishes, so the screen never adds readiness early: never ready while loading and ready at the end, in all 10 recordings.

Why the screen can only add readiness: a regression review replayed the recordings on grids that don't match the PTY (odd sizes, or a resize landing mid-paint). There, Codex's cell-diff repaint garbles the header, and a screen that could veto would turn today's "ready" into a timeout. Checking the text rules first keeps every current verdict. The existing early false positive, where the text copy counts a model: loading header as ready, is left as it is today.

Why only Codex moves to the screen: other agents' rules (for example Cursor's banner) haven't been checked against a visible-rows-only view. The agent gate also stops another agent's screen that merely mentions "OpenAI Codex" from being judged by the Codex rule.

Alternatives considered:

Other orchestrators: herdr renders with an embedded terminal and runs rules on screen rows. gastown, overstory and firstmate read rendered tmux screens or pass the prompt at launch. paseo and paperclip use Codex's JSON interfaces. None match a Codex header against raw output.

Linked Issue

Fixes #23241

Related: #22825, #18019

Visual Proof

N/A: no UI change. The observable difference is that worker-start reaches ready instead of agent_readiness timeout (see Testing).

Testing

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

Automated:

  • New codex-header-readiness-transcripts.test.ts uses four real codex-cli 0.157.1 PTY recordings (plain, -m+-c, -c only, --no-daemon), scrubbed with the transcript recorder:
    • Per recording: the screen never adds readiness while it shows loading, and reads ready on the final screen.
    • No-regression property: at 120x40, 80x24, 30x50, 108x30 and 60x5, for every frame of every recording, whenever today's text rule says ready, the new check also says ready.
    • Through the real onPtyData path at 120x40: a tui-idle wait settles.
    • A mid-task composer screen, a trust dialog below the header, the null-screen fallback, the 80x24 fallback (same answer as today), and a non-Codex pane whose screen shows the Codex header (the screen is never read for it).
  • Red without the fix: with the screen reader disabled, the two override recordings time out in the runtime test (2 failed / 37 passed).
  • All src/main/runtime suites: 413 files passed and 2 skipped; 4870 tests passed, 26 skipped, 0 failed.
  • Checks: pnpm tc, oxlint and check:code-quality:changed pass with 0 new findings.

Live: On an isolated headless dev runtime built from this branch (macOS, codex-cli 0.157.1), I ran orchestration worker-start --agent codex against a scratch repo:

Case Result Time to ready Worker
--model gpt-6-sol --effort high ready / input_accepted, turnStart: observed, launch.effective = gpt-6-sol / high 4 s sent worker_done, task completed
Same again ready / input_accepted, turnStart: observed 4 s sent worker_done, task completed
Control, no flags ready / input_accepted, turnStart: observed 3 s sent worker_done, task completed

Screen polled during the second override run: the ⚠ 1 warning · f2 to view footer is present, and the prompt was pasted only after the header changed from model: loading to model: GPT-6-Sol high. Readiness waited for Codex to finish loading rather than firing on the first header.

I didn't run a pre-fix build live. The failure is reproduced by the issue reports and by the runtime test above (red without the fix).

Platforms: macOS, plus unit and runtime tests (platform-neutral logic).

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 / remote: the check runs wherever the terminal wait runs, using that runtime's existing emulator. When the screen is unavailable (for example right after an execution-context change, while a provider snapshot is preferred), it falls back to today's text rules. It is never worse than today. No wire changes.
  • Size: if a PTY's size is unknown, the emulator defaults to 80x24 and the header garbles, so that case behaves as today. Runtime and CLI spawns set the size before the PTY starts.
  • Delivery: isAgentSettledForDelivery gets the same additive evidence, so it can only start delivering sooner, never later.
  • Not covered: taking over an idle Codex terminal (worker-start --terminal <handle>, mentioned in [Bug]: worker-start for codex times out at agent_readiness when --model/--effort are passed #23241) still times out. After a turn, the Codex header has scrolled off both the screen and the text copy, so neither rule has anything to match. That needs a separate composer-based rule with a working-state guard, which is out of scope here. The main worker-start case is fixed.
  • Serializer sweep: serialize-grid-transcript-replay.test.ts replays every runtime fixture. The new Codex recordings expose a pre-existing restore divergence (the header border restores with an extra attribute bit). It's recorded in that test's KNOWN_PREEXISTING_I2_FAILURES; this PR doesn't touch the serializer.
  • Fixtures: the terminal title in the fixtures still contains this branch's name, which only names this public bug.
  • Performance: one in-memory read of ~40 rows per check, only at existing checkpoints.

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). Typecheck, changed-file lint and targeted suites pass locally; CI covers the full suite and build.

Codex 0.157 runs in embedded mode when Orca passes `-c model_reasoning_effort=…`,
shows a startup warning, and repaints its header by cell diff
(`ESC[5;3Hdir ESC[5;7Hctory:`). The tui-idle body check read the line-folded
tail, which drops those cursor moves and reads `dirctory:`, so worker-start
timed out at agent_readiness while Codex sat idle at its prompt.

For Codex (or unknown) panes whose live emulator screen shows the Codex header,
the screen now decides readiness: `model:` and `directory:` present and neither
still `loading`. Otherwise today's text rules apply unchanged. All six tui-idle
satisfaction sites share one helper so they cannot disagree.

Fixes STA-8628 / #23241.
@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/sta-8628-bug-worker-start-for-codex-times-out-at-agent_readiness-when branch from fb6cc8f to f856c14 Compare September 27, 2026 21:53
Pass the screen as a thunk so non-Codex panes never build the grid, hoist the
pane agent lookup, and share the unblocked-ready check with the Muse rule.

@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 critical issues — one scope observation about the readiness checkpoints, nothing blocking.

Reviewed changes

Read the full 18-file diff at fb6cc8f0, exercised the new transcript tests with and without the screen path, and re-ran the neighbouring readiness suites.

  • Live-screen readiness function: isKnownReadyPromptBody(waitText, screenLines, agent) in terminal-wait-detection.ts — when the live grid shows the OpenAI Codex header and the pane is known-Codex (or unknown), the screen's model:/directory: rows decide, with a new (model|directory):\s+loading veto; otherwise today's text rules apply. isKnownReadyPromptPreview is refactored to share isReadyPromptLive.
  • Screen accessor: readLiveTerminalScreenLines(ptyId) in orca-runtime-visible-snapshot-preview.ts synchronously projects the live HeadlessEmulator visible rows, returning null for no emulator, provider-preferred PTYs, or a pending hydration.
  • Call-site migration: the immediate check (runtime-terminal-wait.ts), the 2 s poll (runtime-terminal-idle-polls.ts), and the resolve/delivery-settle paths (orca-runtime-resolve-exit-waiters.ts) route through the new function; orca-runtime-runtime-id.ts wires readScreenLines into both dependency objects.
  • Captured-transcript tests: four real codex-cli 0.157.1 PTY fixtures plus codex-header-readiness-transcripts.test.ts covering the loading veto, the final ready screen, a mid-turn composer, a trust dialog below the header, the null-screen fallback, and the 80x24 fallback; the pane harness gained a size/getSize seam.

ℹ️ The visible-read probe is still a Codex readiness checkpoint on the text-only check

startTuiIdleVisibleReadProbe still resolves tui-idle with isKnownReadyPromptPreview(snapshotText), so it never applies the new loading veto. It fires only when a Codex pane has no runtime-observed output (waitText.length === 0 and lastAgentStatus === null), so it is not the reported path — but it is the one tui-idle checkpoint that no longer agrees with the others.

Technical details
# Visible read probe bypasses the new loading veto

## Affected sites
- `src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts:80-83` — non-antigravity panes classify a `source: 'screen'` projection with `isKnownReadyPromptPreview`.
- `src/main/runtime/runtime-terminal-wait.ts:161-174` and `:265-274` — the probe is started for a Codex pane when `lastAgentStatus === null` and `waitText.length === 0`.

## Why it matters
`isKnownReadyPromptPreview` matches the Codex header purely on the `model:` + `directory:` substrings, so a provider screen captured while the header still reads `model: loading` classifies ready — the exact false positive `isKnownReadyPromptBody` now vetoes. That resolves the waiter before Codex has attached its input reader (the #9976 class of lost prompt).

## Open question
Is leaving the probe on the text-only check intentional (e.g. it is believed unreachable for Codex), or should the probe also pass its screen lines through `isKnownReadyPromptBody`? The call site already has the projection's visible `tail` lines.

## Required outcome
Either the probe shares the one readiness function like the other checkpoints, or a comment records why it is exempt.

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

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

📝 Walkthrough

Walkthrough

Runtime readiness checks now consider live terminal screen lines for Codex panes when those lines are available. A loading model or directory in a Codex header blocks screen-based readiness. The change also adds Codex 0.157.1 terminal recordings and tests for warning output, loading and ready screens, terminal dimensions, and runtime idle waits.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟠 High · up to 86d03

Readiness may settle before Codex is actually idle, causing prompts to be injected into an active session. This should be fixed before merging.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 86d03

A loaded Codex header can remain visible while Codex is working. Treating that header as an idle signal may cause text to be sent before the terminal is ready. The identified exposure is limited to the affected terminal; a permission bypass has not been established.

Retained concerns

  • Medium · security · inferred: A loaded Codex header can satisfy an idle wait during an active turn because the header check does not assess activity below it and positive body evidence precedes the working-status veto. This can advance prompt delivery before the intended idle transition.
Security review details

Security Blast Radius

  • inferred — The demonstrated decision path concerns text sent to the selected terminal pane. The examined code does not establish a new cross-service or privilege boundary.

Security Findings and Attack Paths

  • inferred — If a loaded header remains visible during an active response, screen-based readiness can settle an idle wait and advance prompt submission without an idle transition. No confirmed approval bypass or privilege escalation follows from the inspected evidence.

Trust Boundaries and Controls

  • observed — Recognized blocking prompts are checked against readiness, but the header detector itself checks loading fields rather than whether Codex is currently responding.

Resilience and Maintainability Implications

  • inferred — A lagging grid can reinforce an early positive readiness decision; later polls cannot retract a wait that has already settled.

Hardening Proposals

  • proposed — Require idle evidence beyond a loaded header before it authorizes prompt delivery, and reconcile screen reads with pending PTY writes before settling a positive wait.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue [#23241] requires worker-start to detect readiness for Codex launches with --model and/or --effort, and for takeover of an idle Codex terminal. The live-screen path settles the recorded se… Make the affected Codex launch and takeover paths detect a loaded header at the default 80×24 grid, or provide another trusted readiness fallback that rejects loading and blocked states. Add runtime coverage for the model/effort case at t…
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The live-screen readiness logic, runtime wiring, Codex transcript fixtures, and tests support the readiness objective in [#23241]. The serialization failure-count update records pre-existing fixture b…
Title check ✅ Passed The title clearly and concisely describes the main change: reading Codex readiness from the live terminal screen.
Description check ✅ Passed The description follows the repository template and provides a clear ELI5 summary, user-facing behavior, mechanism, rationale, linked issue, testing evidence, platform considerations, and checklist st…
Full details: Linked Issues check

Explanation

Issue [#23241] requires worker-start to detect readiness for Codex launches with --model and/or --effort, and for takeover of an idle Codex terminal. The live-screen path settles the recorded sessions at 120×40. The runtime test still expects the effort-override session to time out at the default 80×24 grid, and the readiness function preserves that timeout when the screen header is garbled. Issue [#23241] does not limit the required behavior to 120×40.

Resolution

Make the affected Codex launch and takeover paths detect a loaded header at the default 80×24 grid, or provide another trusted readiness fallback that rejects loading and blocked states. Add runtime coverage for the model/effort case at that grid.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 5c7d576a-4d47-4bb1-bad0-65b01a16c46d

📥 Commits

Reviewing files that changed from the base of the PR and between 0547b32 and 0392241.

📒 Files selected for processing (18)
  • src/main/runtime/__fixtures__/codex-0157-config-override-embedded-warning.meta.json
  • src/main/runtime/__fixtures__/codex-0157-config-override-embedded-warning.txt
  • src/main/runtime/__fixtures__/codex-0157-effort-override-embedded-warning.meta.json
  • src/main/runtime/__fixtures__/codex-0157-effort-override-embedded-warning.txt
  • src/main/runtime/__fixtures__/codex-0157-no-daemon-effort-override.meta.json
  • src/main/runtime/__fixtures__/codex-0157-no-daemon-effort-override.txt
  • src/main/runtime/__fixtures__/codex-0157-plain-ready.meta.json
  • src/main/runtime/__fixtures__/codex-0157-plain-ready.txt
  • src/main/runtime/agent-transcript-pane-test-harness.ts
  • src/main/runtime/codex-header-readiness-transcripts.test.ts
  • src/main/runtime/orca-runtime-resolve-exit-waiters.ts
  • src/main/runtime/orca-runtime-runtime-id.ts
  • src/main/runtime/orca-runtime-visible-snapshot-preview.ts
  • src/main/runtime/runtime-terminal-idle-polls.test.ts
  • src/main/runtime/runtime-terminal-idle-polls.ts
  • src/main/runtime/runtime-terminal-wait.ts
  • src/main/runtime/terminal-wait-detection.ts
  • src/main/runtime/terminal-wait-name-only-idle.test.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.

if (screenLines !== null) {
const screen = screenLines.join('\n').toLowerCase()
if (screen.includes(CODEX_HEADER_TITLE)) {
return isReadyPromptUnblocked(screen, findCodexScreenReadyPromptIndex(screen))

@coderabbitai coderabbitai Bot Sep 27, 2026 •

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- PR diff ---'
git diff --no-ext-diff --unified=50 0547b3222488e7788c0c3631fa18fe19e21ab1ec 03922415a0dd42131dd243ccba7f0e949e102976 -- src/main/runtime/terminal-wait-detection.ts
printf '%s\n' '--- current file ---'
cat -n src/main/runtime/terminal-wait-detection.ts
printf '%s\n' '--- related symbols and tests ---'
rg -n -C 4 'isTuiIdleSatisfied|isKnownReadyPromptBody|findCodexScreenReadyPromptIndex|working status|workingStatus|tui-idle|Codex.*header|directory:' src test tests 2>/dev/null || true

Repository: stablyai/orca

Length of output: 45633


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions

Length of output: 36162


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- target symbols ---'
rg -n -C 12 'function isTuiIdleSatisfied|const isTuiIdleSatisfied|isTuiIdleSatisfied|isKnownReadyPromptBody|findCodexScreenReadyPromptIndex|findCodexReadyPromptIndex' src/main src/renderer tests --glob '*.{ts,tsx}' 2>/dev/null | head -n 1200
printf '%s\n' '--- terminal wait files ---'
git ls-files '*terminal*wait*' '*tui*idle*' '*readiness*' | head -n 200
printf '%s\n' '--- focused tests and fixtures ---'
rg -n -C 8 'OpenAI Codex|openai codex|model:|directory:|loading|working|active turn|tui-idle|ready prompt' src/main/runtime src/main --glob '*terminal*test*.ts' --glob '*wait*.test.ts' --glob '*tui*.test.ts' --glob '*.spec.ts' 2>/dev/null | head -n 1600

Repository: stablyai/orca

Length of output: 42962


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- idle evidence implementation ---'
cat -n src/main/runtime/tui-idle-evidence.ts
printf '%s\n' '--- idle evidence tests ---'
cat -n src/main/runtime/tui-idle-evidence.test.ts
printf '%s\n' '--- readiness test files ---'
rg -l 'mid-turn|Codex|codex|loading|directory:|model:' src/main/runtime --glob '*test.ts' --glob '*.spec.ts' | while read -r f; do
  case "$f" in
    *tui-idle-evidence.test.ts) ;;
    *) printf '%s\n' "--- $f"; rg -n -C 10 'mid-turn|Codex|codex|loading|directory:|model:' "$f" | head -n 500 ;;
  esac
done

Repository: stablyai/orca

Length of output: 45633


Reject fresh working status before accepting Codex body readiness.

A live Codex screen with openai codex, model:, and directory: passes line 69 unless it still contains a loading marker or blocked signal. The matcher does not reject other working activity. isTuiIdleSatisfied accepts this body evidence before it checks fresh first-party working status, so a retained header can settle tui-idle during an active turn.

Suggested fix
-  if (hasExplicitIdleTitle(input.record, input.rendererTitle) || input.readPositiveBodyEvidence()) {
+  if (hasExplicitIdleTitle(input.record, input.rendererTitle)) {
     return true
   }
   if (hasFreshWorkingFirstPartyStatus(input.firstPartyStatus)) {
     return false
   }
+  if (input.readPositiveBodyEvidence()) {
+    return true
+  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by c7cf494: the screen can no longer veto a verdict the text rules give. isKnownReadyPromptBody returns true whenever isKnownReadyPromptPreview(waitText) does, and reads the screen only when the text says not ready. A test covers this across every recording at five grid sizes.

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.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
fd 'tui-idle-evidence|terminal-wait-detection|codex-header-readiness-transcripts' src
ast-grep outline src/main/runtime/tui-idle-evidence.ts --items all --match 'isTuiIdleSatisfied|hasFreshWorkingFirstPartyStatus|hasExplicitIdleTitle'
rg -n -C 12 'isTuiIdleSatisfied|hasFreshWorkingFirstPartyStatus|readPositiveBodyEvidence' src/main/runtime --type ts

Length of output: 37854


@Jinwoo-H, you’re right that isKnownReadyPromptBody now preserves a ready verdict from the text rule. My comment was about a different condition: isTuiIdleSatisfied accepts positive body evidence before it checks fresh first-party working status. A retained Codex header can therefore settle tui-idle during an active turn.

My suggested reorder would also change the existing text rule, so it was too broad. The remaining concern is whether screen-derived readiness should be rejected when first-party status says working.

Thanks for the clarification.


✏️ Learnings added
Learnt from: Jinwoo-H
Repo: stablyai/orca PR: 23475
File: src/main/runtime/terminal-wait-detection.ts:0-0
Timestamp: 2026-09-27T22:41:50.570Z
Learning: In `src/main/runtime/terminal-wait-detection.ts`, `isKnownReadyPromptBody` preserves a true `isKnownReadyPromptPreview(waitText)` verdict before consulting live screen lines. Live screen lines provide an additional readiness path when the text rule does not report ready.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

A grid out of step with the PTY (size mismatch or a resize mid-paint) can garble
Codex's header. Keep every verdict the text rules give today and consult the
screen only when they say not ready, so no flow that settles today can stop.

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 1cda8b36-ef8f-46e2-8576-729dc88a40ff

📥 Commits

Reviewing files that changed from the base of the PR and between 0392241 and c7cf494.

📒 Files selected for processing (2)
  • src/main/runtime/codex-header-readiness-transcripts.test.ts
  • src/main/runtime/terminal-wait-detection.ts

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

Chat below the header can mention "OpenAI Codex" or "model: loading", so the
screen rule now reads model/directory/loading only inside the header box.

The serialize round-trip sweep picks up every runtime fixture; record the
pre-existing header-border attribute divergence the new Codex 0.157 recordings
expose, which this change does not touch.
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Re pullfrog's note on startTuiIdleVisibleReadProbe: since c7cf494 the loading veto is gone, and the screen only adds readiness. The probe's text rule on the snapshot never disagrees in the "says ready" direction; at worst it misses the Codex screen rule, and then the poll path picks it up. Leaving the @ts-nocheck probe untouched keeps this change small.

@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 latest commit makes isKnownReadyPromptBody report ready while the live Codex screen still shows loading, whenever the text copy reassembles the header. That reverses the loading veto added earlier in this PR on the plain and no-daemon paths.

Reviewed changes

Read the delta since the prior pullfrog review (c7cf494, plus the 03922415a0 refactor), the full 18-file diff, and replayed all four Codex fixtures through the live-screen function.

  • Screen may now only add readiness: isKnownReadyPromptBody returns true on the text rules before consulting the screen, so a text-ready verdict can no longer be vetoed by a screen showing loading; the screen branch runs only when the text is not ready.
  • Loading-window test narrowed: the per-recording test now passes '' as waitText (exercising only the screen), and the removed vetoes the append-only text copy while the screen still shows loading test is replaced by a multi-grid assertion that the screen never takes readiness away.
  • Refactor: isKnownReadyPromptPreview/isMuseReadyPromptPreview share isReadyPromptUnblocked; the screen thunk is read lazily and only for Codex/unknown panes.

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Reject stale emulator grids for tui-idle… · orca-runtime-visible-snapshot-preview.ts:143-160

src/main/runtime/orca-runtime-visible-snapshot-preview.ts:143-160
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Reject stale emulator grids for tui-idle evidence.

onPtyData updates the live tail and output sequence before trackHeadlessTerminalData applies the chunk to the emulator queue. During that interval, readLiveTerminalScreenLines can return the previous ready Codex header. The title-triggered tui-idle and delivery checks can then accept that header before the current busy output is applied. This can inject input into a running Codex session.

Return no screen evidence while the emulator sequence differs from the PTY sequence. The next poll can retry after the queued write completes.

Suggested fix
     if (
       !state ||
       this.providerSnapshotPreferredPtys.has(ptyId) ||
       this.headlessHydrationState.get(ptyId) === 'pending'
     ) {
       return null
     }
+    if (state.outputSequence !== this.ptyOutputSequenceById.get(ptyId)) {
+      return null
+    }
     // Why unawaited writeChain: callers are synchronous; a grid one chunk behind is re-read next poll.
     return projectTerminalVisibleLines(state.emulator).lines

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b1d2d780-6aa9-4629-987c-93711154ed00

📥 Commits

Reviewing files that changed from the base of the PR and between c7cf494 and 86d036e.

📒 Files selected for processing (3)
  • src/main/daemon/serialize-grid-transcript-replay.test.ts
  • src/main/runtime/codex-header-readiness-transcripts.test.ts
  • src/main/runtime/terminal-wait-detection.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/runtime/codex-header-readiness-transcripts.test.ts
  • src/main/runtime/terminal-wait-detection.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 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 prior pullfrog review (86d036e only): the screen rule now parses only the header box, and the serialize sweep records the new fixtures' pre-existing divergence.

  • Header-box-only screen parse: findCodexScreenReadyPromptIndex anchors on the first openai codex, slices to the box's ╰ corner, and applies model:/directory:/loading only inside that slice, so chat below the header that mentions OpenAI Codex or model: loading no longer changes the verdict. The added test covers exactly that case, and all 40 transcript tests pass.
  • Fixture allowlist: serialize-grid-transcript-replay.test.ts records the four new Codex recordings' pre-existing header-border restore divergence; the counts are asserted, so the test still fails if the divergence grows.
  • Text-first ordering unchanged: the earlier "screen can only add readiness" decision stands; the updated PR body documents the retained model: loading false positive as intentional.

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

@Jinwoo-H
Jinwoo-H merged commit 433986f into main Sep 27, 2026
44 checks passed
Jinwoo-H added a commit that referenced this pull request Sep 29, 2026
* fix(runtime): read Codex readiness from the live screen

Codex 0.157 runs in embedded mode when Orca passes `-c model_reasoning_effort=…`,
shows a startup warning, and repaints its header by cell diff
(`ESC[5;3Hdir ESC[5;7Hctory:`). The tui-idle body check read the line-folded
tail, which drops those cursor moves and reads `dirctory:`, so worker-start
timed out at agent_readiness while Codex sat idle at its prompt.

For Codex (or unknown) panes whose live emulator screen shows the Codex header,
the screen now decides readiness: `model:` and `directory:` present and neither
still `loading`. Otherwise today's text rules apply unchanged. All six tui-idle
satisfaction sites share one helper so they cannot disagree.

Fixes STA-8628 / #23241.

* refactor(runtime): read the Codex screen lazily and only for Codex panes

Pass the screen as a thunk so non-Codex panes never build the grid, hoist the
pane agent lookup, and share the unblocked-ready check with the Muse rule.

* fix(runtime): let the Codex screen only add readiness

A grid out of step with the PTY (size mismatch or a resize mid-paint) can garble
Codex's header. Keep every verdict the text rules give today and consult the
screen only when they say not ready, so no flow that settles today can stop.

* fix(runtime): read Codex readiness from the header box only

Chat below the header can mention "OpenAI Codex" or "model: loading", so the
screen rule now reads model/directory/loading only inside the header box.

The serialize round-trip sweep picks up every runtime fixture; record the
pre-existing header-border attribute divergence the new Codex 0.157 recordings
expose, which this change does not touch.

(cherry picked from commit 433986f)
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]: worker-start for codex times out at agent_readiness when --model/--effort are passed

1 participant