Skip to content

fix(tui-idle): probe the visible screen for Codex panes and repeat until the wait settles - #22902

Closed
aniruddhaadak80 wants to merge 1 commit into
stablyai:mainfrom
aniruddhaadak80:fix/tui-idle-codex-visible-screen-probe
Closed

aniruddhaadak80 wants to merge 1 commit into
stablyai:mainfrom
aniruddhaadak80:fix/tui-idle-codex-visible-screen-probe

Conversation

@aniruddhaadak80

Copy link
Copy Markdown

ELI5

Starting a Codex worker can hang until it gives up, saying the agent never became ready, even though Codex is sitting right there at its prompt waiting for the task. Orca decides an agent is "ready" by reading the text the terminal has scrolled past, and newer Codex versions draw their startup banner directly onto the screen instead of scrolling it past. So Orca looks at the wrong place, decides nothing is ready, and eventually times out. This change makes Orca also look at what is actually on screen, and keeps looking until the worker is ready or the wait runs out.

What Changed

Before: orca orchestration worker-start --agent codex reaches the Codex prompt, then the receipt comes back state: failed, stage: agent_readiness, lastError: timeout. The task is never injected and the context stays at 0%. The same is true of orca terminal wait --for tui-idle on that pane.

After: the wait settles once the rendered screen shows the settled Codex banner (OpenAI Codex, model:, directory:), the task is injected, and the worker proceeds.

Mechanism, in two parts:

  1. The gate. tui-idle matches the stream tail, but Codex 0.157 turned on tui.fullscreen_transcript, so the session banner is painted into the alternate screen with cursor addressing and never becomes a newline-separated scrollback line. buildTerminalWaitText only ever reads the tail, so findCodexReadyPromptIndex cannot match. The visible-screen read that can prove readiness existed already, but runtime-terminal-wait.ts only started it for AGY panes, panes carrying an AGY banner, or an empty tail:

    (agent === "antigravity" || antigravityHeader(tail) || lastAgentStatus === null)
      && (tail.length === 0 || agent === "antigravity" || antigravityHeader(tail))
    

    A Codex pane whose shell had already printed one line matched neither arm, so the probe never ran. The gate is now expressed once as shouldProbeVisibleScreen and admits the agents whose readiness is painted rather than scrolled: AGY and Codex.

  2. The single look. Even with the gate open, a launch registers the waiter while the TUI is still painting, so one bounded ~750 ms look can read a blank screen and hand the wait back to the tail-only sweep that cannot see the banner at all. startVisibleScreenProbe now re-reads the screen on the provider's existing visible-snapshot retry cadence (1 s) until the waiter settles, so a slow first paint is no longer missed.

The repeat timer is carried on the TerminalWaiter and retired by the registry's single remove path, the same place the wait timeout and the idle poll are already cleaned up, so no probe can outlive its waiter.

Why

  • Widening the gate alone is not enough. It is the necessary half - without it the probe never runs - but a launch-time look at an unpainted screen still returns "not ready", and the tail can never recover, so the wait would still time out. Both halves are required for the reported case.
  • Repeat only for the alternate-screen agents. Panes that already settle from their own tail keep today's single bounded look and today's cost, so this does not add a provider read per waiting pane across the wait path. A test pins that.
  • Considered and rejected: launch Codex with -c tui.fullscreen_transcript=false. The reporter's second comment confirms the config key works as a workaround. Rejected here because it pins Orca's supported behavior to one Codex release's default: the flag disappears in a future version, the setting lives in the user's ~/.codex/config.toml rather than in the pane Orca launches, and Orca would still be unable to read a screen it genuinely cannot see. Reading the screen is the fix that survives the next release. The launch-flag route also leaves every Codex user who has already adopted fullscreen mode broken.
  • Considered and rejected: widening the gate to every agent. That turns a targeted fix into a per-wait provider read on lanes that already answer from the tail, for no reported benefit.
  • Considered and rejected: making the tail normalizer reassemble cursor-addressed output. The banner genuinely never enters scrollback under the alternate screen, so there is nothing in the tail to reassemble.

Linked Issue

Fixes #22825

The second half of the reporter's finding (the -c / --enable / --disable / --search launch skipping the shared Codex app server unless it is embedded) is tracked separately as #22873 and is deliberately not addressed here.

Visual Proof

N/A - no UI or interaction change, and no pixels change. The observable difference is that orca terminal wait --for tui-idle stops timing out on a Codex pane whose rendered screen already shows the settled prompt.

Testing

I have not run any of these commands. This change was authored entirely through the GitHub API against a remote-only checkout, so there is no local working tree, no node_modules, and no installed Codex CLI in the environment it was written in. I am not claiming a green run. Verification is CI's job for this PR, and the exact commands CI runs are the four below plus the sharded vitest matrix.

pnpm lint
pnpm typecheck
pnpm test
pnpm build

The focused suite this PR adds, and the neighboring wait suites a reviewer will want alongside it:

pnpm exec vitest run --config config/vitest.config.ts \
  src/main/runtime/terminal-wait-codex-visible-screen-probe.test.ts \
  src/main/runtime/terminal-wait-name-only-idle.test.ts \
  src/main/runtime/antigravity-readiness-transcripts.test.ts

New tests in src/main/runtime/terminal-wait-codex-visible-screen-probe.test.ts:

  • A Codex pane whose tail already carries a shell line and whose agent status is working starts the visible-screen probe, and the probe is asked for codex. This is the regression lock for the reported bug: before the gate change nothing asks the provider for the screen at all, so this fails without the fix.
  • The probe is re-armed while the waiter is still pending, so a screen that has not painted yet does not end the wait.
  • When the waiter times out, the repeating probe stops; advancing the clock far past the timeout produces no further reads. This is the leak guard for the new timer.
  • A pane that settles from its own tail is not probed, so the gate widening is bounded.
  • A Codex pane whose banner is in scrollback still settles from the tail without a screen read, so the pre-0.157 path is unchanged.

Platform notes, stated plainly:

  • The report is macOS. I have not manually reproduced it on macOS, Linux, or Windows, and I am not claiming a manual run on any of them.
  • The change itself is platform-neutral: it is pure scheduling plus a string-matched agent check. No paths, no process spawning, no shell semantics, no keyboard or shortcut handling, and no wire format between a client and a remote host.
  • CI for this repo runs the unit matrix on ubuntu-latest (Node 24) and the Windows job only on Windows-marked paths, so neither covers a macOS Codex pane. The fix is verified on Linux by construction and by the unit tests; the macOS behavior described in the issue is not machine-verified by anything in this PR.
  • The codex_index_heal_contract job pins a real Codex binary (0.150.1) and is path-filtered, so this diff does not trigger it. The regression it would catch is a different subsystem.

AI Disclosure

Written with the OpenCode agent (model opencode/space-bunny-free) under direction of @aniruddhaadak80, who reviewed the diff and the evidence. The source reading, the fix, and the tests were produced by the agent. Not verified by any human running the suite - see Testing.

Author: @aniruddhaadak80. (X handle not supplied by the author; please add it here before merge if you want the shout-out.)

Review

  • Cross-platform (Linux, Windows, macOS): no platform-specific code, no path usage, no process or shell assumptions. Safe on all three by construction.
  • SSH / remote / local: the probe is a provider screen read against the pane the waiter is already registered on, so it inherits whatever host owns that pane - local, SSH, or runtime. No new remote call and no wire-format change.
  • Agents and integrations: only Codex is added to the alternate-screen arm. AGY keeps its previous behavior and gains the repeat. No git provider or agent-status producer changed.
  • Performance: the new cost is one visible-screen read per second, per waiting pane, only for AGY and Codex panes and only until that wait settles or its own timeout fires. Every other pane keeps a single bounded look. The timer is carried per waiter and retired with it, so no timer outlives its waiter and the sweep's single shared-timer invariant is untouched.
  • Security: none. No new input parsing, no credential or network surface, and the screen read is the same provider read the existing probe already performs.
  • UI: no renderer, layout, token, or style change.
  • Localization: no user-facing string added or changed, so no catalog work.
  • Relation to open PR fix(terminal): stop treating the Codex boot header as tui-idle readiness #18019: complementary and non-overlapping. That PR hardens findCodexReadyPromptIndex against a false positive - treating the booting model: loading header as readiness. This PR changes which projection is read and how often, and does not touch terminal-wait-detection.ts at all. If it merges, the two compose: this one guarantees the screen is read, that one makes the match stricter. fix(terminal): stop treating the Codex boot header as tui-idle readiness #18019 is open and unmerged, and this diff is branched from current main.
  • Other open Codex readiness work (fix(orchestration): wait for opencode's composer marker before worker-start's paste #20451, fix(kimi): recognize the sessionless startup composer #22726, fix(runtime): recognize a resting DeepSeek Harness as tui-idle #22880) targets other agents' composers and is untouched by this diff.

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

  • Verification gap, stated up front: the tests in this PR have not been executed by the author. They are written against the existing tui-idle-wait-test-harness fixtures and the same createWait shape used by terminal-wait-name-only-idle.test.ts, but unverified is unverified. If a test fails in CI, the most likely cause is a fixture expectation rather than the production change, and the fix belongs in the test.
  • Backwards compatibility: no protocol, no persisted shape, and no public API change. TerminalWaiter gains one internal field, and the only reader outside this feature is the waiter registry's cleanup.
  • The max-lines budget was respected: runtime-terminal-wait.ts goes from 237 to 268 counted lines against the 300 cap for src/main/runtime/**/*.ts.
  • The pre-existing // @ts-nocheck split module orca-runtime-start-tui-idle-visible-read-probe.ts was intentionally not edited, so no ts-nocheck ratchet movement is involved. The repeat is armed from runtime-terminal-wait.ts and driven through the existing startVisibleReadProbe dependency, which keeps the single-shot probe implementation byte-identical.

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) - left unchecked because there is no local checkout to run them against. CI is the verification for this PR; see Testing.

@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

pnpm typecheck fails as-is (TS2741 from a TerminalWaiter constructor this PR did not update), and the Codex gate widening can resolve tui-idle on the booting model: loading header until #18019 lands. Both are detailed inline.

Reviewed changes

  • Gate widened to Codex — shouldProbeVisibleScreen is extracted from the inline AGY gate and usesAlternateScreenReadiness now admits codex, so a Codex pane whose shell already printed a line starts the visible-screen probe on both the PTY and leaf paths.
  • Probe repeats — startVisibleScreenProbe chains a 1s setTimeout loop until the waiter's deadline, replacing the single bounded look for AGY/Codex; other agents keep the single-shot path.
  • Waiter plumbing — TerminalWaiter gains a required cancelVisibleProbe, retired by the registry's single remove path alongside the timeout and idle poll.
  • New regression suite — terminal-wait-codex-visible-screen-probe.test.ts (5 tests, passing locally) pins that a Codex pane with shell output is probed, that the probe re-arms, stops at timeout, and is not run for tail-settled panes.

ℹ️ Nitpicks

  • src/main/runtime/terminal-wait-codex-visible-screen-probe.test.ts fails oxfmt --check: the import on lines 5-9 collapses to one line and the file is missing a trailing newline. Run pnpm format.
  • src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts:31 still documents startTuiIdleVisibleReadProbe as "Deliberately single-shot"; that is now false for the AGY/Codex callers this PR routes into it. Worth a follow-up edit even though the file itself was intentionally untouched.

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

