Skip to content

fix(agent-status): keep an unresolved blocker when a pane unmounts - #22459

Open
nvimq wants to merge 3 commits into
stablyai:mainfrom
nvimq:fix/unmount-keeps-pending-agent-blocker
Open

nvimq wants to merge 3 commits into
stablyai:mainfrom
nvimq:fix/unmount-keeps-pending-agent-blocker

Conversation

@nvimq

@nvimq nvimq commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 +263 −14 +249
Prod 2 +59 −3 +56

ELI5

An agent asks you a question. You glance at another Orca tab and come back — the question is gone from the sidebar. It is kept now.

Problem

Switching tabs unmounts a pane. dispose() calls releaseRendererOwnedAgentStatusPane() (session-reconcile-dispose.ts), handing agent-status authority for that pane back to the host. The next mirrored host snapshot that carries no status for the surface reaches buildMirroredAgentStatusPatch's delete loop, and that loop was gated on ownership alone (isClientOwnedAgentStatus). Nothing looked at the row's state, so an unanswered waiting/blocked row took exactly the same path as a stale one: deleted, not retired.

The row was the only record of a question waiting on the user.

Solution

Absence of host status is not a resolution — but only for the panes where the host never had status to begin with. The fix turns on telling those two silences apart:

Silence Meaning Behavior
Host never had status for this pane An OSC-driven pane whose row came from this renderer's bytes; hook-only hosts publish nothing for it Keep a fresh waiting/blocked row; it retires by decaying past AGENT_STATUS_STALE_AFTER_MS
Host withdrew status it had A sidebar dismissal (dropAgentStatus) or a closed split leaf: surface still published, status gone Delete at once, exactly as on main

What Changed

  • renderer-owned-agent-status-registry.ts — the release closure marks releasedAt instead of deleting the entry, and isReleasedClientWrittenAgentStatusPane reads it. isClientAuthoritativeAgentStatusPane still returns false after release, so the live-ownership fence is untouched; the new predicate is a separate, weaker signal. A pane that never proved a byte-derived write leaves nothing behind, and a retained claim is swept at the next registration once it can no longer describe a live row.
  • agent-status-patch.ts — one guard ahead of the ownership gate: a blocked/waiting row that is still fresh and whose pane this renderer wrote and has since unmounted skips the delete. working and done are unchanged, and a host-minted row of any state is unchanged.

Why

Per docs/reference/agent-status-store.md the execution host owns status and readers keep only presentation policy. Unmount is a presentation event, so deciding retirement from it is the wrong layer — and so is overriding a host that deliberately withdrew a row, which is why the guard requires the released client-write claim rather than state alone.

Freshness bounds the retention. An unanswered blocker is not kept forever; it decays on the same boundary every other mirrored row uses. Retaining unconditionally would re-introduce the ghost rows STA-4593 removed.

Linked Issue

Fixes #22445.

Visual Proof

N/A — renderer store state, not pixels. The observable effect is whether an agentStatusByPaneKey row survives an unmount-then-snapshot sequence, which the regression suite asserts at that exact seam.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

web-session-tabs-sync-unmount-pending-blocker.test.ts replays the real path — real snapshot mirror, real ownership registry, real store, driven clock:

Case Expectation
waiting / blocked, client-written, released Row survives the snapshot without status
Same row past AGENT_STATUS_STALE_AFTER_MS Deleted — decay still retires it
done, same handover Deleted — control
Host-minted waiting, host stops publishing status Deleted at once — the withdrawal case

Verified RED on the base commit: the blocker cases fail with expected undefined to be 'waiting' / 'blocked' — the row is gone — and pass with the guard.

renderer-owned-agent-status-registry.test.ts gained the bounded-evidence contract: a released claim is readable while fresh, gone after the window, swept at the next registration, and never retained for a pane that never wrote.

