From 5be44ee92db40f4ee2ddc26fcdfa402d0e739015 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 09:18:03 +0000 Subject: [PATCH 1/7] test(server): t3_thread_list pages fit MCP clients' output limit Fails on main: an allProjects page of 100 threads is about 70 KB, past the ~25k-token result size Claude Code shows inline (#38028). Co-Authored-By: Claude Opus 5.5 --- .../src/mcp/OrchestratorMcpService.test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index 6c488afe7d989..9a7406cbeae1b 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -10,6 +10,7 @@ import { NodeId, ORCHESTRATOR_MCP_RUNNING_TASK_NEXT, type OrchestratorMcpCapabilitiesResult, + type OrchestratorMcpThreadListResult, type OrchestratorMcpListScheduledTasksInput, type Project, OrchestratorMcpTarget, @@ -4970,6 +4971,32 @@ describe("OrchestratorMcpService thread list", () => { }).pipe(Effect.provide(service)), ); + it.effect( + "keeps an allProjects page within an MCP client's output limit and pages the rest", + () => + Effect.gen(function* () { + const mcp = yield* OrchestratorMcpService.OrchestratorMcpService; + const extra = Array.from({ length: 100 }, (_, index) => + shell(`thread:c-${index}`, "project:c", false), + ); + shells.push(...extra); + const listed: Array = []; + let cursor: number | null = 0; + while (cursor !== null) { + const page: OrchestratorMcpThreadListResult = yield* mcp.listThreads(client, { + allProjects: true, + limit: 100, + cursor, + }); + // Claude Code saves MCP results over 25k tokens to a file instead of showing them. + assert.isAtMost(Buffer.byteLength(JSON.stringify(page)), 50_000); + listed.push(...page.threads.map((thread) => thread.threadId)); + cursor = page.nextCursor; + } + assert.equal(listed.length, shells.length); + }).pipe(Effect.ensuring(Effect.sync(() => shells.splice(4))), Effect.provide(service)), + ); + it.effect("points a caller outside any thread at allProjects when it omits projectId", () => Effect.gen(function* () { const mcp = yield* OrchestratorMcpService.OrchestratorMcpService; From 499ab67a8678fb5eca883363ff638809bff75a50 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 09:24:21 +0000 Subject: [PATCH 2/7] fix(server): t3_thread_list pages stay within MCP clients' output limit An allProjects page sliced up to `limit` (100) threads with no size cap, so 60-100 threads came to 54-90 KB and Claude Code saved the result to a file. Stop filling a page at the same 30 KB budget t3_thread_read uses, and point nextCursor at the first thread left out. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/OrchestratorMcpService.ts | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 092d9f3241065..115e6fce3a3df 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -159,7 +159,7 @@ const DEFAULT_THREAD_ITEM_MAX_CHARS = 500; const THREAD_PULL_REQUEST_PREVIEW_LIMIT = 5; // Claude Code saves MCP results over ~25k tokens to a file instead of showing them. Bytes, not // chars: CJK text runs near one token per char, which a char budget lets through at 30k tokens. -const THREAD_READ_RESULT_MAX_BYTES = 30_000; +const THREAD_RESULT_MAX_BYTES = 30_000; interface ResolvedTarget { readonly modelSelection: ModelSelection; @@ -1229,7 +1229,7 @@ function timelineItemWithin( /** * The items, read from the end the caller pages toward, whose result fits - * THREAD_READ_RESULT_MAX_BYTES; `start` is the first kept index. Never empty for a non-empty page. + * THREAD_RESULT_MAX_BYTES; `start` is the first kept index. Never empty for a non-empty page. */ function timelineItemsWithinBudget( envelope: Omit, @@ -1238,8 +1238,8 @@ function timelineItemsWithinBudget( ): { readonly items: Array; readonly start: number } { // An oversized envelope (say, a huge thread title) must not starve items to one char per read. const budget = Math.max( - THREAD_READ_RESULT_MAX_BYTES - jsonBytes({ ...envelope, items: [] }), - THREAD_READ_RESULT_MAX_BYTES / 2, + THREAD_RESULT_MAX_BYTES - jsonBytes({ ...envelope, items: [] }), + THREAD_RESULT_MAX_BYTES / 2, ); const items: Array = []; let bytes = 0; @@ -3325,14 +3325,27 @@ const make = Effect.gen(function* () { total = filtered.length; page = filtered.slice(cursor, cursor + limit); } - const nextCursor = cursor + limit < total ? cursor + limit : null; - return { + const envelope = { projectId, currentThreadId: parent?.thread.id ?? null, - threads: page.map((shell) => listItemFromShell(scope, shell, nowMs)), - nextCursor, + threads: [], + nextCursor: total, total, } satisfies OrchestratorMcpThreadListResult; + const threads: Array = []; + let bytes = jsonBytes(envelope); + for (const shell of page) { + const thread = listItemFromShell(scope, shell, nowMs); + bytes += jsonBytes(thread) + (threads.length === 0 ? 0 : 1); + if (threads.length > 0 && bytes > THREAD_RESULT_MAX_BYTES) break; + threads.push(thread); + } + const end = cursor + threads.length; + return { + ...envelope, + threads, + nextCursor: end < total ? end : null, + } satisfies OrchestratorMcpThreadListResult; }), readThread: Effect.fn("OrchestratorMcpService.readThread")(function* (scope, input) { const runLimit = input.runLimit ?? DEFAULT_THREAD_RUN_LIMIT; From 4f44bf0e087276f812f3a96ecd20ed8ba44367ea Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 10:02:27 +0000 Subject: [PATCH 3/7] fix(server): t3_thread_read filters by author and drops repeated runs on later pages The issue asks for an author filter so a review of a user's own prompts need not page through every agent item, and for later pages to stop repeating recentRuns. Add `author: "user" | "agent"` to t3_thread_read, applied in the timeline query on both the own-rows and full-index paths so positions and paging stay correct, and default recentRuns to none on pages after the first unless runLimit is set. Co-Authored-By: Claude Opus 5.5 --- .../OrchestratorMcpService.activity.test.ts | 8 ++++++ apps/server/src/mcp/OrchestratorMcpService.ts | 12 ++++++--- .../orchestration-v2/ProjectionStore.test.ts | 25 +++++++++++++++++ .../src/orchestration-v2/ProjectionStore.ts | 27 ++++++++++++++----- .../src/provider/agentContextBudget.json | 2 +- packages/contracts/src/orchestratorMcp.ts | 7 ++++- 6 files changed, 68 insertions(+), 13 deletions(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts index 4a7b08fbd870b..196280f658f27 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts @@ -266,6 +266,14 @@ it("readThread preserves caller access errors and prefers activity-run status ov }); expect(laterPage.thread.pullRequests).toBeUndefined(); expect(laterPage.thread.pullRequestCount).toBe(8); + expect(result.recentRuns.length).toBeGreaterThan(0); + expect(laterPage.recentRuns).toEqual([]); + const laterPageWithRuns = yield* service.readThread(makeScope(), { + threadId: parentThreadId, + afterPosition: 0, + runLimit: 1, + }); + expect(laterPageWithRuns.recentRuns).toHaveLength(1); Object.assign(projection, { runs: [makeRun({ id: activeRunId, ordinal: 1, status: "completed" })], diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 115e6fce3a3df..78d0f163031aa 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -3369,6 +3369,7 @@ const make = Effect.gen(function* () { : {}), limit, view, + ...(input.author === undefined ? {} : { author: input.author }), ...(input.itemId === undefined ? {} : { itemId: input.itemId }), }) .pipe(Effect.mapError(threadManagementFailure)); @@ -3389,6 +3390,10 @@ const make = Effect.gen(function* () { { concurrency: 1 }, ); const messagesByThreadId = new Map(sourceMessages); + const firstPage = + input.afterPosition === undefined && + input.beforePosition === undefined && + input.itemId === undefined; const thread = threadDetail( scope, target, @@ -3396,13 +3401,12 @@ const make = Effect.gen(function* () { timeline.totalItems, shell, yield* Clock.currentTimeMillis, - input.afterPosition === undefined && - input.beforePosition === undefined && - input.itemId === undefined, + firstPage, ); + // Later pages repeat the first page's runs unless the caller asks for them. const recentRuns = target.runs .toSorted((left, right) => right.ordinal - left.ordinal) - .slice(0, runLimit) + .slice(0, firstPage || input.runLimit !== undefined ? runLimit : 0) .map((run) => threadRun(target, run)); const { items, start } = timelineItemsWithinBudget( { thread, recentRuns, nextPosition: null, hasMore: false, earlierPosition: null }, diff --git a/apps/server/src/orchestration-v2/ProjectionStore.test.ts b/apps/server/src/orchestration-v2/ProjectionStore.test.ts index 2c667bf43679f..ed1033e302166 100644 --- a/apps/server/src/orchestration-v2/ProjectionStore.test.ts +++ b/apps/server/src/orchestration-v2/ProjectionStore.test.ts @@ -10227,6 +10227,31 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => { assert.deepEqual(earlierPage.items, targetAfterRollback.visibleTurnItems.slice(0, -2)); assert.isTrue(earlierPage.hasMore); assert.isFalse(earlierPage.hasEarlier); + // The source reads its own rows; the fork reads the full index. + const authorPage = ( + threadId: ThreadId, + author: "user" | "agent", + options: Partial = {}, + ) => + projectionStore + .getTimelinePage(threadId, { author, limit: 10, ...options }) + .pipe(Effect.map((page) => page.items.map((row) => [row.position, row.item.type]))); + assert.deepEqual(yield* authorPage(targetThreadId, "user"), [ + [0, "user_message"], + [2, "user_message"], + ]); + assert.deepEqual(yield* authorPage(targetThreadId, "agent", { view: "activity" }), [ + [1, "assistant_message"], + [3, "assistant_message"], + ]); + assert.deepEqual(yield* authorPage(sourceThreadId, "user"), [[0, "user_message"]]); + assert.deepEqual(yield* authorPage(sourceThreadId, "agent", { afterPosition: 0 }), [ + [1, "assistant_message"], + ]); + assert.deepEqual( + yield* authorPage(sourceThreadId, "user", { beforePosition: Number.POSITIVE_INFINITY }), + [[0, "user_message"]], + ); const tracedTimelinePage = (limit: number) => Effect.gen(function* () { const { statements, tracer } = traceSqlStatements(); diff --git a/apps/server/src/orchestration-v2/ProjectionStore.ts b/apps/server/src/orchestration-v2/ProjectionStore.ts index 5b8a636cc24f1..252ba9c970ace 100644 --- a/apps/server/src/orchestration-v2/ProjectionStore.ts +++ b/apps/server/src/orchestration-v2/ProjectionStore.ts @@ -440,8 +440,22 @@ export interface ProjectionTimelinePageOptions { readonly itemId?: TurnItemId; readonly attachmentId?: string; readonly view?: "messages" | "activity"; + /** Only this author's messages, in either view. */ + readonly author?: "user" | "agent"; readonly limit: number; } + +/** The item types a timeline page matches; null matches every type. */ +const timelineViewTypes = ( + options: ProjectionTimelinePageOptions, +): ReadonlyArray | null => + options.author === "user" + ? ["user_message"] + : options.author === "agent" + ? ["assistant_message", "proposed_plan"] + : options.view === "activity" + ? null + : ["user_message", "assistant_message", "proposed_plan"]; export interface ProjectionTimelinePage { readonly items: ReadonlyArray; readonly totalItems: number; @@ -7564,11 +7578,11 @@ export const layer: Layer.Layer = if (start === undefined) return { matching: [], totalItems, hasEarlier: false }; const base = yield* local.visibleBefore(start); const hiddenAfter = local.hidden.filter((row) => row.ordinal >= start).length; - const messagesOnly = options.view !== "activity"; + const types = timelineViewTypes(options); + const messagesOnly = types !== null; const candidates = (yield* local.read( messagesOnly - ? sql`AND item.ordinal >= ${start} - AND item.type IN ('user_message', 'assistant_message', 'proposed_plan')` + ? sql`AND item.ordinal >= ${start} AND item.type IN ${sql.in(types)}` : sql`AND item.ordinal >= ${start}`, sql`LIMIT ${firstPosition - base + Math.min(options.limit, totalItems) + 1 + hiddenAfter}`, )).filter(local.isVisible); @@ -7596,8 +7610,7 @@ export const layer: Layer.Layer = (base > 0 && (!messagesOnly || (yield* local.read( - sql`AND item.ordinal < ${start} - AND item.type IN ('user_message', 'assistant_message', 'proposed_plan')`, + sql`AND item.ordinal < ${start} AND item.type IN ${sql.in(types)}`, sql`LIMIT ${local.hidden.length + 1}`, )).some(local.isVisible))); return { matching, totalItems, hasEarlier }; @@ -7680,12 +7693,12 @@ export const layer: Layer.Layer = (row) => `${row.thread_id}:${row.turn_item_id}`, ), ); + const types = timelineViewTypes(options); const inView = index.visible .map((row, position) => ({ ...row, position })) .filter((row) => options.itemId === undefined - ? options.view === "activity" || - ["user_message", "assistant_message", "proposed_plan"].includes(row.item.type) + ? types === null || types.includes(row.item.type) : row.sourceItemId === options.itemId, ) .filter( diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 9c305c266f3dd..ef222770daf8f 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 52145 + "mcpToolListJsonBytes": 52270 } diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index ed6a62bf1eb7f..e2c7e0de52207 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -446,10 +446,15 @@ export const OrchestratorMcpThreadReadInput = Schema.Struct({ itemId: Schema.optional(TurnItemId), textOffset: Schema.optional(NonNegativeInt), view: Schema.optional(Schema.Literals(["messages", "activity"])), + author: Schema.optional(Schema.Literals(["user", "agent"])).annotate({ + description: "Only this author's messages.", + }), afterPosition: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))), beforePosition: Schema.optional(NonNegativeInt), limit: Schema.optional(clampedPositiveInt(100)).annotate({ description: "Max 100." }), - runLimit: Schema.optional(clampedPositiveInt(50)).annotate({ description: "Max 50." }), + runLimit: Schema.optional(clampedPositiveInt(50)).annotate({ + description: "Max 50. Later pages default to none.", + }), maxCharsPerItem: Schema.optional(clampedPositiveInt(20_000)).annotate({ description: "Max 20000.", }), From ace8698dc5000cdd2abafb91999e7a176817db62 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 10:07:41 +0000 Subject: [PATCH 4/7] fix(server): keep t3_thread_read's added text to the author field Drop the new parameter descriptions so the MCP tool list grows only by the author enum itself (+51 bytes over main). Co-Authored-By: Claude Opus 5.5 --- apps/server/src/provider/agentContextBudget.json | 2 +- packages/contracts/src/orchestratorMcp.ts | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index ef222770daf8f..25fdadacd5dba 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 52270 + "mcpToolListJsonBytes": 52196 } diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index e2c7e0de52207..a7e28efcccfcc 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -446,15 +446,11 @@ export const OrchestratorMcpThreadReadInput = Schema.Struct({ itemId: Schema.optional(TurnItemId), textOffset: Schema.optional(NonNegativeInt), view: Schema.optional(Schema.Literals(["messages", "activity"])), - author: Schema.optional(Schema.Literals(["user", "agent"])).annotate({ - description: "Only this author's messages.", - }), + author: Schema.optional(Schema.Literals(["user", "agent"])), afterPosition: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))), beforePosition: Schema.optional(NonNegativeInt), limit: Schema.optional(clampedPositiveInt(100)).annotate({ description: "Max 100." }), - runLimit: Schema.optional(clampedPositiveInt(50)).annotate({ - description: "Max 50. Later pages default to none.", - }), + runLimit: Schema.optional(clampedPositiveInt(50)).annotate({ description: "Max 50." }), maxCharsPerItem: Schema.optional(clampedPositiveInt(20_000)).annotate({ description: "Max 20000.", }), From 1d0c56b83be72986a1f09da233bbb2a0eb8d6b25 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 10:34:45 +0000 Subject: [PATCH 5/7] fix(server): t3_thread_read author "user" leaves out other agents' messages A message another agent sends with t3_thread_send is a user_message with createdBy "agent", so `author: "user"` returned it among the user's own prompts. Match createdBy "user" in both the windowed and full-index reads. The list test now holds pages to the 30 KB budget they are cut at. Co-Authored-By: Claude Opus 5.5 --- .../src/mcp/OrchestratorMcpService.test.ts | 2 +- .../orchestration-v2/ProjectionStore.test.ts | 29 +++++++++++++++---- .../src/orchestration-v2/ProjectionStore.ts | 12 ++++++-- .../orchestrator-mcp-server.md | 5 +++- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index 9a7406cbeae1b..6828db13a761b 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -4989,7 +4989,7 @@ describe("OrchestratorMcpService thread list", () => { cursor, }); // Claude Code saves MCP results over 25k tokens to a file instead of showing them. - assert.isAtMost(Buffer.byteLength(JSON.stringify(page)), 50_000); + assert.isAtMost(Buffer.byteLength(JSON.stringify(page)), 30_000); listed.push(...page.threads.map((thread) => thread.threadId)); cursor = page.nextCursor; } diff --git a/apps/server/src/orchestration-v2/ProjectionStore.test.ts b/apps/server/src/orchestration-v2/ProjectionStore.test.ts index ed1033e302166..46175e1970c13 100644 --- a/apps/server/src/orchestration-v2/ProjectionStore.test.ts +++ b/apps/server/src/orchestration-v2/ProjectionStore.test.ts @@ -6277,7 +6277,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => { }; const userMessage = (inputIntent: string) => add("user_message", { - createdBy: "user", + createdBy: items.length % 3 === 0 ? "agent" : "user", creationSource: "web", messageId: `message:window-equivalence:${round}:${items.length}`, inputIntent, @@ -6455,17 +6455,36 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => { for (let cursor: string | null = groupCursor; cursor !== null;) cursor = (yield* windowed(history(cursor, anchorId, false, "work"))).nextCursor; } - for (const view of ["messages", "activity"] as const) { + const authors = { user: ["user_message"], agent: ["assistant_message", "proposed_plan"] }; + let authored = 0; + for (const filter of [ + { view: "messages" }, + { view: "activity" }, + { author: "user" }, + { author: "agent" }, + ] as const) { + const read = Effect.fnUntraced(function* ( + options: ProjectionStore.ProjectionTimelinePageOptions, + ) { + const { items } = yield* windowed(timeline({ ...filter, ...options })); + if (!("author" in filter)) return; + authored += items.length; + for (const { item } of items) { + assert.include(authors[filter.author], item.type); + if (item.type === "user_message") assert.equal(item.createdBy, "user"); + } + }); for (const afterPosition of [-1, Math.floor(totalItems / 3), totalItems - 5]) - yield* windowed(timeline({ view, afterPosition, limit: 20 })); + yield* read({ afterPosition, limit: 20 }); for (const beforePosition of [ Number.POSITIVE_INFINITY, Math.floor(totalItems / 3), totalItems - 5, ]) - yield* windowed(timeline({ view, beforePosition, limit: 20 })); - yield* windowed(timeline({ view, afterPosition: 3, beforePosition: 40, limit: 20 })); + yield* read({ beforePosition, limit: 20 }); + yield* read({ afterPosition: 3, beforePosition: 40, limit: 20 }); } + assert.isAbove(authored, 0); for (const itemId of [newest.sourceItemId, ...tiedWithHidden]) yield* windowed(timeline({ itemId, limit: 1 })); diff --git a/apps/server/src/orchestration-v2/ProjectionStore.ts b/apps/server/src/orchestration-v2/ProjectionStore.ts index 252ba9c970ace..0be78a58c160e 100644 --- a/apps/server/src/orchestration-v2/ProjectionStore.ts +++ b/apps/server/src/orchestration-v2/ProjectionStore.ts @@ -7580,9 +7580,14 @@ export const layer: Layer.Layer = const hiddenAfter = local.hidden.filter((row) => row.ordinal >= start).length; const types = timelineViewTypes(options); const messagesOnly = types !== null; + // Another agent's t3_thread_send is a user_message too. + const byUser = + options.author === "user" + ? sql`AND json_extract(item.payload_json, '$.createdBy') = 'user'` + : sql``; const candidates = (yield* local.read( messagesOnly - ? sql`AND item.ordinal >= ${start} AND item.type IN ${sql.in(types)}` + ? sql`AND item.ordinal >= ${start} AND item.type IN ${sql.in(types)} ${byUser}` : sql`AND item.ordinal >= ${start}`, sql`LIMIT ${firstPosition - base + Math.min(options.limit, totalItems) + 1 + hiddenAfter}`, )).filter(local.isVisible); @@ -7610,7 +7615,7 @@ export const layer: Layer.Layer = (base > 0 && (!messagesOnly || (yield* local.read( - sql`AND item.ordinal < ${start} AND item.type IN ${sql.in(types)}`, + sql`AND item.ordinal < ${start} AND item.type IN ${sql.in(types)} ${byUser}`, sql`LIMIT ${local.hidden.length + 1}`, )).some(local.isVisible))); return { matching, totalItems, hasEarlier }; @@ -7698,7 +7703,8 @@ export const layer: Layer.Layer = .map((row, position) => ({ ...row, position })) .filter((row) => options.itemId === undefined - ? types === null || types.includes(row.item.type) + ? (types === null || types.includes(row.item.type)) && + (options.author !== "user" || row.item.createdBy === "user") : row.sourceItemId === options.itemId, ) .filter( diff --git a/docs/orchestration-v2/orchestrator-mcp-server.md b/docs/orchestration-v2/orchestrator-mcp-server.md index fa2770bb10cf7..bd78e377712b1 100644 --- a/docs/orchestration-v2/orchestrator-mcp-server.md +++ b/docs/orchestration-v2/orchestrator-mcp-server.md @@ -368,7 +368,10 @@ Reads the durable state, recent runs, and visible timeline of any thread in the environment by thread ID. A deleted thread returns `thread_not_found`. The default `messages` view returns user messages, assistant messages, and proposed plans. The `activity` view also returns summarized tool, -reasoning, checkpoint, handoff, and runtime-request items. Large item text is +reasoning, checkpoint, handoff, and runtime-request items. `author: "user"` returns +only messages a user wrote, not ones another agent sent, and `author: "agent"` +only assistant messages and plans. Later pages leave out `recentRuns` unless the +read passes `runLimit`. Large item text is bounded and reports whether it was truncated. An agent in a T3 thread that reads without a cursor gets the newest items, and `beforePosition=earlierPosition` reads older ones. Client callers (the CLI, linked environments, outside MCP From 5b7d1d77e2eda2dc901f8d0ef41a9811bc2a117f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 11:17:49 +0000 Subject: [PATCH 6/7] fix(server): t3_thread_read's author field no longer grows the agent context The new `author` parameter added 51 bytes to the MCP tool list, past main's budget. Drop the "Max N." descriptions on t3_thread_read's limit, runLimit and maxCharsPerItem: each value clamps on decode and the page says where the rest starts, so an oversized value cannot go wrong. The tool list is now 25 bytes smaller than main's. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/provider/agentContextBudget.json | 2 +- packages/contracts/src/orchestratorMcp.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 25fdadacd5dba..adb1150c03b1a 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 52196 + "mcpToolListJsonBytes": 52120 } diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index a7e28efcccfcc..5dedeb985ddd7 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -449,11 +449,10 @@ export const OrchestratorMcpThreadReadInput = Schema.Struct({ author: Schema.optional(Schema.Literals(["user", "agent"])), afterPosition: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))), beforePosition: Schema.optional(NonNegativeInt), - limit: Schema.optional(clampedPositiveInt(100)).annotate({ description: "Max 100." }), - runLimit: Schema.optional(clampedPositiveInt(50)).annotate({ description: "Max 50." }), - maxCharsPerItem: Schema.optional(clampedPositiveInt(20_000)).annotate({ - description: "Max 20000.", - }), + // No "Max N." text: each clamps, and a page reports where the rest starts. + limit: Schema.optional(clampedPositiveInt(100)), + runLimit: Schema.optional(clampedPositiveInt(50)), + maxCharsPerItem: Schema.optional(clampedPositiveInt(20_000)), }); export type OrchestratorMcpThreadReadInput = typeof OrchestratorMcpThreadReadInput.Type; From 25a3152ea861cefc6ddce5b6e1a692085b157221 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 11:22:44 +0000 Subject: [PATCH 7/7] Revert "fix(server): t3_thread_read's author field no longer grows the agent context" The "Max N." descriptions are deliberate: the schema has no `maximum` because values clamp, so they are the only place a model sees a limit, and tools.test.ts guards them. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/provider/agentContextBudget.json | 2 +- packages/contracts/src/orchestratorMcp.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index adb1150c03b1a..25fdadacd5dba 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 52120 + "mcpToolListJsonBytes": 52196 } diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index 5dedeb985ddd7..a7e28efcccfcc 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -449,10 +449,11 @@ export const OrchestratorMcpThreadReadInput = Schema.Struct({ author: Schema.optional(Schema.Literals(["user", "agent"])), afterPosition: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))), beforePosition: Schema.optional(NonNegativeInt), - // No "Max N." text: each clamps, and a page reports where the rest starts. - limit: Schema.optional(clampedPositiveInt(100)), - runLimit: Schema.optional(clampedPositiveInt(50)), - maxCharsPerItem: Schema.optional(clampedPositiveInt(20_000)), + limit: Schema.optional(clampedPositiveInt(100)).annotate({ description: "Max 100." }), + runLimit: Schema.optional(clampedPositiveInt(50)).annotate({ description: "Max 50." }), + maxCharsPerItem: Schema.optional(clampedPositiveInt(20_000)).annotate({ + description: "Max 20000.", + }), }); export type OrchestratorMcpThreadReadInput = typeof OrchestratorMcpThreadReadInput.Type;