Repository navigation
fix(agent-hooks): reopen a retired pane on any provider's turn boundary (#12686) - #14626
brennanb2025 wants to merge 1 commit into
Conversation
The retired-but-reusable pane gate only recognized Claude's `UserPromptSubmit` and `SessionStart`. Cursor's turn boundary is `beforeSubmitPrompt`, so once a pane's launch authority retired, every later Cursor hook — including the completed `stop` — was suppressed. The pane never left Working, and because main only stops the 80ms synthetic spinner when an accepted terminal-state hook arrives, the `⠋ Cursor Agent` title kept animating indefinitely. Route the gate through `isNewTurnEvent`, the per-provider boundary table that already exists in the hook listener, so each provider is judged by its own vocabulary. Relay frames without a `source` keep the legacy Claude check for remote wire compatibility. Fixes #12686
|
Warning Review limit reached
Next review available in: 19 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
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 |
…dary fix The idle re-attach assertion posted only before_agent_start, which #14626 turns into a fence-lifting turn boundary. Under that change the test passes whether or not restorePaneAuthority runs, so it stops pinning this PR's mechanism. Assert first on agent_end — a non-turn event — so the test proves the fence was already down when the hook arrived. Verified: with restorePaneAuthority neutered AND before_agent_start added to the restart predicate, the old assertion passes and the new one fails.
…es (STA-4114) (#14624) * fix(agents): lift the pane retirement fence when a live PTY re-attaches (STA-4114) A detach/reattach cycle retires the pane on both sides — the main hook server's closedAgentStatusPaneKeys and the renderer's recentlyRetiredAgentStatusPaneKeys — and nothing ever cleared either one. The pane then rejected every later working/done event for the rest of its life while Pi kept running normally in the same PTY. Bind the fence to the fact it asserts: retirement claims the pane is gone, and binding a live PTY to that exact pane disproves it. Clear both tombstones at the spawn/attach chokepoint and at the daemon-backed reattach path, so recovery does not depend on the agent starting another turn — a pane re-attached mid-turn only has agent_end left to report, and one re-attached while idle emits nothing at all. Closed-tab tombstones are a separate, stronger claim and are deliberately left standing. * test(agent-hooks): re-arm the idle re-attach test against a turn-boundary fix The idle re-attach assertion posted only before_agent_start, which #14626 turns into a fence-lifting turn boundary. Under that change the test passes whether or not restorePaneAuthority runs, so it stops pinning this PR's mechanism. Assert first on agent_end — a non-turn event — so the test proves the fence was already down when the hook arrived. Verified: with restorePaneAuthority neutered AND before_agent_start added to the restart predicate, the old assertion passes and the new one fails. * fix(agents): lift a retired pane's whole fence, aliases included (STA-4114) Retirement fences the pane, its resolved owner, and every alias of it, then deletes those aliases. Restoring only the key handed to us left the rest standing — and a detached pane's process keeps posting the key it launched under (server.ts:1614), so the canonical re-attach case stayed suppressed with the fence apparently lifted. Verified against the real omp binary: the row came back under the stale launch pane instead of the detached owner. Record what each retirement fenced and replay it as a unit, rebuilding the aliases it deleted. Keys and aliases belonging to a closed tab are skipped, so the stronger claim survives and a live process is never routed back into a closed tab. The record is indexed by every fenced key and bounded at 1024 like the maps it mirrors; an evicted record degrades to the old behaviour. Also records why the renderer's restore IPC is deliberately unguarded: that map is not a mirror of main's (retirePtyAgentLaunchAuthority fences main directly on command-finished and PTY exit, and nothing pushes it back), and it is per-window and non-persisted, so gating the send on a local tombstone reintroduces this bug for exactly those panes.
…es (STA-4114) (stablyai#14624) * fix(agents): lift the pane retirement fence when a live PTY re-attaches (STA-4114) A detach/reattach cycle retires the pane on both sides — the main hook server's closedAgentStatusPaneKeys and the renderer's recentlyRetiredAgentStatusPaneKeys — and nothing ever cleared either one. The pane then rejected every later working/done event for the rest of its life while Pi kept running normally in the same PTY. Bind the fence to the fact it asserts: retirement claims the pane is gone, and binding a live PTY to that exact pane disproves it. Clear both tombstones at the spawn/attach chokepoint and at the daemon-backed reattach path, so recovery does not depend on the agent starting another turn — a pane re-attached mid-turn only has agent_end left to report, and one re-attached while idle emits nothing at all. Closed-tab tombstones are a separate, stronger claim and are deliberately left standing. * test(agent-hooks): re-arm the idle re-attach test against a turn-boundary fix The idle re-attach assertion posted only before_agent_start, which stablyai#14626 turns into a fence-lifting turn boundary. Under that change the test passes whether or not restorePaneAuthority runs, so it stops pinning this PR's mechanism. Assert first on agent_end — a non-turn event — so the test proves the fence was already down when the hook arrived. Verified: with restorePaneAuthority neutered AND before_agent_start added to the restart predicate, the old assertion passes and the new one fails. * fix(agents): lift a retired pane's whole fence, aliases included (STA-4114) Retirement fences the pane, its resolved owner, and every alias of it, then deletes those aliases. Restoring only the key handed to us left the rest standing — and a detached pane's process keeps posting the key it launched under (server.ts:1614), so the canonical re-attach case stayed suppressed with the fence apparently lifted. Verified against the real omp binary: the row came back under the stale launch pane instead of the detached owner. Record what each retirement fenced and replay it as a unit, rebuilding the aliases it deleted. Keys and aliases belonging to a closed tab are skipped, so the stronger claim survives and a live process is never routed back into a closed tab. The record is indexed by every fenced key and bounded at 1024 like the maps it mirrors; an evicted record degrades to the old behaviour. Also records why the renderer's restore IPC is deliberately unguarded: that map is not a mirror of main's (retirePtyAgentLaunchAuthority fences main directly on command-finished and PTY exit, and nothing pushes it back), and it is per-window and non-persisted, so gating the send on a local tombstone reintroduces this bug for exactly those panes.
|
An agent started again in an existing terminal can now report its status, including Cursor. The fix landed in #15344. |
…es (STA-4114) (stablyai#14624) * fix(agents): lift the pane retirement fence when a live PTY re-attaches (STA-4114) A detach/reattach cycle retires the pane on both sides — the main hook server's closedAgentStatusPaneKeys and the renderer's recentlyRetiredAgentStatusPaneKeys — and nothing ever cleared either one. The pane then rejected every later working/done event for the rest of its life while Pi kept running normally in the same PTY. Bind the fence to the fact it asserts: retirement claims the pane is gone, and binding a live PTY to that exact pane disproves it. Clear both tombstones at the spawn/attach chokepoint and at the daemon-backed reattach path, so recovery does not depend on the agent starting another turn — a pane re-attached mid-turn only has agent_end left to report, and one re-attached while idle emits nothing at all. Closed-tab tombstones are a separate, stronger claim and are deliberately left standing. * test(agent-hooks): re-arm the idle re-attach test against a turn-boundary fix The idle re-attach assertion posted only before_agent_start, which stablyai#14626 turns into a fence-lifting turn boundary. Under that change the test passes whether or not restorePaneAuthority runs, so it stops pinning this PR's mechanism. Assert first on agent_end — a non-turn event — so the test proves the fence was already down when the hook arrived. Verified: with restorePaneAuthority neutered AND before_agent_start added to the restart predicate, the old assertion passes and the new one fails. * fix(agents): lift a retired pane's whole fence, aliases included (STA-4114) Retirement fences the pane, its resolved owner, and every alias of it, then deletes those aliases. Restoring only the key handed to us left the rest standing — and a detached pane's process keeps posting the key it launched under (server.ts:1614), so the canonical re-attach case stayed suppressed with the fence apparently lifted. Verified against the real omp binary: the row came back under the stale launch pane instead of the detached owner. Record what each retirement fenced and replay it as a unit, rebuilding the aliases it deleted. Keys and aliases belonging to a closed tab are skipped, so the stronger claim survives and a live process is never routed back into a closed tab. The record is indexed by every fenced key and bounded at 1024 like the maps it mirrors; an evicted record degrades to the old behaviour. Also records why the renderer's restore IPC is deliberately unguarded: that map is not a mirror of main's (retirePtyAgentLaunchAuthority fences main directly on command-finished and PTY exit, and nothing pushes it back), and it is per-window and non-persisted, so gating the send on a local tombstone reintroduces this bug for exactly those panes.
ELI5
Orca lets a finished agent pane be reused as a plain shell. When that happens it "retires" the pane, then waits for a hook that proves a new agent has taken it over. It only knew how to recognize Claude saying "new turn." Cursor says it with a different word, so Orca never noticed Cursor came back — it ignored everything Cursor sent afterwards, including "I'm done." The pane sat there spinning on Working forever. Now Orca listens for each agent's own word.
What Changed
getAgentStatusDispositionno longer hardcodes Claude'sUserPromptSubmit/SessionStartwhen deciding whether a live hook may reopen a retired-but-reusable pane. It now asksisNewTurnEvent(source, hookEventName)— the per-provider turn-boundary table that already exists inagent-hook-listener.ts— exported asisAgentHookNewTurnEvent./hook/<source>andingestRemote) now pass the hooksource, which each already had in scope.sourcefall back to the previous Claude-vocabulary check, so older remote clients behave exactly as before.src/main/agent-hooks/retired-pane-turn-restart.test.ts.No behavior changes for a pane that was never retired, for a closed tab, or for replayed events.
Why
#12686 reports Cursor panes stuck on
Workingeven though Cursor emitted a completedstophook. The reported trace shows the affected pane had no persisted authority commitment while the control pane did — i.e. its authority had been retired.The retired-pane gate at
server.ts:1013only accepted Claude's two event names. Cursor's turn boundary isbeforeSubmitPrompt(see thecursorcase inisNewTurnEvent), so a retired Cursor pane could never be reopened:beforeSubmitPrompt,stop, andafterAgentResponsewere all suppressed at the status-ingest boundary. That matches the issue's observation that the events "are being rejected or dropped at the pane-authority/status-ingest boundary."Why the symptom is "stuck Working" rather than "no row":
main/index.tsstarts the 80 ms synthetic spinner (⠋ Cursor Agent) from the accepted-status listener, and only stops it when an accepted terminal-state hook arrives (driveSyntheticTitleFromHook→stopSyntheticTitleSpinner). A suppressedstopnever reaches that listener, so the spinner keeps re-asserting a working OSC title forever and the pane stays visibly Working. One root cause, both halves of the symptom.This was never Cursor-specific. Every provider whose boundary is not spelled the Claude way was equally stranded —
gemini(BeforeAgent),antigravity(PreInvocation),amp(agent.start),pi/omp/prime-agent(before_agent_start),hermes,grok.codex,kimi,droid,devin, andcopilotonly worked because they happen to use Claude-compatible names. Reusing the existing exhaustive table fixes them all and makes a newly addedAgentHookSourcefail typecheck rather than silently regress.The change is strictly widening: no source loses the ability to reopen a pane, and the
isReplayguard plus the closed-tab fence are untouched.Superseded / related
beforeSubmitPromptalongside Claude's names, fixing only Cursor and leaving the other providers broken. It is also stale: main has since addedSessionStart(STA-3386), which that branch's diff would drop.On the flicker cluster (#11075), deliberately not bundled
I tested the flicker hypothesis before writing code, and it is a different defect, so it is not in this PR:
isDecorativeAgentTitleFrameChange('⠋ Cursor Agent', '⠙ Cursor Agent')is alreadytrueon main, so spinner-frame churn is already collapsed in the tab-title path (terminal-tab-title-batch.ts:182,terminals.ts:2100). That machinery post-dates [Bug]: Cursor tab/sidebar title flickers while agent is working #11075.⠋ Cursor Agent↔ barecursor agentalternation is not collapsed by that guard (the native literal detects asnullstatus), butapplyObservedTitlealready suppresses the native re-emission while a Cursor-owned title holds the pane (shouldSuppressCursorNativeTitle).toolName: toolInputsecondary, which rewrites on every hook — a renderer-presentation concern in a different subsystem.I also checked the "hook row appears/disappears" hypothesis: a stale hook row decays to
idleinworktree-agent-rows.ts:236rather than disappearing, so the title-derived fallback does not take over and oscillate.Linked Issue
Fixes #12686
Visual Proof
N/A— no UI code is touched. The change is in main-process hook status ingestion; the user-visible effect (pane leaves Working) is asserted by the automated tests below rather than by a rendered-UI diff.Testing
src/main/agent-hooks/retired-pane-turn-restart.test.ts— 11 tests, driven through the real hook HTTP server andingestRemote:beforeSubmitPrompt→stop status=completed) and assert the pane reachesdone.cursor beforeSubmitPrompt,cursor sessionStart,gemini BeforeAgent,antigravity PreInvocation,pi before_agent_start, plusclaude UserPromptSubmit/claude SessionStartas unchanged controls.postToolUsemust not reopen a retired pane, and a replayedbeforeSubmitPromptmust not either.sourcestill reopens onUserPromptSubmit.Proven non-vacuous. With the test file kept and only the two source files reverted (
git stash push -- <sources>), the suite goes 7 failed / 4 passed; with the fix applied it is 11 passed. The 4 that pass pre-fix are exactly the controls the fix must not change (both Claude cases, the sourceless relay frame, and mid-turn suppression).Scoped checks run locally (full
pnpm typecheckskipped deliberately — OOM risk on this box; the node project is the one this diff touches):pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/— 41 files, 756 passed / 4 skippedpnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/server.test.ts— 276 passedpnpm exec vitest run --config config/vitest.config.ts src/shared/agent-hook— 8 files, 173 passedtsc --noEmit -p config/tsconfig.node.json --composite false— clean--type-aware, React Doctor) — cleanoxfmt --writeon the changed filesPlatforms actually exercised: macOS. The remote/relay path is covered by unit tests rather than a live SSH host.
Review
isReplayfence, the closed-tab fence, and the launch-token strip on therestartpath are all untouched. The gate is still narrow — only a live, non-replayed turn boundary reopens a pane.opencode,mimo-code, andcommand-codereturnfalsefrom the table and keep their existing never-reopen behavior.ingestRemotereadssource, an existing relay field the server already consumes forproviderPromptIdandcompactTrigger— no new wire field and no new opcode. Frames without it keep the old Claude-vocabulary behavior, so a mixed-version client/host pair is safe in both directions.Author