Skip to content

Fix hide completed agents after tab close - #5914

Closed
Br1NKOL wants to merge 1 commit into
stablyai:mainfrom
Br1NKOL:fix/pi-agent-tab-close-cleanup
Closed

Br1NKOL wants to merge 1 commit into
stablyai:mainfrom
Br1NKOL:fix/pi-agent-tab-close-cleanup

Conversation

@Br1NKOL

@Br1NKOL Br1NKOL commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a stale compact agent row after closing a Pi terminal tab. Completed agent rows that are only worktree-attributed are no longer rendered as live sidebar rows once their owning terminal tab is gone.

The existing worktree-attribution fallback is preserved for active rows, so early child-agent statuses can still appear before their tab reaches the renderer.

Fixes #5913

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Targeted checks run:

  • pnpm test src/renderer/src/components/sidebar/worktree-agent-row-selectors.test.ts - passed
  • pnpm typecheck - passed

AI Review Report

The fix was narrowed after live debugging the dev renderer state. The stale Pi row was present in agentStatusByPaneKey, not retainedAgentsByPaneKey; its tabId no longer existed in tabsByWorktree / unifiedTabsByWorktree, but the sidebar selector still fell back to entry.worktreeId and rendered the completed row as live.

Main risks checked:

  • Avoided removing the worktree-attribution fallback entirely, because existing tests cover active child-agent rows that may arrive before their tab is visible in the renderer.
  • Scoped the behavior change to completed done rows whose parsed tab is not in the current terminal tab index.
  • Added a regression test for a completed Pi-style row whose tab is gone.
  • Kept the patch limited to the sidebar row selector and its test after trimming broader speculative cleanup.

Cross-platform compatibility:

  • This PR touches renderer selector logic only.
  • No platform-specific shortcuts, labels, shell behavior, filesystem paths, process launching, IPC contracts, or Electron main/preload behavior are changed.
  • The behavior is data-shape based and applies consistently on macOS, Linux, and Windows.

Security Audit

This PR changes only local renderer selection of already-present agent status records.

Reviewed risk areas:

  • Input handling: no new user input parsing.
  • Command execution: no command execution changes.
  • Path handling: no path handling changes.
  • Auth/secrets: no auth, token, credential, or secret handling changes.
  • Dependencies: no dependency changes.
  • IPC/network: no IPC, preload, main-process, network, or persistence changes.

No security follow-up identified.


Open in Stage

@ghost

ghost commented Jun 20, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 1 individual chapter for you:

Title
1 Hide completed agent rows when tabs are closed
Open in Stage

Chapters generated by Stage for commit 86c7059 on Jun 20, 2026 10:43am UTC.

@Br1NKOL Br1NKOL changed the title fix: hide completed agents after tab close Fix hide completed agents after tab close Jun 20, 2026
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0db3efd5-ff56-4fd6-be99-38afdd7c2821

📥 Commits

Reviewing files that changed from the base of the PR and between 6dd82b9 and 86c7059.

📒 Files selected for processing (2)
  • src/renderer/src/components/sidebar/worktree-agent-row-selectors.test.ts
  • src/renderer/src/components/sidebar/worktree-agent-row-selectors.ts

📝 Walkthrough

Walkthrough

The getLiveEntriesByWorktree function in worktree-agent-row-selectors.ts is updated so that the worktreeId for a live entry is derived from the tab-to-worktree mapping when available. When no mapping exists, the previous entry.worktreeId fallback is now withheld for entries whose state is 'done', leaving them without a worktree association and causing them to be filtered out of the sidebar. A corresponding Vitest test case is added to worktree-agent-row-selectors.test.ts asserting that selectLiveAgentStatusEntriesForWorktree returns an empty array when a completed row's tabId is not present in tabsByWorktree.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main bug fix: preventing completed agent rows from remaining visible after tab closure.
Description check ✅ Passed The PR description comprehensively covers all required template sections including summary, screenshots, testing checklist with all items marked complete, detailed AI review, security audit, and cross-platform compatibility notes.
Linked Issues check ✅ Passed The PR fully addresses issue #5913 by preventing completed agent rows from rendering when their tab no longer exists, while preserving worktree-attribution fallback for active rows.
Out of Scope Changes check ✅ Passed All changes are narrowly scoped to the sidebar row selector logic and its test, directly addressing the stated objectives without extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@brennanb2025

Copy link
Copy Markdown
Contributor

I opened a root-cause fix in #6095 that clears the main-process cache on tab close and suppresses late hook/status replays for that closed tab id. That should make this selector-only guard unnecessary for the original bug, since the stale row should no longer exist in renderer state after the tab is closed.

I’m going to hold off on merging this PR and treat #6095 as the fix. If you're still seeing this issue after updating to the version with #6095 (should be out in less than a day), we can revisit this patch separately. Thanks for the PR!

