Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(source-control): keep clipped repository error details valid Unicode #48286

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

Problem

transportSafeSourceControlErrorValue clips error metadata at 256 UTF-16 code units with String.prototype.slice, which can split a surrogate pair in half. Through Add Project → GitLab, an unchecked repository selector reaches SourceControlRepositoryService.lookupRepository → GitLabCli.getRepositoryCloneUrls (glab api projects/<encoded>) and its 404 (not-found) branch (packages/source-control-gitlab/src/server/GitLabCli.ts:748), where repositoryNotFoundDetail interpolates that malformed value into userFacingDetail; SourceControlRepositoryService.mapRepositoryError forwards it as SourceControlRepositoryError.detail over JSON WebSocket RPC (RpcSerialization.layerJson, apps/server/src/ws.ts:4086), which escapes the lone high surrogate as \ud83d and restores the unpaired U+D83D code unit on decode before it reaches the mobile ErrorBanner (apps/mobile/src/features/projects/AddProjectScreen.tsx:1040,1059) and the web/Electron error toast description (apps/web/src/components/CommandPalette.tsx:2466-2472, including its unclipped copy text).

Deterministic formatter-only repro on origin/main (4b8199987cb63f82912b8f3dbe9de6a96cdb057b): Run from packages/source-control-core after installing dependencies (this exercises the formatter and JSON/UTF-8 boundaries directly, not a live RPC or rendered client):

node --input-type=module <<'JS'
import {
  repositoryNotFoundDetail,
  transportSafeSourceControlErrorValue,
} from "./src/server/SourceControlProvider.ts";

const straddling = `team/${"a".repeat(250)}🚀`;
const clipped = transportSafeSourceControlErrorValue(straddling);
const detail = repositoryNotFoundDetail(straddling);
const jsonWire = JSON.stringify({ detail });
const decodedDetail = JSON.parse(jsonWire).detail;
const utf8RoundTripped = new TextDecoder().decode(new TextEncoder().encode(decodedDetail));
console.log(JSON.stringify({
  clippedLength: clipped.length,
  clippedLastCodeUnitHex: `0x${clipped.charCodeAt(clipped.length - 1).toString(16)}`,
  jsonWireContainsEscapedHighSurrogate: jsonWire.includes("\\ud83d"),
  decodedDetailWellFormed: decodedDetail.isWellFormed(),
  utf8RoundTrippedTail: utf8RoundTripped.slice(245, 290),
}));
JS
  • Observed: clippedLastCodeUnitHex: "0xd83d", JSON escapes it as \ud83d, and decodedDetail.isWellFormed() is false (a formatter-only UTF-8 round-trip renders …aaaaaaaaaaaaaaaaaaaaa\uFFFD was not found. Check t).
  • Expected: Keep the 256-code-unit cap and drop the straddling emoji whole (clippedLength: 255, decodedDetailWellFormed: true), so decoded error details contain no lone surrogate.

Change

Before slicing safe at MAX_ERROR_TRANSPORT_VALUE_LENGTH in packages/source-control-core/src/server/SourceControlProvider.ts, step the cut back by one code unit when index 255 is a high surrogate (0xd800–0xdbff) followed by a low surrogate (0xdc00–0xdfff) at index 256. This shared sanitizer covers all callers that sanitize error metadata (including SourceControlProviderRegistry and Azure DevOps error metadata fields), as well as repositoryNotFoundDetail used by GitLab, GitHub, Bitbucket, Forgejo, GitCafe, and Cursor Origin, without wire contract changes.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Base (4b8199987cb63f82912b8f3dbe9de6a96cdb057b): vp test run packages/source-control-core/src/server/SourceControlProvider.test.ts -t "surrogate" failed on the new regression case with the trailing unpaired surrogate (U+D83D).
  • Head (717d70051d4429f530e7a9506cb2717d639d8b39): all 13 tests in packages/source-control-core/src/server/SourceControlProvider.test.ts pass, covering a surrogate pair straddling the 256-code-unit cut, a pair fitting at exactly 256 code units, and a pair fitting at 256 followed by trailing ASCII.
  • vp run check:changed exited 0 on 717d70051d4429f530e7a9506cb2717d639d8b39 (format, lint, knip, typecheck across 22 packages, and 15 tests across 2 files).
  • Before/after runtime & test transcript: formatter-only JSON/UTF-8 before/after output plus SHA-stamped base failure and head test/check:changed results.

Not shown: live forge API calls, full WebSocket RPC round-trips, rendered web/Electron/mobile client UI screenshots, or a scenarios:prove run; the transcript and tests exercise the real server formatter directly with a synthetic repository name.

Authored by Gemini 4 Neon (Antigravity); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • Draft PR body, Verification — The linked gist contains formatter-only before/after output, not the claimed SHA-stamped test and check:changed logs. Relabel it as formatter evidence and attach the run logs separately if available.
  • packages/source-control-gitlab/src/server/GitLabCli.ts:727 — No live GitLab lookup, full WebSocket exchange, rendered client check, or scenarios:prove run was performed; reachability was traced in source, and the regression was independently reproduced at the formatter and JSON boundaries.
    1. tanstack-source added labelsbug

    2. Approvability

      Verdict: Approved at 717d700

      Macroscope's review found this PR approvable — Error-detail clipping now avoids cutting Unicode surrogate pairs in half. The change is limited to error text and preserves existing length limits and sanitization.

      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 source-control error clipping function now avoids splitting surrogate pairs at its 256-code-unit limit. Tests cover boundary behavior and UTF-8 round-tripping of repository-not-found details.

      Changes: Source-control error clipping

      Layer / File(s)Summary
      Surrogate-safe clipping
      packages/source-control-core/src/server/SourceControlProvider.ts, packages/source-control-core/src/server/SourceControlProvider.test.ts
      Values up to 256 UTF-16 code units remain unchanged. Longer values are clipped without splitting a surrogate pair. Tests cover boundary cases and UTF-8 round-tripping of repository-not-found details.

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

      Change: Bug fix

      Suggested reviewers: only21mil

      Merge Risk: Minimal · up to 717d7

      This change keeps clipped repository error details valid Unicode without altering the wire contract. No merge-blocking risk was identified.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: clipped repository error details are kept as valid Unicode. The raw summary and objectives both say the sanitizer now moves the 256-code-unit cut back so a surrogate p…
      Description checkPassedThe description follows the repository template sections: Problem, Change, Scope, and Verification. It explains the surrogate-pair bug and its path to the client, and it describes the cut-back fix in …
      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: clipped repository error details are kept as valid Unicode. The raw summary and objectives both say the sanitizer now moves the 256-code-unit cut back so a surrogate pair is not split. The title follows the conventional commit style and is specific enough for a teammate scanning history.

      Full details: Description check

      Explanation

      The description follows the repository template sections: Problem, Change, Scope, and Verification. It explains the surrogate-pair bug and its path to the client, and it describes the cut-back fix in the shared sanitizer. It states the small-fix scope and gives base and head test results. It also lists what was not checked. The Verification section links a gist that the reviewer note says contains formatter-only output, not the SHA-stamped test logs the description claims. The Verification section also does not describe the template's required model and harness attribution beyond a parenthetical, which is present. The author should relabel the gist evidence or attach the logs, but the description is mostly complete.

      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 4b8199987cb63f82912b8f3dbe9de6a96cdb057b and 717d70051d4429f530e7a9506cb2717d639d8b39.

      Files selected for processing: 2

      • packages/source-control-core/src/server/SourceControlProvider.test.ts
      • packages/source-control-core/src/server/SourceControlProvider.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Sign in to join this conversation.