Skip to content

fix(agent-status): prevent ghost sidebar row on completed split-pane detach - #10698

Merged
OrcaWin merged 2 commits into
stablyai:mainfrom
forwaryan:fix/10675-detach-pane-ghost-agent-row
Jul 28, 2026
Merged

OrcaWin merged 2 commits into
stablyai:mainfrom
forwaryan:fix/10675-detach-pane-ghost-agent-row

Conversation

@forwaryan

@forwaryan forwaryan commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #10675 — detaching a completed (done-state) split-pane agent into its own tab split the same agent session into two sidebar rows: one working, one a stale unclickable duplicate, plus an inflated worktree agent count.

Root cause: detaching a pane onto the tab strip keeps the leafId but changes the tabId, so the agent's paneKey migrates oldTab:leaf → newTab:leaf. transferAgentPaneAuthority moves the live status to the new key, but the sidebar's useRetainedAgentsSync hook tracks live pane keys in its own prevAgentsRef and only observes the old key disappearing. A live/done agent has no retention suppressor on the source key (suppressors are only planted on explicit teardown), so moving suppressors is a no-op and the source key is left unguarded — the hook misreads the migration as a "done agent that vanished" and resurrects it as a retained snapshot. The retained row's activation callback is a no-op, so the duplicate can't be opened.

Fix

Plant a one-shot retention suppressor on the source key during transferAgentPaneAuthority, so the disappear the hook later observes is consumed instead of retained. Guarded on from in s.agentStatusByPaneKey (the source actually held a live agent) — mirroring the existing hasLive guards elsewhere in the slice — so a suppressor is never leaked for a pane that never had an agent (e.g. detaching a plain terminal pane).

Changes

  • agent-status.ts — transferAgentPaneAuthority now plants a guarded one-shot suppressor on the source paneKey.
  • terminal-pane-detach-agent-identity.test.ts — flipped the stale assertion (source key now carries the suppressor).
  • terminal-pane-detach-agent-retention.test.ts (new) — regression coverage for the store→retention-hook contract: a detached done agent produces no ghost row, and an agent-less pane detach plants no (leaking) suppressor.

Test plan

  • vitest on affected suites — 56 passed (agent-status, detach-identity, detach-retention, useRetainedAgents, useRetainedAgentsSync)
  • Renderer typecheck (tsc -p config/tsconfig.tc.web.json) — clean
  • Independent codex exec review — no correctness issues found
  • Live app inspection via CDP after a done-agent detach — retainedAgentsByPaneKey empty (no ghost row), suppressor consumed

Notes

  • Desktop + web client share this renderer store, so both are fixed. orca-mobile is a separate app that doesn't use this slice and is unaffected.

🤖 Generated with Claude Code

ELI5

Detaching a finished split-pane agent into its own tab left a ghost duplicate sidebar row and wrong agent counts. Detach now moves identity cleanly so only one real row remains.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Pane authority transfer now applies conditional source-pane retention suppression when migrating live agent state, while continuing to move pane-keyed state. Tests cover suppression expectations, migrated completed-agent status, consumption by retained-agent collection, and the absence of suppression when the detached pane had no live agent.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning Summary/testing are detailed, but the required Screenshots, AI Review Report, and Security Audit sections are missing. Add the missing template sections, including 'No visual change' for screenshots, a cross-platform AI review report, and a security audit summary.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code and tests address #10675 by preserving the detached agent on the new pane key while suppressing retention of the old key, preventing duplicates and count inflation.
Out of Scope Changes check ✅ Passed The changes stay focused on the detach/retention bug and related tests; no unrelated code paths or features were introduced.
Title check ✅ Passed Title is concise and matches the main bug fix: preventing duplicate sidebar rows on completed split-pane detach.

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.

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

🧹 Nitpick comments (1)
src/renderer/src/store/slices/agent-status.ts (1)

1306-1314: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Condense the duplicated retention rationale.

Keep a single concise “why” beside the production mutation and remove or reduce the test preamble; the test name and assertions already convey the scenario.

  • src/renderer/src/store/slices/agent-status.ts#L1306-L1314: replace the multi-line walkthrough with a one-line explanation of suppressing the old live key during migration.
  • src/renderer/src/store/slices/terminal-pane-detach-agent-retention.test.ts#L8-L14: remove the duplicated mechanism description or reduce it to one line.

As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 14d45ec1-f952-4de9-af17-3c89e7c52c90

📥 Commits

Reviewing files that changed from the base of the PR and between c67aadb and c6f19827d46df3c5bb3329a15e480e68437842af.

