Skip to content

Fix new-thread draft reuse for worktree defaults#2003

Merged
juliusmarminge merged 1 commit intomainfrom
t3code/investigate-issue-1989
Apr 13, 2026
Merged

Fix new-thread draft reuse for worktree defaults#2003
juliusmarminge merged 1 commit intomainfrom
t3code/investigate-issue-1989

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 13, 2026

Summary

  • Prevents the new-thread flow from reusing an existing draft when the project default environment mode is worktree.
  • Preserves promoting draft threads so they are not reused while promotion is still in progress.
  • Adds coverage for the sidebar seed-context logic and the browser-level new-thread flow.

Testing

  • bun fmt
  • bun lint
  • bun typecheck
  • bun run test
  • Not run: additional manual verification beyond the automated tests

Note

Medium Risk
Touches new-thread draft creation/reuse logic and draft-store cleanup rules, which can impact routing and draft persistence across projects. Changes are localized and covered by new unit and browser-level tests, reducing regression risk.

Overview
New-thread draft reuse is tightened for worktree defaults and promotion in-flight. When the project default env mode is worktree, sidebar seed context now forces envMode: "worktree" instead of inheriting an active thread’s branch/worktree path, ensuring the next thread starts as a fresh worktree draft.

Draft reuse/cleanup is also guarded so promoting draft threads aren’t reused or deleted mid-promotion (useHandleNewThread checks promotedTo == null; composerDraftStore won’t evict a prior draft if it’s promoting). Adds regression coverage in ChatView.browser.tsx and Sidebar.logic.test.ts.

Reviewed by Cursor Bugbot for commit 33d6b03. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix new-thread draft reuse when the default environment mode is worktree

  • Fixes two bugs in the new-thread flow: promoting drafts were being reused instead of creating a new draft, and worktree-defaulted projects were inheriting branch/path context from active threads.
  • In useHandleNewThread.ts, draft reuse is now skipped when the active draft has already been promoted (promotedTo != null).
  • In composerDraftStore.ts, deletion of a previous logical-project draft is skipped when that draft is in a promoting state.
  • In Sidebar.logic.ts, resolveSidebarNewThreadSeedContext returns { envMode: 'worktree' } immediately when defaultEnvMode is 'worktree', ignoring any active thread context.

Macroscope summarized 33d6b03.

- Prefer worktree mode when the server default is worktree
- Avoid reusing promoting drafts as the source for new threads
- Preserve existing worktree drafts instead of deleting them
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 13, 2026

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: fc5eb936-4c33-4383-bf48-15c5c0aaa69d

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
  • Commit unit tests in branch t3code/investigate-issue-1989

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Apr 13, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 13, 2026

Approvability

Verdict: Approved

Small bug fix adding guard conditions to prevent incorrect draft thread reuse when worktree defaults are set or when drafts are being promoted. Production changes are minimal (~12 lines) with defensive null/state checks, accompanied by comprehensive test coverage (~114 lines). Low-risk, well-scoped fix.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge juliusmarminge merged commit 5f7ec73 into main Apr 13, 2026
12 checks passed
@juliusmarminge juliusmarminge deleted the t3code/investigate-issue-1989 branch April 13, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant