Repository navigation
fix(runtime): keep tui-idle blocked on Codex's plan menu painted after its Stop hook - #33335
Conversation
…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.
|
No actionable comments were generated in the recent review.
|
…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.
ELI5
When Codex finishes a plan, it shows an "Implement this plan?" menu.
orca terminal wait --for tui-idleshould report "blocked on a menu" there. Instead it said "ready", so the next message picked a menu option. There were two causes: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_hooksviahook_runtime.rs:374) runs the Stop hook inside the core turn, beforeTurnCompleteis sent to the TUI.codex-rs/tui/src/chatwidget/turn_runtime.rs:213,243-267: the TUI handlesTurnComplete, thenmaybe_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, soprogram_status_blocked_kind()isNone. Codex's OSC 7501 reportsdone, notblocked, so there's no upstream "blocked" signal to read.evaluateHookTurn(tui-idle-hook-lane.ts) returnedready-strongfor any freshdonefrom aturn-endagent (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
readTuiIdleHookTurnmarks aturn-endagent'sdoneyounger than 750 ms withfinalFrameAt.evaluateHookTurnreturnspendingwithrecheckAtuntil then. If the menu paints in that window, its stamp is newer than thedone, so the existing arbiter returnsblocked.RuntimeTerminalIdlePollsarms a one-shot tick atrecheckAt, so a turn with no menu settles about 0.75 s afterdonerather than at the next 2 s sweep.flushPendingWaitBlockedCheckabstract inruntime-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.How verified
Real Codex 0.164.0 in
/planmode, in a visible (pane-backed) terminal of a background dev instance (ORCA_BACKGROUND_LAUNCH=1, isolated profile). Loop: answer3, send a new plan prompt, thenorca terminal wait --for tui-idle, then read the screen.satisfied: true(bug)satisfied: true. The wait returned 8-21 ms before the menu stamp and ~70-300 ms after the hookdone.satisfied: false, blockedReason: agent-interactive-promptNegative control on this PR, ordinary Codex turns with no menu: 6/6
satisfied: true. The wait returned 0.78-1.5 s after the hookdone(CLI overhead included), versus ~0.1-0.3 s before.Tests:
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 menunow needs the re-tick. It times out witharmRecheckdisabled.pnpm tcandcheck:code-quality:changedare clean. 89 related suites (1267 tests) pass.Risk
doneis held only while the pane's retained output contains Codex'sProposed Planheader. Every other Codex/DSH turn settles on itsdoneimmediately, as before. While held,tui-idlesettles about 750 ms after thedone, 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).receivedAtcomes 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]