Skip to content

Preserve checkout context when creating threads#3918

Open
jakeleventhal wants to merge 1 commit into
pingdotgg:mainfrom
jakeleventhal:t3code/preserve-branch-when-creating-threads
Open

Preserve checkout context when creating threads#3918
jakeleventhal wants to merge 1 commit into
pingdotgg:mainfrom
jakeleventhal:t3code/preserve-branch-when-creating-threads

Conversation

@jakeleventhal

@jakeleventhal jakeleventhal commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve the active draft's branch and worktree when creating another thread from the same project
  • preserve the active server thread's branch or worktree even when the global default thread mode is New worktree
  • retain the configured default mode as the fallback when there is no matching active thread context
  • add regression coverage for existing branches, existing worktrees, and active drafts

Why

Creating a thread from an existing branch or worktree communicates that the new thread should operate in that same checkout. Previously, resolveSidebarNewThreadSeedContext checked the global defaultThreadEnvMode first. When that setting was worktree, 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 worktree is the configured default.

Validation

  • pnpm exec vp test apps/web/src/components/Sidebar.logic.test.ts
  • pnpm exec vp check
  • pnpm exec vp run typecheck

Note

Preserve checkout context when creating new threads in resolveSidebarNewThreadSeedContext

  • Previously, resolveSidebarNewThreadSeedContext would immediately override context with 'worktree' mode whenever defaultEnvMode was 'worktree', ignoring any active thread or draft state.
  • Now, the function checks for a matching activeDraftThread first, returning its full context (branch, worktreePath, envMode, startFromOrigin), then falls back to activeThread context with envMode derived from the presence of worktreePath, and finally falls back to defaultEnvMode.
  • Behavioral Change: new threads now inherit branch and worktree context from the active thread or draft instead of defaulting to the project-level env mode.

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
resolveSidebarNewThreadSeedContext no longer treats global “New worktree” as overriding the checkout you’re already on. The early return that dropped branch and worktreePath whenever defaultEnvMode was worktree is removed.

New threads in the same project now seed from matching active draft (full draft context, including startFromOrigin), then matching active server thread (envMode is worktree only when that thread has a worktreePath), and only then fall back to defaultEnvMode alone. 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.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

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: 912cd379-ca2c-45b8-9d43-66651c48801f

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

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Jul 12, 2026
@jakeleventhal jakeleventhal marked this pull request as ready for review July 12, 2026 18:27
@macroscopeapp

macroscopeapp Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant