Skip to content

fix: name the notification project by the worktree's own host - #20958

Merged
Jinwoo-H merged 2 commits into
mainfrom
perf/notification-host-qualified-worktree-label
Sep 16, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
perf/notification-host-qualified-worktree-label

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​155 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​155
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​63

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 with worktreeMatchesHost (the same predicate the destructive findWorktreeOnConfirmedHost path uses) and the repo row with findIndexedRepoOwnerForHost. 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)

getResolvedExecutionHostIdForWorktree only has a preferredHostId when 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:

  • colliding + active workspace → correct label (was: coin flip)
  • colliding + background workspace → omitted label (was: coin flip)

That is better in both directions, but it is not a complete fix, and one case is still wrong rather than merely omitted: because getResolvedExecutionHostIdForWorktree picks 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.ts passes a bare repoId::path, and pane keys carry no host segment. The alternatives are a new host signal for background workspaces (contestedPrimaryHostBySessionKey is 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 worktree dup::/laptop/dup was labelled Dup 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

  • 4 new tests in terminal-notification-state.test.ts. The colliding state is built by the production mergeWorktreesForHost (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.
  • Mutation-checked: with the source change reverted, all 4 fail; with it, all 14 in the file pass.
  • pnpm tc clean; pnpm run check:code-quality:changed 0 new findings; targeted suites (terminal-pane/, lib/, notification formatting) 1011 files / 9788 tests pass.

@pullfrog pullfrog 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.

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): adds findWorktreeRowOnItsOwnHost and findNotificationRepo. A multi-row id resolves its owning execution host via getResolvedExecutionHostIdForWorktree, picks the row with the production worktreeMatchesHost / worktreeHostMatchOptions predicate (same as the destructive findWorktreeOnConfirmedHost path), and picks the repo with findIndexedRepoOwnerForHost, omitting labels when ownership is unprovable.
  • 4 new tests (terminal-notification-state.test.ts): builds the colliding state through the production mergeWorktreesForHost so 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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.
@Jinwoo-H
Jinwoo-H force-pushed the perf/notification-host-qualified-worktree-label branch from 5d436b2 to 4300896 Compare September 16, 2026 05:01
@Jinwoo-H
Jinwoo-H changed the base branch from perf/notification-disambiguation-scan to main September 16, 2026 05:01
@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a18a224d-e815-4ea1-8bf7-446cc8b56132

📥 Commits

Reviewing files that changed from the base of the PR and between 4300896 and 21f1ecd.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-notification-state.test.ts
  • src/renderer/src/components/terminal-pane/terminal-notification-state.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/terminal-notification-state.ts
  • src/renderer/src/components/terminal-pane/terminal-notification-state.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

Terminal 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 21f1e

Notification labels now avoid guessing across host collisions, with no identified merge-blocking issue.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: resolving notification project names using the worktree host.
Description check ✅ Passed The description is detailed and on topic. It explains the problem, implementation, scope, known limitations, linked context, and verification results. It does not use the template headings for ELI5, L…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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: Advanced

Run ID: fc6d7f95-4df2-4428-826d-0aab1445b30a

📥 Commits

Reviewing files that changed from the base of the PR and between 9ed561c and 4300896.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-notification-state.test.ts
  • src/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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Repo lookup gated on ambiguity (terminal-notification-state.ts): findNotificationRepo now only resolves the owning host when resolveIndexedRepoOwner reports the repo id as ambiguous, 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.
  • worktreeId threaded through (terminal-notification-state.ts): findNotificationRepo takes the workspace id so it can call getResolvedExecutionHostIdForWorktree for the single-row repo-id collision case; getNotificationWorkspaceLabels hoists 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".

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 7c43254 into main Sep 16, 2026
28 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…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.
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.

1 participant