Repository navigation
fix(prime): recognize idle screens and recover Factory readiness - #22154
Alex-wangyang wants to merge 2 commits into
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change adds Prime Agent identity handling and maps Prime titles to the Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Prime Agent readiness and identity handling are covered for settled, busy, retry, and lifecycle states, with no concrete merge-blocking risk remaining. 🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 6c37f364-1e98-4068-91cf-5a378cef7087
📒 Files selected for processing (16)
src/main/runtime/__fixtures__/prime-095-ready.meta.jsonsrc/main/runtime/__fixtures__/prime-095-ready.txtsrc/main/runtime/__fixtures__/prime-095-turn.meta.jsonsrc/main/runtime/__fixtures__/prime-095-turn.txtsrc/main/runtime/__fixtures__/prime-ready.meta.jsonsrc/main/runtime/__fixtures__/prime-ready.txtsrc/main/runtime/__fixtures__/prime-turn.meta.jsonsrc/main/runtime/__fixtures__/prime-turn.txtsrc/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.tssrc/main/runtime/prime-readiness-transcripts.test.tssrc/main/runtime/runtime-terminal-wait.tssrc/main/runtime/terminal-wait-detection.tssrc/shared/agent-name-token-match.tssrc/shared/agent-title-identity.tssrc/shared/synthetic-agent-title.tssrc/shared/terminal-title-agent-type.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
Important
The 0.9.5 busy-screen veto can be defeated, so a mid-turn Prime pane may resolve tui-idle. I projected the committed prime-095-turn.txt capture at its own 120×35 geometry and isKnownReadyPromptPreview returns true (its final frame is a bare spinner-clear), leaving only the lastAgentStatus === 'working' guard — which is skipped when Orca's window is hidden and the synthetic working title is suppressed. The committed test does not cover the projection the probe actually reads. Details inline.
Reviewed changes
- 0.9.5 / 0.9.4 idle-screen matcher —
findPrimeReadyPromptIndexrecognizes the← manage <model> · <n> (<pct>)footer and the legacy← agents/resume … ? for shortcutsfooter. - Prime probe retry — the single-shot visible read now retries every ~500 ms within the original waiter lifetime, with a
lastAgentStatus === 'working'busy veto. - Prime wait admission —
paneAgent === 'prime-agent'starts the visible probe in both the PTY and leaf wait paths even when retained output is nonempty. - Prime identity —
'prime agent'added toAGENT_NAMES, aprime-agentsynthetic-title profile, bothcomputeAgentLabelladders returnPrime Agent, andTITLE_LABEL_TO_AGENTmaps it toprime-agent. - Fixtures and tests — two captured fixtures per Prime version plus
prime-readiness-transcripts.test.ts.
ℹ️ Title-derived Prime rows lose their agent identity in the renderer
getAgentLabel now returns 'Prime Agent', but the renderer's parallel label map was not updated. A Prime pane whose status comes from the title alone (hook-less SSH, or the window before hooks fire) resolves agentType: 'unknown' instead of its known prime-agent owner, so it renders the neutral icon and collapses into the unknown summary group.
Technical details
# Register 'Prime Agent' in the renderer title→type map
## Affected sites
- `src/renderer/src/components/sidebar/worktree-title-derived-agent-rows.ts:37-53` — `TITLE_AGENT_LABEL_TO_TYPE` has `OMP: 'omp'`, `Hermes`, `Devin`, but no `'Prime Agent'`. Lookup at line 253 does `TITLE_AGENT_LABEL_TO_TYPE[label] ?? 'unknown'`.
- `src/renderer/src/components/sidebar/worktree-title-derived-agent-rows.ts:195` — `titleAgentType ?? ownerAgentType` never falls back, because `'unknown'` is truthy.
## Required outcome
- A title-derived Prime row carries `agentType: 'prime-agent'` (as the shared `TITLE_LABEL_TO_AGENT` already does at `src/shared/terminal-title-agent-type.ts:249`).
## Suggested approach
- Add `'Prime Agent': 'prime-agent'` to `TITLE_AGENT_LABEL_TO_TYPE`. (The map is also missing `'MiMo Code'` and `'OpenCode 2'`, so those rows share the same fallthrough — worth fixing together.)ℹ️ Nitpicks
- The Prime retry re-reads the visible snapshot roughly every 500 ms for the whole waiter lifetime (previously one deliberate single-shot read), and each read can serialize a provider buffer. Consider a growing backoff as the deadline approaches so a long wait is not 60+ snapshot reads.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| if (!blockedReason && !ready) { | ||
| if ( | ||
| !blockedReason && | ||
| (!ready || (isPrime && this.ptysById.get(primePtyId)?.lastAgentStatus === 'working')) |
There was a problem hiding this comment.
lastAgentStatus is derived only from OSC titles, so this veto is disabled whenever the synthetic working frame is not ingested — sendSyntheticTitle drops non-forced frames when the Orca window is hidden/minimized (shouldSendSyntheticTitleFrame is force || windowVisible), and Prime's own title (prime-agent - …) detects as no status. On its own that would be survivable, but the 0.9.5 branch's only other busy signal is a braille glyph on the sampled screen, and I reproduced isKnownReadyPromptPreview returning true for prime-095-turn.txt projected at its captured 120×35 geometry (its last frame is a bare spinner-clear). A background terminal wait --for tui-idle can therefore resolve while Prime is still generating.
Technical details
# A mid-turn Prime screen can resolve tui-idle
## Affected sites
- `src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts:103` — busy veto reads OSC-derived `lastAgentStatus`, which is never written when the working synthetic frame is suppressed.
- `src/main/runtime/terminal-wait-detection.ts:102` — the only other busy signal is `/[⠁-⣿]/` anywhere on the sampled projection.
- `src/main/startup/synthetic-title-runtime.ts:39-46` — `sendSyntheticTitle` drops non-forced frames when the window is not visible.
- `src/shared/agent-title-status.ts:182-264` — `detectAgentStatusFromTitle('prime-agent - …')` is `null` (the hyphen breaks the `'prime agent'` token), so Prime's own OSC title contributes no status.
## Required outcome
- A mid-turn 0.9.5 Prime screen must not satisfy `tui-idle`, including when Orca's window is hidden and no working title was ever ingested.
## Suggested approach
- Do not rely on the title-derived `lastAgentStatus` as the sole veto; read the hook status (`lastExplicitAgentStatus`) or a freshness-gated variant, and/or require positive settled evidence on the screen (a composer stable across two samples, or the 0.9.4 equivalent of `? for shortcuts`) rather than only the absence of a spinner glyph.
- Add a test that drives `waitForTerminal` on `prime-095-turn` at the captured geometry with no working title ingested.| expect( | ||
| isKnownReadyPromptPreview(snapshot.tail.join('\n')), | ||
| JSON.stringify(snapshot.tail) | ||
| ).toBe(expected) |
There was a problem hiding this comment.
This case asserts on readTerminal(handle) at the harness's default geometry, not on the visibleScreenOnly projection the probe actually reads. At the captured 120×35 geometry the same fixture projects to a screen isKnownReadyPromptPreview accepts, so expected=false here is an artifact of the harness's line wrapping rather than a semantic busy veto; the runtime-level wait tests only use the 0.9.4 fixture, so nothing pins the 0.9.5 probe path.
Technical details
# The busy-transcript assertion does not exercise the probe path
## Affected sites
- `src/main/runtime/prime-readiness-transcripts.test.ts:35-39` — asserts on the default read (retained tail).
- `src/main/runtime/agent-transcript-pane-test-harness.ts` — `createTranscriptPane` exposes no `cols`/`rows`, so the fixture's captured geometry is not reproduced.
## Required outcome
- A test must fail if a mid-turn 0.9.5 screen is classified ready on the visible projection the probe consumes.
## Suggested approach
- Let `createTranscriptPane` take `cols`/`rows` (the fixtures already ship them in `.meta.json`), assert the matcher on both the retained tail and the visible projection, and add a runtime `waitForTerminal` case for `prime-095-turn`.There was a problem hiding this comment.
ℹ️ No new issues in the follow-up commit — the hyphenated-identity fix is correct and its test would fail without it. One behavioral side effect worth confirming.
Reviewed changes (since 2c59ddea3)
86164516a5recognizes hyphenated Prime titles.'prime-agent'is added toAGENT_NAMES, bothcomputeAgentLabelladders now also match the hyphenated token, and aPrime title spellingcharacterization case pinsgetAgentLabel/resolveTerminalTitleAgentType.- Correct effect:
getAgentLabel('⠋ prime-agent')previously fell through toisClaudeAgent's braille branch and read asClaude Code; it now resolves toPrime Agent/prime-agent. - The earlier busy-veto finding is unchanged by this commit (the veto needs
lastAgentStatus === 'working', and this change makes the native titleidle, notworking).
ℹ️ Prime's name-only native title now counts as idle
Adding the hyphenated token also makes detectAgentStatusFromTitle('prime-agent - <cwd>') return 'idle' (the classifier defaults a name-only agent title to idle). That title now feeds tier 3 of isTuiIdleSatisfied, so a hook-less Prime pane can settle tui-idle from its own title alone once the 3s quiescence window passes. It is gated (tier-2 hook veto, and nameOnlyIdleNeedsCorroboration('prime-agent') requires quiescence), but it is worth confirming Prime does not keep prime-agent - <cwd> on screen while a turn is running.
Technical details
# Prime native title is now a tier-3 idle signal
## Affected sites
- `src/shared/agent-name-token-match.ts:32` — `'prime-agent'` joins `AGENT_NAMES`, so `containsLegacyAgentName` matches the hyphenated native title.
- `src/shared/agent-title-status.ts:236-263` — a name-only legacy-agent title falls through to `return 'idle'`.
- `src/main/runtime/tui-idle-evidence.ts:81-101` — tier 3 (`hasSustainedTitleIdle`) reads `lastAgentStatus === 'idle'`; `nameOnlyIdleNeedsCorroboration('prime-agent')` is true, so it waits `quiescenceMs` (3000ms).
## Required outcome
- Confirm the intent: either Prime's native title is genuinely rest-only (`prime-agent - <cwd>` is emitted only at rest, with a distinct working title while a turn runs), or tier 3 should not treat the hyphenated name-only title as a rest signal.
## Suggested approach
- If Prime can hold `prime-agent - <cwd>` during a silent working stretch, gate tier 3 on the explicit idle label / ready prompt for Prime rather than the name-only token (the visible-screen probe already provides that evidence).DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| 'devin' | ||
| 'devin', | ||
| 'prime agent', | ||
| 'prime-agent' |
There was a problem hiding this comment.
Adding the hyphenated token also makes the name-only native title prime-agent - <cwd> classify as idle, since detectAgentStatusFromTitle defaults a name-only agent title to idle. That now feeds isTuiIdleSatisfied tier 3, so a hook-less Prime pane can settle tui-idle from its own title after the 3s quiescence window — please confirm Prime does not keep prime-agent - <cwd> on screen while a turn is running.
Technical details
# Prime native title becomes a tier-3 idle signal
## Affected sites
- `src/shared/agent-title-status.ts:236-263` — name-only legacy-agent title falls through to `return 'idle'` (verified: `detectAgentStatusFromTitle('prime-agent - orca-readiness-fix') === 'idle'`).
- `src/main/runtime/tui-idle-evidence.ts:81-101` — tier 3 reads `lastAgentStatus === 'idle'`; for `prime-agent` it waits `quiescenceMs` (3000ms) before settling.
## Required outcome
- Either confirm Prime emits a distinct working title during a turn (so the name-only title only appears at rest), or stop tier 3 from treating the hyphenated name-only title as rest evidence for Prime.…the live screen (#24222) * fix(runtime): decide Antigravity readiness from the live screen agy paints its composer with cursor addressing, so the line-folded wait text misses the 1.2.14 accept-edits and plan composers and an ended turn, while the grid keeps the bare `>` caret painted mid-turn and behind the /model picker. Read the screen's bottom rows instead: rule, caret, rule, `? for shortcuts`. A clocked pane is held to quiescence (tier 1b) because the submit repaint reads ready for a moment; a clockless restored pane settles from the screen alone. When a trustworthy screen exists it decides, so the name-only title lane no longer settles an open picker. Retires the visible-read probe's Antigravity branch: the probe now runs the shared screen rule for any screen-ruled agent without an output clock, and keeps its generic empty-pane read for everyone else. Adds twelve agy 1.2.14 recordings and a replay suite shared by screen-ruled agents. STA-8741. * fix(runtime): decide Cline readiness from the live screen Cline paints its composer box with cursor addressing on the alternate screen, so no text rule saw it and worker-start timed out at agent_readiness (#23268). Read the box off the grid: rule, an empty composer with one of the captured placeholders, rule, the Plan/Act row and the auto-approve row, with no braille spinner above it. A streaming reply repaints the same box once its spinner has scrolled away, so Cline is tier 1b only: a clocked pane waits for quiet and a clockless one never settles from the screen. The screen now decides for a Cline pane, which shuts the quiet-process lane that would have settled its unworded tool-approval prompt and the Cline Desktop promo. readLiveTerminalScreenLines now returns raw rows: the read projection blanks a composer it takes for a draft, and it takes Cline's placeholder for one, so a typed draft and an empty composer looked the same. Adds nine cline 3.0.66 recordings (macOS) and the 3.0.65 Windows capture from #23269. STA-8741. * fix(runtime): decide Prime Agent readiness from the live screen Prime redraws its composer on the alternate screen, so the text tail never showed a settled prompt and tui-idle timed out (#22153). Read the grid instead: a bare `>` directly over the `<- manage` footer, with no braille status row (`Writing - 6s`) above it. The footer and caret alone stay painted for a whole turn. Replayed chunk by chunk, Prime erases that status row before redrawing it, and on first launch paints the idle composer just before the trace-sharing question covers it. Both keep repainting, so a clocked pane is held to quiescence (tier 1b); a clockless restored pane settles from the screen alone. Adds nine prime-agent 0.9.8 recordings (isolated HOME, OpenRouter) and the two 0.9.5 captures from #22154. STA-8741. * refactor(runtime): drop Cline-only readiness branches Cline now follows the same pattern as Antigravity and Prime: a screen rule plus table entries. - Drop MID_TURN_COMPOSER_AGENTS. onPtyData stamps lastOutputAt on every chunk, so a re-attached streaming pane has an output clock from its first byte; the exception only guarded a pane that printed nothing since attach. A clockless Cline pane now settles from its screen like the other two. - Drop the 'ready-body' rest-signal entries for all three agents. The rest signal is read only by quietForegroundLane, and a readable screen already shuts that lane and the title lane (isReadinessDecidedByScreen), so the entries only removed the quiet-process fallback for a pane with no trustworthy grid. The census now checks that screen-shut instead. - Drop the Cline rule's auto-approve row check; no recorded verdict depends on it. Kept: raw rows from readLiveTerminalScreenLines. Every frame of every codex-* and qoder-* capture at 120x40, 80x24 and 100x32 gives the same isKnownReadyPromptBody (with and without a clock) and isQuietReadyScreenBody verdict through both readers. Serializer known-failures for the new captures are pre-existing serializer behaviour, not this branch: row-0 cells restore with a true-colour background where the source has the default (the DSH class), and Prime's cursor restores at column 119 instead of the pending wrap at 120 (the qoder class). STA-8741. * fix(runtime): trust a screen rule only on the PTY's own grid Review findings on the screen-ruled readiness (STA-8741): - A grid out of step with the PTY garbles cursor-addressed chrome, and a model resize does not make the TUI repaint. readLiveTerminalScreenLines now returns null unless the emulator's grid matches the PTY's reported size and was never reflowed without a repaint (a re-attach that learned the real size late), so the pre-existing lanes decide there instead of timing out. - The visible-read probe reads the draft-blanking projection, which turns Cline's `❯ Ask anything...` into a bare `❯`. It now restores the blanked composer row before the rule reads it; `terminal read --screen` output is unchanged. - The quiet lane no longer ORs the text rules over a trustworthy screen that refused; without one, tier 1 already ran them. No recorded verdict changes. Tests: ready recordings on a mismatched and on a reflowed grid settle through the old lanes; the restored-pane probe runs every ready recording through the real projection; the rest-signal census checks the lane verdict with and without a screen. * test(runtime): trim STA-8741 recordings to the screens they prove * refactor(runtime): one screen verdict for every screen-ruled lane readScreenRuledReady, readScreenRuledQuietReady and isReadinessDecidedByScreen each re-derived the same thing: the agent's rule applied to a trustworthy live screen. They collapse into readScreenRuledVerdict (true / false / null), which tier 1, tier 1b and the lane gate read. This also makes a refusal final in tier 1: a clockless pane whose trustworthy screen refused fell through to the text rules, so retained ready text could settle over an open picker (Greptile review). The quiet tier already refused there; now both do. The tier-1b agent set derives the screen-ruled agents from the rule table instead of listing them again, and the lane test that repeated the census case is dropped. * refactor(runtime): let the visible-read probe read its own output clock The probe's clock was captured at start and threaded through the wait dependencies as a one-off parameter. The probe now reads it from the live record when its screen read returns, which is also the fresher answer. * fix(runtime): trust a reflowed grid again once a PTY resize repaints it The reattach-reflow flag was never cleared, so a pane stayed on the old lanes for the rest of its life even after a real resize made the TUI repaint (Greptile review). The record now keeps the reflowed grid, and a PTY resize off that grid clears it; an echo of the same size sends no SIGWINCH and keeps it. Tests: the reflow case in every screen-ruled suite now includes a same-size echo, and an Antigravity recording only the screen reads ready settles after a resize and repaint. * refactor(runtime): keep screen-rule trust and raw rows to screen-ruled agents Two shared changes reached agents this PR does not target: the live screen reader returned raw rows, and it refused a grid that did not match the PTY. Both now live in readScreenRuledLines, which only the screen-ruled agents read (screenReader picks it from the rule table); readLiveTerminalScreenLines is main's again. The probe keeps main's Antigravity-banner trigger, so a Codex or unknown pane is probed exactly as before. Proof: the non-screen-ruled suites give identical pass sets on this branch and its base (1,781 tests), and replaying every other recording frame by frame through the readiness and blocked verdicts, for its agent and for an unknown pane, gives identical results (93 pairs). A new test keeps a Codex pane reading its screen when the PTY reports another grid; it fails if the trust check moves back into the shared reader.

ELI5
Prime can be ready and answering normally while Orca keeps waiting for it to start. This lets Orca recognize Prime's idle screen and reuse the same agent for the next task.
What Changed
Why
Prime's alternate-screen redraws do not reliably leave a settled prompt in the retained stream tail. Increasing the timeout does not repair that missing evidence. This extends the existing detection/probe path instead of adding a separate readiness service or bypassing worker-start.
The title changes overlap with open #13707. This PR also covers captured cold-start screen recovery; no headless commit environment changes are included. Latest-main Antigravity handling is preserved.
Linked Issue
Fixes #22153
Visual Proof
N/A — no application layout changes. CLI behavior before:
terminal wait --for tui-idletimes out on a ready Prime pane. After: readiness succeeds, followed by two successful Factory dispatches to the same Prime session, each with a separate verifiedworker_donereceipt.Testing
macOS arm64, Prime 0.9.4/0.9.5. Installed patched Orca 1.4.206 was tested with Prime 0.9.5 using an explicit provider/model: cold readiness, native tool execution, task completion, idle detection, and a second Factory dispatch on the same session. This installed validation predates the rebase onto current main; the rebase was tested separately.
Current-main focused suite: 204 passed, 10 existing skips across Prime readiness, terminal wait detection/name-only idle, synthetic titles, title identity, agent detection, and Antigravity transcript tests. Changed-file lint and diff checks pass. The main-process build and full node TypeScript check also pass on the rebased branch (Node 24 with expanded stack/heap). Raw fixtures pass the repository privacy scanner.
Windows, Linux and SSH execution were not manually tested. No global timeout, wire protocol, model defaults or authorization policy changes. Full repository lint/test/build coverage is left to CI; focused validation does not claim full-suite acceptance.
AI Disclosure
Prepared with OpenAI Codex. Prime/DeepSeek V4.1 Flash performed two diagnostic Factory tasks during installed validation; their completion receipts were independently checked.
Review
Self-reviewed the original-waiter deadline/cancellation boundary, busy-screen veto and retained Prime identity. Captured fixtures contain no account identifiers or credentials.
Agent skill upstream boundary
Checklist