Skip to content

Default branch worktree shows a stale merged PR #695

Description

@Snirpini

What happened?

A clean worktree checked out on the repository's default branch (main) displays a merged pull request badge (PR #320 "Main", merged) as if that PR belonged to the worktree.

I expected a worktree on the default branch with no pending changes to show just the branch (default), with no PR attached.

This affects any workflow that opens sync PRs from the default branch into another branch (e.g. main → dev), because those PRs have headRefName: main and never go away for the default branch (the branch persists after merge instead of being deleted like a feature branch).

Steps to reproduce

  1. Use a repo whose default branch is main, with a workflow that opens sync PRs from main into another branch (e.g. main → dev), so main has merged PRs whose headRefName is main.
  2. Open the repo in Supacode with the main worktree checked out on main, clean, with no local changes.
  3. Observe the main worktree shows a merged PR badge (the most recently updated merged head=main PR) instead of no PR.

Cause (from the source)

Tracing the PR auto-matching:

  • GithubCLIClient.makeBatchPullRequestsQuery fetches, per branch, pullRequests(first: 5, states: [OPEN, MERGED], headRefName: "<branch>", orderBy: {field: UPDATED_AT, direction: DESC}).
  • For the default branch this matches historical default → X sync PRs (they use the default branch as the head).
  • GithubGraphQLPullRequestResponse.pullRequestsByBranch ranks candidates by state (OPEN > MERGED) then recency, so with no open head=main PR it selects the newest merged one.
  • RepositoriesFeature.refreshRepositoryPullRequests then assigns it to the worktree via pullRequestsByWorktreeID[worktree.id] = prsByBranch[worktree.name].

The matcher never special-cases the repository's default branch, so a worktree on the default branch permanently shows a stale merged PR.

A possible direction (happy to implement once triaged): exclude the repository's default branch from PR association in refreshRepositoryPullRequests. One open question for triage — suppress all PRs on the default branch, or only merged/closed ones (keeping a currently-open sync PR visible)?

Supacode version and build

0.10.6 (1783877721)

macOS version

macOS 26.5

System locale

en_IL

Mac hardware

Apple M1 (MacBookPro17,1)


Disclosure: diagnosis assisted by an AI agent (Claude Code). All commits for any follow-up PR will be authored by me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreadyApproved for a pull request. Added by a maintainer once an issue is triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions