Preserve checkout context when creating threads#3918
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: Approved Straightforward bug fix that removes an early-return condition that was incorrectly discarding checkout context when creating threads. The change is small, self-contained, and well-covered by updated unit tests demonstrating the intended behavior. You can customize Macroscope's approvability policy. Learn more. |
Summary
New worktreeWhy
Creating a thread from an existing branch or worktree communicates that the new thread should operate in that same checkout. Previously,
resolveSidebarNewThreadSeedContextchecked the globaldefaultThreadEnvModefirst. When that setting wasworktree, it returned only{ envMode: "worktree" }and discarded the active branch and worktree path.On the first message, that missing worktree path satisfied the worktree-bootstrap condition. T3 Code therefore created a new worktree with a temporary branch and later renamed the branch from the prompt. This made a contextual "new thread" action unexpectedly mutate repository structure and move the conversation away from the branch the user was already viewing.
That behavior is wrong because the default is a fallback preference, not an explicit request to override concrete checkout context. It is also risky and confusing: users can unintentionally accumulate branches and worktrees, and separate threads that were meant to collaborate on the same changes can end up in isolated checkouts.
The active matching context now takes precedence. A new branch is still created when the user is actually starting a new-worktree draft, or when there is no active context and
New worktreeis the configured default.Validation
pnpm exec vp test apps/web/src/components/Sidebar.logic.test.tspnpm exec vp checkpnpm exec vp run typecheckNote
Preserve checkout context when creating new threads in
resolveSidebarNewThreadSeedContextresolveSidebarNewThreadSeedContextwould immediately override context with'worktree'mode wheneverdefaultEnvModewas'worktree', ignoring any active thread or draft state.activeDraftThreadfirst, returning its full context (branch, worktreePath, envMode, startFromOrigin), then falls back toactiveThreadcontext withenvModederived from the presence ofworktreePath, and finally falls back todefaultEnvMode.Macroscope summarized c2c6a2a.
Note
Medium Risk
Changes thread creation and worktree bootstrap behavior for users with default “New worktree,” which can affect git checkout state but is a targeted logic fix with solid test coverage.
Overview
resolveSidebarNewThreadSeedContextno longer treats global “New worktree” as overriding the checkout you’re already on. The early return that dropped branch andworktreePathwheneverdefaultEnvModewasworktreeis removed.New threads in the same project now seed from matching active draft (full draft context, including
startFromOrigin), then matching active server thread (envModeisworktreeonly when that thread has aworktreePath), and only then fall back todefaultEnvModealone. That stops sidebar “new thread” from bootstrapping a fresh worktree when the user was viewing an existing branch or worktree.Regression tests cover draft-over-default, local branch, existing worktree, and the no-context fallback.
Reviewed by Cursor Bugbot for commit c2c6a2a. Bugbot is set up for automated code reviews on this repo. Configure here.