Checks on 8d6fec597b:

  • vitest run src/renderer/src/components/terminal-pane src/renderer/src/runtime: 679 files, 6264 tests pass — including the suites that pin this delete loop (paired-reconnect-sidebar-agent-count, web-session-tabs-sync-host-tab-retraction-ghost-rows, mirrored-status-tab-retractions, web-session-tabs-sync-remote-status-title-flap).
  • vitest run src/renderer/src/store: 369 files, 3390 tests pass — covers the store-test-helpers signature change.
  • pnpm tc:web, oxlint, oxfmt --check, check-changed-code-quality.mjs: pass.

Not run: native Windows/Linux, live SSH, e2e. Mobile is unaffected — it does not go through buildMirroredAgentStatusPatch.

Review

Independently reviewed by @pullfrog, which caught that gating on state and freshness alone also outlived host-withdrawn rows. That is fixed in 0ba9b46298 and covered by the withdrawal case above; the retention now requires the released client-write claim.

store-test-helpers.ts gained a named TestAppStore export and createTestStore an explicit return type, because the repo rule against publishing contracts through ReturnType<typeof fn> applies to the new suite. Existing suites keep their local aliases; migrating them is not this PR's job.

Two existing registry assertions pinned "release deletes immediately, zero entries left". That contract is intentionally different now, so they were retargeted at the bounded-evidence invariant and renamed to say so, not re-pinned to new numbers.

The SSH / Remote Orca Server case the issue asks about runs the same mirrored-snapshot path with the same environment-scoped ownership check, so the guard covers it; there is no separate branch for it.

Agent skill upstream boundary

  • Not applicable; no agent skill source changes.

Notes

  • No wire, execution-host, persistence or Git-provider change. The host's authority is unchanged — this only stops the reader from deleting on a silence that says nothing.
  • Retraction is untouched: a host-retracted tab still reaches the retirement sweep through the existing retractedTabIds skip above this guard.
  • The retained claim is renderer-process memory only, bounded by the staleness window, and never crosses a process boundary.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • pnpm lint, pnpm typecheck, focused pnpm test, and the changed-code quality gate pass; packaging left to CI

Unmounting a pane cedes renderer ownership of its agent status back to the
host. The next mirrored snapshot that carries no status for the surface then
reached buildMirroredAgentStatusPatch's delete loop, which was gated only on
ownership, so a genuine waiting/blocked row was deleted rather than retired:
a pending question disappeared from the sidebar because the user switched
tabs.

Gate the delete on state as well. A still-fresh waiting/blocked row survives
the handover and retires the way an owned row does, by decaying past the
freshness boundary; every other state keeps the previous behavior.

Fixes stablyai#22445

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The retention guard keys on the absence of host status alone, so it also outlives panes and rows the host genuinely removed — a closed split leaf, and a host-side dismissal/clear — until the 30-minute decay. Details inline on the guard.

Reviewed changes

  • Keep a fresh pending blocker across an ownership handover — buildMirroredAgentStatusPatch now continues past the delete loop for a blocked/waiting row that is still isAgentStatusFresh, so an unmounted pane's unanswered question is not deleted when the next mirrored snapshot carries no status for the surface.
  • Regression coverage for the unmount-then-snapshot sequence — the new suite replays the real snapshot mirror, renderer-ownership registry, and store with a driven clock: waiting/blocked survive, done is still deleted, and a stale waiting still decays.
  • Named test-store type — store-test-helpers.ts exports TestAppStore and gives createTestStore an explicit return type, so suites stop reaching through ReturnType.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +176 to +188
// Why: unmount cedes renderer ownership (session-reconcile-dispose), so the
// ownership gate below stops covering a pane the moment the user switches
// tabs. A host snapshot carrying no status is not a resolution, and deleting
// an unanswered question drops it from the sidebar (#22445). Retire a pending
// blocker the way an owned row retires: by decaying past the freshness
// boundary, never by the absence of a host value.
const pendingBlocker = state.agentStatusByPaneKey[paneKey]
if (
(pendingBlocker.state === 'blocked' || pendingBlocker.state === 'waiting') &&
isAgentStatusFresh(pendingBlocker, now)
) {
continue
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retention here is keyed only on the entry's state and freshness — not on whether the pane still exists, nor on whether the host deliberately removed the row. A host-side drop/dismissal (dropAgentStatus → agentStatus.drop, which republishes the worktree with the surface present but no agentStatus) and a closed split leaf (tab still published through a sibling leaf) both now keep a blocked/waiting row alive for up to 30 minutes. For a host-authoritative row the host is the owner per docs/reference/agent-status-store.md, so this is the reader overriding a host removal rather than a presentation-policy decision.

Technical details
# Blanket absence-retention also outlives host removals

## Affected sites
- `src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts:182-188` — the guard; runs after the ownership, retraction, and `nextByPaneKey` gates, so it is the last word for any absent-status row.
- `src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts:70-78` and `agent-status-primitives.ts:59-65` — `mirroredTabIds`/`isMirroredAgentPaneKeyForTabs` are tab-level only, so a closed leaf's pane key still reaches the guard while a sibling leaf keeps the tab published.
- `src/renderer/src/store/slices/agent-status-drop-actions.ts:112-117` — dismissal drops the authoritative row and fans out `agentStatus.drop`; the worktree republish then carries the surface with `agentStatus` omitted (`hook-status-session-tabs-republish.ts`).
- `src/shared/runtime-mobile-session-tab-contracts.ts:19` — the wire schema has no per-surface clear marker, so "host removed the row" and "hook-only host never published one" are the same signal.

## Required outcome
- A `blocked`/`waiting` row the host has actually removed (dismissal/clear) must still leave a paired client promptly; retention should not override host authority for rows the client never wrote.
- A closed pane/leaf must not leave a sidebar ghost for 30 minutes.

## Suggested approach (optional)
- Scope retention to the ownership-handover case the issue describes: retain only when the row was client-authored before the release (or while an ownership handover is in flight), rather than for every fresh blocker whose host snapshot omits status. The current form cannot distinguish those, which is why it is worth deciding explicitly.

## Open questions for the human (optional)
- Is host-side dismissal of a `waiting`/`blocked` row a supported flow? If so, its 30-minute client-side lag is a regression, not a tradeoff.
- Is a 30-minute ghost after closing a split leaf acceptable, given STA-4593 removed exactly this class of ghost for retracted tabs?
- No test pins either case (the new suite publishes a single surface; the ghost-row suite covers tab retraction only). Worth a control in a follow-up if the behavior is intended.

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The registry retains time-limited evidence of panes that wrote agent status before release. The retirement logic uses this evidence to preserve fresh renderer-written waiting and blocked rows when a host snapshot omits them. Regression tests cover handover, stale and completed rows, and host-minted status withdrawal. The test-store helper also adds an exported store type and an explicit return type for createTestStore.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 82eaf

A remounted pane can incorrectly regain client status authority, and a withdrawn host blocker can remain visible while fresh. Resolve both status-retirement paths before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed #22445 requires unresolved blockers to survive pane unmount when the renderer wrote them and the host snapshot omits status. The mirrored-status patch now preserves fresh waiting and blocked rows …
Out of Scope Changes check ✅ Passed The changes support #22445. The registry changes distinguish renderer-written blockers from host-minted rows, the tests cover the required handover and withdrawal behavior, and the TestAppStore type…
Title check ✅ Passed The title clearly identifies the primary change: preserving unresolved agent-status blockers when a pane unmounts.
Description check ✅ Passed The description follows the repository template and explains the problem, solution, rationale, linked issue, visual proof, testing, review notes, scope, and checklist status. It also clearly records t…
  • Fix all pre-merge checks with AI

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.

Review catch: gating retention on state and freshness alone also outlived
rows the host deliberately removed — a sidebar dismissal (dropAgentStatus) and
a closed split leaf both republish the surface without status, and both were
held for the full staleness window.

Distinguish the two silences. The ownership registry now keeps a released
claim instead of deleting it, so the mirror can tell a pane whose status only
ever came from this renderer's bytes (the host publishes nothing for it, so
its silence carries no information) from a pane the host minted status for
(where absence is the host withdrawing it). Only the former retains a pending
blocker; a host-minted row is deleted on the first snapshot without status,
exactly as before.

The retained claim is bounded: it is swept once it can no longer describe a
live row, and a pane that never proved a byte-derived write leaves nothing
behind.
@nvimq

nvimq commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Valid on both counts, and fixed in 0ba9b46.

The guard keyed on state and freshness alone, which cannot tell two different silences apart:

  • the host never had status for this pane — an OSC-driven pane whose row only ever came from this renderer's bytes. The host publishes nothing for it by design, so its silence carries no information about the agent.
  • the host withdrew status it had — dropAgentStatus from the sidebar, or a closed split leaf. The surface is still published, the status is gone, and that is a decision, not silence.

Retention was covering both. Your reading of docs/reference/agent-status-store.md is right: overriding the second case is the reader deciding retirement for a row the host owns.

What changed. The ownership registry now keeps a released claim rather than deleting it, and exposes isReleasedClientWrittenAgentStatusPane. The retention guard requires it, so it only covers a row whose authority was this renderer's bytes and whose pane has since unmounted. A host-minted row hits the delete on the first snapshot without status, exactly as on main — including your dismissal and closed-leaf cases.

Two details worth naming:

  • isClientAuthoritativeAgentStatusPane still returns false after release, so the live-ownership fence above is unchanged. The new predicate is a separate, weaker signal.
  • The retained claim is bounded, not a leak: it is swept at the next registration once it can no longer describe a live row (AGENT_STATUS_STALE_AFTER_MS), and a pane that never proved a byte-derived write leaves nothing behind at all.

Coverage. New case in the suite: a host-minted waiting row, host then republishes the surface without status, row is deleted at once. renderer-owned-agent-status-registry.test.ts gained the bounded-evidence contract (released claim readable while fresh, gone after the window, nothing retained for a pane that never wrote); its "leaks no entry" assertions were retargeted rather than dropped.

Checks on the new head: vitest run src/renderer/src/components/terminal-pane src/renderer/src/runtime 679 files / 6264 tests pass, src/renderer/src/store 369 / 3390 pass, pnpm tc:web, oxlint, oxfmt and the changed-code quality gate pass.

A blanket oxfmt run swept three files this change does not touch into the
previous commit. Restore them to main so the PR diff is only the agent-status
retention change.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The retention guard is now scoped to the pane's write history rather than to the row's author, so a host-authored blocked/interactivePrompt row on a pane that ever emitted OSC status is still retained after the host withdraws it. This is the prior review's host-removal case, only narrowed — details and a verified repro inline.

Reviewed changes

  • Scope blocker retention to panes this renderer wrote — the ownership registry now records a releasedAt on the claim and exposes isReleasedClientWrittenAgentStatusPane(paneKey, now); the delete-loop guard requires it, so a host-minted blocker on a never-written pane is deleted immediately again.
  • Tighten isClientAuthoritativeAgentStatusPane — it now also requires releasedAt === null, preserving the previous external result (release used to delete the entry outright).
  • Registry lifecycle coverage — tests for release/remount/sweep, the reworked "leaks nothing" case, and a host-minted control; plus a TestAppStore export in store-test-helpers.ts. The pty-connection-* and mirrored-status-tab-retractions edits are formatting-only.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +184 to +191
