Skip to content

Commit 204f6f0

Browse files
fix(agent): bound oversized Codex conversations (#3567)
Co-authored-by: posthog[bot] <206114724+posthog[bot]@users.noreply.github.com> Co-authored-by: richardsolomou <2622273+richardsolomou@users.noreply.github.com>
1 parent 95b90f0 commit 204f6f0

5 files changed

Lines changed: 69 additions & 31 deletions

File tree

apps/code/scripts/download-binaries.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const DEST_DIR = join(__dirname, "..", "resources", "codex-acp");
2222
const BINARIES = [
2323
{
2424
name: "codex",
25-
version: "0.140.0",
25+
version: "0.144.0",
2626
getUrl: (version, target) => {
2727
if (target.includes("windows")) {
2828
return `https://github.com/openai/codex/releases/download/rust-v${version}/codex-${target}.exe.zip`;

packages/agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
"@anthropic-ai/sdk": "0.109.0",
143143
"@earendil-works/pi-coding-agent": "catalog:",
144144
"@hono/node-server": "^1.19.9",
145-
"@openai/codex": "0.140.0",
145+
"@openai/codex": "0.144.0",
146146
"@opentelemetry/api-logs": "^0.208.0",
147147
"@opentelemetry/exporter-logs-otlp-http": "^0.208.0",
148148
"@opentelemetry/resources": "^2.0.0",

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
@@ -1305,6 +1305,18 @@ export class CodexAppServerAgent extends BaseAcpAgent {
13051305
this.turns.fail(RequestError.internalError(undefined, message));
13061306
return;
13071307
}
1308+
if (
1309+
message.includes("413") ||
1310+
message.toLowerCase().includes("request body too large")
1311+
) {
1312+
this.turns.fail(
1313+
RequestError.internalError(
1314+
undefined,
1315+
"This conversation is too large to continue. Start a new task and carry over a text summary instead of image or tool output.",
1316+
),
1317+
);
1318+
return;
1319+
}
13081320
void this.finalizeTurn("refusal");
13091321
}
13101322
}

pnpm-lock.yaml

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)