Repository navigation
fix(runtime): require sustained quiescence for tui-idle waits - #6012
revofusion wants to merge 1 commit into
Conversation
terminal wait --for tui-idle returned satisfied in ~0s while an agent TUI was actively working. Root cause: the wait satisfied on a single instantaneous OSC-title sample (lastAgentStatus === 'idle'), and detectAgentStatusFromTitle() defaults any name-bearing agent title (e.g. 'Devin', 'Codex', 'aider') to 'idle' because the working spinner / 'esc to interrupt' render in the terminal body, not the title. Gate every title-derived idle satisfaction (fast paths, fallback polls, and the working->idle transition resolvers) behind sustained output quiescence (no PTY output for TUI_IDLE_QUIESCENCE_MS). Body-level ready-prompt detection stays immediate, and adopted/daemon handles with no output stream keep their explicit-title signal. Adds a regression test.
|
Ready to review this PR? Stage has broken it down into 4 individual chapters for you:
Chapters generated by Stage for commit 02202e0 on Jun 21, 2026 11:49pm UTC. |
📝 WalkthroughWalkthroughThe change tightens 🚥 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 |
…ilence `terminal wait --for tui-idle` returned satisfied in ~0s while an agent was mid-turn. The shared title detector defaults a name-only agent title to `idle` so the sidebar can clear a stale spinner, and the wait accepted that stored value as completion. Rank the evidence instead. An explicit idle marker in the agent's own title or a known ready prompt settles the wait; a fresh first-party OSC 9999 status saying working/blocked/waiting vetoes it; a name-only title is a last resort that settles only once the stream has also gone quiet. The rank is derived at read time from `lastOscTitle` rather than stamped onto the record, because `syncWindowGraph` rebuilds leaves from an explicit field list and would drop a bespoke provenance field on any renderer publish. Two things the ranking alone gets wrong are handled here too. A quiet non-shell foreground process no longer proves idle on a pane where Orca launched a known agent — that is an agent still booting, and resolving on it is what let `dispatch --inject` lose the prompt (#9976). And the idle poll re-reads the live leaf each tick, because a record captured at registration stops advancing and its frozen `lastOutputAt` makes the quiescence gate pass while the pane streams. The demotion is scoped to agents that go on to announce rest explicitly. Grok, Copilot, Aider, Mimo, agy and OpenCode emit their name and nothing more at rest: a real idle Grok pane repaints its banner about four times a second forever, so demanding quiescence from it left no settle signal at all and the wait ran to timeout. The design is Brennan Benson's, from #14642, which won a cross-review against #6012, #6555 and this branch's earlier approach; it is ported here only because that branch shares no git history with main and cannot be merged. Neil's #6555 first drew the explicit-vs-ambiguous line the ranking rests on, and Revofusion's #6012 first identified that a single title sample cannot prove completion. Fixes #6011 Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com> Co-authored-by: Revofusion <syed@moonai.org>
…ilence `terminal wait --for tui-idle` returned satisfied in ~0s while an agent was mid-turn. The shared title detector defaults a name-only agent title to `idle` so the sidebar can clear a stale spinner, and the wait accepted that stored value as completion. Rank the evidence instead. An explicit idle marker in the agent's own title or a known ready prompt settles the wait; a fresh first-party OSC 9999 status saying working/blocked/waiting vetoes it; a name-only title is a last resort that settles only once the stream has also gone quiet. The rank is derived at read time from `lastOscTitle` rather than stamped onto the record, because `syncWindowGraph` rebuilds leaves from an explicit field list and would drop a bespoke provenance field on any renderer publish. Two things the ranking alone gets wrong are handled here too. A quiet non-shell foreground process no longer proves idle on a pane where Orca launched a known agent — that is an agent still booting, and resolving on it is what let `dispatch --inject` lose the prompt (#9976). And the idle poll re-reads the live leaf each tick, because a record captured at registration stops advancing and its frozen `lastOutputAt` makes the quiescence gate pass while the pane streams. The demotion is scoped to agents that go on to announce rest explicitly. Grok, Copilot, Aider, Mimo, agy and OpenCode emit their name and nothing more at rest: a real idle Grok pane repaints its banner about four times a second forever, so demanding quiescence from it left no settle signal at all and the wait ran to timeout. The design is Brennan Benson's, from #14642, which won a cross-review against #6012, #6555 and this branch's earlier approach; it is ported here only because that branch shares no git history with main and cannot be merged. Neil's #6555 first drew the explicit-vs-ambiguous line the ranking rests on, and Revofusion's #6012 first identified that a single title sample cannot prove completion. Fixes #6011 Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com> Co-authored-by: Revofusion <syed@moonai.org>
…ilence (#20155) `terminal wait --for tui-idle` returned satisfied in ~0s while an agent was mid-turn. The shared title detector defaults a name-only agent title to `idle` so the sidebar can clear a stale spinner, and the wait accepted that stored value as completion. Rank the evidence instead. An explicit idle marker in the agent's own title or a known ready prompt settles the wait; a fresh first-party OSC 9999 status saying working/blocked/waiting vetoes it; a name-only title is a last resort that settles only once the stream has also gone quiet. The rank is derived at read time from `lastOscTitle` rather than stamped onto the record, because `syncWindowGraph` rebuilds leaves from an explicit field list and would drop a bespoke provenance field on any renderer publish. Two things the ranking alone gets wrong are handled here too. A quiet non-shell foreground process no longer proves idle on a pane where Orca launched a known agent — that is an agent still booting, and resolving on it is what let `dispatch --inject` lose the prompt (#9976). And the idle poll re-reads the live leaf each tick, because a record captured at registration stops advancing and its frozen `lastOutputAt` makes the quiescence gate pass while the pane streams. The demotion is scoped to agents that go on to announce rest explicitly. Grok, Copilot, Aider, Mimo, agy and OpenCode emit their name and nothing more at rest: a real idle Grok pane repaints its banner about four times a second forever, so demanding quiescence from it left no settle signal at all and the wait ran to timeout. The design is Brennan Benson's, from #14642, which won a cross-review against #6012, #6555 and this branch's earlier approach; it is ported here only because that branch shares no git history with main and cannot be merged. Neil's #6555 first drew the explicit-vs-ambiguous line the ranking rests on, and Revofusion's #6012 first identified that a single title sample cannot prove completion. Fixes #6011 Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com> Co-authored-by: Revofusion <syed@moonai.org>
|
Closing this, with credit: you were first to the root cause of #6011, and you are a co-author on the commit that landed it (e9065dd). Your diagnosis is the one everything since is built on: a single OSC-title sample cannot prove an agent finished, because Why sustained quiescence alone could not be the remedyThis is a real measurement, not a dismissal. I drove the actual
So a genuinely idle Grok pane can never go quiet, and gating idle on silence means it can never report idle at all. Measured end-to-end: 45,003ms timeout where the parent commit returned in 1ms. That applies to every quiescence-gated approach, ours included — we hit exactly the same wall and had to scope the demotion to agents that go on to announce rest explicitly. One further note specific to this PR: it gates every idle on quiescence, including explicit markers like Claude's Mechanically, this branch also cannot be merged by anyone: it shares no git history with Thank you — the root-cause call was correct and it is the foundation of the fix. |
Problem
orca terminal wait --terminal <h> --for tui-idle --timeout-ms 30000 --jsonreturns in ~0swith
{"satisfied": true, "status": "running"}even when the target agent TUI is activelyworking (spinner animating, output streaming,
esc to interruptvisible). That makestui-idleuseless as a "task done" signal — it fires mid-work.Fixes #6011.
Root cause
Two compounding defects:
detectAgentStatusFromTitledefaults agent titles toidle(src/shared/agent-detection.ts).A title with an agent name but no explicit working marker (no braille spinner, no
working|thinking|running, no Claude.prefix, noaction required|permission|waiting)falls through to
return 'idle'. Agents render their spinner /esc to interruptin theterminal body, not the OSC title, so a busy agent with a name-only title
(
Devin,Codex,aider, …) is classifiedidle.The tui-idle wait trusts a single instantaneous title sample (
src/main/runtime/orca-runtime.ts,waitForTerminal). It returns satisfied the momentlastAgentStatus === 'idle'— the exactvalue (1) mis-computes — with no sustained-idle requirement. The existing
TUI_IDLE_QUIESCENCE_MS = 3000debounce is only consulted in the foreground-processfallback (which runs only when
lastAgentStatus === null), so a title-derivedidlebypasses it.
Fix
Require sustained idle: a title-derived
idlesatisfiestui-idleonly after PTY outputhas been quiet for
TUI_IDLE_QUIESCENCE_MS. An actively-working agent keeps producing output,so
lastOutputAtstays recent and the wait does not fire; when it finishes, output stops andthe debounce elapses.
Two small helpers (
isTuiOutputActive,hasSustainedTuiIdle) replace the barelastAgentStatus === 'idle'checks at every title-derived satisfaction site:startPtyTuiIdleFallbackPoll,startTuiIdleFallbackPoll)resolvePtyTuiIdleWaiters,resolveTuiIdleWaiters)Preserved as-is:
isKnownReadyPromptPreview) stays immediate — itdirectly detects the cursor at the input prompt, the strongest idle signal.
lastOutputAt == null) keep theirexplicit-title signal, so the existing "resolve from renderer ready title" /
"resolve from Codex/Antigravity ready prompt" tests still pass.
Defect (1)'s broad default-to-idle is intentionally left in place (it's a renderer-shared
classifier driving badges/indicators); the debounce neutralizes its impact on
tui-idlewithout changing UI semantics. Tightening it could be a follow-up.
Tests
Adds
does not report tui-idle while a name-only agent title keeps streaming output:a
Codex(name-only → defaults toidle) agent that streams output must not satisfytui-idlewhile output is flowing, and must satisfy once output goes quiet forTUI_IDLE_QUIESCENCE_MS. (Fails before this change — the fast path resolved in ~0s.)🤖 Generated with Claude Code
ELI5
terminal wait --for tui-idlecould return success while an agent was still working. Idle waits now require sustained quiet so “done” is not reported mid-spinner.