-
-
Notifications
You must be signed in to change notification settings - Fork 67.5k
Description
openai-codex-responses provider sends oversized instructions field, gets 400 Bad Request
Summary
The openai-codex provider (targeting chatgpt.com/backend-api/codex/responses) does not cap the instructions field before sending. When workspace bootstrap files + system prompt + tool schemas exceed ~32 KiB, the API returns {"detail":"Bad Request"} (400). This makes GPT-5.4 unusable for agents with larger workspaces.
Environment
- OpenClaw v2026.3.28
- Provider:
openai-codex(ChatGPT Plus OAuth) - Model:
gpt-5.4 - Agent workspace: ~87 KB across bootstrap files (SOUL.md, AGENTS.md, MEMORY.md, USER.md, IDENTITY.md, THINKING.md, RULES.md, HEARTBEAT.md)
Steps to Reproduce
- Configure an agent with workspace bootstrap files totaling ~80+ KB (after OpenClaw's per-file
bootstrapMaxCharstruncation at 20K) - Set primary model to
openai-codex/gpt-5.4 - Send any message via Telegram (or other channel)
- Observe 400
{"detail":"Bad Request"}from the Codex API
Actual Behavior
OpenClaw assembles the full system prompt (LCM context, workspace files, tool definitions, conversation history) into the instructions field of the request payload. For agents with larger workspaces, this produces a 172 KB request body where instructions alone is ~58K+ characters.
The Codex API rejects it with 400 Bad Request.
Expected Behavior
The openai-codex-responses provider should enforce a cap on the instructions field (approximately 32 KiB, matching OpenAI's own project_doc_max_bytes default for the Codex CLI) before sending the request. Excess context could be:
- Truncated with a warning log
- Moved into the
inputmessages array (which has higher limits) - Compressed/summarized
Evidence
Ran a parallel test with two agents on the same gateway, same auth token, same model:
| Metric | Barnaby | Hendrix |
|---|---|---|
| Request body size | 172,502 bytes | 94,913 bytes |
| Result | 400 Bad Request | Success |
| Workspace total | ~87 KB | ~16 KB |
| MEMORY.md | 31,688 chars (truncated to 20K) | 1,314 chars |
The only difference is workspace size. Same auth, same endpoint, same model.
Additionally, binary search testing showed:
- 30,000 char instructions → Success
- 58,000 char instructions → 400 Bad Request
This aligns with OpenAI's documented project_doc_max_bytes default of 32 KiB for the Codex CLI (~/.codex/config.toml).
Logs
warn agent/embedded workspace bootstrap file MEMORY.md is 31688 chars (limit 20000); truncating in injected context
error [codex-debug] body length: 172502 first 200: {"model":"gpt-5.4","store":false,"stream":true,"instructions":"## LCM Recall...
error [codex-debug] response status: 400 body: {"detail":"Bad Request"}
Compare with successful request from agent with smaller workspace:
error [codex-debug] body length: 94913 first 200: {"model":"gpt-5.4","store":false,"stream":true,"instructions":"## LCM Recall...
info gateway/channels/telegram telegram sendMessage ok
Workaround
Reducing workspace bootstrap content (especially MEMORY.md and RULES.md) to keep the total instructions field under ~32K characters. This is a band-aid — the fix should be in the provider layer.
Related
- OpenAI Codex CLI has a built-in
project_doc_max_bytessetting (default 32 KiB) that caps instructions: https://developers.openai.com/codex/guides/agents-md - Multiple reports of Codex CLI truncating long prompts: Codex CLI truncates outputs openai/codex#5163