📒 Files selected for processing (3)
  • src/renderer/src/store/slices/agent-status.ts
  • src/renderer/src/store/slices/terminal-pane-detach-agent-identity.test.ts
  • src/renderer/src/store/slices/terminal-pane-detach-agent-retention.test.ts

forwaryan and others added 2 commits July 28, 2026 16:18
…detach

Detaching a done-state split pane into its own tab migrated the agent
paneKey from oldTab:leaf to newTab:leaf. useRetainedAgentsSync only saw
the old key vanish and, finding no suppressor, resurrected it as an
unclickable duplicate sidebar row (and inflated the worktree count).

Plant a one-shot retention suppressor on the source key during
transferAgentPaneAuthority, but only when the source actually held a
live agent, so a suppressor is never leaked for a pane that had none.

Fixes stablyai#10675

Co-Authored-By: Claude <[email protected]>
…tion comments

Type the migrated retentionSuppressedPaneKeys as Record<string, true> so a
computed-key `true` isn't widened to boolean, which broke the web typecheck.
Also condense the retention rationale comments per review.

Co-Authored-By: Claude <[email protected]>
@OrcaWin
OrcaWin force-pushed the fix/10675-detach-pane-ghost-agent-row branch from 059861d to fb09feb Compare July 28, 2026 23:20
@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a ghost sidebar row that appeared when detaching a completed split-pane agent into its own tab. The root cause was that transferAgentPaneAuthority migrated the paneKey atomically but left the source key unguarded, causing useRetainedAgentsSync to misread the migration as a "done agent that vanished" and resurrect a stale, unclickable duplicate row.

  • agent-status.ts: transferAgentPaneAuthority now plants a one-shot retention suppressor on the source key (guarded by fromWasLive to avoid leaking suppressors for agent-less panes), mirroring the existing pattern used in explicit-teardown paths.
  • terminal-pane-detach-agent-identity.test.ts: Existing assertion flipped to toBe(true) to reflect the new suppressor placement.
  • terminal-pane-detach-agent-retention.test.ts (new): End-to-end regression tests that verify no ghost row is produced after a done-agent detach and that a plain terminal detach plants no suppressor.

Confidence Score: 5/5

Safe to merge — the change is a single atomic store update that closes a narrow retention-hook race without touching any public APIs or rendering paths.

The fix is minimal and well-scoped: one new suppressor write in transferAgentPaneAuthority, guarded exactly the same way existing suppressors are guarded elsewhere in the slice. The atomic set() ensures the suppressor and the paneKey migration land in the same snapshot, so the retention hook can never observe a window where the source key is absent but unguarded. Two new tests exercise the store→hook contract directly, and the updated identity test locks in the expected suppressor state.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/store/slices/agent-status.ts Targeted fix in transferAgentPaneAuthority: plants a guarded one-shot suppressor on the source paneKey to prevent useRetainedAgentsSync from creating a ghost row; logic is atomic, correctly guarded on fromWasLive, and mirrors existing suppressor patterns in the slice.
src/renderer/src/store/slices/terminal-pane-detach-agent-identity.test.ts Single assertion correctly flipped from toBeUndefined() to toBe(true) to reflect the new suppressor planted on the source key during transfer.
src/renderer/src/store/slices/terminal-pane-detach-agent-retention.test.ts New regression test covering both the done-agent detach (suppressor consumed, no ghost row) and the agent-less pane detach (no suppressor leak) scenarios; exercises the full store→hook contract via collectRetainedAgentsOnDisappear.

Reviews (1): Last reviewed commit: "fix(agent-status): annotate suppressor r..." | Re-trigger Greptile

@OrcaWin
OrcaWin merged commit 638c3ca into stablyai:main Jul 28, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…detach (stablyai#10698)

* fix(agent-status): prevent ghost sidebar row on completed split-pane detach

Detaching a done-state split pane into its own tab migrated the agent
paneKey from oldTab:leaf to newTab:leaf. useRetainedAgentsSync only saw
the old key vanish and, finding no suppressor, resurrected it as an
unclickable duplicate sidebar row (and inflated the worktree count).

Plant a one-shot retention suppressor on the source key during
transferAgentPaneAuthority, but only when the source actually held a
live agent, so a suppressor is never leaked for a pane that had none.

Fixes stablyai#10675

Co-Authored-By: Claude <[email protected]>

* fix(agent-status): annotate suppressor record type and condense retention comments

Type the migrated retentionSuppressedPaneKeys as Record<string, true> so a
computed-key `true` isn't widened to boolean, which broke the web typecheck.
Also condense the retention rationale comments per review.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
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.

[Bug]: Detaching a completed split-pane agent into its own tab splits the same session into two sidebar rows, and the old row can't be opened

4 participants