Skip to content

Commit 58e877b

Browse files
fix(agent): surface oversized Codex requests
Reject non-retried 413 responses with recovery guidance instead of ending the turn as a silent refusal. Generated-By: PostHog Code Task-Id: 64d16b4c-2c25-4e05-ba9d-824311186124
1 parent e02e0c1 commit 58e877b

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,32 @@ describe("CodexAppServerAgent", () => {
16361636
);
16371637
});
16381638

1639+
it("rejects the prompt with guidance when the gateway request is too large", async () => {
1640+
const stub = makeStubRpc({ "thread/start": { thread: { id: "t" } } });
1641+
const { client } = makeFakeClient();
1642+
const agent = new CodexAppServerAgent(client, {
1643+
processOptions: { binaryPath: "/x/codex" },
1644+
rpcFactory: stub.factory,
1645+
});
1646+
1647+
await agent.newSession({ cwd: "/r" } as unknown as NewSessionRequest);
1648+
const done = agent.prompt({
1649+
sessionId: "t",
1650+
prompt: [{ type: "text", text: "continue" }],
1651+
} as unknown as PromptRequest);
1652+
stub.emit("error", {
1653+
willRetry: false,
1654+
error: {
1655+
message:
1656+
"unexpected status 413 Payload Too Large: Request body too large",
1657+
},
1658+
});
1659+
1660+
await expect(done).rejects.toThrow(
1661+
"This conversation is too large to continue",
1662+
);
1663+
});
1664+
16391665
it("ends the turn without turn/start when no prompt block is usable", async () => {
16401666
const stub = makeStubRpc({ "thread/start": { thread: { id: "t" } } });
16411667
const { client } = makeFakeClient();

packages/agent/src/adapters/codex-app-server/codex-app-server-agent.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,18 @@ export class CodexAppServerAgent extends BaseAcpAgent {
13021302
this.turns.fail(RequestError.internalError(undefined, message));
13031303
return;
13041304
}
1305+
if (
1306+
message.includes("413") ||
1307+
message.toLowerCase().includes("request body too large")
1308+
) {
1309+
this.turns.fail(
1310+
RequestError.internalError(
1311+
undefined,
1312+
"This conversation is too large to continue. Start a new task and carry over a text summary instead of image or tool output.",
1313+
),
1314+
);
1315+
return;
1316+
}
13051317
void this.finalizeTurn("refusal");
13061318
}
13071319
}

0 commit comments

Comments
 (0)