Skip to content

improve and prevent silent thread branch drift and PR fetching#2284

Open
justsomelegs wants to merge 10 commits intopingdotgg:mainfrom
justsomelegs:t3code/git-audit-stability
Open

improve and prevent silent thread branch drift and PR fetching#2284
justsomelegs wants to merge 10 commits intopingdotgg:mainfrom
justsomelegs:t3code/git-audit-stability

Conversation

@justsomelegs
Copy link
Copy Markdown
Contributor

@justsomelegs justsomelegs commented Apr 22, 2026

What Changed

Improves the local branch mismatch warning in the branch picker.

  • Highlights the branch picker with a warning color when the thread branch and current checkout differ.
  • Adds an inline warning icon to the picker.
  • Shows a popover above the picker explaining the mismatch.
  • Adds actions to either switch the checkout back to the thread branch or update the thread to use the current checkout.
  • Keeps server thread branch metadata from being overwritten when the shared local checkout changes.
  • Tightens PR/status indicator behavior so local checkout PR state is scoped to the relevant thread branch.
  • Improves PR fetching so that forked repos with PR on upstream not origin allow showing PR status in application

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 current in the warning popover. It should not change just because the shared local checkout moved while viewing an existing server thread.

UI Changes

image image

Screenshots/video to attach:

  • Before screenshot of the old picker state.
  • After screenshot of the warning picker and popover.
  • Short video showing hover/click on the warning icon and the Use current / Switch actions.

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

Fix silent thread branch drift and PR fetching for shared checkouts and worktrees

  • Prevents background git sync in GitActionsControl from overwriting an existing server thread's branch when using a shared checkout; branch sync now only runs for draft threads.
  • Adds a warning UI in BranchToolbarBranchSelector when the thread's stored branch differs from the current checkout, with actions to either switch the checkout or update the thread.
  • Fixes resolveThreadPr in ThreadStatusIndicators so dedicated worktree threads always surface PR info even if the stored branch is stale or missing.
  • Hardens matchesBranchHeadContext in GitManager to reject same-repo PRs for cross-repo head contexts and avoid false matches when head identity metadata is absent.
  • Behavioral Change: threads with dedicated worktrees now fetch git status and show PR indicators even without a stored branch; matchesBranchHeadContext is stricter about cross-repo vs same-repo PR reuse.

Macroscope summarized c4e2315.


Open in Devin Review

Note

Medium Risk
Touches PR matching logic and thread/ref state synchronization across server + UI, which can affect which PRs are reused/displayed and when thread branch metadata updates. Changes are well-covered by new unit/integration tests but could still cause edge-case regressions in ref/PR selection flows.

Overview
Prevents silent thread branch drift in local-checkout mode by detecting when the thread’s stored ref differs from the current checkout and surfacing an inline warning + popover actions (switch checkout to thread ref, or re-associate thread to current ref) in BranchToolbarBranchSelector.

Tightens PR/status scoping so PR indicators for local checkouts only show when vcsStatus.refName matches the thread’s stored branch, while dedicated worktree threads always show the worktree’s PR even if stored branch metadata is stale/missing; PR tooltips are now rendered via structured tooltipLead/tooltipTitle (PrStatusTooltipContent).

Fixes cross-repo PR reuse edge cases by reworking matchesBranchHeadContext to compare head identity only when comparable metadata exists, rejecting ambiguous cross-repo PRs when GitHub omits head identity fields; adds new server-side tests for these scenarios. Also introduces vcs*-named query/status wrappers (vcsQueryKeys, vcsRefSearchInfiniteQueryOptions, useVcsStatus/refreshVcsStatus) while keeping git* aliases for compatibility.

Reviewed by Cursor Bugbot for commit e0314cf. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

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

Run ID: 023a253a-93fc-443f-94d4-b4fb3c22e4b7

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 22, 2026
Comment thread apps/server/src/git/Layers/GitManager.ts
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Apr 22, 2026

Approvability

Verdict: Needs human review

1 blocking correctness issue found. This PR introduces a new branch mismatch warning feature with user-facing UI changes, refactors core PR matching logic, and has an unresolved bug where setThreadBranch is not called after checkout in the new switch function. These behavioral additions and the identified issue warrant human review.

You can customize Macroscope's approvability policy. Learn more.

Comment thread apps/server/src/git/GitManager.ts
@justsomelegs justsomelegs changed the title improve and prevent silent thread branch drift improve and prevent silent thread branch drift and PR fetching Apr 22, 2026
@juliusmarminge
Copy link
Copy Markdown
Member

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

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. and removed vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 30, 2026
@justsomelegs justsomelegs force-pushed the t3code/git-audit-stability branch from f1ffd01 to 02bb838 Compare May 1, 2026 22:56
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes 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.

Reviewed by Cursor Bugbot for commit 23355c1. Configure here.

Comment thread apps/server/src/git/GitManager.ts
@juliusmarminge
Copy link
Copy Markdown
Member

either i messed soemthing up when mergin main or i don't understand this PR:

CleanShot.2026-05-02.at.23.02.21.mp4

@github-actions github-actions Bot added size:XXL 1,000+ changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels May 3, 2026
@justsomelegs justsomelegs force-pushed the t3code/git-audit-stability branch from e0314cf to beb7b1a Compare May 4, 2026 09:20
@vercel
Copy link
Copy Markdown

vercel Bot commented May 4, 2026

@justsomelegs is attempting to deploy a commit to the Ping Labs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). and removed size:XXL 1,000+ changed lines (additions + deletions). labels May 4, 2026
@justsomelegs
Copy link
Copy Markdown
Contributor Author

either i messed soemthing up when mergin main or i don't understand this PR:

CleanShot.2026-05-02.at.23.02.21.mp4

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

Comment thread apps/web/src/components/BranchToolbarBranchSelector.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants