Allow empty server threads to bootstrap new worktrees#1936
Allow empty server threads to bootstrap new worktrees#1936juliusmarminge wants to merge 1 commit intomainfrom
Conversation
- Let the first send on an empty server thread override env mode and base branch - Use shorter locked workspace labels in the branch toolbar - Add coverage for worktree bootstrap and env-mode resolution
|
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)
Comment |
| isGitRepo, | ||
| }); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
🟠 High components/ChatView.tsx:2231
When switching from one server thread to another, both allowing environment mode overrides, pendingServerThreadEnvMode and pendingServerThreadBranch from Thread A incorrectly persist and apply to Thread B. The cleanup effect at lines 2231-2237 only resets these states when the new thread doesn't allow overrides, but when both threads allow overrides, the effect early-returns without clearing the pending state. This causes Thread B to use Thread A's pending branch selection when creating a worktree. Consider resetting the pending override state whenever activeThread.id changes, regardless of whether the new thread allows overrides.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/web/src/components/ChatView.tsx around line 2231:
When switching from one server thread to another, both allowing environment mode overrides, `pendingServerThreadEnvMode` and `pendingServerThreadBranch` from Thread A incorrectly persist and apply to Thread B. The cleanup effect at lines 2231-2237 only resets these states when the *new* thread doesn't allow overrides, but when both threads allow overrides, the effect early-returns without clearing the pending state. This causes Thread B to use Thread A's pending branch selection when creating a worktree. Consider resetting the pending override state whenever `activeThread.id` changes, regardless of whether the new thread allows overrides.
Evidence trail:
ChatView.tsx lines 2220-2237 at REVIEWED_COMMIT - specifically lines 2231-2237 show the cleanup effect that early-returns when `canOverrideServerThreadEnvMode` is true, and lines 2223-2226 show how `pendingServerThreadBranch` is used to compute `activeThreadBranch` without regard to which thread the pending value was set for.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Pending override state leaks between empty server threads
- Added a ref to track the previous thread ID so the cleanup effect resets pendingServerThreadEnvMode and pendingServerThreadBranch whenever activeThread.id changes, even when canOverrideServerThreadEnvMode remains true for both threads.
Or push these changes by commenting:
@cursor push a440ab779e
Preview (a440ab779e)
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -2228,12 +2228,15 @@
isGitRepo,
});
+ const prevThreadIdForPendingReset = useRef(activeThread?.id);
useEffect(() => {
- if (canOverrideServerThreadEnvMode) {
- return;
+ const threadChanged = prevThreadIdForPendingReset.current !== activeThread?.id;
+ prevThreadIdForPendingReset.current = activeThread?.id;
+
+ if (threadChanged || !canOverrideServerThreadEnvMode) {
+ setPendingServerThreadEnvMode(null);
+ setPendingServerThreadBranch(undefined);
}
- setPendingServerThreadEnvMode(null);
- setPendingServerThreadBranch(undefined);
}, [canOverrideServerThreadEnvMode, activeThread?.id]);
useEffect(() => {You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 9efc9f9. Configure here.
| } | ||
| setPendingServerThreadEnvMode(null); | ||
| setPendingServerThreadBranch(undefined); | ||
| }, [canOverrideServerThreadEnvMode, activeThread?.id]); |
There was a problem hiding this comment.
Pending override state leaks between empty server threads
Medium Severity
The cleanup effect includes activeThread?.id in its dependency array, suggesting it intends to reset pending state on thread navigation. However, the early return when canOverrideServerThreadEnvMode is true prevents the reset from ever running when switching between two empty server threads. pendingServerThreadEnvMode and pendingServerThreadBranch set on thread A will incorrectly apply to thread B, causing the toolbar to display the wrong env mode and branch, and potentially sending with the wrong base branch.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 9efc9f9. Configure here.
ApprovabilityVerdict: Needs human review 1 blocking correctness issue found. New feature adding worktree bootstrap capability for empty server threads with significant state management changes. Two unresolved review comments identify the same bug: pending override state leaks between empty server threads when navigating, potentially causing incorrect branch selection. You can customize Macroscope's approvability policy. Learn more. |



Summary
New worktreemode and bootstrap the first send without forcing a separate draft thread.Testing
bun fmtbun lintbun typecheckbun run testapps/web/src/components/ChatView.browser.tsxfor:New worktreemode from an empty server threadNote
Medium Risk
Changes first-send behavior for server threads by allowing transient env-mode/branch overrides and affecting worktree bootstrap parameters; regressions could alter how/when worktrees are created on send. Impact is bounded to chat composer send/workspace selection and covered by new unit/browser tests.
Overview
Empty server threads (no messages, no worktree path) can now temporarily switch into
New worktreemode and pick a base branch in theBranchToolbar, with those selections carried through to the firstthread.turn.startbootstrap.This adds pending override state in
ChatViewfor env mode/branch, threads it throughBranchToolbar/BranchToolbarBranchSelector, and adjusts send-time logic to use the overridden branch and a newresolveSendEnvModeguard (forcinglocalwhen not in a git repo).UI copy for locked workspace display is shortened via
resolveLockedWorkspaceLabel, and new unit + browser tests cover the empty-server-thread worktree bootstrap and base-branch selection behavior.Reviewed by Cursor Bugbot for commit 9efc9f9. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Allow empty server threads to select env mode and base branch before bootstrapping a new worktree
pendingServerThreadEnvModeandpendingServerThreadBranchstate toChatView.tsx, passed down as overrides toBranchToolbarandBranchToolbarBranchSelector.resolveSendEnvModeinChatView.logic.tsto force'local'env mode when the project is not a git repository, regardless of the selected mode.'Local checkout'/'Worktree'labels inBranchToolbarEnvModeSelectorvia the newresolveLockedWorkspaceLabelutil.'local'at send time.📊 Macroscope summarized 9efc9f9. 9 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues