fix(web): new worktree threads no longer reset their workspace on launch #15701
main fromrefs/pull/15701/head·opened View on GitHubProblem#
Starting a new Claude thread in New worktree mode from a client connected over T3 Connect fails about a second after launch with "The provider event stream closed unexpectedly". The same launch from the host's own app works. Expected: the thread starts in the worktree the server prepares. Details and the server timeline are in #15695.
Cause: the branch selector's automatic base-branch default (BranchToolbarBranchSelector.tsx) also ran for a thread that already existed on the server while the server was still preparing its worktree. The thread's branch and path are null until preparation finishes, so the effect called setThreadBranch(defaultBranch, null). For a server thread that sends thread.metadata.update { branch: "main", worktreePath: null }. The server sees a changed worktreePath, detaches the provider session ("Workspace changed."), and the Claude turn that just started fails. Codex survives the detach. On the host the window is usually missed. Over the relay, branches load after the launch and the effect fires inside it.
Change#
The automatic base-branch default only applies to drafts now. The condition moves into resolveWorktreeBaseBranchDefault in BranchToolbar.logic.ts, which returns null once the thread exists on the server. Workspace preparation already sets the branch and worktree for launched threads. The draft behavior is unchanged, and so are manual branch picks.
For a server thread, resolveEffectiveEnvMode only reports worktree without a worktree path while preparingWorktree is set. So the launch window is the only server-thread case this guard removes. Mobile picks its default branch in its local new-task flow and never sends this update. Desktop uses the web client.
Scope and approval#
This fixes the bug reported in #15695 (not triaged yet). I think it qualifies as a small, focused fix for an obvious bug: an automatic UI default overwrote the workspace the server was preparing. The fix restricts that default to drafts, which is what its comment and draft-only fields assume. It doesn't change the server or any contract. The server could also refuse worktree changes during an active run. That would be a separate change, so it isn't included here.
Verification#
- Found on a real setup: desktop 0.0.46-nightly.20261004.2648 as host, a second Mac connected through T3 Connect. 5 of 5 Claude launches from the remote client failed. The host's
orchestration_eventsshow the remote connection'sthread.metadata.update(branch=main, worktreePath=null) 0.4 s after the server set the prepared worktree. Then comeprovider-session.detachedwith reason "Workspace changed." and the failed run. The same prompt and model launched on the host succeeded. Full timeline in #15695. vp test run src/components/BranchToolbar.logic.test.ts(apps/web): 79 passed. With thehasServerThreadcheck removed, only the new "leaves a launched thread to the server while its worktree is prepared" test fails (1 failed, 78 passed).vp lintandvp fmt --checkon the three changed files: clean.tsc --noEmitinapps/web: clean.- Not checked: I did not run a patched client against a remote host end to end. Building the desktop app on the second machine was out of scope. There is no visual change, so there are no screenshots.
Claude Opus 5.5 via Claude Code
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
9a5ff117-c345-40ee-a12a-abbfef59af5c
📥 Commits
Reviewing files that changed from the base of the PR and between 4ee6bfd50ef4a089440d5c3662db2298da9cc50e and dd54e157e822b9605558846935f8b7c8534f14ff.
📒 Files selected for processing (3)
apps/web/src/components/BranchToolbar.logic.test.tsapps/web/src/components/BranchToolbar.logic.tsapps/web/src/components/BranchToolbarBranchSelector.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The PR adds a resolver for worktree base-branch defaults, integrates it into branch selection, and adds tests for eligible and ineligible draft states.
Changes#
Worktree base branch defaulting
Layer / File(s) Summary Default resolution and validation
apps/web/src/components/BranchToolbar.logic.ts,apps/web/src/components/BranchToolbar.logic.test.tsresolveWorktreeBaseBranchDefaultreturns the candidate only for a new worktree draft without an active worktree, thread branch, or server thread. Tests cover these conditions.Branch selector integration
apps/web/src/components/BranchToolbarBranchSelector.tsxThe selector derives a candidate from repository refs and the current Git branch, then assigns the resolver result with automatic selection. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
dd54eNo actionable merge blocker is evident; the change is mergeable after normal checks.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
dd54eThe change prevents automatic branch defaults from overwriting a launched thread’s workspace. No increased access or authority was identified, but cleanup after failed or interrupted workspace preparation was not fully validated.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
- inferred — The changed automatic path affects the selected draft/thread workspace and its provider-session lifecycle. Comparing parent and head shows reduced server-write reachability, without a new environment selector, thread identity, or mutation command.
Trust Boundaries and Controls
- observed — Repository-derived branch candidates can reach automatic draft updates only when no server thread, existing branch, or worktree path is present. Existing environment and thread references continue to scope the mutation target; the change does not add server-side identity enforcement.
Resilience and Maintainability Implications
- inferred — A stale draft-render effect uses its captured draft setter rather than acquiring server metadata authority. Repeated defaulting becomes ineligible once a branch is present, and updates to removed drafts are no-ops. These properties bound the selector-side race but do not prove interruption or worktree-cleanup guarantees on the server.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Title check ✅ Passed The title clearly describes the main fix: new worktree threads no longer reset their workspace during launch. Description check ✅ Passed The description covers the problem, cause, change, scope rationale, and focused verification results. It also explains why screenshots are not included because there is no visual change, and identifie… Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. - Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This changes the automatic worktree base-branch behavior in the production web client and affects launch-time workspace updates for server-backed threads. The implementation is focused and covered by unit tests, but the changed default and runtime workspace behavior warrant human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).