Skip to content

fix(runtime): keep tui-idle blocked on Codex's plan menu painted after its Stop hook - #33335

Merged
nwparker merged 6 commits into
mainfrom
nwparker/agint-25912
Oct 25, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/agint-25912

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​137 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​137
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115 $\color{#cf222e}{\Huge{\mathbf{−}}}$​26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​89

ELI5

When Codex finishes a plan, it shows an "Implement this plan?" menu. orca terminal wait --for tui-idle should report "blocked on a menu" there. Instead it said "ready", so the next message picked a menu option. There were two causes:

  1. Codex tells Orca "done" (its Stop hook) before it draws the menu. A wait that was already running accepted that "done" right away, about 0.1 s before the menu existed.
  2. When Orca did notice the menu late, it recorded the notice only on the PTY record, not on the pane that window-backed waits read.

This PR keeps @Jinwoo-H's fix for (2) from #26492, rebased onto the #27602 file move. It adds a fix for (1): after a turn-end hook's done, Orca waits 750 ms for the agent to draw its final frame before calling it ready, and re-checks at exactly that moment.

Root cause (upstream refs, openai/codex origin/main 970111f6cb)

  • codex-rs/core/src/session/turn.rs:457 (run_turn_stop_hooks via hook_runtime.rs:374) runs the Stop hook inside the core turn, before TurnComplete is sent to the TUI.
  • codex-rs/tui/src/chatwidget/turn_runtime.rs:213,243-267: the TUI handles TurnComplete, then maybe_prompt_plan_implementation() → open_plan_implementation_prompt(), and the popup is painted on the next frame.
  • codex-rs/tui/src/bottom_pane/bottom_pane_view.rs:236 / bottom_pane/mod.rs:1850: the plan popup is an ordinary selection view, so program_status_blocked_kind() is None. Codex's OSC 7501 reports done, not blocked, so there's no upstream "blocked" signal to read.
  • On the Orca side, evaluateHookTurn (tui-idle-hook-lane.ts) returned ready-strong for any fresh done from a turn-end agent (codex, dsh). The next title edge (Codex rewrites its title the moment the turn completes) resolved the waiter before the menu bytes arrived.

What changed

  • fix(runtime): report Codex's plan menu as blocked after its hook's done #26492 (Jinwoo-H, kept as its own commit): the trailing-edge blocked scan also stamps panes that mirror the PTY, and the status snapshot flushes a pending scan first.
  • On top:
    • readTuiIdleHookTurn marks a turn-end agent's done younger than 750 ms with finalFrameAt.
    • evaluateHookTurn returns pending with recheckAt until then. If the menu paints in that window, its stamp is newer than the done, so the existing arbiter returns blocked.
    • RuntimeTerminalIdlePolls arms a one-shot tick at recheckAt, so a turn with no menu settles about 0.75 s after done rather than at the next 2 s sweep.
    • Declares flushPendingWaitBlockedCheck abstract in runtime-construction-services.ts. After Typecheck terminal waits #27602 the rebased fix(runtime): report Codex's plan menu as blocked after its hook's done #26492 commit did not typecheck without it.
  • Authoritative-hook agents (opencode, pi, omp) and Claude are unchanged.

How verified

Real Codex 0.164.0 in /plan mode, in a visible (pane-backed) terminal of a background dev instance (ORCA_BACKGROUND_LAUNCH=1, isolated profile). Loop: answer 3, send a new plan prompt, then orca terminal wait --for tui-idle, then read the screen.

Build Result with menu on screen
main 8/8 satisfied: true (bug)
#26492 alone 5/8 then 6/6 satisfied: true. The wait returned 8-21 ms before the menu stamp and ~70-300 ms after the hook done.
this PR 10/10 satisfied: false, blockedReason: agent-interactive-prompt

Negative control on this PR, ordinary Codex turns with no menu: 6/6 satisfied: true. The wait returned 0.78-1.5 s after the hook done (CLI overhead included), versus ~0.1-0.3 s before.

Tests:

  • New blocks a wait issued between the done and the menu it paints (replays the Codex 0.160 capture). It fails with the hold disabled.
  • settles on a done that follows output quoting the menu now needs the re-tick. It times out with armRecheck disabled.
  • The existing fix(runtime): report Codex's plan menu as blocked after its hook's done #26492 test fails on main.
  • pnpm tc and check:code-quality:changed are clean. 89 related suites (1267 tests) pass.

Risk

  • The 750 ms hold now applies only after a turn that showed a plan: a turn-end hook's fresh done is held only while the pane's retained output contains Codex's Proposed Plan header. Every other Codex/DSH turn settles on its done immediately, as before. While held, tui-idle settles about 750 ms after the done, and mailbox delivery waits for its existing quiescence recheck. This is deliberate: delivering into the plan menu is the failure being fixed. Because the check reads retained output rather than only the current turn, a plan still in the tail can also hold the next few turns until it scrolls out (a small extra delay, never a wrong verdict).
  • A menu painted more than 750 ms after the hook would still be missed. Observed gaps were 64-280 ms.
  • receivedAt comes from the local hook server's clock, the same clock as the stamps, so no remote clock skew. There's no wire change, so mixed client/server versions are unaffected. Not platform-specific.

Visual Proof

N/A: no UI change; evidence is the CLI wait results above.

Fixes #25912
Supersedes #26492

Co-authored-by: Jinwoo-H [email protected]

Jinwoo-H and others added 2 commits October 24, 2026 18:16
…ne's leaf (STA-9655)

The blocked-text scan is throttled, so a dialog whose last bytes arrive within
50 ms of a previous scan is stamped on a trailing-edge timer. That stamp went
only to the PTY record: its mirroring leaves had already copied the old value,
and a pane-backed wait reads the leaf's. The permission arbiter therefore saw
the hook's `done` as the newest event and let tui-idle settle ready over
Codex's "Implement this plan?" menu, which Codex paints after its Stop hook.

The trailing-edge stamp now reaches the leaves that mirror the PTY's tail, and
a status snapshot runs a pending scan first, so a wait issued inside the
throttle window judges the menu too. Replayed against the 0.160.0 capture.
…st frame

Codex runs its Stop hook in core before it sends TurnComplete, and the TUI opens
"Implement this plan?" only on TurnComplete (codex-rs/core/src/session/turn.rs,
tui/src/chatwidget/turn_runtime.rs maybe_prompt_plan_implementation). A tui-idle
wait already pending settled on the done at the next title edge, ~0.1 s before the
menu reached the PTY, so the leaf-stamp fix alone still let 5/8 live plan turns
read ready. A turn-end agent's done now settles only once 750 ms have passed, and
the idle poll re-checks at that moment instead of on its 2 s sweep.

Also declares flushPendingWaitBlockedCheck where runtime-service-state.ts can
reach it after the #27602 file move.
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: f3443213-f3da-452d-8b93-ecf0af9904eb
Commits

Reviewing files that changed from the base of the PR and between 75855c7 and d782a31.

Files selected for processing: 10
  • src/main/runtime/construction/runtime-construction-services.ts
  • src/main/runtime/construction/runtime-service-state.ts
  • src/main/runtime/runtime-terminal-agent-status-query.ts
  • src/main/runtime/terminal/input/pty-write-host-platform.ts
  • src/main/runtime/terminal/wait/terminal-idle-polls.ts
  • src/main/runtime/terminal/wait/terminal-wait-blocked-checks.ts
  • src/main/runtime/terminal/wait/terminal-wait-permission.ts
  • src/main/runtime/tui-idle-codex-plan-menu.test.ts
  • src/main/runtime/tui-idle-evidence.ts
  • src/main/runtime/tui-idle-hook-lane.ts

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

Walkthrough

The runtime now checks retained terminal output for Codex’s “Proposed Plan” menu when a turn-end hook reports done. A matching menu can keep the idle verdict pending until a timed recheck. The runtime can flush pending blocked checks before reading terminal status and stamps matching PTY leaves when it detects a blocked reason. PTY write-host platform selection now uses a shared helper. Tests cover menu display timing, quoted menu text, and turns without a proposed plan.

Fixed issue severity: <fixed_issue_severity>Medium</fixed_issue_severity>

Priority: Normal

Merge Risk: Minimal · up to d782a

Ordinary waits remain usable. A short wait after a previous plan turn may time out, but this bounded edge case does not block merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 10 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 identifies the primary fix: keeping tui-idle blocked when Codex paints its plan menu after the Stop hook.
Description check Passed The description is detailed and covers the user impact, root cause, implementation, linked issue, testing results, visual proof, and risks. Some template sections such as the checklist and review note…
Linked Issues check Passed The PR meets the coding requirements in #25912. readTuiIdleHookTurn holds a fresh Codex turn-end done when retained output contains Proposed Plan. evaluateHookTurn returns pending until th…
Out of Scope Changes check Passed The changes stay within #25912. The pane-stamping, pending-flush, timer, type, and platform-resolution changes support reliable Codex plan-menu detection and preserve PTY host behavior. The new tests …
Full details: Description check

Explanation

The description is detailed and covers the user impact, root cause, implementation, linked issue, testing results, visual proof, and risks. Some template sections such as the checklist and review notes are omitted, but the required change rationale and verification details are complete.

Full details: Linked Issues check

Explanation

The PR meets the coding requirements in #25912. readTuiIdleHookTurn holds a fresh Codex turn-end done when retained output contains Proposed Plan. evaluateHookTurn returns pending until the final-frame deadline. RuntimeTerminalIdlePolls rechecks at that deadline. The blocked scan stamps pane records that share the PTY tail, so a painted menu returns agent-interactive-prompt. The new suite covers a menu painted after done, a wait started before the menu, quoted menu text without a visible menu, and a no-plan negative case.

Full details: Out of Scope Changes check

Explanation

The changes stay within #25912. The pane-stamping, pending-flush, timer, type, and platform-resolution changes support reliable Codex plan-menu detection and preserve PTY host behavior. The new tests validate the target behavior and its negative cases. The implementation limits the delay to Codex plan output; no unrelated agent or menu behavior is added.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

…osed plan

Codex opens its plan menu only after a turn that rendered a proposed plan, and
no hook field carries plan mode (permission_mode is never 'plan'), so gate the
750 ms final-frame hold on the pane's retained output showing Codex's
'Proposed Plan' header. Ordinary Codex/DSH turns settle on their done again.
# Conflicts:
#	src/main/runtime/terminal/wait/terminal-wait-permission.ts
…minal-wait-permission

Keeps terminal-wait-permission.ts under the 300-line lint limit after the main merge.
@nwparker
nwparker merged commit 7d493ea into main Oct 25, 2026
44 of 45 checks passed
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]: tui-idle still reports Codex's 'Implement this plan?' menu as ready on 1.4.221 (hook done short-circuits the #24536 anchor)

2 participants