Repository navigation
fix: name the notification project by the worktree's own host - #20958
Conversation
There was a problem hiding this comment.
Important
The two-row collision branch is correct and well-tested, but the single-row fast path (rows.length <= 1) skips host resolution entirely. When the same repo id is registered on two hosts but the worktrees sit at different paths — the supported shape proven by persistence-duplicate-repo-id-host-scope.test.ts (dup at /laptop/dup and /remote/dup) — each worktree id has exactly one row, so the project name still comes from the last-wins id-keyed repo map. Reproduced locally: a local worktree dup::/laptop/dup is labelled Dup Remote. That is the same STA-4343 misinformation this PR targets.
Reviewed changes
- Host-qualified worktree resolution (
terminal-notification-state.ts): addsfindWorktreeRowOnItsOwnHostandfindNotificationRepo. A multi-row id resolves its owning execution host viagetResolvedExecutionHostIdForWorktree, picks the row with the productionworktreeMatchesHost/worktreeHostMatchOptionspredicate (same as the destructivefindWorktreeOnConfirmedHostpath), and picks the repo withfindIndexedRepoOwnerForHost, omitting labels when ownership is unprovable. - 4 new tests (
terminal-notification-state.test.ts): builds the colliding state through the productionmergeWorktreesForHostso both rows are reachable, arranges the rival host to win both bare-id maps, and pins active-host naming plus background omission. Existing 10 tests are untouched; all 14 pass locally (node_modules/.bin/vitest run --config config/vitest.config.ts <file>).
️ The active-host preference keys on bare-id equality alone
getResolvedExecutionHostIdForWorktree only takes preferredHostId when state.activeWorktreeId === worktreeId. On a collision, the notification's id equals the active id even when the completion came from the other host, so such a background completion resolves to the active host rather than being omitted — a nuance distinct from the PR's documented "background workspace → omitted" gap. Not a regression (the old path was a coin flip, sometimes even mixing worktree and repo rows from different hosts), but it does mean "never turns a correct label into a wrong one" is not yet strictly true.
Technical details
# Active-host preference is id-keyed, not notification-source-keyed
## Affected sites
- `src/renderer/src/lib/resolved-worktree-execution-host.ts:70-76` — `preferredHostId` is chosen by `state.activeWorktreeId === worktreeId`, with no host component in the comparison.
- `src/renderer/src/components/terminal-pane/use-notification-dispatch.ts:170` — the dispatch contract carries only `request.workspaceId` (a bare `repoId::path`), and `parsePaneKey` (stable-pane-id.ts) has no host segment, so the notification path cannot name its source host today.
## Required outcome
- Either accept this as a documented residual gap, or thread the workspace's execution host through the notification dispatch so a completion on the non-active host is resolved by its own host.
## Open questions for the human
- Is the intended contract "the notification's host owns the label" or "the active workspace's host owns the label"? The current code implements the latter for a shared id.
- `contestedPrimaryHostBySessionKey` is mentioned in the PR body as a hydration-only candidate — worth confirming it cannot cover an in-session background completion before closing this out of scope.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
STA-4343: a worktree id is `repoId::path` with no host component, so the local host and an SSH host publish one id for two different workspaces. The id-keyed worktree map is first-wins and the repo map is last-wins, so a colliding workspace could be labelled with the other host's project and branch. Resolve the owning host first and name nothing when hydrated ownership cannot prove one; an omitted label beats a wrong one. Only the collision branch changes: a single-row id still takes the same map lookups it did before.
5d436b2 to
4300896
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughTerminal notification label lookup now resolves worktree rows and repositories by execution host when IDs collide across hosts. New helpers use indexed worktree rows, host matching, and host-specific repository ownership. Tests cover local and SSH rows with the same worktree ID, verify active-host labels, and verify fallback labels when the active workspace references a different worktree. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Notification labels now avoid guessing across host collisions, with no identified merge-blocking issue. 🚥 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: fc6d7f95-4df2-4428-826d-0aab1445b30a
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/terminal-notification-state.test.tssrc/renderer/src/components/terminal-pane/terminal-notification-state.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
A repo id is registered per host, so two hosts can hold one id at different paths. Their worktree ids are then unique, so the single-row path skipped host resolution and fell back to the id-keyed repo map, which is last-wins — a local worktree got the ssh project's name. Gate the repo lookup on the id actually being ambiguous: one owner keeps the plain map lookup and its cost, and only a spanning id resolves the owning host, naming nothing when ownership is unprovable.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Repo lookup gated on ambiguity (
terminal-notification-state.ts):findNotificationReponow only resolves the owning host whenresolveIndexedRepoOwnerreports the repo id asambiguous, so the single-row path keeps the cached id-keyed map for unique ids and fails closed (no label) when a spanning id has no provable host. worktreeIdthreaded through (terminal-notification-state.ts):findNotificationRepotakes the workspace id so it can callgetResolvedExecutionHostIdForWorktreefor the single-row repo-id collision case;getNotificationWorkspaceLabelshoists the id it already computed.- Two repo-id collision tests (
terminal-notification-state.test.ts): pin the local project name for a unique worktree id whose repo id spans hosts, and pin omission when the row names no provable host. Verified 16/16 pass locally.
The prior repo-id-collision thread is addressed and resolved; the active-host preference residual stays as documented in the PR body's "Known residual gap".
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ai#20958) * fix: name the notification project by the worktree's own host STA-4343: a worktree id is `repoId::path` with no host component, so the local host and an SSH host publish one id for two different workspaces. The id-keyed worktree map is first-wins and the repo map is last-wins, so a colliding workspace could be labelled with the other host's project and branch. Resolve the owning host first and name nothing when hydrated ownership cannot prove one; an omitted label beats a wrong one. Only the collision branch changes: a single-row id still takes the same map lookups it did before. * fix: name the project by its host when a repo id spans hosts A repo id is registered per host, so two hosts can hold one id at different paths. Their worktree ids are then unique, so the single-row path skipped host resolution and fell back to the id-keyed repo map, which is last-wins — a local worktree got the ssh project's name. Gate the repo lookup on the id actually being ambiguous: one owner keeps the plain map lookup and its cost, and only a spanning id resolves the owning host, naming nothing when ownership is unprovable.

Stacked on #20931 — must land after it. The base branch is
perf/notification-disambiguation-scan, so this diff only makes sense once that PR merges.What's wrong
An Orca worktree id is
repoId::path. It carries no host component, so if you have the same project registered both locally and on an SSH host, both hosts publish the same id for two genuinely different workspaces (STA-4343). The renderer's id-keyed worktree map is documented first-wins and explicitly cannot represent that collision; the repo map is last-wins.Notification labels went through both. Before #20931 the project name was only shown when several projects were active, so the collision mostly hid. #20931 made the project name always present, which turns a latent ambiguity into visible misinformation: a completion on your build box could be announced as the laptop project, on the laptop branch.
#20931 already host-qualified the folder-workspace half of
getNotificationWorkspaceLabels. This does the git-worktree half.What this does
When an id has more than one row, resolve the owning execution host via the existing
getResolvedExecutionHostIdForWorktree, then pick the worktree row withworktreeMatchesHost(the same predicate the destructivefindWorktreeOnConfirmedHostpath uses) and the repo row withfindIndexedRepoOwnerForHost. If ownership cannot be proven, name nothing and fall back to the terminal title.Omitting a label is a cosmetic gap; naming the wrong project is misinformation, so this fails closed.
A single-row id is untouched — same map lookups, same result, no extra work. Only the collision branch changes.
Known residual gap (honest scope)
getResolvedExecutionHostIdForWorktreeonly has apreferredHostIdwhen the workspace is the active one; for a background workspace it falls back to a bare-id lookup, which returns null on an ambiguous id. So:That is better in both directions, but it is not a complete fix, and one case is still wrong rather than merely omitted: because
getResolvedExecutionHostIdForWorktreepicks its preferred host on bare-id equality (state.activeWorktreeId === worktreeId), a completion arriving from the non-active host of a colliding id resolves to the active host and is labelled with it. That was a coin flip before, so it is not a regression — but it means this change does not yet guarantee "never wrong", only "never wrong for an unambiguous id".Closing both gaps needs the notification to name its own source host. The dispatch contract cannot today:
use-notification-dispatch.tspasses a barerepoId::path, and pane keys carry no host segment. The alternatives are a new host signal for background workspaces (contestedPrimaryHostBySessionKeyis a candidate — it is hydration-only, so it would not cover in-session workspaces either) or threading execution-host identity through the dispatch contract. Neither belongs in this change.Repo-id collision (added after review)
A second, independent collision: a repo id is registered per host, so two hosts can hold one id at different paths (
src/main/persistence-duplicate-repo-id-host-scope.test.ts). The worktree ids are then unique, so the single-row path skipped host resolution and the id-keyed repo map — which is last-wins — named the wrong project. A local worktreedup::/laptop/dupwas labelledDup Remote.The repo lookup is now gated on the id actually being ambiguous: a single-owner id keeps the plain map lookup and its cost, and only a spanning id resolves the owning host, naming nothing when ownership is unprovable.
Verification
terminal-notification-state.test.ts. The colliding state is built by the productionmergeWorktreesForHost(two per-host refreshes), not a hand-written array, so the two-row shape is reachable rather than assumed. Each case is arranged so the rival host wins both the first-wins worktree map and the last-wins repo map, so naming the right host cannot pass by accident.pnpm tcclean;pnpm run check:code-quality:changed0 new findings; targeted suites (terminal-pane/,lib/, notification formatting) 1011 files / 9788 tests pass.