fix(server): default MCP worktree launch keeps trailing Unicode whitespace in branch names #48236
main fromrefs/pull/48236/head·opened View on GitHubProblem#
When an external MCP client calls t3_thread_launch without an explicit workspaceStrategy on a project configured with defaultThreadEnvMode: "worktree", defaultWorktreeStrategy in apps/server/src/mcp/toolkits/project/handlers.ts trims git symbolic-ref --quiet --short HEAD stdout with .trim(). JavaScript's .trim() strips trailing Unicode whitespace (such as NBSP \u00A0) from valid Git branch names, turning main\u00A0 into nonexistent baseRef: "main", which ThreadLaunchService.checkWorktreeBase rejects before creating the thread.
Deterministic repro on origin/main (9a08ffb84084c441dcf4a2f595682a44632ecc89):
dir=$(mktemp -d)
git -C "$dir" init -b $'main\u00A0'
git -C "$dir" -c user.email=t@t -c user.name=t commit --allow-empty -m init
Register "$dir" (with no remotes) as a project with defaultThreadEnvMode: "worktree" (via Settings or t3.json), then invoke external MCP tool t3_thread_launch with { "title": "Fix", "projectId": "<projectId>" } (omitting workspaceStrategy).
- Observed on
origin/main:defaultWorktreeStrategyproduces{ type: "worktree", baseRef: "main" };ThreadLaunchService.checkWorktreeBasefails becausemaindoes not exist, sot3_thread_launchreturns aninvalid_requestfailure (Base ref "main" does not resolve to a commit...) and creates no thread. - Expected:
defaultWorktreeStrategypreserves{ type: "worktree", baseRef: "main\u00A0" }(while continuing to preserve Git's disambiguatedheads/<name>short ref when a tag shares a branch name), andt3_thread_launchproceeds with thatbaseRef.
Change#
In apps/server/src/mcp/toolkits/project/handlers.ts, keep git symbolic-ref --quiet --short HEAD so Git's heads/<name> tag-collision disambiguation stays intact through worktree provisioning, and replace head.stdout.trim() with trimAsciiWhitespace(head.stdout) from @t3tools/contracts. No contracts, clients, or UI copy are affected.
Scope#
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification#
- Base failure -> head pass: Added
"a defaulted worktree launch keeps trailing Unicode whitespace and disambiguated branch refs"inapps/server/src/mcp/toolkits/project/handlers.test.tscovering bothmain\u00A0(baseRef: "main\u00A0") and branchrelease+ tagrelease(baseRef: "heads/release"). On unmodifiedorigin/main(9a08ffb84084c441dcf4a2f595682a44632ecc89), the NBSP case failed withAssertionError: trailing NBSP: expected { type: 'worktree', … } to match object { type: 'worktree', baseRef: 'main\u00A0' }(receivedbaseRef: "main"). On head (09f2d910eb6925755f1c29356f4ce4c50b102198),vp test run apps/server/src/mcp/toolkits/project/handlers.test.tspasses all27/27tests. - Scoped checks:
vp run check:changedon09f2d910eb6925755f1c29356f4ce4c50b102198exited0(format,lint,knip,graphql (apps/server),typecheck (3 packages), andtest (2 files)—29/29passed). - Before/after transcript (including SHA-bound
check:changedsummary): https://gist.github.com/saphid/a45a034d58bf1416589c1953bad06da0 - Not shown: End-to-end live MCP HTTP transport request/response against a running server process (tested via the in-process
ProjectToolkithandler harness with stubbedThreadLaunchService), repo-wide test suites, and desktop/mobile builds (owned by CI).
Authored by Gemini 4 Neon (Antigravity); reviewed by GPT-6.2 Sol (Codex).
Not shown#
- draft PR body:8 — The repro command is split by the reviewer instructions and the detached suffix does not encode an NBSP. Remove the embedded reviewer instructions and use
git -C "$dir" init -b $'main\u00A0'on one line. - draft PR body:9 — State that the MCP client must be authorized to launch threads and the project must have a usable default model; otherwise the head run can fail for unrelated reasons. Keep the existing disclosure that no live MCP scenario was run.
- 1
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Approvability#
Verdict: Approved at
09f2d91Macroscope's review found this PR approvable — Preserves valid Unicode whitespace in branch names when selecting the base for MCP worktree launches. Existing default settings and launch safeguards remain unchanged.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Walkthrough
-
The default worktree strategy now uses
trimAsciiWhitespaceto process the Git branch name. A new test covers trailing non-breaking spaces and a branch name that collides with a tag.Changes: Worktree base ref handling
Layer / File(s) Summary Normalize and test the base ref
apps/server/src/mcp/toolkits/project/handlers.ts,apps/server/src/mcp/toolkits/project/handlers.test.tsdefaultWorktreeStrategyusestrimAsciiWhitespaceinstead oftrim(). The test checks that a trailing non-breaking space remains part of the base ref and that a branch/tag collision resolves toheads/release.Estimated code review effort: 2 (Simple) | ~5 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge,iamshadmantaqi
Merge Risk:
Minimal · up to09f2d-
This fixes default worktree launches for branch names ending in Unicode whitespace. No concrete remaining risk was found, so the change looks safe to merge.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: default MCP worktree launches keep trailing Unicode whitespace in branch names. It matches the changeset (replacing .trim() with trimAsciiWhitespace in defaultWorktree… Description check The description follows the template. It has Problem, Change, Scope, and Verification sections, and each is filled in with specific detail: the repro steps, the root cause, the fix, the issue-free jus… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title names the main change: default MCP worktree launches keep trailing Unicode whitespace in branch names. It matches the changeset (replacing .trim() with trimAsciiWhitespace in defaultWorktreeStrategy and adding a test) and uses the conventional commit format.
Full details: Description check
-
Explanation
The description follows the template. It has Problem, Change, Scope, and Verification sections, and each is filled in with specific detail: the repro steps, the root cause, the fix, the issue-free justification under CONTRIBUTING.md, and the test and check results with a transcript link. Verification includes the before/after results and states what was not checked. The description also includes a draft-review note block (the 'Not shown' section with notes about the repro command and authorization) that does not belong in the PR body. The template's required agent/model line is present (Gemini 4 Neon, GPT-6.2 Sol). Remaining gaps are minor: the stray review notes should be removed and the repro command should be kept on one line.
Resolution
Remove the embedded reviewer notes (the '### Not shown' block with draft PR body remarks and the HTML comment marker). Keep the repro command on one line as
git -C "$dir" init -b $'main\u00A0'. Optionally state that the live repro needs an authorized MCP client and a project with a usable default model.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 9a08ffb
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8770f3cc-23b4-4fed-99aa-06ee374bcfcf
Commits-
Reviewing files that changed from the base of the PR and between 9a08ffb84084c441dcf4a2f595682a44632ecc89 and 09f2d910eb6925755f1c29356f4ce4c50b102198.
Files selected for processing: 2-
apps/server/src/mcp/toolkits/project/handlers.test.tsapps/server/src/mcp/toolkits/project/handlers.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
-
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes