Skip to content

fix(runtime): require sustained quiescence for tui-idle waits - #6012

Closed
revofusion wants to merge 1 commit into
stablyai:mainfrom
revofusion:fix/tui-idle-sustained-debounce
Closed

revofusion wants to merge 1 commit into
stablyai:mainfrom
revofusion:fix/tui-idle-sustained-debounce

Conversation

@revofusion

@revofusion revofusion commented Jun 21, 2026 •

Copy link
Copy Markdown

Problem

orca terminal wait --terminal <h> --for tui-idle --timeout-ms 30000 --json returns in ~0s
with {"satisfied": true, "status": "running"} even when the target agent TUI is actively
working
(spinner animating, output streaming, esc to interrupt visible). That makes
tui-idle useless as a "task done" signal — it fires mid-work.

Fixes #6011.

Root cause

Two compounding defects:

  1. detectAgentStatusFromTitle defaults agent titles to idle (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, no action required|permission|waiting)
    falls through to return 'idle'. Agents render their spinner / esc to interrupt in the
    terminal body, not the OSC title, so a busy agent with a name-only title
    (Devin, Codex, aider, …) is classified idle.

  2. The tui-idle wait trusts a single instantaneous title sample (src/main/runtime/orca-runtime.ts,
    waitForTerminal). It returns satisfied the moment lastAgentStatus === 'idle' — the exact
    value (1) mis-computes — with no sustained-idle requirement. The existing
    TUI_IDLE_QUIESCENCE_MS = 3000 debounce is only consulted in the foreground-process
    fallback (which runs only when lastAgentStatus === null), so a title-derived idle
    bypasses it.

Fix

Require sustained idle: a title-derived idle satisfies tui-idle only after PTY output
has been quiet for TUI_IDLE_QUIESCENCE_MS. An actively-working agent keeps producing output,
so lastOutputAt stays recent and the wait does not fire; when it finishes, output stops and
the debounce elapses.

Two small helpers (isTuiOutputActive, hasSustainedTuiIdle) replace the bare
lastAgentStatus === 'idle' checks at every title-derived satisfaction site:

  • synchronous fast paths (pty + leaf)
  • in-promise registration checks (pty + leaf)
  • fallback polls (startPtyTuiIdleFallbackPoll, startTuiIdleFallbackPoll)
  • working→idle transition resolvers (resolvePtyTuiIdleWaiters, resolveTuiIdleWaiters)

Preserved as-is:

  • Body-level ready-prompt detection (isKnownReadyPromptPreview) stays immediate — it
    directly detects the cursor at the input prompt, the strongest idle signal.
  • Adopted / daemon handles with no PTY output stream (lastOutputAt == null) keep their
    explicit-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-idle
without 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 to idle) agent that streams output must not satisfy
tui-idle while output is flowing, and must satisfy once output goes quiet for
TUI_IDLE_QUIESCENCE_MS. (Fails before this change — the fast path resolved in ~0s.)

🤖 Generated with Claude Code


Open in Stage

ELI5

terminal wait --for tui-idle could return success while an agent was still working. Idle waits now require sustained quiet so “done” is not reported mid-spinner.

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.
@ghost

ghost commented Jun 21, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 4 individual chapters for you:

Title
1 Define sustained idle detection helpers
2 Update PTY and leaf wait fast-paths
3 Update wait resolvers and fallback polls
4 Verify sustained idle with streaming output test
Open in Stage

Chapters generated by Stage for commit 02202e0 on Jun 21, 2026 11:49pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change tightens tui-idle resolution in orca-runtime.ts by replacing all bare lastAgentStatus === 'idle' checks with two new helpers: isTuiOutputActive, which checks whether terminal output has been quiet for less than TUI_IDLE_QUIESCENCE_MS, and hasSustainedTuiIdle, which requires both an idle agent status and output quiescence. These helpers are threaded through resolveTuiIdleWaiters (leaf and PTY loops), all PTY/live-PTY/leaf/live-leaf wait-handling branches, and foreground/background polling checks. Title-derived idle fast-paths gain an additional !isTuiOutputActive(...) guard. A new regression test verifies that streaming output under a name-only "Codex" OSC title prevents waitForTerminal from resolving until output stops and quiescence elapses.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is informative, but it does not follow the required template and omits Screenshots, Testing, AI Review Report, Security Audit, and Notes. Rewrite the description to match the repository template and add the missing sections, including the testing checklist, AI review report, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(runtime): require sustained quiescence for tui-idle waits' clearly and concisely describes the main change: implementing a sustained quiescence requirement for tui-idle waits to fix the root cause of the issue.
Linked Issues check ✅ Passed The PR fully implements the fix for issue #6011 by adding sustained idle checks via isTuiOutputActive() and hasSustainedTuiIdle() helper functions across all title-derived idle satisfaction sites, and includes a regression test validating the fix.
Out of Scope Changes check ✅ Passed All changes are in scope: the test file validates the fix, and orca-runtime.ts modifications directly address the two defects identified in #6011 (sustained quiescence requirement without altering existing title detection).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@AmethystLiang
AmethystLiang requested a review from Jinwoo-H June 22, 2026 17:22
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:44
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
nwparker added a commit that referenced this pull request Sep 12, 2026
…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>
nwparker added a commit that referenced this pull request Sep 13, 2026
…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>
nwparker added a commit that referenced this pull request Sep 13, 2026
…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>
@nwparker

Copy link
Copy Markdown
Contributor

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 detectAgentStatusFromTitle defaults a name-only agent title to idle, so a busy Codex/Devin/aider is routinely titled idle and terminal wait --for tui-idle fired in ~0s mid-work. Every subsequent attempt — #6555, #14642, and ours — restates that finding.

Why sustained quiescence alone could not be the remedy

This is a real measurement, not a dismissal. I drove the actual grok binary through a real PTY:

  • it emits a bare grok OSC title at rest, so it lands in the name-only tier;
  • it repaints a braille banner continuously — max gap between output bytes 891ms across a 22s observation, still emitting 76ms before the window closed;
  • tail-preview quiescence is no better: 79 preview changes in 20 idle seconds, longest stable window 2.1s against a 3s threshold;
  • isKnownReadyPromptPreview does not match its banner, and it has no synthetic idle title.

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 ✳ and Gemini's ◇, which delays agents that already told us they were done. #6555 later drew the explicit-vs-ambiguous line that fixed that, and #14642 generalised it into the evidence ranking that landed.

Mechanically, this branch also cannot be merged by anyone: it shares no git history with main (different root commit, git merge refuses unrelated histories), as do #6555, #9929 and #14642. That is why all of this landed as a port with co-authorship rather than as your branch.

Thank you — the root-cause call was correct and it is the foundation of the fix.

@nwparker nwparker closed this Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terminal wait --for tui-idle returns satisfied:true in ~0s while an agent TUI is actively working

4 participants