Repository navigation
fix(agent-status): clear worktree-attributed orphans on relay/daemon teardown (#9030) - #9878
Conversation
📝 WalkthroughWalkthroughTransient agent-status cleanup now derives worktree IDs from a connection’s repository and execution-host relationships. Rows are cleared when their connection ID matches or their worktree belongs to the connection, while the existing cutoff timestamp remains enforced. Tests cover missing connection stamps, newer rows, unrelated worktrees, and hosts sharing repository identifiers. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6d1fe7c1-bdf2-4cd8-8ba0-58a8e397f662
📥 Commits
Reviewing files that changed from the base of the PR and between e600600 and 02b6634300c05bc6f3c2c96bff2073a8c338c5cb.
📒 Files selected for processing (2)
src/renderer/src/store/slices/agent-status-ssh-connection-clear.test.tssrc/renderer/src/store/slices/agent-status.ts
…teardown (#9030) After a relay daemon restarts on an SSH host, main drops its status rows but renderer agentStatusByPaneKey entries whose connectionId stamp never matched (unstamped / SSH-mis-normalized) survived, stayed 'fresh' for 30 minutes, and made their sidebar rows permanently un-clickable (tab gone, handleActivateAgentTab silently returns). Broaden the transient clear to also drop worktree-attributed rows whose owning repo is on the torn-down connection, proving the host via the worktree->repo mapping instead of relying solely on the entry's connectionId. Co-authored-by: Orca <[email protected]>
02b6634 to
a9974b0
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/store/slices/agent-status-ssh-connection-clear.test.ts (1)
120-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover explicit local ownership in the inferred-worktree path.
The existing local fixture has no
worktreeId, so this test would still pass if a future nullish check clearedconnectionId: nullrows during worktree inference. Add a local row onwt-aand assert it survives.Suggested regression case
const otherHostB = 'tab-b:33333333-3333-4333-8333-333333333333' + const localOnA = 'tab-local:44444444-4444-4444-8444-444444444444' ... + store.getState().setAgentStatus( + localOnA, + { state: 'working', prompt: 'local', agentType: 'codex' }, + undefined, + { updatedAt: 10 }, + { connectionId: null, worktreeId: 'wt-a' } + ) ... expect(store.getState().agentStatusByPaneKey[otherHostB]).toBeDefined() + expect(store.getState().agentStatusByPaneKey[localOnA]).toBeDefined()As per PR objectives, cleanup must not remove local rows.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d7bb0c9a-aadb-477e-a2a9-585cc1d13543
📥 Commits
Reviewing files that changed from the base of the PR and between 02b6634300c05bc6f3c2c96bff2073a8c338c5cb and a9974b0.
📒 Files selected for processing (2)
src/renderer/src/store/slices/agent-status-ssh-connection-clear.test.tssrc/renderer/src/store/slices/agent-status.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/store/slices/agent-status.ts
…teardown (stablyai#9030) (stablyai#9878) After a relay daemon restarts on an SSH host, main drops its status rows but renderer agentStatusByPaneKey entries whose connectionId stamp never matched (unstamped / SSH-mis-normalized) survived, stayed 'fresh' for 30 minutes, and made their sidebar rows permanently un-clickable (tab gone, handleActivateAgentTab silently returns). Broaden the transient clear to also drop worktree-attributed rows whose owning repo is on the torn-down connection, proving the host via the worktree->repo mapping instead of relying solely on the entry's connectionId. Co-authored-by: Orca <[email protected]>
Fixes #9030.
What & why
After an SSH host's relay/daemon restarts (crash or manual kill), agent rows for that host stayed visible in the sidebar but clicking them did nothing for up to 30 minutes.
On teardown, main clears its agent-status rows and broadcasts a transient clear, but the renderer's
clearTransientAgentStatusesonly removed rows whoseconnectionIdstamp matched. Orphaned rows on that host have an absent/mis-normalizedconnectionId, so they never matched and lived on as "fresh" forAGENT_STATUS_STALE_AFTER_MS(30 min). Their backing tab is gone, so the row's click handler silently no-ops (WorktreeCardAgentskeeps a live-looking row and returns).Fix: when clearing a lost connection, also drop rows whose owning worktree's host belongs to that connection — resolved via the canonical
getWorktreeExecutionHostIdprecedence (worktreehostIdfirst, repo fallback). The renderer now converges to main's already-clean state (exactly what a window reload does today), so there's no dead row left to click.ELI5
When a remote host's background service restarts, the app is supposed to forget that host's "agent is working" rows. Some rows had a missing host label, so it kept them for 30 minutes — they looked clickable but did nothing. Now we read each row's host from its worktree, so the stale ones clear right away.
Proof of fix
Unit test: an unstamped orphan row on a torn-down host's worktree is now cleared (it survived before).
Proof of no regression
This is a clearing path, so the risk is over-clearing (hiding live rows). Guards:
worktreesByRepobucket, distinguished byWorktree.hostId). Fixed by resolving each worktree's host viagetWorktreeExecutionHostId— the exact hostId-first precedence every other sidebar host decision uses. Regression test added (shared repo id across two hosts → the other host's row survives).connectionId: nullnever matches a real target).connected).oxlint+oxfmtclean.Made with Orca 🐋