Skip to content

Allow empty server threads to bootstrap new worktrees#1936

Merged
juliusmarminge merged 5 commits intomainfrom
feature/empty-server-worktree-bootstrap
Apr 13, 2026
Merged

Allow empty server threads to bootstrap new worktrees#1936
juliusmarminge merged 5 commits intomainfrom
feature/empty-server-worktree-bootstrap

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 11, 2026

Summary

  • Enables empty server threads to enter New worktree mode and bootstrap the first send without forcing a separate draft thread.
  • Preserves selected base-branch state for empty server threads so branch changes made in the toolbar are used when creating the worktree.
  • Clarifies workspace labeling for locked env mode states and adds logic coverage for the new send/env-mode behavior.
  • Adds browser-level coverage for first-send worktree bootstrap and base-branch selection on empty server threads.

Testing

  • bun fmt
  • bun lint
  • bun typecheck
  • bun run test
  • Browser flow checks added in apps/web/src/components/ChatView.browser.tsx for:
    • bootstrapping the first send in New worktree mode from an empty server thread
    • updating the selected worktree base branch before send

Note

Medium Risk
Medium risk because it changes first-send behavior and branch/env-mode selection for server threads, which affects worktree creation and command dispatch paths; mistakes could create worktrees off the wrong base branch or leave UI state inconsistent.

Overview
Enables empty server threads (no messages, no worktree) to temporarily opt into New worktree mode, select a base branch in the toolbar, and have that choice used to bootstrap worktree creation on the first send (via pending overrides cleared on thread switch / when no longer eligible).

Extracts temporary-worktree branch utilities into @t3tools/shared/git (WORKTREE_BRANCH_PREFIX, buildTemporaryWorktreeBranchName, isTemporaryWorktreeBranch) and updates server/web to use them, while adding resolveSendEnvMode to force local sends for non-git repos.

UI/UX tweaks: introduces resolveLockedWorkspaceLabel so locked workspace state shows shorter labels, and expands unit + browser tests to cover the new first-send bootstrap and override-reset flows.

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

Note

Allow empty server threads to bootstrap new worktrees with a user-selected base branch

  • Adds pendingServerThreadEnvMode and pendingServerThreadBranch state to ChatView.tsx so empty server threads can remain in 'New worktree' mode before the first message is sent.
  • On first send, calls prepareWorktree using a temporary t3code/<8-hex> branch name generated by the new buildTemporaryWorktreeBranchName helper in packages/shared/src/git.ts.
  • Centralizes WORKTREE_BRANCH_PREFIX, buildTemporaryWorktreeBranchName, and isTemporaryWorktreeBranch into the shared git module, removing duplicate definitions from ChatView.logic.ts and ProviderCommandReactor.ts.
  • Adds resolveSendEnvMode in ChatView.logic.ts to force non-git repositories to 'local' mode regardless of the user's selected env mode.
  • Updates BranchToolbar and BranchToolbarBranchSelector to accept override props for env mode and active branch, enabling the pre-send selection UI for empty server threads.

Macroscope summarized ae19339.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 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: d968b7dc-9bbf-45c8-a48c-3624a3066774

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 feature/empty-server-worktree-bootstrap

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

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

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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.

Create PR

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.

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 11, 2026

Approvability

Verdict: Needs human review

This PR introduces new feature capability allowing empty server threads to be configured for worktree mode before the first message is sent. While well-tested and the code is reasonable, this changes runtime behavior for thread bootstrapping workflows and introduces new user-facing functionality that warrants human review.

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

- 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
@juliusmarminge juliusmarminge force-pushed the feature/empty-server-worktree-bootstrap branch from 9efc9f9 to db1833b Compare April 13, 2026 17:14
- Clear staged server thread env/branch overrides when the active thread changes
- Add regression coverage for switching between empty server threads
- Move worktree branch prefix and matcher into shared git utils
- Add coverage for temporary branch detection
- Generate temp worktree branch names in `packages/shared`
- Update the web chat view to use the shared helper
- Add coverage for the generated branch format
@juliusmarminge juliusmarminge merged commit 801b83e into main Apr 13, 2026
12 checks passed
@juliusmarminge juliusmarminge deleted the feature/empty-server-worktree-bootstrap branch April 13, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 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