Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): retain terminal PR badges after checkout switch #4755

Mergedsebbonit(GitHub profile, opens in a new tab)merged 7 commits intomain fromrefs/pull/4755/headmerged by juliusmarminge View on GitHub

What Changed

Fixes #4752.

Sidebar V2 now keeps a parent-level PR snapshot (branch, full PR object, provider) instead of only "open" | "merged" | "closed".

  • Snapshots update only when live VCS status matches the thread branch.
  • Branch mismatch / missing VCS data leaves the snapshot alone.
  • Display and settlement both use one resolver: live PR on match; cached merged/closed PR on mismatch.
  • Open PRs are not retained across a checkout switch.

Why

After a local-checkout thread’s PR was observed as merged/closed, switching the shared checkout to main made resolveThreadPr return null (branch mismatch). That cleared the parent map, unssettled the thread, and dropped the PR badge. Retaining the previously verified terminal PR at the Sidebar V2 parent is enough; no contracts/server changes.

UI Changes

Settled local-checkout rows keep their PR number, link, title, provider terminology, and terminal color after switching away from the thread branch. No layout changes.

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

Retain merged/closed PR badges for local threads after branch checkout switch

  • Introduces ThreadChangeRequestSnapshot in ThreadStatusIndicators.tsx to cache per-thread PR state (branch, PR, provider) in a global keep-alive atom (threadChangeRequestSnapshotsAtom).
  • Adds resolveDisplayedThreadPr and nextThreadChangeRequestSnapshot to decide when to show a live PR vs. a retained terminal (merged/closed) PR for local checkouts where the branch no longer matches.
  • Updates ChatView and Sidebar to read from the global atom and pass snapshots down to thread rows, replacing per-mount local state with shared atom state that survives remounts.
  • Worktree threads do not retain terminal PRs on branch mismatch; only local checkouts do.
  • Behavioral Change: threads previously showing no PR badge after a branch switch may now show the last merged/closed PR badge until the snapshot is explicitly cleared.
Macroscope summarized 6361523.

Note

Medium Risk Changes sidebar settlement partitioning and chat PR/settlement inputs via new retained-state rules; logic is well-tested but incorrect retention could mis-settle threads or show wrong PR metadata.

Overview Fixes sidebar and chat losing merged/closed PR badges when a local-checkout thread’s shared repo is checked out on another branch (e.g. main).

Thread change-request snapshots replace per-row PR state callbacks: a threadChangeRequestSnapshotsAtom holds branch, full PR, and provider per thread key so data survives row remounts and navigation. Rows call nextThreadChangeRequestSnapshot from live VCS; Sidebar partitioning and ChatView settlement/PR UI both use resolveDisplayedThreadPr (and provider helper) with retainTerminalOnBranchMismatch for local threads (worktreePath === null).

Rules: live PR when checkout matches thread branch; retain only terminal (merged/closed) snapshots across mismatch for local checkouts; never attach unrelated PRs from the current branch; worktrees do not retain; open PRs clear on mismatch. Extensive tests cover resolvers, atom keep-alive, and effectiveSettled with retained merge state.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6361523c6bff472984f92840ce0477978281e6e5. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    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: a023e2d7-880f-4e3b-a12f-af7d13dd1f80

      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
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

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

      Approvability

      Verdict: Needs human review

      This PR introduces new UI state retention behavior for PR badges with non-trivial state management. An unresolved Medium severity finding identifies potential state divergence between sidebar and chat settlement when branch is cleared, warranting human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6361523c6bff472984f92840ce0477978281e6e5. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -128,0 +244,21 @@
      244+ * survives that metadata changing to the newly checked-out branch. Open PRs
      245+ * are never retained — their state can still change.
      246+ */
      247+export function resolveDisplayedThreadPr(input: {
      248+ threadBranch: string | null;
      249+ gitStatus: VcsStatusResult | null;
      250+ snapshot: ThreadChangeRequestSnapshot | null | undefined;
      251+ retainTerminalOnBranchMismatch: boolean;
      252+}): ThreadPr | null {
      253+ const { threadBranch, gitStatus, snapshot, retainTerminalOnBranchMismatch } = input;
      254+ if (
      255+ threadBranch !== null &&
      256+ gitStatus !== null &&
      257+ gitStatus.refName === threadBranch &&
      258+ gitStatus.pr != null
      259+ ) {
      260+ return gitStatus.pr;
      261+ }
      262+
      263+ if (
      264+ threadBranch !== null &&

      Settlement diverges on cleared branch

      Medium Severity

      resolveDisplayedThreadPr now ignores a retained terminal snapshot when threadBranch is null, and ChatView settlement follows that. The Sidebar partition still treats a local-checkout snapshot as authoritative without requiring a non-null branch, so the parked banner and sidebar can disagree. For local rows the VCS query is also skipped when branch is null, so nextThreadChangeRequestSnapshot never clears the atom and the mismatch can persist.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6361523c6bff472984f92840ce0477978281e6e5. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. juliusmarminge approved these changes

      Re-approved after the focused regression fix and verification.

    6. juliusmarminge merged thisd5465ae

    7. juliusmarminge closed this

Sign in to join this conversation.