Skip to content
Source
Sign inSign up
pingdotgg/t3code

Preserve pull request status across branch checkouts #5407

Closedjuliusmarmingewants to merge 2 commits intomain fromt3code/0b776cceopened View on GitHub

juliusmarmingecommented

What Changed

  • Added branch-specific pull request lookup through the VCS workflow and WebSocket RPC layers.
  • Preserved thread and branch PR indicators when the working tree checkout changes.
  • Serialized local and remote VCS refreshes to prevent stale status from overwriting current checkout data.
  • Updated branch selectors, sidebar indicators, chat, and Git actions to resolve PR status from the thread’s recorded branch.
  • Simplified terminal font inheritance so terminal surfaces use the configured code font unless explicitly overridden.
  • Added coverage for checkout changes, refresh ordering, and remote status recovery.

Why

PR status was derived from the current checkout, causing thread badges and PR actions to show stale or incorrect information after switching branches. Branch-keyed lookups keep each thread associated with its own PR while preserving fast stream-fed status for the active checkout. Refresh serialization prevents slow remote lookups from publishing results for a previous branch.

The typography cleanup keeps monospace surfaces consistent and removes unused advanced-font preference logic.

UI Changes

The sidebar, chat, branch selector, and Git actions now continue to display and act on the correct PR after switching checkouts. No visual layout changes were made, so before/after screenshots are not applicable.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk Touches VCS caching, concurrency, and checkout/switch RPC ordering where stale or mismatched PR/ref data could briefly surface; changes are localized to git status/PR resolution with added test coverage.

Overview PR indicators and thread badges now follow each thread’s recorded branch, not whatever is checked out in the repo. A new vcs.branchPr RPC (and cached client query) resolves PR/MR state from git branch config and upstream tracking, reusing the same lookupStatusPr path as live status.

Web and mobile replace checkout-only resolveThreadPr with useThreadPr / selectBranchPr: streamed status wins when refName matches the thread branch (including “no PR”), otherwise the branch-keyed query keeps the badge. Sidebar, chat, and the branch toolbar use this; resolveBranchToolbarPrBranch is removed. Git actions stay gated on checkout status only.

VcsStatusBroadcaster gets per-cwd local/remote semaphores, drops cached remote data on refName change, discards superseded in-flight remote reads, and publishes a local-only snapshot (remote: null) on checkout change before async remote refresh. vcsSwitchRef triggers refreshLocalStatus before the full refresh so clients don’t see the old branch after await.

Contracts add VcsBranchPrInput / VcsBranchPrResult; tests cover refresh races and branch PR selection.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4a42ee1ad0afecdfe15ccaf169eb51dd110e305d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Preserve pull request status by branch across checkout changes

  • Adds a vcs.branchPr RPC endpoint that resolves a PR for any branch (not necessarily checked out) by reading git config to infer upstream and default branch, without requiring an active checkout.
  • Introduces selectBranchPr and useThreadPr utilities that prefer live git status when it matches the thread's branch, but fall back to the branch-keyed vcs.branchPr query when the checkout has moved away.
  • Updates PR badges in the sidebar rows, chat view, and branch toolbar to use useThreadPr instead of the removed resolveThreadPr function, so badges persist after a checkout change.
  • Fixes VcsStatusBroadcaster to prevent stale remote or local status from overriding newer state during concurrent refreshes; remote halves are cleared on ref changes and repopulated asynchronously.
  • Behavioral Change: switching refs now triggers an immediate local status publish before the full refresh, so clients see the new ref name sooner in the status stream.
