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. |
There was a problem hiding this comment.
💡 Codex Review
When defaultEnvMode is worktree, this newly reachable path also runs for matching active server threads that have neither branch nor worktreePath (for example, the auto-bootstrap empty thread is created with both fields null in serverRuntimeStartup.ts). In that case there is no checkout context to preserve, but this returns envMode: "local", so the sidebar “new thread” action silently ignores the user's New worktree default and creates a local draft instead of falling back to the default mode. Consider only overriding the default when the active thread actually has a branch or worktree path.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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 d123417.
Note
Medium Risk
Changes thread creation and git worktree/branch bootstrap behavior for users with default “New worktree”; wrong precedence could still spawn unexpected worktrees, but scope is limited to sidebar seed logic with solid test coverage.
Overview
New threads from the sidebar now inherit the active checkout instead of blindly applying the global “New worktree” default.
resolveSidebarNewThreadSeedContextno longer returns early with only{ envMode: "worktree" }whendefaultEnvModeis worktree. Resolution order is now matching active draft (branch, worktree, env mode,startFromOrigin), then matching active server thread (branch/worktree with env inferred fromworktreePath), then the configured default env mode when nothing matches.That stops contextual “new thread” actions from dropping branch/worktree and triggering unintended worktree bootstrap on first message. Regression tests cover drafts, local branches, existing worktrees, and the no-context fallback.
Reviewed by Cursor Bugbot for commit d123417. Bugbot is set up for automated code reviews on this repo. Configure here.