Repository navigation
Fix Codex worker readiness on cursor-painted terminal screens - #22891
seonghobae wants to merge 1 commit into
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe PTY and leaf waiter checks now allow Codex panes to use the visible-screen probe. The probe requests screen snapshots for all agents and retries Codex reads when the snapshot is missing, is not a screen projection, or has neither a blocked reason nor a ready prompt. It stops when the waiter is no longer registered or the retry window is insufficient. A new test verifies that a Codex wait succeeds after a second screen read returns a ready header. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to A Codex wait may occasionally time out when its screen becomes ready near the deadline. The narrow timing issue is worth fixing, but does not appear to prevent merging with owner awareness. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change broadens how Codex readiness is detected, but the reviewed path still requires a recognized visible prompt or a blocked state before completing a wait. No introduced security issue was established. Live behavior remains unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: beb7bf3d-55ad-47fa-937b-ea857c8b326b
📒 Files selected for processing (3)
src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.tssrc/main/runtime/runtime-terminal-wait.tssrc/main/runtime/terminal-wait-name-only-idle.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| if (remainingMs <= providerTimeoutMs + settleMarginMs) { | ||
| return | ||
| } | ||
| const timer = setTimeout(probe, Math.min(2_000, remainingMs - providerTimeoutMs)) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,145p' src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts
rg -n 'startTuiIdleVisibleReadProbe|settleMarginMs|providerTimeoutMs' src/main/runtime/runtime-terminal-wait.ts src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.tsRepository: stablyai/orca
Length of output: 6824
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- constants ---'
rg -n -C 8 'TUI_IDLE_VISIBLE_PROBE_SETTLE_MARGIN_MS|VISIBLE_TERMINAL_SNAPSHOT_TIMEOUT_MS' src/main/runtime
printf '%s\n' '--- probe callers and waiter lifecycle ---'
rg -n -C 12 'startTuiIdleVisibleReadProbe|setTimeout|deadline|waiterTimeoutMs|TerminalWaiter' src/main/runtime/runtime-terminal-wait.ts src/main/runtime
printf '%s\n' '--- focused runtime-terminal-wait source ---'
sed -n '1,260p' src/main/runtime/runtime-terminal-wait.tsRepository: stablyai/orca
Length of output: 45662
🏁 Script executed:
set -o pipefail
rg -n -C 10 'TUI_IDLE_VISIBLE_PROBE_SETTLE_MARGIN_MS|VISIBLE_TERMINAL_SNAPSHOT_TIMEOUT_MS' src/main/runtime/orca-runtime-postlude.ts
rg -n -C 14 'startTuiIdleVisibleReadProbe' src/main/runtime
rg -n -C 12 'waiterTimeoutMs|setTimeout.*waiter|terminalWaiters.*resolve|waiter.*timeout|deadline' src/main/runtime/runtime-terminal-wait.ts src/main/runtime/terminal-wait* src/main/runtime/*terminal*wait*.tsRepository: stablyai/orca
Length of output: 26357
Schedule the Codex retry before the settle margin is consumed.
VISIBLE_TERMINAL_SNAPSHOT_TIMEOUT_MS is 750 ms and settleMarginMs is 10 ms. For a remainingMs value just above 760 ms, the current delay starts the next probe with about 750 ms remaining. The waiter can then expire before a slow screen read classifies the ready screen.
Proposed change
- const timer = setTimeout(probe, Math.min(2_000, remainingMs - providerTimeoutMs))
+ const timer = setTimeout(
+ probe,
+ Math.min(2_000, remainingMs - providerTimeoutMs - settleMarginMs)
+ )Keep the <= guard. Exact equality provides no positive settle margin and should not schedule another retry.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const timer = setTimeout(probe, Math.min(2_000, remainingMs - providerTimeoutMs)) | |
| const timer = setTimeout( | |
| probe, | |
| Math.min(2_000, remainingMs - providerTimeoutMs - settleMarginMs) | |
| ) |
There was a problem hiding this comment.
Important
The Codex visible-screen probe resolves tui-idle without the first-party working-status veto or the quiescence gate that every other satisfaction site applies, and no captured Codex working-turn transcript exists to show the ready header is absent while Codex is mid-turn. Please pin the busy case before merging.
Reviewed changes
- Codex joins the visible-read probe unconditionally —
paneAgent === 'codex'is added to both gate clauses in the PTY and leaf paths, so the probe now runs for Codex even when retained text is nonempty and the last status is not null. - Probe retries for Codex — the single-shot probe becomes a bounded retry loop that re-reads the rendered screen roughly every two seconds until the waiter deadline; every other agent stays single-shot.
- Probe always reads the rendered screen — read options change from
{}to{ screen: true }for all agents (Antigravity already passedscreen: true), which is what lets Codex's cursor-painted banner be observed. - New focused regression test — spies on
readTerminalto return a boot screen and then a ready header, asserting the wait settles after exactly two reads with{ screen: true }.
⚠️ No captured Codex transcript pins the screen-reading rule
The new test replaces readTerminal with a spy, so it pins the retry loop and the read options but not the load-bearing claim that a real Codex 0.157 screen contains the ready header. src/main/runtime/__fixtures__/ has busy/ready pairs for Antigravity and Muse and none for Codex, and AGENTS.md/docs/reference/agent-pty-transcript-capture.md require any rule that reads an agent CLI's screen to be written against a captured raw transcript. Without a real Codex busy/ready pair, the false-idle window in the inline finding cannot be ruled out.
Technical details
# Pin Codex readiness to captured transcripts
## Affected sites
- `src/main/runtime/terminal-wait-name-only-idle.test.ts:298-319` — new test mocks `readTerminal`, so the actual rendered-screen path is never exercised.
- `src/main/runtime/__fixtures__/` — has `antigravity-busy-mid-turn.txt` / `antigravity-busy-turn-ended.txt` but no `codex-*` fixture.
## Required outcome
A raw `node-pty` capture of a real Codex pane in both the ready state and an active-turn state, replayable through `agent-transcript-pane-test-harness.ts`, so the detector's verdict on a working screen is observed rather than assumed.
## Suggested approach (optional)
Mirror `antigravity-readiness-transcripts.test.ts`: add a `codex-busy-mid-turn` / `codex-ready-composer` fixture pair and assert the wait refuses the busy screen and accepts the ready screen.ℹ️ Nitpicks
- The
{}→{ screen: true }change also applies to the null-agent / AGY-header probe paths. If that broadening is intended, the probe's JSDoc could name it; if not, gate it to the agents that need the rendered grid.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // pane is identified as AGY (or its banner is present), regardless of that | ||
| // stale status. | ||
| (paneAgent === 'antigravity' || | ||
| (paneAgent === 'codex' || |
There was a problem hiding this comment.
The added paneAgent === 'codex' gate starts the visible-screen probe while Codex may be mid-turn, and that probe resolves satisfied straight from isKnownReadyPromptPreview — it never consults getFirstPartyAgentStatus or the quiescence gate that isTuiIdleSatisfied applies to every other satisfaction site. Codex's ready header is a session-start history cell that stays in the viewport until the transcript scrolls it off, so a tui-idle wait created early in a turn can settle against a still-working Codex and the orchestrator will type into it. Please add a busy-screen guard (first-party working veto and/or a Codex interrupt/spinner marker) or a captured working-turn transcript proving the header is absent.
Technical details
# Codex probe bypasses the tui-idle evidence ranking
## Affected sites
- `src/main/runtime/runtime-terminal-wait.ts:157` and `:162` (PTY), `:259`/`:264` (leaf) — the added `paneAgent === 'codex'` gates start the probe when retained text is nonempty and the status is not null.
- `src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts:92-105` — `isKnownReadyPromptPreview(snapshotText)` decides readiness and `terminalWaiters.resolve` commits it without going through `isTuiIdleSatisfied`.
- `src/main/runtime/tui-idle-evidence.ts:59-61,168-170` — tier 2 documents that a fresh first-party `working`/`blocked` status vetoes inferred body evidence; the probe path never calls this, unlike the poll path.
## Required outcome
A Codex pane that is mid-turn must not resolve `satisfied: true` from a visible header alone. Route the probe verdict through the same ranking (at minimum the `getFirstPartyAgentStatus` veto and the quiescence demand), or reject a screen that still shows a live busy marker (e.g. `esc to interrupt`, a Codex spinner) after the header.
## Evidence
- `tests/e2e/ssh-codex-repro-remote-fixtures.ts:117-126` redraws `>_ OpenAI Codex` at the viewport top on every synthetic busy frame.
- `src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-07.spec.ts:22-57` already asserts a booting Codex (MCP startup lines plus header) is idle from the tail path.
- `findCodexReadyPromptIndex` (`src/main/runtime/terminal-wait-detection.ts:143-151`) has no busy veto, unlike `findCursorReadyPromptIndex` at `:119-128`.
## Open question for the human
Is the Codex header guaranteed to have scrolled off the viewport before a completion `tui-idle` wait is created, or is settling during MCP startup accepted by design?|
I independently reproduced the Codex 0.157
Local evidence for the completed candidate: 74/74 focused Vitest tests; Node and CLI typechecks; oxlint/oxfmt on the five changed files; and 1/1 hidden Electron |
|
Thanks @seonghobae for digging into the cursor-painted Codex 0.157 banner. Main already fixes this in #23475 (433986f), and the rules were later moved into rule files in #24375. For Codex panes, tui-idle now reads the live emulator screen, so a header painted by cell diff is rebuilt correctly whatever the retained text says. Because that check runs on every idle poll, a slow first paint gets picked up on a later tick, and the 0.158+ empty-composer screen is covered too. If |

ELI5
A Codex worker can be sitting at its input prompt while Orca keeps waiting for it to start. Orca now checks the visible terminal screen during that wait.
What Changed
The terminal wait path starts a visible-screen probe for Codex even when its retained text is nonempty or its title looks idle. The probe asks for the rendered screen and retries at most every two seconds until the existing wait deadline. A ready screen settles the wait; an interactive prompt still blocks it.
Why
Codex 0.157 paints its banner with cursor movement. The retained text and short preview can omit the
OpenAI Codex,model:, anddirectory:lines although the rendered screen shows all three. The previous probe skipped Codex when retained text was nonempty, and one early snapshot could miss a slow first paint. This uses Orca's existing screen reader and readiness matcher, with no new prompt-text rule.Linked Issue
Fixes #22825
Visual Proof
N/A — the rendered UI does not change. Before: the existing s1 Codex 0.157 terminal shows the empty
Ask Codex to do anythingcomposer whileterminal wait --for tui-idle --timeout-ms 1500exits 1 withtimeout. After: the focused regression supplies a boot screen followed by that ready screen; the wait resolves and the test exits 0. The patched runtime has not been deployed to s1.Testing
ORCA_BACKGROUND_LAUNCH=1 node_modules/.bin/vitest run src/main/runtime/terminal-wait-name-only-idle.test.ts -t 'reads the visible Codex screen again' --reporter=dot— exit 0, one passed.oxfmt --checkandoxlinton the three changed files — exit 0.Tested the focused regression on macOS. The affected worker was on a paired s1 runtime; no patched Linux or Windows run was performed.
Review
Agent skill upstream boundary
Notes
The probe uses the existing host-owned terminal screen API and existing timeout, so SSH and paired-host execution keep the same ownership boundary. It adds no wire field or Git command. The Codex-only retry is bounded by the waiter deadline; timers stop probing after the waiter settles. Full repository checks and builds were not run because of the current disk and memory constraint.
Checklist