@devries-cameron20 / t3code Mirror · read-only / commits / 85b160658f
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 21, 18:30 UTC

fix(server): keep thread tool responses small by default (#29268)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Lakshmi Tanmay committed Nov 13, 2026 at 03:39 UTC 85b160658f83039c22ec25c5f146a1709715efc9
5 files changed +95 -19
apps/server/src/cli/thread.ts
+10 -1
@@ -50,6 +50,7 @@ const TERMINAL_RUN_STATUSES = new Set<OrchestratorMcpThreadRun["status"]>([
50 "rolled_back",
51 ]);
52 const READ_PAGE_LIMIT = 100;
53 +const READ_ITEM_MAX_CHARS = 20_000;
54 const TITLE_MAX_CHARS = 80;
55
56 export class ThreadServerNotRunningError extends Schema.TaggedError<ThreadServerNotRunningError>()(
@@ -394,6 +395,7 @@ const readTimeline = Effect.fn("cli.thread.readTimeline")(function* (
395 threadId,
396 view,
397 limit: READ_PAGE_LIMIT,
398 + maxCharsPerItem: READ_ITEM_MAX_CHARS,
399 runLimit: 1,
400 ...(afterPosition === undefined ? {} : { afterPosition }),
401 },
@@ -439,6 +441,7 @@ export const readLatestMessages = Effect.fn("cli.thread.readLatestMessages")(fun
441 threadId,
442 view: "messages",
443 limit: READ_PAGE_LIMIT,
444 + maxCharsPerItem: READ_ITEM_MAX_CHARS,
445 runLimit: 1,
446 ...(afterPosition < 0 ? {} : { afterPosition }),
447 },
@@ -473,7 +476,13 @@ const readFullText = Effect.fn("cli.thread.readFullText")(function* (
476 while (nextTextOffset !== null) {
477 const page = yield* tools.call(
478 "t3_thread_read",
476 - { threadId, itemId: item.itemId, textOffset: nextTextOffset, runLimit: 1 },
479 + {
480 + threadId,
481 + itemId: item.itemId,
482 + textOffset: nextTextOffset,
483 + runLimit: 1,
484 + maxCharsPerItem: READ_ITEM_MAX_CHARS,
485 + },
486 OrchestratorMcpThreadReadResult,
487 );
488 const chunk = page.items.find((candidate) => candidate.itemId === item.itemId);
apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
+35 -6
@@ -301,17 +301,35 @@ it("readThread pages cut-off text without splitting an emoji across pages", asyn
301 updatedAt: now,
302 },
303 };
304 + const rows = [
305 + row,
306 + ...Array.from({ length: 11 }, (_, index) => ({
307 + ...row,
308 + position: index + 1,
309 + sourceItemId: TurnItemId.make(`turn-item-mcp-${index}`),
310 + item: { ...row.item, text: "x".repeat(600) },
311 + })),
312 + ];
313
314 const layer = layerOrchestratorService.pipe(
315 Layer.provide(
316 Layer.mergeAll(
317 Layer.mock(ThreadManagementService.ThreadManagementService)({
309 - getTimelinePage: () =>
310 - Effect.succeed({
311 - items: [row] as unknown as OrchestrationV2ThreadProjection["visibleTurnItems"],
312 - totalItems: 1,
313 - hasMore: false,
314 - }),
318 + getTimelinePage: (_threadId, options) => {
319 + const remaining = rows.filter(
320 + (candidate) =>
321 + candidate.position > (options.afterPosition ?? -1) &&
322 + (options.itemId === undefined || candidate.sourceItemId === options.itemId),
323 + );
324 + return Effect.succeed({
325 + items: remaining.slice(
326 + 0,
327 + options.limit,
328 + ) as unknown as OrchestrationV2ThreadProjection["visibleTurnItems"],
329 + totalItems: rows.length,
330 + hasMore: remaining.length > options.limit,
331 + });
332 + },
333 getThreadRecords: () => Effect.succeed(projection),
334 getProjectThreadRecords: () => Effect.succeed(projection),
335 getThreadShell: () =>
@@ -358,6 +376,17 @@ it("readThread pages cut-off text without splitting an emoji across pages", asyn
376 });
377 }
378 }
379 + const first = yield* service.readThread(makeScope(), {
380 + threadId: parentThreadId,
381 + view: "activity",
382 + });
383 + expect(first.items[1]).toMatchObject({
384 + text: "x".repeat(500),
385 + textTruncated: true,
386 + nextTextOffset: 500,
387 + });
388 + expect(first.items).toHaveLength(10);
389 + expect(first).toMatchObject({ nextPosition: 9, hasMore: true });
390 }).pipe(Effect.provide(layer), Effect.runPromise);
391 });
392
apps/server/src/mcp/OrchestratorMcpService.ts
+11 -10
@@ -142,10 +142,10 @@ const TASK_WAKE_EVENTS = [
142 { thread: "child", eventType: "runtime-request.updated" },
143 ] as const;
144 const SECRET_REQUEST_POLL_INTERVAL_MS = 500;
145 -const DEFAULT_THREAD_LIST_LIMIT = 50;
146 -const DEFAULT_THREAD_READ_LIMIT = 50;
145 +const DEFAULT_THREAD_LIST_LIMIT = 10;
146 +const DEFAULT_THREAD_READ_LIMIT = 10;
147 const DEFAULT_THREAD_RUN_LIMIT = 10;
148 -const DEFAULT_THREAD_ITEM_MAX_CHARS = 20_000;
148 +const DEFAULT_THREAD_ITEM_MAX_CHARS = 500;
149
150 interface ResolvedTarget {
151 readonly modelSelection: ModelSelection;
@@ -638,6 +638,7 @@ function pageIncludesTerminalTaskResult(input: {
638 "thread" | "runs" | "contextTransfers" | "messages" | "turnItems" | "providerTurns"
639 >;
640 readonly maxChars: number;
641 + readonly textOffset: number;
642 }): boolean {
643 const transfer = taskResultTransfer(input.parentThreadId, input.target, input.task);
644 if (transfer === undefined) return false;
@@ -660,7 +661,11 @@ function pageIncludesTerminalTaskResult(input: {
661 if (!matchesResult) return false;
662
663 const text = turnItemText(row.item);
663 - return text !== null && text.length <= textPageEnd(text, 0, input.maxChars);
664 + return (
665 + text !== null &&
666 + (input.textOffset === 0 || input.textOffset < text.length) &&
667 + text.length <= textPageEnd(text, input.textOffset, input.maxChars)
668 + );
669 });
670 }
671
@@ -3102,12 +3107,7 @@ const make = Effect.gen(function* () {
3107 target,
3108 returnedRunIds,
3109 );
3105 - if (
3106 - parent !== undefined &&
3107 - scope.thread !== undefined &&
3108 - tasks.length > 0 &&
3109 - (input.textOffset ?? 0) === 0
3110 - ) {
3110 + if (parent !== undefined && scope.thread !== undefined && tasks.length > 0) {
3111 for (const task of tasks) {
3112 const transfer = taskResultTransfer(parent.thread.id, target, task);
3113 const resultRunId = transfer?.sourcePoint.runId ?? delegatedTaskRun(target, task)?.id;
@@ -3127,6 +3127,7 @@ const make = Effect.gen(function* () {
3127 task,
3128 target: { ...target, ...resultRecords },
3129 maxChars,
3130 + textOffset: input.itemId === undefined ? 0 : (input.textOffset ?? 0),
3131 })
3132 ) {
3133 yield* readTask(
apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
+38 -2
@@ -11,6 +11,7 @@ import {
11 OrchestratorMcpDelegateTaskResult,
12 OrchestratorMcpThreadInterruptResult,
13 OrchestratorMcpThreadSendResult,
14 + OrchestratorMcpThreadReadResult,
15 ProjectId,
16 ProviderDriverKind,
17 ProviderInstanceId,
@@ -79,6 +80,7 @@ const delegatedResult = "Delegated API boundary inspected.";
80 const cancellationPrompt = "Remain active until the parent cancels this delegated task.";
81 const queuedFollowupPrompt = "Complete the queued follow-up and return the final result.";
82 const queuedFollowupResult = "Queued delegated follow-up completed.";
83 +const decodeThreadRead = Schema.decodeUnknownEffect(OrchestratorMcpThreadReadResult);
84
85 const decodeDelegateTaskResult = Schema.decodeUnknownEffect(OrchestratorMcpDelegateTaskResult);
86 const decodeThreadInterruptResult = Schema.decodeUnknownEffect(
@@ -199,6 +201,11 @@ describe("orchestrator MCP toolkit", () => {
201 { label: "distinct", result: queuedFollowupResult, latestSummary: queuedFollowupResult },
202 { label: "identical", result: delegatedResult, latestSummary: null },
203 { label: "emoji", result: "😀", latestSummary: "😀" },
204 + {
205 + label: "paginated",
206 + result: "git safety ".repeat(120),
207 + latestSummary: "git safety ".repeat(120),
208 + },
209 ])("reports $label child results", ({ result, latestSummary }) =>
210 Effect.scoped(
211 Effect.gen(function* () {
@@ -724,11 +731,40 @@ describe("orchestrator MCP toolkit", () => {
731 const read = yield* invoke("t3_thread_read", {
732 threadId: delegated.childThreadId,
733 limit: 100,
727 - maxCharsPerItem: result === "😀" ? 1 : 20_000,
734 + ...(result === "😀" ? { maxCharsPerItem: 1 } : {}),
735 }).pipe(Effect.withTracer(tracer));
736 expect(read.isError).not.toBe(true);
737 expect(transferReads.length).toBeGreaterThan(0);
731 - expect(read.structuredContent).toEqual(parentlessRead.structuredContent);
738 + const firstPage = yield* decodeThreadRead(read.structuredContent);
739 + const finalItem = firstPage.items.find((item) => item.text === result.slice(0, 500));
740 + expect(finalItem).toBeDefined();
741 + if (result.length > 500) {
742 + yield* invoke("t3_thread_read", {
743 + threadId: delegated.childThreadId,
744 + itemId: finalItem!.itemId,
745 + textOffset: result.length,
746 + });
747 + } else {
748 + expect(read.structuredContent).toEqual(parentlessRead.structuredContent);
749 + }
750 + let text = finalItem!.text ?? "";
751 + let nextTextOffset = finalItem?.nextTextOffset ?? null;
752 + while (nextTextOffset !== null) {
753 + const beforeContinuation = yield* orchestrator.getThreadProjection(parentThreadId);
754 + expect(
755 + beforeContinuation.subagents.find((task) => task.id === queuedFollowup.taskId)
756 + ?.completionDelivery?.state,
757 + ).toBe("claimed");
758 + const continuation = yield* invoke("t3_thread_read", {
759 + threadId: delegated.childThreadId,
760 + itemId: finalItem!.itemId,
761 + textOffset: nextTextOffset,
762 + }).pipe(Effect.withTracer(tracer));
763 + const nextPage = yield* decodeThreadRead(continuation.structuredContent);
764 + text += nextPage.items[0]?.text ?? "";
765 + nextTextOffset = nextPage.items[0]?.nextTextOffset ?? null;
766 + }
767 + expect(text).toBe(result);
768 // The acknowledgement reads the task and its spawning run by id, not the parent's history.
769 expect(acknowledgementReads.length).toBeGreaterThan(0);
770 expect(
apps/server/src/peer/RemoteDelegation.ts
+1
@@ -613,6 +613,7 @@ const make = Effect.gen(function* () {
613 view: failed ? "activity" : "messages",
614 limit: 100,
615 runLimit: 50,
616 + maxCharsPerItem: 20_000,
617 ...(afterPosition === undefined ? {} : { afterPosition }),
618 });
619 run ??= read.recentRuns.find((candidate) => candidate.runId === runId);