@devries-cameron20 / t3code-1 / commits / 2ad6712c6d
Fork 0

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

fix(provider-core): text generation context cuts no longer split an emoji (#29653)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Alex Southwell committed Nov 3, 2026 at 23:29 UTC 2ad6712c6d8054f32de9e04df89bd659380f48a3
4 files changed +23 -5
packages/provider-core/src/server/textGenerationUtils.test.ts
+7 -1
@@ -1,6 +1,12 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { sanitizeCommitSubject, sanitizeThreadTitle } from "./textGenerationUtils.ts";
3 +import { limitSection, sanitizeCommitSubject, sanitizeThreadTitle } from "./textGenerationUtils.ts";
4 +
5 +describe("limitSection", () => {
6 + it("cuts a long section without splitting an emoji", () => {
7 + expect(limitSection(`${"a".repeat(9)}🚀 more`, 10)).toBe(`${"a".repeat(9)}\n\n[truncated]`);
8 + });
9 +});
10
11 describe("sanitizeCommitSubject", () => {
12 // regression: #19181 truncation split grapheme clusters at the subject limit
packages/provider-core/src/server/textGenerationUtils.ts
+3 -1
@@ -19,7 +19,9 @@ export function toJsonSchemaObject(schema: Schema.Top): unknown {
19
20 export function limitSection(value: string, maxChars: number): string {
21 if (value.length <= maxChars) return value;
22 - const truncated = value.slice(0, maxChars);
22 + // Half an emoji serializes to a lone surrogate escape, which provider JSON parsers reject.
23 + const last = value.charCodeAt(maxChars - 1);
24 + const truncated = value.slice(0, last >= 0xd800 && last <= 0xdbff ? maxChars - 1 : maxChars);
25 return `${truncated}\n\n[truncated]`;
26 }
27
packages/provider-core/src/server/threadTitleContext.test.ts
+6 -1
@@ -1,7 +1,7 @@
1 import { describe, expect, it } from "vite-plus/test";
2 import { ChatAttachmentId } from "@t3tools/contracts";
3 import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
4 -import { formatThreadTitleContext } from "./threadTitleContext.ts";
4 +import { formatThreadTitleContext, limitTitleMessage } from "./threadTitleContext.ts";
5
6 describe("thread title context", () => {
7 it.each(["", "Ultrathink:\n"])("keeps attachments without bootstrap text (%j)", (prefix) => {
@@ -54,4 +54,9 @@ describe("thread title context", () => {
54 expect(result.message).not.toContain("System instructions");
55 expect(result.message.match(/USER:/g)).toHaveLength(1);
56 });
57 +
58 + it("cuts both ends of a long message without splitting an emoji", () => {
59 + const result = limitTitleMessage(`${"a".repeat(9)}🚀${"b".repeat(20)}🚀${"c".repeat(9)}`, 41);
60 + expect(result).toBe(`${"a".repeat(9)}\n[Content truncated]\n${"c".repeat(9)}`);
61 + });
62 });
packages/provider-core/src/server/threadTitleContext.ts
+7 -2
@@ -17,8 +17,13 @@ export function limitTitleMessage(text: string, budget: number): string {
17 if (text.length <= budget) return text;
18 if (budget <= TRUNCATED.length) return "";
19 const available = budget - TRUNCATED.length;
20 - const head = Math.ceil(available / 2);
21 - const tail = available - head;
20 + let head = Math.ceil(available / 2);
21 + let tail = available - head;
22 + // Half an emoji serializes to a lone surrogate escape, which provider JSON parsers reject.
23 + const last = text.charCodeAt(head - 1);
24 + if (last >= 0xd800 && last <= 0xdbff) head -= 1;
25 + const first = text.charCodeAt(text.length - tail);
26 + if (tail > 0 && first >= 0xdc00 && first <= 0xdfff) tail -= 1;
27 return `${text.slice(0, head)}${TRUNCATED}${tail > 0 ? text.slice(-tail) : ""}`;
28 }
29