Skip to content

fix(github): never attach a PR to the primary worktree#37

Open
zaridan wants to merge 1 commit into
mainfrom
zaridan/fix-github-pr-attached-to-primary
Open

fix(github): never attach a PR to the primary worktree#37
zaridan wants to merge 1 commit into
mainfrom
zaridan/fix-github-pr-attached-to-primary

Conversation

@zaridan

@zaridan zaridan commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Symptom

A feature PR (e.g. RIQAPP-363: Phase 2 …) showed up attached to the Primary / default-branch worktree in the sidebar — the primary worktree idles on main and must never carry a PR badge.

Root cause

A stale persisted linkedPR was bound to the primary worktree id (${repoId}::${repoPath}). The renderer passed it as linkedPRNumber, and getPRForBranchOutcome re-hydrated it via exact PR lookup by number. This is not the implicit branch-match path that stablyai#5524 already guards (and the merged-only guard from stablyai#5524/stablyai#5877 didn't catch it because the PR is open).

Fix — 3 layers + cleanup

  1. getPRForBranchOutcome short-circuits to no-pr when the new isPrimaryWorktree option is set, before any lookup — ignoring stale linked/fallback numbers and skipping implicit branch matching. The PR-refresh coordinator passes the flag from candidate.isMainWorktree, threaded from worktree.isMainWorktree in the renderer candidate builder.
  2. mergeWorktree drops linkedPR for the main worktree, provider-agnostically (GitHub/GitLab/Bitbucket/etc), so no badge renders regardless of provider.
  3. clearLinkedPRForPrimaryWorktrees scrubs any stale linkedPR off disk at load (idempotent), so the existing stuck badge clears rather than just being hidden going forward.

Tests

Lint (oxlint) clean; node + web typechecks clean.

🤖 Generated with Claude Code

The primary (default-branch) worktree could surface a feature PR badge
when a stale linked PR number was persisted on it. Enforce the invariant
that the primary worktree is categorically PR-free:

- getPRForBranchOutcome short-circuits to no-pr when isPrimaryWorktree is
  set, ignoring any stale persisted linked/fallback number and skipping
  implicit branch matching. The PR-refresh coordinator passes the flag
  from the candidate's isMainWorktree.
- mergeWorktree drops linkedPR for the main worktree so no badge renders,
  provider-agnostically (GitHub/GitLab/Bitbucket/etc).
- A load-time persistence cleanup scrubs any stale linkedPR persisted on
  the primary worktree (idempotent), dropping the existing bad state.

Merged-implicit (stablyai#5524) and merged-for-current-head (stablyai#5877) behavior is
unchanged for non-primary worktrees.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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