const pendingBlocker = state.agentStatusByPaneKey[paneKey]
if (
(pendingBlocker.state === 'blocked' || pendingBlocker.state === 'waiting') &&
isReleasedClientWrittenAgentStatusPane(paneKey, now) &&
isAgentStatusFresh(pendingBlocker, now)
) {
continue
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scopes retention to the pane's write history, not to which writer authored the row. A host permission block pierces the client fence (hostAgentStatusPiercesClientAuthority) and overwrites a client-written pane's store row with a host-authored blocked/interactivePrompt entry, while hasClientWrite stays true. So on unmount plus host withdrawal such a row is still retained for up to 30 minutes — exactly the host-removal case the prior review asked to fix, just narrowed. The new control test (web-session-tabs-sync-unmount-pending-blocker.test.ts:210) does not catch it because it never registers the pane, so hasClientWrite is false there.

Technical details
# Pane-level write history still retains host-authored rows on host withdrawal

## Affected sites
- `src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts:184-191` — the guard checks `isReleasedClientWrittenAgentStatusPane(paneKey, now)` (pane-level) and the row's `state`, never the row's author.
- `src/renderer/src/components/terminal-pane/renderer-owned-agent-status-registry.ts:87-94` — predicate keys on the pane entry's `hasClientWrite`/`releasedAt`; it is not consulted per row.
- `src/renderer/src/runtime/web-session-tabs-sync/agent-status-primitives.ts:70-72` — `blocked` or any `interactivePrompt` row is host-only and pierces the fence.
- `src/renderer/src/runtime/web-session-tabs-sync-remote-status-title-flap.test.ts:493-516` — pins the supported mixed flow: client OSC `working` then a host `blocked` + `interactivePrompt` overwrite on the same pane, leaving `hasClientWrite === true`.
- `src/renderer/src/runtime/web-session-tabs-sync-unmount-pending-blocker.test.ts:210-221` — the host-minted control uses a pane with no registration, so it only covers the never-client-written subcase.

## Verified repro (temporary test against this head, since removed)
client OSC `working` on a registered pane -> host snapshot with `state: 'blocked'` + `interactivePrompt` -> `release()` -> host snapshot without status. Result: `agentStatusByPaneKey[PANE_KEY]?.state === 'blocked'` (retained) instead of deleted.

## Required outcome
- A `blocked`/`interactivePrompt` row the host has withdrawn must retire promptly on the client, regardless of whether the pane earlier produced byte-derived status; retention should not outlive host authority for a row the host itself authored.
- The control test should exercise a pane that has emitted OSC status and then received a host-pierced row, so the intended scoping is actually pinned.

## Suggested approach (optional)
- Skip retention when the row's present state is one the client's bytes cannot author: `hostAgentStatusPiercesClientAuthority(pendingBlocker)` is already available in this module. That keeps retention for client-authored `waiting` rows while letting host-authored blocks retire on withdrawal.

## Open questions for the human
- Is host-side dismissal/withdrawal of a `blocked`/`interactivePrompt` row a supported flow? If so this 30-minute lag is a regression, not a tradeoff (this is the prior review's first open question, still unanswered).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 05f78f85-2f24-4ed5-97a6-7db92538bcfc

📥 Commits

Reviewing files that changed from the base of the PR and between a5b5644 and 82eaf77.

📒 Files selected for processing (4)
  • src/renderer/src/components/terminal-pane/renderer-owned-agent-status-registry.test.ts
  • src/renderer/src/components/terminal-pane/renderer-owned-agent-status-registry.ts
  • src/renderer/src/runtime/web-session-tabs-sync-unmount-pending-blocker.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

const entry: RendererOwnedAgentStatusPane = {
environmentId,
hasClientWrite: existing?.environmentId === environmentId && existing.hasClientWrite
hasClientWrite: existing?.environmentId === environmentId && existing.hasClientWrite,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Expire a released claim before copying its write history.

If a pane releases, remains unregistered for more than AGENT_STATUS_STALE_AFTER_MS, and then re-registers with the same paneKey, this line copies hasClientWrite before forgetExpiredReleases runs. The new entry sets releasedAt to null, so the sweep cannot delete it. The expired claim becomes active client authority again and can retain or fence a stale row without a new renderer write.

Run the expiry sweep before reading existing, and add a same-paneKey re-registration test after the stale boundary.

This branch has not been deployed

No deployments
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]: unmounting a pane deletes a genuine pending agent blocker, not just a stale one

1 participant