Add per-chat branch tracking and branch switch prompts#2529
Add per-chat branch tracking and branch switch prompts#2529taschaub wants to merge 2 commits intopingdotgg:mainfrom
Conversation
…d Sidebar components - Introduced `useThreadBranchTracking` hook to manage branch auto-linking and mismatch notifications for chat threads. - Added `SidebarThreadBranchBadge` component to display the current branch for each chat in the sidebar. - Removed `resolveLiveThreadBranchUpdate` function to prevent silent overwrites of chat branches, enhancing user awareness of branch mismatches. - Updated `ChatView` to utilize the new branch tracking logic and display appropriate banners for branch mismatches. - Refactored related components and tests to support the new branch tracking functionality.
- Renamed `initialThreadBranch` to `liveThreadBranch` for clarity in branch resolution logic. - Updated logic to determine the initial thread branch based on message presence and live thread branch. - Ensured that worktree mode checks for the correct base branch before sending messages, enhancing user experience and error handling.
|
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 |
| [input.projectCwd, input.threadRef, input.worktreePath], | ||
| ); | ||
|
|
||
| const handleRelink = useCallback( |
There was a problem hiding this comment.
🟡 Medium chat/useThreadBranchTracking.tsx:117
In handleRelink, the optimistic setThreadBranch call at line 123 updates local state before the API call, but when the API fails (lines 132-139), the local state is never rolled back. The UI shows the chat relinked to the new branch while the error toast reports failure, leaving the user in an inconsistent state. Consider moving setThreadBranch after the successful API response, or rolling back local state in the catch block.
🤖 Copy this AI Prompt to have your agent fix this:
In file apps/web/src/components/chat/useThreadBranchTracking.tsx around line 117:
In `handleRelink`, the optimistic `setThreadBranch` call at line 123 updates local state before the API call, but when the API fails (lines 132-139), the local state is never rolled back. The UI shows the chat relinked to the new branch while the error toast reports failure, leaving the user in an inconsistent state. Consider moving `setThreadBranch` after the successful API response, or rolling back local state in the catch block.
Evidence trail:
apps/web/src/components/chat/useThreadBranchTracking.tsx lines 117-145 (handleRelink function): setThreadBranch called at line ~123 before API call, catch block at lines ~132-139 shows toast only with no state rollback. apps/web/src/store.ts lines 1922-1944: setThreadBranch mutates Zustand store state (thread.branch, thread.worktreePath).
ApprovabilityVerdict: Needs human review 1 blocking correctness issue found. This PR introduces new user-facing behavior with branch mismatch banners and sidebar badges, replacing silent auto-relinking with explicit user prompts. Additionally, there is an unresolved review comment identifying a potential state consistency issue when API calls fail. You can customize Macroscope's approvability policy. Learn more. |
|
Duplicate of #2284 |
What Changed
Adds per-chat branch tracking so each chat can stay associated with the git branch it belongs to.
This PR:
Why
Chats often represent work on a specific branch. If the user later switches branches and continues the same chat, the agent can accidentally run against the wrong checkout.
This makes the branch relationship explicit. It also gives the user a clear recovery path instead of silently changing chat metadata or letting the agent continue on the wrong branch.
UI Changes
This adds branch context in two places:
Checklist
Note
Add per-chat branch tracking and branch-mismatch banner in the composer
useThreadBranchTrackinghook that auto-links a server thread to the current git branch when the thread has none, and detects mismatches between the thread's stored branch and the active checkout.vcs.switchRef) or relink the chat to the current branch.SidebarThreadBranchBadgeto display each thread's associated branch in the sidebar row.resolveLiveThreadBranchUpdateauto-sync behavior fromGitActionsControl; branch syncing now happens only via explicit user actions or the new banner.📊 Macroscope summarized 9f69ecd. 6 files reviewed, 4 issues evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues