fix(codex): retry an oversized history page with smaller pages (#9432)

thread/items/list asks for 100 items a page. On image-heavy threads a page
can exceed the app-server's line cap, and the history stopped at the first
such page with a "too large to load" warning, dropping every later item
even when each one fits. The reader now halves the page and retries the
same cursor, and shows the warning only when a single item cannot fit.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RockandClaude Opus 5.5 authored and GitHub committed 2026-11-12 21:02:10 +00:00
1 parent d426088c3f
commit 21709812bb
2 files changed
+29 -9

No files matched your search

@@ -147,7 +147,7 @@ describe("Codex thread history", () => {
appServer.assertNoErrors();
});
test("a page too big to send shows a warning row and stops loading", async () => {
test("a page too big to send retries smaller pages, then warns at the item that cannot fit", async () => {
const answers = Array.from({ length: 120 }, (_, index) =>
agentItem(`agent-${index}`, `Answer ${index}`),
);
@@ -163,11 +163,12 @@ describe("Codex thread history", () => {
);
const loaded = [
{ type: "user_message", text: "One", messageId: "user-1" },
...answers.slice(0, 99).map((answer) => ({
...answers.map((answer) => ({
type: "assistant_message",
text: answer.text,
messageId: answer.id,
})),
{ type: "user_message", text: "Two", messageId: "user-2" },
{
type: "notification",
level: "warning",
@@ -176,6 +177,12 @@ describe("Codex thread history", () => {
];
try {
expect(timelineItems(await readHistory(session))).toEqual(loaded);
// Each oversized page retries the same cursor at half the size until it fits.
expect(
historyRequests(appServer)
.filter((request) => request.method === "thread/items/list")
.map((request) => (request.params as { limit: number }).limit),
).toEqual([100, 100, 50, 25, 12, 12, 6, 6, 3, 3, 1, 1]);
// The oversized reply failed only its own request; the session still answers.
expect(timelineItems(await readHistory(session))).toEqual(loaded);
} finally {
@@ -124,15 +124,28 @@ async function* readPaginatedHistory(
): AsyncGenerator<CodexHistoryRow> {
const seenCursors = new Set<string>();
let cursor: string | undefined;
let limit = PAGE_SIZE;
for (;;) {
const page = CodexItemsPageSchema.parse(
await requestHistory(
client,
"thread/items/list",
{ threadId, limit: PAGE_SIZE, sortDirection: "asc", cursor },
let response: unknown;
try {
response = await client.request("thread/items/list", {
threadId,
limit,
sortDirection: "asc",
cursor,
});
} catch (error) {
if (!(error instanceof CodexAppServerResponseTooLargeError)) throw error;
// Image-heavy items can push a full page past the line cap; retry the same cursor smaller.
if (limit > 1) {
limit = Math.max(1, Math.floor(limit / 2));
continue;
}
throw new CodexThreadHistoryTooLargeError(
"The rest of this Codex thread's history is too large to load.",
),
);
);
}
const page = CodexItemsPageSchema.parse(response);
for (const row of page.data) {
yield {
item: row.item,