Repository navigation
fix(sidebar): retain remote OMP rows before tab hydration - #20616
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change keeps completed remote OMP entries visible until host retraction while hiding local completed orphans. It adds environment- and worktree-specific mirrored-tab mapping and retraction. It scopes cleanup to host-owned panes during collisions. Unit tests and a hidden Electron fixture cover attribution, isolation, hydration, rendering, and empty-state behavior. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Mixed retraction batches can leave stale terminal and agent state behind. Scope collision handling per tab before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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: Advanced
Run ID: 87b3ce3f-133f-4b46-9ca4-72640dd05321
📒 Files selected for processing (13)
src/renderer/src/components/sidebar/worktree-agent-live-index-patch.tssrc/renderer/src/components/sidebar/worktree-agent-remote-attribution.test.tssrc/renderer/src/runtime/web-session-tabs-sync/agent-status-primitives.tssrc/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.tssrc/renderer/src/runtime/web-session-tabs-sync/apply-preparation-base.tssrc/renderer/src/runtime/web-session-tabs-sync/mirrored-status-tab-retractions.test.tssrc/renderer/src/runtime/web-session-tabs-sync/mirrored-status-tab-retractions.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking-mappings.tstests/tools/omp-remote-sidebar-rendered/README.mdtests/tools/omp-remote-sidebar-rendered/fixture.csstests/tools/omp-remote-sidebar-rendered/fixture.tsxtests/tools/omp-remote-sidebar-rendered/index.htmltests/tools/omp-remote-sidebar-rendered/run.mjs
💤 Files with no reviewable changes (1)
- src/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions on the retraction surface, inline.
Reviewed changes
- Remote row retention —
liveEntryWorktreeIdnow keepsdonerows whose entry carries aconnectionIdor whose pane key uses aweb-terminal-*tab id, so paired/SSH OMP rows render before their tab hydrates; the live-index patch bail-out also watchesconnectionIdpresence. - Host-tab retraction — new
collectUnhydratedMirroredTabRetractionssweeps a mirrored row whose host stopped publishing even whentabsByWorktreenever held its tab, driven by the previous snapshot's host mapping;buildRetractedMirroredTabSweepPatchno longer receives a worktree id. - Tests — attribution/retraction/host-isolation coverage, a 100-workspace single-enumeration regression, and a hidden Electron rendered fixture. Verified 7/7 pass, and reverting only the
liveEntryWorktreeIdpredicate fails 3 of them — the regression tests are real.
ℹ️ Retraction still depends on a host mapping that other lifecycle events clear
collectUnhydratedMirroredTabRetractions derives its candidates from hostSessionTabIdsByLocalTabForWorktree, which updateHostSessionTabIdMappings clears and rebuilds on every snapshot apply, and which clearWebSessionTabsTrackingForWorktree / clearWebSessionTabsTrackingForEnvironment delete outright. Because the collect runs in the base stage before the unified stage rebuilds the mapping, an ordinary in-worktree retraction sees the previous mapping and works. The gap is states where a mapping is cleared with no in-worktree snapshot to rebuild it afterwards, leaving the row relying on entry.worktreeId with no remaining retraction trigger.
Technical details
# Retraction depends on a mapping that tracking teardown clears
## Affected sites
- `src/renderer/src/runtime/web-session-tabs-sync/mirrored-status-tab-retractions.ts:17-28` — candidates require an entry in `hostSessionTabIdsByLocalTabForWorktree`.
- `src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts:145` — `clearHostSessionTabIdMappings` on worktree removal / visibility tombstone; `:207-216` clears an entire environment.
- `src/renderer/src/runtime/web-session-tabs-sync/apply-preparation-base.ts:193` and `apply-final-patch.ts:63` — the tombstone frame skips both retraction branches by design.
- `src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts:164` — mirrored non-client-owned rows are deleted on the tombstone; client-owned rows (`isClientAuthoritativeAgentStatusPane`) are exempt and survive.
- `src/renderer/src/components/sidebar/worktree-agent-live-index-patch.ts:34` — the row then renders because it is "remote".
## Required outcome
- Either guarantee that a remote `done` row which outlives its host mapping is still retractable (or bounded), or make the "remove them when the authoritative host retracts the tab — even if local hydration never occurred" claim match what the code does.
## Open questions for the human
- Is the tombstone an intentional retention boundary (row should survive a visibility removal and re-render when the worktree returns), or should a client-owned mirrored row be reaped once its host mapping is gone?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| } | ||
| const tabWorktreeId = tabIdToWorktreeId.get(parsed.tabId) | ||
| return tabWorktreeId ?? (entry.state === 'done' ? undefined : entry.worktreeId) | ||
| const remote = Boolean(entry.connectionId) || isWebTerminalSurfaceTabId(parsed.tabId) |
There was a problem hiding this comment.
This predicate keeps a done row visible for any truthy connectionId, but collectUnhydratedMirroredTabRetractions only retracts web-terminal-* tab ids that appear in hostSessionTabIdsByLocalTabForWorktree.
Technical details
# Render predicate is broader than the retraction surface
## Affected sites
- `src/renderer/src/components/sidebar/worktree-agent-live-index-patch.ts:34` — `remote = Boolean(entry.connectionId) || isWebTerminalSurfaceTabId(parsed.tabId)`.
- `src/renderer/src/runtime/web-session-tabs-sync/mirrored-status-tab-retractions.ts:21-25` — candidate filter requires `isWebTerminalSurfaceTabId(tabId)` AND a host mapping; a truthy `connectionId` alone never qualifies.
- `src/renderer/src/hooks/ipc-events/agent-status-event-applicator.ts:84-95` — runtime-backed attribution (`hasRuntimeBackedWorktreeAttribution`) can mint a remote entry with a `worktreeId` while its tab is absent, and `routing.connectionId` is set from the hook (`:240`).
## Required outcome
- Every `done` row the new predicate keeps visible should have a reachable retraction, or the predicate should be narrowed to the ids the retraction covers.
## Open question for the human
- For a paired host, do hook statuses arrive keyed by a raw host tab id (non-`web-terminal-`) in every code path, or are they always re-keyed through the mirrored surface? If any path produces the former, those rows are now rendered with no retraction here.| // cutoffs means a republished pane cannot replay activity the user cleared on this client. | ||
| const sweep = buildRetiredTerminalTabStateSweepPatch(sweepState, retractedTabIds, worktreeId, { | ||
| // The host retracts exact tab ids; a worktree-wide orphan sweep could erase a sibling host. | ||
| const sweep = buildRetiredTerminalTabStateSweepPatch(sweepState, retractedTabIds, undefined, { |
There was a problem hiding this comment.
Passing undefined here disables findCompletedOrphanPaneKeysForTabClose's worktree-wide branch, which sweepRetiredTerminalTabState documents as the Pi stranded-completed-row cleanup (retired-terminal-tab-state-sweep.ts:42). The new collect only covers mapped web-terminal-* ids, so a non-mirrored completed orphan dropped by a paired apply is no longer swept on this path.
Technical details
# Worktree-wide completed-orphan sweep is now dead on the paired retraction path
## Affected sites
- `src/renderer/src/runtime/web-session-tabs-sync/agent-status-primitives.ts:187` — `buildRetiredTerminalTabStateSweepPatch(sweepState, retractedTabIds, undefined, ...)`.
- `src/renderer/src/store/slices/retired-terminal-tab-state-sweep.ts:78` — `worktreeId` is only forwarded when truthy.
- `src/renderer/src/store/slices/agent-status-pane-key-tab-binding.ts:74-76` — `findCompletedOrphanPaneKeysForTabClose` returns `[]` without a worktree id.
- Only remaining worktree-id caller is the explicit local close (`src/renderer/src/store/terminals/terminal-tab-close.ts:250`).
## Required outcome
- Confirm the dropped cleanup is intentional and that removed tabs cover the client-owned/provisional rows the worktree sweep used to catch.
## Note
- No test exercises completed-orphan removal through the retraction path, so this change is not pinned either way.|
Risk-reduction review at Two new failing production-snapshot tests: retracting host A deletes live host B status when tab IDs collide, even with distinct leaves/workspaces. Existing 7 tests pass. Remaining user-facing consequence: An active remote agent can disappear from status/sidebar. Needs host-scoped retraction, not another reader cache. |
There was a problem hiding this comment.
Caution
The new host-identity guard disables the remote-tab retraction this PR exists to add, and leaves the PR's own worktree-agent-remote-attribution.test.ts red (3 of 6 tests fail). Detail inline.
Reviewed changes
- Host-identity scoping —
collectUnhydratedMirroredTabRetractionsnow retracts a candidate only whenentry.connectionId === environmentId(or, for a local nullishconnectionId,environmentId === 'local'). - Tests — added a
connectionId: 'host'stamp to the 100-workspace enumeration fixture and a newdoes not retract a colliding tab id owned by another hostcase.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 33decdd5-6a4d-421f-83d6-b0fb81ea84c9
📒 Files selected for processing (4)
src/renderer/src/components/sidebar/worktree-agent-remote-attribution.test.tssrc/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.tssrc/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.tstests/e2e/omp-risk-remote-review.unit.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| it.each(['folder:same','folder:other'])('does not erase a different environment sharing a host tab ID (%s)',otherWorktree=>{ | ||
| const initial=makeState();const a=applyWebSessionTabsSnapshot(initial,snapshot('folder:same',LEAF_ID),'host-a',NOW);const b=applyWebSessionTabsSnapshot(initial,snapshot(otherWorktree,SECOND_LEAF_ID),'host-b',NOW); | ||
| const state=makeState({agentStatusByPaneKey:{...a.agentStatusByPaneKey,...b.agentStatusByPaneKey}}); | ||
| setHostSessionTabIdMapping({environmentId:'host-b',worktreeId:'folder:same',tabId:'same-host-tab'},'same-host-tab'); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use the host B snapshot worktree for the mapping.
When otherWorktree is "folder:other", this mapping records host B under "folder:same" while its status belongs to "folder:other". The regression case then does not exercise the real cross-workspace mapping and retraction path. Replace the fixed value with otherWorktree.
Proposed fix
- setHostSessionTabIdMapping({environmentId:'host-b',worktreeId:'folder:same',tabId:'same-host-tab'},'same-host-tab');
+ setHostSessionTabIdMapping({environmentId:'host-b',worktreeId:otherWorktree,tabId:'same-host-tab'},'same-host-tab');📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| setHostSessionTabIdMapping({environmentId:'host-b',worktreeId:'folder:same',tabId:'same-host-tab'},'same-host-tab'); | |
| setHostSessionTabIdMapping({environmentId:'host-b',worktreeId:otherWorktree,tabId:'same-host-tab'},'same-host-tab'); |
There was a problem hiding this comment.
Caution
The isolation test added in 597b781 (tests/e2e/omp-risk-remote-review.unit.test.ts) fails on this commit — both cases. The mirrored retraction sweep deletes every row under the retracted tab id, so host-a's retraction still erases host-b's row; the collect guard only gates which tab ids are collected. The connectionId stamp also drops palette agent metadata for mirrored tabs. Details inline.
Reviewed changes
- Host identity on mirrored statuses —
buildMirroredAgentStatusPatchnow stampsconnectionId: environmentIdwhen a remapped host entry has none, socollectUnhydratedMirroredTabRetractions's guard matches and the paired retraction fires; the prior review's failing attribution/retraction tests pass again. - Retraction sweep scoping —
buildRetractedMirroredTabSweepPatchdrops its worktree-id parameter and always passesundefined, with a comment that a worktree-wide orphan sweep could erase a sibling host. - Isolation test — new
tests/e2e/omp-risk-remote-review.unit.test.tsasserts two environments sharing a mirrored host tab id stay isolated.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| nextByPaneKey.get(hostEntry.paneKey) ?? state.agentStatusByPaneKey[hostEntry.paneKey] | ||
| const entry = withMirroredEvidenceReceipt(hostEntry, existing, now) | ||
| const entry = withMirroredEvidenceReceipt( | ||
| hostEntry.connectionId === undefined ? { ...hostEntry, connectionId: environmentId } : hostEntry, |
There was a problem hiding this comment.
Stamping the environment id here is read as an SSH host alias by an existing reader this PR does not touch: collectAgentMetadataFromIndex (lib/workspace-tab-agent-metadata.ts:289-291) calls isExecutionHostAliasForWorktree(toSshExecutionHostId(entry.connectionId), worktree), and toSshExecutionHostId(environmentId) can never equal a mirrored worktree's runtime:<env> host. Mirrored terminal tabs that previously qualified (undefined connectionId, non-ambiguous worktree) now drop their agent metadata in the Cmd+J palette.
Technical details
# `connectionId` stamp changes palette agent-metadata inclusion
## Affected sites
- `src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts:104-108` — the new stamp.
- `src/renderer/src/lib/workspace-tab-agent-metadata.ts:289-291` — reader compares `toSshExecutionHostId(connectionId)` against the worktree host.
- `src/renderer/src/lib/worktree-execution-host-alias.ts:12-16` and `src/shared/execution-host.ts:53-57` — `ssh:<env>` never equals `runtime:<env>` or `ssh:<target>`.
- `src/renderer/src/lib/workspace-tab-palette-entry-builder.ts:248-253` — feeds the mirrored terminal tab's `entityId` into that reader.
## Required outcome
- Mirror rows keep their agent metadata in the palette: either carry the environment id in a runtime-host field readers already understand, or make `collectAgentMetadataFromIndex` runtime-aware (`toRuntimeExecutionHostId`).
## Note
- `workspace-tab-agent-metadata.ts` is not in this PR's changed set, so no test pins the transition.There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 2834ede7-b1c3-4132-b8a3-d10ca4d26560
📒 Files selected for processing (6)
src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.tssrc/renderer/src/runtime/web-session-tabs-sync/agent-status-primitives.tssrc/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.tssrc/renderer/src/store/slices/agent-status-drop-reducer.tssrc/renderer/src/store/slices/retired-terminal-tab-state-sweep.tstests/e2e/omp-risk-remote-review.unit.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
ℹ️ No new issues in the delta — the owner-blind retraction sweep is fixed and the isolation test is green. One residual on the collision detector's input set, inline.
Reviewed changes
- Collision-scoped retraction —
collectCollidingRetractionPaneKeysdetects a pane under a retracted tab that this environment/worktree does not own, then scopes the sweep to the owned pane keys via a newpaneKeysoption threaded throughbuildRetiredTerminalTabStateSweepPatchandbuildAgentStatusTabPrefixDropPatch. - Mirror delete guard —
buildMirroredAgentStatusPatchnow takesenvironmentId/worktreeId/retractedTabIds, skips panes this environment does not own, and defers retracted tabs so the retirement sweep can see the live row. - Tests —
tests/e2e/omp-risk-remote-review.unit.test.tsexpanded to 16 host/worktree/hydration/batch permutations; the two prior failures now pass, andpnpm tc:webplus the sync/sidebar suites (2806 tests) are green.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review at 7c1f928 — the collision detector's input set, per-tab sweep scoping, and batch indexing.
- Collision detector covers every swept map —
collectCollidingRetractionPaneKeysmoved toretraction-pane-ownership.ts, now returns a per-tabMap<tabId, owned pane keys>, and scansacknowledgedAgentsByPaneKey,agentLaunchConfigByPaneKey,paneForegroundAgentByPaneKey, andmigrationUnsupportedByPtyIdin addition to status/retained entries, so an auxiliary-only foreign pane forces the scoped sweep. - Per-tab retraction sweep —
buildRetractedMirroredTabSweepPatchtakesscopedPaneKeysByTabIdand sweeps each retracted tab independently, scoping only the colliding tab instead of applying the scope to every tab in the frame. - Batch memoization —
WebSessionTabsBatchContext.retractionPaneKeysByRecordindexes each auxiliary record once per batch and refreshes on record replacement. - Tests — new
retraction-pane-ownership.test.ts(mirrored/local collision scoping, single enumeration + replacement) and a foreign-auxiliary-without-status-row matrix inomp-risk-remote-review.unit.test.ts; 35 focused tests pass locally.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in the delta — one non-blocking observation on the shared helper's blast radius.
Reviewed changes
Reviewed the delta since the prior pullfrog review at 8dbc1a8 — remote workspace attribution now survives tab hydration.
- Host attribution wins after hydration —
resolveAgentStatusWorktreeIdnow acceptsconnectionIdand returnsentry.worktreeIdfor remote entries (truthyconnectionIdor aweb-terminal-*tab id), so a mirrored tab id that collides with another workspace's tab cannot re-bucket the row once its tab appears in the index. - Live-index delegates —
liveEntryWorktreeIdroutes remote entries through that helper instead of a rawtabIdToWorktreeId.get(tabId); the local completed-orphan rule is unchanged. - Tests — new
worktree-agent-host-attribution.test.ts(four states × full-rebuild and patch paths) plus two helper cases; 9/9 pass, and reverting the early return fails 6 of them.
ℹ️ The shared helper change also moves the worktree activity dot
resolveAgentStatusWorktreeId is not sidebar-only: worktree-activity-state.ts:51 (the worktree dot) and worktree-agent-activity-summary.ts:117 now also prefer a remote entry's worktreeId over the tab-index mapping. That is a reasonable extension of the same fix, but the new tests pin only the sidebar row selector and the helper itself, so the dot/summary callers have no remote-collision coverage.
Technical details
# Shared attribution precedence changed for callers outside the PR's file set
## Affected sites
- `src/renderer/src/lib/agent-status-worktree-attribution.ts:31-36` — the new remote early return.
- `src/renderer/src/lib/worktree-activity-state.ts:51` — `getLiveAgentStatusByWorktreeId` now attributes remote entries by `entry.worktreeId`.
- `src/renderer/src/components/sidebar/worktree-agent-activity-summary.ts:117` — same helper, feeds the per-worktree activity summary.
## Required outcome
- Confirm the dot/summary behavior change is intended; if so no code change is needed. If those surfaces must keep the tab-index precedence, the early return needs to be parameterized rather than baked into the shared resolver.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

When a remote OMP status arrives before its tab inventory, the worktree can show a green dot while its child row is missing until clicked. Keep SSH and paired-host rows visible using their existing workspace attribution, then remove them when the authoritative host retracts the tab—even if local hydration never occurred. Local completed-orphan suppression and host/workspace isolation remain intact.
ELI5: the sidebar can show a remote agent as soon as the host reports it, without waiting for you to click its workspace. When the host removes it, the row disappears too.
Fixes #18704.
Validation: independent sub-agent review; 249 sync/sidebar tests, renderer typecheck and full changed-code quality gate passed. A 100-workspace regression verifies one status-key enumeration per snapshot batch; parent independently reran seven attribution/retraction tests. Hidden Electron proof uses production selectors and compact rows with injected SSH/paired status and empty tab inventories, followed by retraction. The original Ubuntu pair was not reproduced; transport authority is covered by snapshot tests.
Reproduce the rendered fixture with
tests/tools/omp-remote-sidebar-rendered/README.md.