@devries-cameron20 / t3code Mirror · read-only / commits / 5e2a331bce
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 08:15 UTC

fix(server): preserve surrogate pairs in generated thread titles (#27483)

maco committed Nov 1, 2026 at 22:46 UTC 5e2a331bce1f3c387c3ddd7dfeec7e7318a2002a
2 files changed +21 -2
packages/provider-core/src/server/textGenerationUtils.test.ts
+14 -1
@@ -1,6 +1,6 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { sanitizeCommitSubject } from "./textGenerationUtils.ts";
3 +import { sanitizeCommitSubject, sanitizeThreadTitle } from "./textGenerationUtils.ts";
4
5 describe("sanitizeCommitSubject", () => {
6 // regression: #19181 truncation split grapheme clusters at the subject limit
@@ -14,3 +14,16 @@ describe("sanitizeCommitSubject", () => {
14 expect(sanitizeCommitSubject(`${prefix}${character} more`)).toBe(prefix);
15 });
16 });
17 +
18 +describe("sanitizeThreadTitle", () => {
19 + it.each([
20 + { name: "a split surrogate pair", prefixLength: 116, character: "🚀", retained: "" },
21 + { name: "a complete surrogate pair", prefixLength: 115, character: "🚀", retained: "🚀" },
22 + { name: "a BMP character", prefixLength: 116, character: "界", retained: "界" },
23 + ])("truncates without splitting $name", ({ prefixLength, character, retained }) => {
24 + const prefix = "a".repeat(prefixLength);
25 + const title = `${prefix}${character} more`;
26 +
27 + expect(sanitizeThreadTitle(title)).toBe(`${prefix}${retained}...`);
28 + });
29 +});
packages/provider-core/src/server/textGenerationUtils.ts
+7 -1
@@ -74,7 +74,13 @@ export function sanitizeThreadTitle(raw: string): string {
74 return normalized;
75 }
76
77 - return `${normalized.slice(0, MAX_THREAD_TITLE_CHARS - 3).trimEnd()}...`;
77 + let end = MAX_THREAD_TITLE_CHARS - 3;
78 + const previous = normalized.charCodeAt(end - 1);
79 + const next = normalized.charCodeAt(end);
80 + if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
81 + end -= 1;
82 + }
83 + return `${normalized.slice(0, end).trimEnd()}...`;
84 }
85
86 function cliLabel(cliName: string): string {