Repository navigation
fix: hide completed Pi agent row after closing its terminal tab - #6584
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughCompleted agent entries are now hidden when their tabs are absent. Tab-close cleanup can identify completed orphan entries within the closing tab’s worktree and remove related status, launch, retention, and acknowledgement state. The closing tab now passes its worktree scope to cleanup, with tests covering removal of targeted entries and preservation of unrelated rows. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
Evidence1. Regression test fails on the pre-fix treeWith only the new test added and the source fallback reverted ( 2. Passes after the fix (8/8)3. Full sidebar suite — no neighboring regressions4. Live verification in the running Electron renderer (CDP attach)Attached to the dev build of this branch ( {"doneOrphanRows":0,"doneOrphanStates":[],"activeChildRows":1,"activeChildStates":["working"]}
5. Local gate
Before / after reasoningBefore: After: |
Note on the screenshot / live agent reproThe end-to-end visual repro (start a real Pi agent, let it reach |
ec722cd to
1d09e99
Compare
Takeover updateRebased this PR onto latest Tradeoff status: zero user-visible tradeoff remains. In addition to the selector backstop, closing a terminal tab now passes the closing worktree into Validation:
Note: this supersedes the body's earlier future-suggestion note about relying only on the selector. The selector remains as a defensive guard for stale/hydrated rows, but the normal renderer tab-close path now removes the completed Pi orphan at source. |
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]>
1d09e99 to
84aa3b5
Compare
|
Final current-head validation (supersedes the older takeover update): rebased onto origin/main c5669cc at head 84aa3b5; GitHub reports MERGEABLE/CLEAN. Exact production-selector red/green reproduced the stale pi/done row before the guard and zero rows after it. The closeTab lifecycle regression plus neighboring suites pass 137/137; full node/CLI/web typecheck, changed-file oxlint, reliability-manifest validation, max-lines ratchet, and diff check pass. Fresh GitHub verify and CodeRabbit checks both passed; CodeRabbit generated no actionable inline comments. The PR body now contains the requested Description, before/after Evidence, ELI5, User-facing trade-offs, and explicit reliability/provider/performance gaps. Full repo lint remains blocked only by the unrelated current-main ja.json localization mismatch documented in the body. |
…lose 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]>
|
Reviewed on top of latest main (clean rebase check; merge result verified byte-identical on all touched files).
|
…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]>
Description
Fixes #5913.
Closing a terminal tab could leave Pi's completed compact agent row visible as
Doneon the workspace card. The stale entry was still inagentStatusByPaneKey, but its pane key referred to a tab that no longer existed intabsByWorktree. The sidebar selector then used the entry'sworktreeIdfallback—originally added so active child agents can appear before their tab reaches the renderer—and rendered the orphan as live.This PR hardens both lifecycle boundaries:
closeTabpasses the closing worktree into agent-status teardown so it also removes completed, worktree-attributed orphan rows whose pane-key tab does not match the tab being closed. It preserves active pre-render child rows, completed rows with an open tab, and rows owned by other worktrees.The branch was rebased onto current
origin/main(c5669cceb5) and its terminal teardown conflict was resolved against the current cleanup path.This PR supersedes community PR #5914 and preserves its original author credit in the commit.
Evidence of fix (before + after)
Before: current
mainselector behaviorOn the rebased worktree, I temporarily restored the current-main unconditional fallback while keeping the regression assertion, then ran:
Result: 1 failed. The production selector returned the stale row instead of
[]:This reproduces the issue comment's post-close state: the completed Pi tab is absent from
tabsByWorktree, but the live-status map still contains its attributed row.After: PR head
Restoring the PR guard and running the same command produced:
The selector returned zero live rows for the orphaned
doneentry.The source-level lifecycle test now calls
closeTabitself. It proves that closing a tab removes the mismatched completed Pi orphan and its matching row, while retaining an active pre-render child row, a completed row with an open tab, and another worktree's orphan.Electron sidebar evidence
I launched the rebased PR in an isolated Electron profile and injected the confirmed post-close state through the real renderer store:
agentStatusByPaneKeycontained a Pidoneentry attributed to the visible worktree, and its tab was absent.Donerow rendered.workingentry rendered on the same card as Working, proving the early active-row behavior remains visible.The Pi CLI is not installed on this machine, so this Electron check exercises the production store/selector/render path but not a real Pi hook process or terminal teardown.
Validation commands
pnpm lintpasses oxlint, switch exhaustiveness, styled-scrollbar checks, reliability-manifest validation, and the max-lines ratchet, then stops on an unrelated current-main localization mismatch inja.jsonforcomponents.native-chat.composer.uploadingAttachments. This PR does not edit localization files.ELI5
The sidebar has a backup rule: if an agent's tab has not appeared yet, use the workspace name on its badge so the user can still see that active agent. Pi could leave an old badge behind after its finished tab was closed, so the backup rule kept seating a ghost at the table.
Now the backup rule still helps agents that are actively working or waiting for attention, but it does not revive a finished agent whose tab is gone. Closing a tab also sweeps that specific kind of finished orphan from memory.
User-facing trade-offs
Donerow on the workspace card.donelive-status entry that has no renderer tab is hidden rather than shown through the early-attribution fallback. Completed-session history remains the responsibility of the existing retained-agent path.Terminal/session reliability proof
agent-session.tab-close-status-ownership.closeTabtest proves the orphan is removed at the lifecycle source while the three preservation cases survive.tabsByWorktree,agentStatusByPaneKey, and the deterministic selector/closeTabassertions.none). The existingagent-session.provider-ownershipgate is unchanged and does not claim this display-cleanup invariant; a new manifest entry would be premature without a real Pi integration fixture.Security audit
No new input parsing, command execution, path handling, auth, secret, dependency, IPC, or network surface is introduced. The fix operates on existing structured in-memory state.
Made with Orca 🐋