nwparker added a commit that referenced this pull request Jun 30, 2026
A 'done' Pi agent entry lingers in agentStatusByPaneKey after its
terminal tab is closed: its paneKey's tabId no longer matches any open
tab, so dropAgentStatusByTabPrefix never sweeps it. The sidebar selector
getLiveEntriesByWorktree used an unconditional fallback
(tabIdToWorktreeId.get(parsed.tabId) ?? entry.worktreeId), added in
#4371 to surface early child-agent rows before their tab reaches the
renderer. That fallback re-attributed the orphaned 'done' entry to the
worktree, so buildWorktreeAgentRows rendered it as a stale live 'Done'
row forever (Codex/Claude tear down cleanly because their pane/tab
keying matches the closed tab).

Restrict the worktree-attribution fallback to non-'done' entries so
completed rows whose tab is gone are dropped, while still surfacing
active child rows whose tab has not yet reached the renderer.

Supersedes #5914 (adopted and re-verified).

Fixes #5913

Co-authored-by: Alberto Cuervo <[email protected]>
nwparker added a commit that referenced this pull request Jul 10, 2026
A 'done' Pi agent entry lingers in agentStatusByPaneKey after its
terminal tab is closed: its paneKey's tabId no longer matches any open
tab, so dropAgentStatusByTabPrefix never sweeps it. The sidebar selector
getLiveEntriesByWorktree used an unconditional fallback
(tabIdToWorktreeId.get(parsed.tabId) ?? entry.worktreeId), added in
#4371 to surface early child-agent rows before their tab reaches the
renderer. That fallback re-attributed the orphaned 'done' entry to the
worktree, so buildWorktreeAgentRows rendered it as a stale live 'Done'
row forever (Codex/Claude tear down cleanly because their pane/tab
keying matches the closed tab).

Restrict the worktree-attribution fallback to non-'done' entries so
completed rows whose tab is gone are dropped, while still surfacing
active child rows whose tab has not yet reached the renderer.

Supersedes #5914 (adopted and re-verified).

Fixes #5913

Co-authored-by: Alberto Cuervo <[email protected]>
nwparker added a commit that referenced this pull request Jul 11, 2026
* fix: sweep completed Pi agent row when its terminal tab is closed

A 'done' Pi agent entry lingers in agentStatusByPaneKey after its
terminal tab is closed: its paneKey's tabId no longer matches any open
tab, so dropAgentStatusByTabPrefix never sweeps it. The sidebar selector
getLiveEntriesByWorktree used an unconditional fallback
(tabIdToWorktreeId.get(parsed.tabId) ?? entry.worktreeId), added in
#4371 to surface early child-agent rows before their tab reaches the
renderer. That fallback re-attributed the orphaned 'done' entry to the
worktree, so buildWorktreeAgentRows rendered it as a stale live 'Done'
row forever (Codex/Claude tear down cleanly because their pane/tab
keying matches the closed tab).

Restrict the worktree-attribution fallback to non-'done' entries so
completed rows whose tab is gone are dropped, while still surfacing
active child rows whose tab has not yet reached the renderer.

Supersedes #5914 (adopted and re-verified).

Fixes #5913

Co-authored-by: Alberto Cuervo <[email protected]>

* fix: drop completed Pi orphan during tab close

* fix: skip retention suppressor for completed-orphan keys during tab close

A completed-orphan key's tab is already gone, so buildRetainedAgentsSyncSnapshot
never snapshots it and no live->gone transition ever fires to consume a planted
retention suppressor. Planting one leaked a permanent retentionSuppressedPaneKeys
entry per swept orphan. Plant suppressors only for prefix-matched keys.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Alberto Cuervo <[email protected]>
Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lyai#6584)

* fix: sweep completed Pi agent row when its terminal tab is closed

A 'done' Pi agent entry lingers in agentStatusByPaneKey after its
terminal tab is closed: its paneKey's tabId no longer matches any open
tab, so dropAgentStatusByTabPrefix never sweeps it. The sidebar selector
getLiveEntriesByWorktree used an unconditional fallback
(tabIdToWorktreeId.get(parsed.tabId) ?? entry.worktreeId), added in
stablyai#4371 to surface early child-agent rows before their tab reaches the
renderer. That fallback re-attributed the orphaned 'done' entry to the
worktree, so buildWorktreeAgentRows rendered it as a stale live 'Done'
row forever (Codex/Claude tear down cleanly because their pane/tab
keying matches the closed tab).

Restrict the worktree-attribution fallback to non-'done' entries so
completed rows whose tab is gone are dropped, while still surfacing
active child rows whose tab has not yet reached the renderer.

Supersedes stablyai#5914 (adopted and re-verified).

Fixes stablyai#5913

Co-authored-by: Alberto Cuervo <[email protected]>

* fix: drop completed Pi orphan during tab close

* fix: skip retention suppressor for completed-orphan keys during tab close

A completed-orphan key's tab is already gone, so buildRetainedAgentsSyncSnapshot
never snapshots it and no live->gone transition ever fires to consume a planted
retention suppressor. Planting one leaked a permanent retentionSuppressedPaneKeys
entry per swept orphan. Plant suppressors only for prefix-matched keys.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Alberto Cuervo <[email protected]>
Co-authored-by: Orca <[email protected]>
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]: Pi compact agent row remains after closing its terminal tab

2 participants