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): t3_thread_read pages no longer split an emoji in half (#27273)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
MarcoDotIO committed
Nov 1, 2026 at 16:42 UTC
febd3777c9c39ea871c41837ea92f5e0f7856dbb
3 files changed
+111
-3
apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
+93
@@ -9,6 +9,7 @@ import {
9
RunId,
10
ScheduledTaskId,
11
ThreadId,
12
+ TurnItemId,
13
} from "@t3tools/contracts";
14
import * as DateTime from "effect/DateTime";
15
import * as Effect from "effect/Effect";
@@ -205,6 +206,98 @@ it("readThread preserves caller access errors and prefers activity-run status ov
206
}).pipe(Effect.provide(layer), Effect.runPromise);
207
});
208
209
+it("readThread pages cut-off text without splitting an emoji across pages", async () => {
210
+ const text = "a😀bc";
211
+ const itemId = TurnItemId.make("turn-item-mcp-reasoning");
212
+ const projection = {
213
+ thread: baseThread({
214
+ threadId: parentThreadId,
215
+ title: "Parent",
216
+ instanceId: parentInstanceId,
217
+ model: "gpt-5.4",
218
+ }),
219
+ runs: [makeRun({ id: activeRunId, ordinal: 1, status: "running" })],
220
+ visibleTurnItems: [],
221
+ runtimeRequests: [],
222
+ messages: [],
223
+ contextTransfers: [],
224
+ subagents: [],
225
+ updatedAt: now,
226
+ } as unknown as OrchestrationV2ThreadProjection;
227
+ const row = {
228
+ position: 0,
229
+ visibility: "visible",
230
+ sourceThreadId: parentThreadId,
231
+ sourceItemId: itemId,
232
+ item: {
233
+ type: "reasoning",
234
+ runId: activeRunId,
235
+ status: "completed",
236
+ title: null,
237
+ text,
238
+ updatedAt: now,
239
+ },
240
+ };
241
+
242
+ const layer = layerOrchestratorService.pipe(
243
+ Layer.provide(
244
+ Layer.mergeAll(
245
+ Layer.mock(ThreadManagementService.ThreadManagementService)({
246
+ getTimelinePage: () =>
247
+ Effect.succeed({
248
+ items: [row] as unknown as OrchestrationV2ThreadProjection["visibleTurnItems"],
249
+ totalItems: 1,
250
+ hasMore: false,
251
+ }),
252
+ getThreadRecords: () => Effect.succeed(projection),
253
+ getProjectThreadRecords: () => Effect.succeed(projection),
254
+ getThreadShell: () =>
255
+ Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell),
256
+ } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
257
+ ServerSettings.layerTest(),
258
+ Layer.mock(ProviderRegistry.ProviderRegistry)({
259
+ getProviders: Effect.succeed([]),
260
+ } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
261
+ Layer.mock(ProjectService.ProjectService)({}),
262
+ Layer.mock(SecretRequests.SecretRequests)({}),
263
+ Layer.mock(RemoteDelegation.RemoteDelegation)({}),
264
+ Layer.mock(ScheduledTaskService.ScheduledTaskService)({
265
+ list: () => Effect.succeed({ tasks: [] }),
266
+ } satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>),
267
+ Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
268
+ list: () => Effect.succeed([]),
269
+ } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
270
+ NodeCrypto.layer,
271
+ ),
272
+ ),
273
+ );
274
+
275
+ await Effect.gen(function* () {
276
+ const service = yield* OrchestratorMcpService.OrchestratorMcpService;
277
+ for (const [maxCharsPerItem, expected] of [
278
+ [2, ["a", "😀", "bc"]],
279
+ [1, ["a", "😀", "b", "c"]],
280
+ ] as const) {
281
+ let textOffset = 0;
282
+ for (const [index, text] of expected.entries()) {
283
+ const result = yield* service.readThread(makeScope(), {
284
+ threadId: parentThreadId,
285
+ view: "activity",
286
+ itemId,
287
+ textOffset,
288
+ maxCharsPerItem,
289
+ });
290
+ textOffset += text.length;
291
+ expect(result.items[0]).toMatchObject({
292
+ text,
293
+ textTruncated: index < expected.length - 1,
294
+ nextTextOffset: index < expected.length - 1 ? textOffset : null,
295
+ });
296
+ }
297
+ }
298
+ }).pipe(Effect.provide(layer), Effect.runPromise);
299
+});
300
+
301
it("taskStatus returns task.providerInstanceId rather than the driver kind", async () => {
302
const parentProjection = {
303
thread: baseThread({
apps/server/src/mcp/OrchestratorMcpService.ts
+11
-2
@@ -631,7 +631,7 @@ function pageIncludesTerminalTaskResult(input: {
631
if (!matchesResult) return false;
632
633
const text = turnItemText(row.item);
634
- return text !== null && text.length <= input.maxChars;
634
+ return text !== null && text.length <= textPageEnd(text, 0, input.maxChars);
635
});
636
}
637
@@ -948,6 +948,15 @@ function turnItemText(item: OrchestrationV2TurnItem): string | null {
948
}
949
}
950
951
+/** A cut inside a surrogate pair would leave half an emoji on each page. */
952
+function textPageEnd(text: string | null, offset: number, maxChars: number): number {
953
+ const end = offset + maxChars;
954
+ if (text === null || end >= text.length) return end;
955
+ const last = text.charCodeAt(end - 1);
956
+ if (last < 0xd800 || last > 0xdbff) return end;
957
+ return end - 1 > offset ? end - 1 : end + 1;
958
+}
959
+
960
function timelineItem(input: {
961
readonly row: OrchestrationV2ThreadProjection["visibleTurnItems"][number];
962
readonly maxChars: number;
@@ -956,7 +965,7 @@ function timelineItem(input: {
965
}): OrchestratorMcpThreadTimelineItem {
966
const text = turnItemText(input.row.item);
967
const offset = input.textOffset ?? 0;
959
- const end = offset + input.maxChars;
968
+ const end = textPageEnd(text, offset, input.maxChars);
969
const textTruncated = text !== null && text.length > end;
970
const messageId =
971
input.row.item.type === "user_message" || input.row.item.type === "assistant_message"
apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
+7
-1
@@ -195,6 +195,7 @@ describe("orchestrator MCP toolkit", () => {
195
it.live.each([
196
{ label: "distinct", result: queuedFollowupResult, latestSummary: queuedFollowupResult },
197
{ label: "identical", result: delegatedResult, latestSummary: null },
198
+ { label: "emoji", result: "😀", latestSummary: "😀" },
199
])("reports $label child results", ({ result, latestSummary }) =>
200
Effect.scoped(
201
Effect.gen(function* () {
@@ -660,7 +661,11 @@ describe("orchestrator MCP toolkit", () => {
661
).toHaveLength(1);
662
const parentlessRead = yield* invoke(
663
"t3_thread_read",
663
- { threadId: delegated.childThreadId, limit: 100 },
664
+ {
665
+ threadId: delegated.childThreadId,
666
+ limit: 100,
667
+ maxCharsPerItem: result === "😀" ? 1 : 20_000,
668
+ },
669
{ ...invocation, thread: undefined },
670
).pipe(Effect.withTracer(tracer));
671
expect(parentlessRead.isError).not.toBe(true);
@@ -674,6 +679,7 @@ describe("orchestrator MCP toolkit", () => {
679
const read = yield* invoke("t3_thread_read", {
680
threadId: delegated.childThreadId,
681
limit: 100,
682
+ maxCharsPerItem: result === "😀" ? 1 : 20_000,
683
}).pipe(Effect.withTracer(tracer));
684
expect(read.isError).not.toBe(true);
685
expect(transferReads.length).toBeGreaterThan(0);