Repository navigation
fix(server): t3_thread_list pages stay within MCP clients' output limit #38039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5be44ee
499ab67
4f44bf0
ace8698
1d0c56b
5b7d1d7
25a3152
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<OrchestrationV2TurnItem["type"]> | null => | ||
| options.author === "user" | ||
| ? ["user_message"] | ||
| : options.author === "agent" | ||
| ? ["assistant_message", "proposed_plan"] | ||
|
Comment on lines
+452
to
+455
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filter
Apply the creator check to
|
||
| : options.view === "activity" | ||
| ? null | ||
| : ["user_message", "assistant_message", "proposed_plan"]; | ||
| export interface ProjectionTimelinePage { | ||
| readonly items: ReadonlyArray<OrchestrationV2ProjectedTurnItem>; | ||
| readonly totalItems: number; | ||
|
|
@@ -7564,11 +7578,16 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> = | |
| 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; | ||
| // 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 ('user_message', 'assistant_message', 'proposed_plan')` | ||
| ? 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); | ||
|
|
@@ -7596,8 +7615,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> = | |
| (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)} ${byUser}`, | ||
| sql`LIMIT ${local.hidden.length + 1}`, | ||
| )).some(local.isVisible))); | ||
| return { matching, totalItems, hasEarlier }; | ||
|
|
@@ -7680,12 +7698,13 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> = | |
| (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)) && | ||
| (options.author !== "user" || row.item.createdBy === "user") | ||
| : row.sourceItemId === options.itemId, | ||
| ) | ||
| .filter( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "claudeSystemAppendBytes": 5930, | ||
| "codexAdditionalContextBytes": 7324, | ||
| "mcpToolListJsonBytes": 52145 | ||
| "mcpToolListJsonBytes": 52196 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bound list-item titles, or an oversized thread title makes its page exceed the result budget.
listItemFromShellcopiesshell.titlewithout truncation (OrchestratorMcpService.ts:949). The title type has no length limit:TrimmedNonEmptyStringisTrimmedString.check(isNonBlank)(packages/contracts/src/baseSchemas.ts:29). A thread title can therefore exceed the 30,000-byte budget. The loop always admits the first item (OrchestratorMcpService.ts:3340), so a page that starts with such a thread exceedsTHREAD_RESULT_MAX_BYTESeven atlimit=1. Paging cannot skip the item, so that listing fails until the thread is renamed.Cap the title in the list output, or enforce a maximum title length at the contract, so that the first item always fits the budget.