improve and prevent silent thread branch drift and PR fetching#2284
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
ApprovabilityVerdict: Needs human review 1 blocking correctness issue found. This PR introduces new branch mismatch detection and repair features with significant runtime behavior changes. Four unresolved review comments identify potential bugs in the new logic, including missing query conditions and stale state handling issues that require resolution. You can customize Macroscope's approvability policy. Learn more. |
|
Heya I will properly review your PRs when we get back from Miami. Seems like some good stuff just don't have capacity to review big PRs while we're here |
f1ffd01 to
02bb838
Compare
|
either i messed soemthing up when mergin main or i don't understand this PR: CleanShot.2026-05-02.at.23.02.21.mp4 |
e0314cf to
beb7b1a
Compare
|
@justsomelegs is attempting to deploy a commit to the Ping Labs Team on Vercel. A member of the Team first needs to authorize it. |
It meant to warn the user when switching branches that the thread was last working on another branch so that they dont accidently try and continue the work on the wrong branch. just pushed my local version up that is rebased onto main if you wanna try that one out. Screen.Recording.2026-05-04.101354.mp4 |
9aa14c4 to
f64b18f
Compare
f64b18f to
22c6338
Compare
There was a problem hiding this comment.
🟡 Medium
t3code/apps/web/src/components/Sidebar.tsx
Line 428 in 22c6338
For a dedicated-worktree thread whose branch is null, the PR indicator never appears even though resolveThreadPr was updated to handle that case. The VCS status query at line 427 is gated on thread.branch != null, so gitStatus.data stays null and resolveThreadPr receives gitStatus: null, causing it to return null regardless of hasDedicatedWorktree. This means the PR status indicator is silently missing for exactly the missing-branch dedicated-worktree case this change intended to support. The query condition should also allow fetching when thread.worktreePath != null, e.g. (thread.branch != null || thread.worktreePath != null) && gitCwd !== null.
| thread.branch != null && gitCwd !== null |
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/Sidebar.tsx around line 428:
For a dedicated-worktree thread whose `branch` is `null`, the PR indicator never appears even though `resolveThreadPr` was updated to handle that case. The VCS status query at line 427 is gated on `thread.branch != null`, so `gitStatus.data` stays `null` and `resolveThreadPr` receives `gitStatus: null`, causing it to return `null` regardless of `hasDedicatedWorktree`. This means the PR status indicator is silently missing for exactly the missing-branch dedicated-worktree case this change intended to support. The query condition should also allow fetching when `thread.worktreePath != null`, e.g. `(thread.branch != null || thread.worktreePath != null) && gitCwd !== null`.
22c6338 to
f762024
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f762024. Configure here.
|
|
||
| useEffect(() => { | ||
| if (isGitActionRunning || isSelectingWorktreeBase) { | ||
| if (isGitActionRunning || isSelectingWorktreeBase || activeServerThread) { |
There was a problem hiding this comment.
Git actions still sync thread branch
Medium Severity
Live git-status branch reconciliation for server-backed threads is skipped when activeServerThread is set, so checkout can stay on one branch while stored thread metadata keeps another. Stacked git actions still call syncThreadBranchAfterGitAction → persistThreadBranchSync, which can update the server thread branch (for example when a new feature branch is created) without the user choosing Update thread or Switch checkout in the mismatch UI.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit f762024. Configure here.
| }), | ||
| ); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Stale mismatch after checkout switch
Medium Severity
After a successful Switch checkout, the picker label can update via optimistic state while resolveLocalCheckoutBranchMismatch still compares the thread branch to a stale currentGitBranch from VCS status until refresh completes, so the warning styling and popover can remain visible even though checkout already matches the thread branch.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit f762024. Configure here.
|
|
||
| setThreadBranch(localCheckoutBranchMismatch.currentBranch, null); | ||
| setIsBranchMenuOpen(false); | ||
| onComposerFocusRequest?.(); |
There was a problem hiding this comment.
Update thread keeps warning visible
Medium Severity
Update thread calls setThreadBranch for server threads, but activeThreadBranchOverride and onActiveThreadBranchOverrideChange are only passed for empty new server threads, so established threads keep showing a branch mismatch until server metadata arrives asynchronously.
Reviewed by Cursor Bugbot for commit f762024. Configure here.
- Surface mismatch state inside the branch picker - Replace the inline popover with embedded actions and tooltips - Tighten list height when a branch mismatch is shown
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
4ccda21 to
e30be8e
Compare
Co-authored-by: codex <codex@users.noreply.github.com>
f51b7de to
d3910e1
Compare
…otgg#2284) Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: codex <codex@users.noreply.github.com>
…r refresh (#7) * feat(web): copy branch name via right-click in the branch selector (pingdotgg#4275) Co-authored-by: Claude Fable 5 <noreply@anthropic.com> * Add remote server updates and standalone service management (pingdotgg#4286) Co-authored-by: codex <codex@users.noreply.github.com> * Refine light-mode sidebar surfaces (pingdotgg#4268) Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: codex <codex@users.noreply.github.com> * fix(mobile): don't mark Android VPN/Tailscale as offline when connected (pingdotgg#3949) * improve and prevent silent thread branch drift and PR fetching (pingdotgg#2284) Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: codex <codex@users.noreply.github.com> --------- Co-authored-by: Theo Browne <me@t3.gg> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: codex <codex@users.noreply.github.com> Co-authored-by: Rushikesh Gaikwad <81632222+Wraient@users.noreply.github.com> Co-authored-by: legs <145564979+justsomelegs@users.noreply.github.com>


What Changed
Improves the local branch mismatch warning in the branch picker.
Why
When using local checkout mode, the active Git branch can drift away from the branch a thread was last associated with. Previously this was easy to miss and could lead to continuing work on the wrong branch.
This makes the mismatch visible in-place and gives users clear recovery actions without changing branches automatically.
The thread’s associated branch should only change when the user intentionally chooses a branch for the thread, creates/checks out a branch through the picker, or clicks
Use currentin the warning popover. It should not change just because the shared local checkout moved while viewing an existing server thread.UI Changes
Screenshots/video to attach:
Use current/Switchactions.Checklist
Note
Fix thread branch drift and PR matching for local checkouts and worktrees
resolveThreadPrto return the correct PR for dedicated worktrees (ignoring stale branch metadata) and to requiregitStatus.refNameto matchthreadBranchfor local checkouts.matchesBranchHeadContextin GitManager.ts to use normalized head identities, correctly rejecting cross-repo PRs in same-repo contexts and vice versa, and tolerating missing GitHub head identity metadata.resolveLocalCheckoutBranchMismatchto detect when the active git checkout differs from the thread's stored branch, and surfaces a warning banner in ChatView.tsx with actions to repair the mismatch or update the thread branch on send.resolveThreadMetadataUpdateForNextTurnto compute minimal thread metadata updates (model and/or branch) before sending a message.Macroscope summarized d3910e1.
Note
Medium Risk
Changes git PR reuse/matching and when thread branch metadata updates from the UI; mistakes could show wrong PRs or leave thread branch out of sync, though behavior is covered by new tests.
Overview
Prevents silent drift between a thread’s stored branch and the shared local checkout, and tightens when PRs and status indicators apply to a thread.
In local checkout mode, the branch picker now detects when the thread branch and current Git checkout differ (
resolveLocalCheckoutBranchMismatch), highlights the trigger, and shows a “Branches diverged” panel with Update thread (reassign to checkout) or Switch checkout (checkout the thread branch).GitActionsControlno longer auto-syncs thread branch from live git status while a server-backed thread is active—only draft threads still reconcile from status.PR indicators (
resolveThreadPr) now require the stored thread branch to match git status for local checkouts, but still show PR state for dedicated worktree threads even when thread branch metadata is stale or missing. PR tooltips use a richerPrStatusTooltipContentlayout.On the server,
matchesBranchHeadContextis exported and reworked to compare expected vs PR head identity more carefully: reject same-repo PRs for cross-repo head contexts, refuse ambiguous PRs when GitHub omits head repo/owner on cross-repo lookups, and accept cross-repo PR metadata when the checkout remote is the fork. NewGitManagertests cover these matching paths and fork PR reuse behavior.Reviewed by Cursor Bugbot for commit f762024. Bugbot is set up for automated code reviews on this repo. Configure here.