Macroscope summarized 4a42ee1.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 366c55e3-c521-4f3c-9fa5-ebf0a7adbba8

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This multi-layer change adds branch-keyed PR lookups and substantially changes shared VCS cache and refresh concurrency across server and client surfaces. An unresolved race concern remains around stale remote status being paired with a new checkout, so the runtime behavior needs human review.

      Not approved because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. @@ -29,7 +33,17 @@
      2933 })
      3034 : null,
      3135 );
      36+ const branchPr = useEnvironmentQuery(
      37+ thread.branch !== null && cwd !== null
      38+ ? vcsEnvironment.branchPr({
      39+ environmentId: thread.environmentId,
      40+ input: { cwd, branch: thread.branch },
      41+ })
      42+ : null,
      43+ );
      3244
      3345 const status = gitStatus.data;
      34- if (status === null || thread.branch === null || status.refName !== thread.branch) {
      35- return null;
      46+ // When the status describes the thread's own branch it is authoritative
      47+ // about that branch's PR — including when it reports none, so this must not
      48+ // fall through to a warm branch lookup that would resurrect a stale badge.
      49+ if (status !== null && thread.branch !== null && status.refName === thread.branch) {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium state/use-thread-pr.ts:49

      When the VCS status stream reports a matching refName with pr: null before the remote PR lookup resolves, useThreadPr returns null instead of falling through to the already-subscribed branchPr result. This causes the PR badge to flicker off immediately after checkout and can leave it permanently absent if that remote refresh later fails. The guard at line 49 treats any matching status as authoritative, including the transient state where the PR field is still pending, so the branch-keyed fallback is never reached. Consider distinguishing a status that has confirmed no PR from one whose PR field is still pending before short-circuiting.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/state/use-thread-pr.ts around line 49:
      
      When the VCS status stream reports a matching `refName` with `pr: null` before the remote PR lookup resolves, `useThreadPr` returns `null` instead of falling through to the already-subscribed `branchPr` result. This causes the PR badge to flicker off immediately after checkout and can leave it permanently absent if that remote refresh later fails. The guard at line 49 treats any matching status as authoritative, including the transient state where the PR field is still pending, so the branch-keyed fallback is never reached. Consider distinguishing a status that has confirmed no PR from one whose PR field is still pending before short-circuiting.
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor Bugbot Autofix is [ON](https://www.cursor.com/dashboard/bugbot), but a cloud agent failed to start. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4a42ee1ad0afecdfe15ccaf169eb51dd110e305d. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -376,4 +477,18 @@
      376- [workflow.localStatus({ cwd }), workflow.remoteStatus({ cwd })],
      377- { concurrency: "unbounded" },
      477+ const local = yield* withLocalLock(
      478+ cwd,
      479+ Effect.gen(function* () {
      480+ const localResult = yield* workflow.localStatus({ cwd });
      481+ return (yield* updateCachedLocalStatus(cwd, localResult, { publish: true })).local;
      482+ }),
      378483 );
      379- return yield* updateCachedStatus(cwd, local, remote, { publish: true });
      484+ const remote = yield* refreshRemoteStatus(cwd, { invalidate: false });
      485+ // A checkout can land between the two reads. refreshRemoteStatus discards
      486+ // a superseded remote result, which would leave `local` describing the old
      487+ // branch — returning that pair would hand the caller a status the cache
      488+ // itself no longer agrees with. Prefer the cache's halves, which the
      489+ // concurrent refresh has already reconciled for the new branch.
      490+ const cached = yield* getCachedStatus(cwd);
      491+ return mergeGitStatusParts(
      492+ cached?.local?.value ?? local,
      493+ cached?.remote ? cached.remote.value : remote,
      494+ );

      Stale remote paired after checkout

      Medium Severity

      refreshStatusCore prefers cached local status after a mid-refresh checkout, but when that checkout cleared the cached remote half it falls back to the in-flight remote value. A checkout that lands after refreshRemoteStatus succeeds but before getCachedStatus can therefore return the new refName merged with the previous branch’s ahead/behind and PR data, even though the cache itself already dropped that remote half.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4a42ee1ad0afecdfe15ccaf169eb51dd110e305d. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. UtkarshUsername(GitHub profile, opens in a new tab) approved these changes

    7. UtkarshUsername(GitHub profile, opens in a new tab)commented

      (ignore the approval please, sorry, was testing it for our pr page discussion. It can't be dismissed because github does not allow that when there are conflicts)

    8. closing this version as part of a pr cleanup at the request of @StiensWout.

      thread-to-pr associations now come from the server, and web and mobile consume those references. this version adds a parallel client lookup path instead of building on that ownership model. any remaining checkout refresh race would be better addressed in a focused pr against the current implementation.

      thanks for the contribution. if you disagree with this decision, you are welcome to open a new pr, link back to this one, and explain how your proposal addresses these concerns or why a different approach is warranted.

    9. reopened at the request of @StiensWout. this pr was included in the cleanup closure by mistake; the earlier closure decision is withdrawn.

    10. juliusmarminge added labelsmacroscope-review

    11. juliusmarminge closed this

Sign in to join this conversation.