Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): default MCP worktree launch keeps trailing Unicode whitespace in branch names #48236

Opensaphid(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48236/headopened View on GitHub

Problem

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: defaultWorktreeStrategy produces { type: "worktree", baseRef: "main" }; ThreadLaunchService.checkWorktreeBase fails because main does not exist, so t3_thread_launch returns an invalid_request failure (Base ref "main" does not resolve to a commit...) and creates no thread.
  • Expected: defaultWorktreeStrategy preserves { type: "worktree", baseRef: "main\u00A0" } (while continuing to preserve Git's disambiguated heads/<name> short ref when a tag shares a branch name), and t3_thread_launch proceeds with that baseRef.

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" in apps/server/src/mcp/toolkits/project/handlers.test.ts covering both main\u00A0 (baseRef: "main\u00A0") and branch release + tag release (baseRef: "heads/release"). On unmodified origin/main (9a08ffb84084c441dcf4a2f595682a44632ecc89), the NBSP case failed with AssertionError: trailing NBSP: expected { type: 'worktree', … } to match object { type: 'worktree', baseRef: 'main\u00A0' } (received baseRef: "main"). On head (09f2d910eb6925755f1c29356f4ce4c50b102198), vp test run apps/server/src/mcp/toolkits/project/handlers.test.ts passes all 27/27 tests.
  • Scoped checks: vp run check:changed on 09f2d910eb6925755f1c29356f4ce4c50b102198 exited 0 (format, lint, knip, graphql (apps/server), typecheck (3 packages), and test (2 files) — 29/29 passed).
  • Before/after transcript (including SHA-bound check:changed summary): 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 ProjectToolkit handler harness with stubbed ThreadLaunchService), 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

    2. Approvability

      Verdict: Approved at 09f2d91

      Macroscope'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).
    3. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The default worktree strategy now uses trimAsciiWhitespace to 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.ts
      defaultWorktreeStrategy uses trimAsciiWhitespace instead of trim(). The test checks that a trailing non-breaking space remains part of the base ref and that a branch/tag collision resolves to heads/release.

      Estimated code review effort: 2 (Simple) | ~5 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge, iamshadmantaqi

      Merge Risk: Minimal · up to 09f2d

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe 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 checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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

      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.ts
      • apps/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.