Skip to content

fix(agent-hooks): reopen a retired pane on any provider's turn boundary (#12686) - #14626

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/cursor-status-12686
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/cursor-status-12686

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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

  • getAgentStatusDisposition no longer hardcodes Claude's UserPromptSubmit / SessionStart when deciding whether a live hook may reopen a retired-but-reusable pane. It now asks isNewTurnEvent(source, hookEventName) — the per-provider turn-boundary table that already exists in agent-hook-listener.ts — exported as isAgentHookNewTurnEvent.
  • Both hook-status call sites (local HTTP /hook/<source> and ingestRemote) now pass the hook source, which each already had in scope.
  • Relay frames that carry no source fall back to the previous Claude-vocabulary check, so older remote clients behave exactly as before.
  • New focused suite 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 Working even though Cursor emitted a completed stop hook. 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:1013 only accepted Claude's two event names. Cursor's turn boundary is beforeSubmitPrompt (see the cursor case in isNewTurnEvent), so a retired Cursor pane could never be reopened: beforeSubmitPrompt, stop, and afterAgentResponse were 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.ts starts 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 suppressed stop never 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, and copilot only worked because they happen to use Claude-compatible names. Reusing the existing exhaustive table fixes them all and makes a newly added AgentHookSource fail typecheck rather than silently regress.

The change is strictly widening: no source loses the ability to reopen a pane, and the isReplay guard plus the closed-tab fence are untouched.

Superseded / related

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 already true on 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.
  • The ⠋ Cursor Agent ↔ bare cursor agent alternation is not collapsed by that guard (the native literal detects as null status), but applyObservedTitle already suppresses the native re-emission while a Cursor-owned title holds the pane (shouldSuppressCursorNativeTitle).
  • The remaining churn the reporter describes is the sidebar compact row's toolName: toolInput secondary, 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 idle in worktree-agent-rows.ts:236 rather 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 and ingestRemote:

  • Reproduces [Bug]: Some Cursor panes remain Working despite completed stop hooks #12686 end-to-end: retire authority, then run a full Cursor turn (beforeSubmitPrompt → stop status=completed) and assert the pane reaches done.
  • Table-driven per-provider boundary coverage: cursor beforeSubmitPrompt, cursor sessionStart, gemini BeforeAgent, antigravity PreInvocation, pi before_agent_start, plus claude UserPromptSubmit / claude SessionStart as unchanged controls.
  • Negative controls that must keep suppressing: a mid-turn postToolUse must not reopen a retired pane, and a replayed beforeSubmitPrompt must not either.
  • Wire compatibility: a relay frame with no source still reopens on UserPromptSubmit.

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 typecheck skipped 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 skipped
  • pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/server.test.ts — 276 passed
  • pnpm exec vitest run --config config/vitest.config.ts src/shared/agent-hook — 8 files, 173 passed
  • tsc --noEmit -p config/tsconfig.node.json --composite false — clean
  • All three changed-code quality scans (oxlint, --type-aware, React Doctor) — clean
  • oxfmt --write on the changed files

Platforms actually exercised: macOS. The remote/relay path is covered by unit tests rather than a live SSH host.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

  • Security: no change to hook authentication. The HTTP token requirement, the isReplay fence, the closed-tab fence, and the launch-token strip on the restart path are all untouched. The gate is still narrow — only a live, non-replayed turn boundary reopens a pane.
  • Backwards compatibility: strictly widening. Every source that could reopen a pane before still can, with identical event names. opencode, mimo-code, and command-code return false from the table and keep their existing never-reopen behavior.
  • Remote / SSH: ingestRemote reads source, an existing relay field the server already consumes for providerPromptId and compactTrigger — 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.
  • Cross-platform: no paths, shell invocations, shortcuts, accelerator labels, or platform branches. Identical on macOS, Linux, and Windows.
  • Mobile: unaffected; this is main-process status ingestion.
  • Performance: one extra table lookup, and only on the already-rare retired-pane path.

Author

  • X / Twitter: @BrennanKB5

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
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 81e7407b-d24d-4eb4-bf31-4bfb787bbdd7

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb8836 and a5bba26.

📒 Files selected for processing (3)
  • src/main/agent-hooks/retired-pane-turn-restart.test.ts
  • src/main/agent-hooks/server.ts
  • src/shared/agent-hook-listener.ts

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.

brennanb2025 added a commit that referenced this pull request Aug 17, 2026
…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.
brennanb2025 added a commit that referenced this pull request Aug 17, 2026
…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.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

An agent started again in an existing terminal can now report its status, including Cursor. The fix landed in #15344.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Some Cursor panes remain Working despite completed stop hooks

1 participant