fix(host-service): don't link workspaces to default-branch PRs
Problem
A workspace on branch roshvan/mcp-1703-mcp-surface-area showed PR #1522 "chore: sync main into feat/signal-pages" (head branch = main) in its right-sidebar Review panel — a PR unrelated to the workspace. A reviewer even flagged it: "Wrong direction — head=main can't be up-to-date with feat/signal-pages".
Root cause (primary — what renders)
resolveWorkspaceUpstream() keys the PR match on the branch's tracked remote merge ref (branch.<name>.merge) rather than the local branch name. A workspace branched off main keeps tracking origin/main until its own branch is pushed (@{push} unconfigured), so the resolved upstream branch is main. performProjectRefresh then builds the key owner/repo#main and links whatever open PR has head=main — here the "sync main into X" PR. Any workspace still tracking origin/main gets glued to a default-branch-headed PR.
The sidebar Review panel reads this authoritative link (git.getPullRequest → workspace.pullRequestId), so the bad link written by PullRequestRuntimeManager is exactly what shows on screen.
Fix (commit 1 — fix(host-service))
Guard link assignment: a workspace may only key on the base repo's default branch when its local branch actually is that default branch. When the resolved upstream branch equals the repo default but the local branch differs (and the upstream is the base repo), treat it as "no upstream PR". The default branch is derived from the refs/remotes/<remote>/HEAD symref and cached per project.
- Fork PRs whose head happens to be named
main(e.g. agh pr checkoutrename) still link — the guard is scoped to the base repo. - The workspace whose local branch is the default branch still links correctly.
upstreamKeycase-sensitivity is preserved.
Unit tests added; each was verified to fail without the guard (mutation-tested): the origin/main-tracking workspace must not link to the head=main PR, the default-branch workspace must still link, and a fork PR head-named main must still link.
Secondary latent bug (commit 2 — fix(desktop))
useAccessibleV2Workspaces re-derived the workspace→PR link client-side for the workspaces list rows / hover cards using a fuzzy repositoryId::branch map — no head-SHA verification, no fork/owner qualifier, first-match-wins on a non-unique key. Two PRs sharing a head branch (main, patch-1) across forks mistracked, and the list could visibly disagree with the sidebar, which reads the authoritative pullRequestId.
Fix: fan getByWorkspaces out per host exactly as useDashboardSidebarData does to obtain the authoritative PR number per workspace, then key the rich collection row by the unique (repositoryId, prNumber) pair instead of the branch. The list and the sidebar now agree.
Testing
bun test(host-service pull-requests): 27 passbun run typecheck: clean (35/35)bun run lint: exit 0
Summary by cubic
Prevents workspaces from linking to default-branch-headed PRs (e.g., “sync main into X”), and switches the v2 workspaces list to the host’s authoritative workspace→PR link so the list and sidebar always agree.
- Bug Fixes
host-service: Add a default-branch guard when deriving the workspace upstream key; only link on the base repo’s default branch if the local branch is that branch. Fork PRs with head namedmainstill link. Default branch is resolved via sharedresolveDefaultBranchName(origin/HEAD).desktop:useAccessibleV2Workspacesnow queriespullRequests.getByWorkspacesper host and keys PRs by(repositoryId, prNumber)instead ofrepositoryId::branch, fixing fork branch-name collisions and keeping the list in sync with the sidebar. Also stabilizes the PR-number map to reduce unnecessary re-renders.
Summary by CodeRabbit
- Bug Fixes
- Improved pull request linking across workspaces using authoritative host-aware associations instead of branch-based inference.
- Updated refresh/enrichment so workspace PR matching no longer relies on head branch data.
- Added a default-branch guard to prevent incorrect links when an upstream tracks the repo default but the workspace’s local branch differs.
- More reliably clears stale or mismatched pull request links, while preserving correct behavior for forks and local default branches.
- Tests
- Added default-branch guard coverage and improved test stubs/fixture parsing for deterministic refresh behavior.