@@ -191,6 +191,8 @@ export type TerminalWaiter = {
timeout: NodeJS.Timeout | null
/** Retires this waiter from the shared idle-poll sweep; null when not polling. */
cancelIdlePoll: (() => void) | null
/** Retires the repeated visible-screen probe armed for this waiter; null when not probing. */
cancelVisibleProbe: (() => void) | null

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.

Adding cancelVisibleProbe as a required field breaks an existing constructor this PR does not update: runtime-terminal-idle-polls.test.ts:42 makeWaiter omits it, so pnpm typecheck (and tc:node) fails with TS2741: Property 'cancelVisibleProbe' is missing. Update that fixture (or make the field optional) before merge. Verified locally with tsc --noEmit -p config/tsconfig.node.json.

* Agents whose settled readiness is painted to the screen instead of written to scrollback.
*/
function usesAlternateScreenReadiness(agent: TuiAgent | null): boolean {
return agent === 'antigravity' || agent === 'codex'

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.

Widening the probe to Codex routes the probe's readiness check through isKnownReadyPromptPreview on the live screen. Open PR #18019 exists precisely because findCodexReadyPromptIndex matches the booting banner (openai codex + model: + directory:) while model: loading / directory: loading are still showing. Until #18019 merges, this change can resolve tui-idle during model load and let worker-start paste onto the splash screen — trading the reported timeout for an early paste.

Technical details
# Codex readiness probe can settle on the booting header

## Affected sites
- `src/main/runtime/runtime-terminal-wait.ts:35` — `usesAlternateScreenReadiness` now routes codex through the repeating probe.
- `src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts:83` — for codex the probe classifies readiness with `isKnownReadyPromptPreview`.
- `src/main/runtime/terminal-wait-detection.ts:143` — `findCodexReadyPromptIndex` matches `openai codex` + `model:` + `directory:` and does not reject `loading` values.

## Required outcome
- A codex `tui-idle` wait must not settle while the banner still reads a loading value for `model:` or `directory:`.

## Suggested approach (optional)
- Land #18019 first, or reject `loading` values in the screen-path readiness check before enabling the repeat for codex.

@aniruddhaadak80

Copy link
Copy Markdown
Author

Overlap with #22891 (noted by the author)

@seonghobae posted #22891 for this same issue at 16:04 UTC, roughly 50 minutes after this PR was opened, and it reaches the same conclusion by the same two-part mechanism: start the visible-screen probe for a Codex pane whose retained text is non-empty, and re-read the screen until the wait deadline. My dedup pass against this issue ran at about 15:47 UTC, before that PR existed, which is why it did not turn up in my search.

I am flagging the overlap rather than quietly leaving both open, so a reviewer can pick one. This PR is not withdrawn; the differences a reviewer may care about:

  • The @ts-nocheck split module is untouched. Fix Codex worker readiness on cursor-painted terminal screens #22891 rewrites orca-runtime-start-tui-idle-visible-read-probe.ts (+59/-43), whose header says it is mechanically split and covered by AST-equivalence and characterization tests. This PR arms the repeat from runtime-terminal-wait.ts and drives it through the existing startVisibleReadProbe dependency, so that file stays byte-identical and no ts-nocheck ratchet moves.
  • Blast radius is pinned by a test. Only the alternate-screen agents (AGY, Codex) re-read the screen; panes that already settle from their tail keep today's single bounded look. Fix Codex worker readiness on cursor-painted terminal screens #22891's summary does not state a bound for the non-Codex lanes, and that gate is shared with AGY, the empty-tail lane and the lastAgentStatus === null lane.
  • There is an explicit leak test. The repeat rides on the TerminalWaiter and is retired by the registry's single remove path; one test asserts no further reads happen after the waiter times out. Fix Codex worker readiness on cursor-painted terminal screens #22891 says timers stop after the waiter settles but does not appear to pin it.
  • Retry cadence is 1 s here versus 2 s in Fix Codex worker readiness on cursor-painted terminal screens #22891 - a cost/speed trade, not a correctness one.
  • max-lines headroom. This PR lands runtime-terminal-wait.ts at 268 counted lines against the 300 cap. The neighbouring terminal-wait-name-only-idle.test.ts, where Fix Codex worker readiness on cursor-painted terminal screens #22891 adds its test, is already at 286 of 300, so that test file has 14 lines of headroom for a 23-line addition - worth checking against the cap before either is merged.

Both approaches are legitimate. Whoever merges first, the other should close. Leaving the choice to the maintainers either way.

Separately, the same honest caveat as in the body applies here: I have not executed any test. This PR was authored through the GitHub API with no local checkout, so CI is the verification.

@aniruddhaadak80

Copy link
Copy Markdown
Author

Correction with exact numbers on the max-lines point above

I understated this in my previous comment, so here is the measured version.

  • src/main/runtime/terminal-wait-name-only-idle.test.ts is 286 counted lines on main (blank lines and comment-only lines excluded, matching the rule's skipBlankLines / skipComments).
  • The cap for **/*.test.ts is 300 (config/oxlint-*.json override: max-lines: ["error", {"max": 300, ...}] in .oxlintrc.json).
  • Fix Codex worker readiness on cursor-painted terminal screens #22891 adds 23 lines to that file, of which 21 are counted code lines, projecting the file to 307.
  • config/max-lines-baseline.txt is a ratchet of exactly 7 inline entries, all under src/main/ipc, src/main/ssh, src/relay, and src/renderer. It does not grandfather this test file, and the ratchet is append-only-rejected: the list may only shrink.

So as it stands #22891 projects 7 counted lines over the cap on a file that is not grandfathered, which would fail oxlint in the static_analysis job and therefore the verify gate. This PR does not touch that file at all, and lands runtime-terminal-wait.ts at 268 of 300.

I am flagging this as a mechanical cap conflict, not as a judgement on the approach - the fix in #22891 is sound and the test belongs in a sensible place. Either it moves to its own test file (as this PR does) or the existing file needs splitting first. Noting it here so whoever picks this up is not surprised by a red static_analysis.

I did not run pnpm exec oxlint to confirm the 21-line count; it is a line count of the patch under the rule's documented skip behavior, not a lint result. CI is the authority.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Terminal waits now select visible-screen probes for Codex and Antigravity regardless of status or tail content. These agents are probed immediately and every 1,000 ms until the waiter deadline or removal. Other agents receive one probe. Both PTY and leaf wait paths use the shared probe logic, and waiter removal cancels its retry timer. Tests cover Codex probing, timeout, and cases that do not start a probe.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to d460d

Typechecking is blocked by the missing waiter fixture field, so that should be fixed before merging. A waiter that settles immediately can also continue unnecessary screen reads until its deadline.

Security architecture risk: 🟡 Moderate · up to 6cf08

A worker may now be considered ready based on text visible in its terminal even while its recorded status says it is working. The impact appears limited to that worker's pane, but premature readiness could affect when its task is sent.

Retained concerns

  • Medium · security · inferred: Codex visible-screen text can now be evaluated repeatedly for readiness while the pane reports working. If the recognized banner remains visible or is reproduced during work, the waiter can settle without confirming that the current turn is idle; downstream task timing remains unverified.
Security review details

Security Blast Radius

  • inferred — The identified exposure is readiness for the waited-on terminal handle. The inspected probe does not select another pane or directly submit a task.

Security Findings and Attack Paths

  • inferred — Screen text displaying the recognized Codex banner during an active turn could settle a newly eligible waiter prematurely. The evidence does not establish that such text persists in a working pane or that a task is injected into one.

Trust Boundaries and Controls

  • observed — Terminal reads use the waiter handle, validate that its live target still has the expected PTY ID after the asynchronous read, and reject non-screen projections or results for removed waiters.

Resilience and Maintainability Implications

  • observed — Timeout, abort, and resolution use registry removal, which retires the repeated-probe timer; asynchronous completions additionally require the original waiter object to remain registered.

Hardening Proposals

  • proposed — Establish whether the ready banner can remain on screen during active Codex work, and require a current-turn idle signal if it can. Verify downstream task behavior when a screen probe and working status disagree.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: repeated visible-screen probing for Codex panes during TUI-idle waits.
Description check Passed The description covers the required sections and provides clear user impact, implementation details, rationale, linked issue, testing scope, platform considerations, and checklist status. It openly st…
Linked Issues check Passed No active directly linked issue remains. Closed #22825 supplies historical context only, and #22873 is explicitly separate. The implementation nevertheless matches the reported context: Codex and Anti…
Out of Scope Changes check Passed The changes stay within the visible-screen readiness fix described for #22825. The waiter field, retry scheduling, registry cleanup, and focused tests directly support probe lifecycle and Codex readin…
Full details: Description check

Explanation

The description covers the required sections and provides clear user impact, implementation details, rationale, linked issue, testing scope, platform considerations, and checklist status. It openly states that local tests and commands were not run and identifies CI as the planned verification.

Full details: Linked Issues check

Explanation

No active directly linked issue remains. Closed #22825 supplies historical context only, and #22873 is explicitly separate. The implementation nevertheless matches the reported context: Codex and Antigravity use repeated visible-screen probes, and registry removal cancels the probe timer. Focused tests cover probe selection, retries, timeout cleanup, and tail-based readiness.

Full details: Out of Scope Changes check

Explanation

The changes stay within the visible-screen readiness fix described for #22825. The waiter field, retry scheduling, registry cleanup, and focused tests directly support probe lifecycle and Codex readiness. No unrelated app-server, UI, protocol, or agent-launch changes are shown.

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

🧹 Nitpick comments (1)
src/main/runtime/terminal-wait-codex-visible-screen-probe.test.ts (1)

131-138: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add an early-settlement probe cancellation test.

The timeout test can pass even if remove does not call cancelVisibleProbe, because the probe loop stops at its own deadline. Configure the probe mock to settle the waiter before the deadline, then advance past several retry intervals and assert that no further probes run. This also verifies that a later visible read satisfies the Codex wait.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d18851e7-208c-4d6e-893a-63b984d80c85

📥 Commits

Reviewing files that changed from the base of the PR and between 646e9a5 and 6cf08f8368f7d9f70ca07ccd89ebd698e7745085.

📒 Files selected for processing (4)
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/runtime-terminal-wait.ts
  • src/main/runtime/runtime-terminal-waiter-registry.ts
  • src/main/runtime/terminal-wait-codex-visible-screen-probe.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +57 to +60
const alternateScreen = usesAlternateScreenReadiness(agent)
return (
(alternateScreen || hasAntigravityTerminalHeader(waitText) || lastAgentStatus === null) &&
(waitText.length === 0 || alternateScreen || hasAntigravityTerminalHeader(waitText))

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 | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect getPaneAgent bindings and the metadata they read.
rg -n -C 5 -P '\bgetPaneAgent\s*[:(]' src/main/runtime
rg -n -C 4 -P '\b(foregroundAgent|launchAgent)\s*[:=]' src/main/runtime

Repository: stablyai/orca

Length of output: 41903


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- getter definitions and callers ---'
rg -n -C 12 'getPaneAgentForTuiIdle|shouldProbeVisibleScreen' src/main/runtime
printf '%s\n' '--- waiter registration and probe setup ---'
rg -n -C 18 'register|waitFor|startVisibleScreenProbe|shouldProbeVisibleScreen' src/main/runtime/runtime-terminal-wait.ts
printf '%s\n' '--- foreground agent updates ---'
rg -n -C 18 'foregroundAgent|runtime-pty-foreground-agent|onForeground|setForeground' src/main/runtime --glob '*.ts'
printf '%s\n' '--- Codex launch and terminal-wait call sites ---'
rg -n -C 10 'codex|terminalWait|terminal.wait|waitForTerminal|createTerminal' src/main/runtime --glob '*.ts'

Repository: stablyai/orca

Length of output: 45662


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- waitForTerminal call sites in runtime orchestration ---'
rg -n -C 14 'waitForTerminal\(' src/main/runtime --glob '*.ts' | rg -v 'test' 
printf '%s\n' '--- worker-start readiness flow ---'
rg -n -C 20 'agent_readiness|wait-for-setup|workerStart|sendTerminalAgentPrompt' src/main/runtime/rpc src/main/runtime --glob '*.ts' | head -n 1200
printf '%s\n' '--- terminal creation and launchAgent storage ---'
rg -n -C 18 'launchAgent.*pty|pty.*launchAgent|createTerminal\(|register.*Pty|pty\.launchAgent' src/main/runtime --glob '*.ts' | head -n 1600

Repository: stablyai/orca

Length of output: 45660


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- exact waitForTerminal calls ---'
rg -n 'waitForTerminal\(' src/main/runtime/orca-runtime-create-agent-prompt-render-gate.ts src/main/runtime/orca-runtime-structured-agent-session-launch-tui.ts src/main/runtime/rpc/methods/agent-launch-terminal-prompt.ts src/main/runtime/rpc/methods/orchestration/worker/local-worker-start.ts src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts
printf '%s\n' '--- local worker readiness ---'
sed -n '110,225p' src/main/runtime/rpc/methods/orchestration/worker/local-worker-start.ts
printf '%s\n' '--- structured launch ---'
sed -n '1,105p' src/main/runtime/orca-runtime-structured-agent-session-launch-tui.ts
printf '%s\n' '--- prompt render gate ---'
sed -n '80,150p' src/main/runtime/orca-runtime-create-agent-prompt-render-gate.ts
printf '%s\n' '--- agent session terminal creation ---'
sed -n '170,215p' src/main/runtime/orca-runtime-create-agent-session.ts
printf '%s\n' '--- PTY registration definitions ---'
rg -n -C 20 'registerPty\(|launchAgent:' src/main/runtime/orca-runtime-runtime-id.ts src/main/runtime --glob '*.ts' | head -n 1000

Repository: stablyai/orca

Length of output: 42068


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- placeWorkerAgent definition and external terminal branch ---'
rg -n -C 25 'function placeWorkerAgent|const placeWorkerAgent|placeWorkerAgent\s*=' src/main/runtime/rpc/methods/orchestration/worker src/main/runtime --glob '*.ts' | head -n 1400
printf '%s\n' '--- worker terminal parameter and agent propagation ---'
rg -n -C 18 'params\.terminal|terminalHandle|agentLaunchAuthority|launchAgent' src/main/runtime/rpc/methods/orchestration/worker --glob '*.ts' | head -n 1800
printf '%s\n' '--- registerPty implementation ---'
rg -n -C 35 'registerPty\(.*worktree|agentLaunchAuthority' src/main/runtime --glob '*.ts' | rg -v 'node_modules' | head -n 1800
printf '%s\n' '--- Codex worker tests with supplied terminals ---'
rg -n -C 14 'terminal:.*|agent: .codex.|agent.*codex' src/main/runtime/rpc/methods/orchestration/worker --glob '*test.ts' | head -n 1600

Repository: stablyai/orca

Length of output: 45667


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- WorkerStartInput schema and agent resolution ---'
rg -n -C 25 'WorkerStartInput|WorkerStartParams|terminal:|agent:' src/main/runtime/rpc/methods/orchestration/worker --glob '*.ts' | head -n 1800
printf '%s\n' '--- local worker setup and resolved agent ---'
sed -n '1,125p' src/main/runtime/rpc/methods/orchestration/worker/local-worker-start.ts
printf '%s\n' '--- reused-terminal worker tests ---'
rg -n -C 18 'terminal: .term_worker.|terminal:.*agent|startWorker.*terminal|existing.*terminal|reused.*terminal' src/main/runtime/rpc/methods/orchestration/worker --glob '*test.ts' | head -n 1800

Repository: stablyai/orca

Length of output: 45667


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- worker start schema ---'
cat -n src/main/runtime/rpc/methods/orchestration/worker/worker-start-schema.ts
printf '%s\n' '--- local worker first 125 lines ---'
cat -n src/main/runtime/rpc/methods/orchestration/worker/local-worker-start.ts | sed -n '1,125p'
printf '%s\n' '--- explicit terminal validation remainder ---'
cat -n src/main/runtime/rpc/methods/orchestration/worker/explicit-worker-terminal-validation.ts | sed -n '1,180p'
printf '%s\n' '--- worker launch preference guard ---'
cat -n src/main/runtime/rpc/methods/orchestration/worker/worker-launch-preferences.ts | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 15206


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- shared worker-start schema ---'
cat -n shared/rpc-contract/orchestration-worker-start-params.ts
printf '%s\n' '--- prepareLocalWorkerStart ---'
rg -n -C 30 'prepareLocalWorkerStart' src/main/runtime/rpc/methods/orchestration/worker --glob '*.ts'

Repository: stablyai/orca

Length of output: 275


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- exact schema file ---'
rg --files | rg 'orchestration-worker-start-params|worker-start-validation'
printf '%s\n' '--- prepareLocalWorkerStart locations ---'
rg -n -C 20 'prepareLocalWorkerStart' src/main/runtime --glob '*.ts'

Repository: stablyai/orca

Length of output: 18227


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- isTerminalRunningAgent ---'
rg -n -C 30 'isTerminalRunningAgent' src/main/runtime --glob '*.ts'
printf '%s\n' '--- getPtyAgent and agent detection ---'
rg -n -C 25 'getPtyAgent\(|foregroundAgent|detect.*Agent|AgentPresence' src/main/runtime --glob '*.ts' | head -n 1800

Repository: stablyai/orca

Length of output: 45655


🏁 Script executed:

#!/bin/bash
set -e
files=$(rg -l 'isTerminalRunningAgent' src/main/runtime --glob '*.ts' | rg -v '\.test\.ts$|\.spec\.ts$')
printf '%s\n' "$files"
for f in $files; do
  printf '%s\n' "--- $f ---"
  rg -n -C 18 'isTerminalRunningAgent|isRunningAgent|getTerminalAgentStatus' "$f"
done

Repository: stablyai/orca

Length of output: 19214


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- terminal agent presence implementation ---'
rg -n -C 30 'class .*TerminalAgentPresence|terminalAgentPresence|isRunning\(' src/main/runtime --glob '*.ts' | rg -v '\.test\.ts|\.spec\.ts' | head -n 1800

Repository: stablyai/orca

Length of output: 32702


🏁 Script executed:

#!/bin/bash
set -e
cat -n src/main/runtime/runtime-terminal-agent-presence.ts | sed -n '39,190p'

Repository: stablyai/orca

Length of output: 6752


🏁 Script executed:

#!/bin/bash
set -e
cat -n src/main/runtime/runtime-terminal-idle-polls.ts | sed -n '95,225p'

Repository: stablyai/orca

Length of output: 6193


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- title presence predicate ---'
rg -n -C 25 'function ptyTitleProvesAgentPresence|ptyTitleProvesAgentPresence[[:space:]]*=' src/main/runtime/runtime-worktree-status-projection.ts
printf '%s\n' '--- PTY launch/foreground initialization ---'
rg -n -C 12 'launchAgent: null|foregroundAgent: null|launchAgent,' src/main/runtime --glob '*.ts' | head -n 1000

Repository: stablyai/orca

Length of output: 41487


🏁 Script executed:

#!/bin/bash
set -e
rg -n -C 18 'launchAgent: null|foregroundAgent: null' src/main/runtime/orca-runtime-record-pty-worktree.ts

Repository: stablyai/orca

Length of output: 1948


Retry the Codex visible-screen probe after pane identification.

A reused terminal can pass isTerminalRunningAgent from title evidence while both launchAgent and foregroundAgent remain unset. The waiter then receives null from getPaneAgentForTuiIdle.

For a nonempty shell tail, shouldProbeVisibleScreen skips the probe. Later idle polls do not select a visible-screen probe. Codex readiness that exists only on the alternate screen can therefore time out.

Retry the probe when the pane becomes identified as codex, or preserve that identity before registering the waiter.

…til the wait settles

codex 0.157 turned on `tui.fullscreen_transcript`, so the session banner is painted
into the alternate screen with cursor addressing instead of being written to scrollback
as newline-separated lines. `buildTerminalWaitText` only ever reads the stream tail, so
`findCodexReadyPromptIndex` can never match such a pane even when the rendered screen
already shows the settled prompt. `tui-idle` therefore times out at `agent_readiness`
and `worker-start` never injects the task.

The visible-screen read that can prove readiness was gated to AGY and an empty tail, so
a Codex pane whose shell had already printed something never took that branch.

- widen the gate to the agents whose readiness is painted to the screen (AGY, codex),
  leaving every tail-settled lane on its existing single bounded look
- re-read the screen on the provider snapshot retry cadence until the waiter settles,
  so a slow first paint is not missed; the timer rides on the waiter and the registry's
  single `remove` path retires it with the wait timeout and the idle poll

Refs stablyai#22825
@aniruddhaadak80
aniruddhaadak80 force-pushed the fix/tui-idle-codex-visible-screen-probe branch from 6cf08f8 to d460d25 Compare October 22, 2026 15:36
Copilot AI balanced review requested due to automatic review settings October 22, 2026 15:36
@aniruddhaadak80

Copy link
Copy Markdown
Author

Rebased onto main; conflicts resolved (file moved to terminal/wait, probe ported to the typed runtime).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7cff3aa7-5e05-419c-9373-5abc193e8a21
📥 Commits

Reviewing files that changed from the base of the PR and between 6cf08f8368f7d9f70ca07ccd89ebd698e7745085 and d460d25.

📒 Files selected for processing: 4
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/terminal-wait-codex-visible-screen-probe.test.ts
  • src/main/runtime/terminal/wait/terminal-wait.ts
  • src/main/runtime/terminal/wait/terminal-waiter-registry.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.

Comment on lines +133 to +134
waiter.cancelVisibleProbe = cancel
probe()

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.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect the ready-weak path and whether a null screen read lets it settle synchronously.
ast-grep outline src/main/runtime/terminal/wait/terminal-idle-polls.ts \
  --match 'start|tick|readScreenBlockedReason' --view expanded
rg -n -C 5 'ready-weak|readScreenBlockedReason|readScreenLines' \
  src/main/runtime/terminal/wait/terminal-idle-polls.ts \
  src/main/runtime/tui-idle-evidence.ts

Repository: stablyai/orca

Length of output: 6447


🏁 Script executed:

set -eu
printf '%s\n' '--- terminal-wait relevant declarations ---'
ast-grep outline src/main/runtime/terminal/wait/terminal-wait.ts --view expanded
printf '%s\n' '--- terminal-wait changed/current blocks ---'
nl -ba src/main/runtime/terminal/wait/terminal-wait.ts | sed -n '1,220p'
printf '%s\n' '--- idle polls relevant blocks ---'
nl -ba src/main/runtime/terminal/wait/terminal-idle-polls.ts | sed -n '90,275p'
printf '%s\n' '--- evidence alternate-screen and readiness conditions ---'
rg -n -C 8 -F -e 'alternate' -e 'antigravity' -e 'codex' -e 'ready-weak' src/main/runtime/tui-idle-evidence.ts src/main/runtime/terminal/wait
printf '%s\n' '--- registry removal and probe references ---'
rg -n -C 8 -F -e 'cancelVisibleProbe' -e 'class RuntimeTerminalWaiterRegistry' -e 'remove(' src/main/runtime/terminal/wait
printf '%s\n' '--- base to head diff for target file ---'
git diff --no-ext-diff 6af21633e995668aa659144e2cb46416643580a0 d460d25ec5aec9f2e1210b7130d02c6d16db438b -- src/main/runtime/terminal/wait/

Repository: stablyai/orca

Length of output: 41562


🏁 Script executed:

set -eu
printf '%s\n' '--- readVisibleScreen declarations and bindings ---'
rg -n -C 8 -F 'readVisibleScreen' src
printf '%s\n' '--- TuiIdleEvidenceSource declaration ---'
rg -n -C 12 -F 'export type TuiIdleEvidenceSource' src/main
printf '%s\n' '--- visible probe implementation ---'
rg -n -C 12 -F 'startVisibleReadProbe' src/main
printf '%s\n' '--- focused terminal wait tests ---'
rg -n -C 10 -F -e 'cancelVisibleProbe' -e 'ready-weak' -e 'readVisibleScreen' -e 'antigravity' -e 'codex' src --glob '*test*' --glob '*spec*'

Repository: stablyai/orca

Length of output: 45476


🏁 Script executed:

set -eu
printf '%s\n' '--- focused idle-polls tests around alternate agents and null screen reads ---'
nl -ba src/main/runtime/runtime-terminal-idle-polls.test.ts | sed -n '210,430p'
printf '%s\n' '--- terminal-wait tests around visible probe lifecycle ---'
rg -l -F -e 'cancelVisibleProbe' -e 'visible screen' -e 'alternate-screen' src/main/runtime --glob '*test.ts' | while read -r f; do
  echo "--- $f"
  rg -n -C 8 -F -e 'cancelVisibleProbe' -e 'visible screen' -e 'alternate-screen' "$f"
done
printf '%s\n' '--- headless terminal ownership and population ---'
rg -n -C 6 -F -e 'headlessTerminals' -e 'readHeadlessVisibleTerminalState' src/main

Repository: stablyai/orca

Length of output: 42170


🏁 Script executed:

set -eu
printf '%s\n' '--- focused Codex visible-probe test ---'
nl -ba src/main/runtime/terminal-wait-codex-visible-screen-probe.test.ts | sed -n '1,260p'
printf '%s\n' '--- PTY and headless registration paths ---'
rg -n -C 10 -F -e 'registerPty(' -e 'seedHeadlessTerminal(' -e 'headlessTerminals.set' -e 'providerSnapshotPreferredPtys' src/main/runtime | head -n 500
printf '%s\n' '--- runtime visible-screen and provider mode declarations ---'
nl -ba src/main/runtime/construction/runtime-identity-state.ts | sed -n '350,400p'
rg -n -C 12 -F -e 'providerSnapshotPreferredPtys' -e 'replaceHeadlessTerminal' -e 'createHeadless' src/main/runtime/terminal src/main/runtime/terminal-output src/main/runtime/output src/main/runtime | head -n 600

Repository: stablyai/orca

Length of output: 42088


Check waiter membership before starting the repeat probe.

When readVisibleScreen returns null, a ready-weak poll can settle synchronously. The registry removes the waiter before startVisibleScreenProbe installs cancelVisibleProbe, but the helper still starts probe() and can arm retries. This applies to Codex and Antigravity because they always select the visible-screen path.

🐛 Suggested fix
   private startVisibleScreenProbe(
     waiter: TerminalWaiter,
     waiterTimeoutMs: number,
     agent: TuiAgent | null
   ): void {
+    if (!this.waiters.get(waiter.handle)?.has(waiter)) {
+      return
+    }
     const deadlineAt = Date.now() + Math.max(0, waiterTimeoutMs)

@nwparker

Copy link
Copy Markdown
Contributor

Thank you @aniruddhaadak80 for this PR and for rebasing it. The Codex readiness problem it targeted (#22825) was fixed by #23765 and Codex readiness now reads the live screen from rule files in #24375, so I am closing this as superseded. We appreciate the contribution.

@nwparker nwparker closed this Oct 24, 2026
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]: Codex 0.157 worker-start times out at agent_readiness while the TUI is already at its prompt

3 participants