Skip to content

fix(agent-status): clear worktree-attributed orphans on relay/daemon teardown (#9030) - #9878

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-9030-agent-status-clear
Jul 22, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-9030-agent-status-clear

Conversation

@nwparker

@nwparker nwparker commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

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 clearTransientAgentStatuses only removed rows whose connectionId stamp matched. Orphaned rows on that host have an absent/mis-normalized connectionId, so they never matched and lived on as "fresh" for AGENT_STATUS_STALE_AFTER_MS (30 min). Their backing tab is gone, so the row's click handler silently no-ops (WorktreeCardAgents keeps 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 getWorktreeExecutionHostId precedence (worktree hostId first, 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:

  • Host-scoped, not repo-scoped. An adversarial review caught that an earlier repo-id-based version would clear a live row on a different host that happens to share a repo id (Orca supports the same repo id on multiple hosts, sharing one worktreesByRepo bucket, distinguished by Worktree.hostId). Fixed by resolving each worktree's host via getWorktreeExecutionHostId — 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).
  • Freshness cutoff preserved: rows updated after the clear watermark survive, so a genuinely live-but-quiet row isn't dropped.
  • Local rows untouched (connectionId: null never matches a real target).
  • Repopulation intact: a still-live agent's row replays after reconnect (the existing block flag resets on connected).
  • 14 tests pass across the clear/activation suites, including the existing "keep a live worktree-attributed row visible while its tab is hydrating" contract. oxlint + oxfmt clean.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Transient 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description has useful content but misses most required template sections, including Screenshots, Testing, AI Review Report, Security Audit, and Notes. Add the required template sections and complete the Testing, AI Review Report, Security Audit, and Notes entries.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the core fix: clearing orphaned agent-status rows during relay/daemon teardown.
Linked Issues check ✅ Passed The code and tests address #9030 by clearing orphaned SSH agent rows via worktree host ownership while preserving freshness and cross-host safety.
Out of Scope Changes check ✅ Passed The changes stay within the agent-status clearing path and its regression tests, with no obvious unrelated functionality added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

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.ts
  • src/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]>
@nwparker
nwparker force-pushed the nwparker/fix-9030-agent-status-clear branch from 02b6634 to a9974b0 Compare July 22, 2026 09:43

@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-ssh-connection-clear.test.ts (1)

120-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover 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 cleared connectionId: null rows during worktree inference. Add a local row on wt-a and 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.ts
  • src/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

@nwparker
nwparker merged commit 7304776 into main Jul 22, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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]: Sidebar agent rows become permanently unclickable after the remote relay daemon restarts

1 participant