openclaw - 💡(How to fix) Fix openai-codex-responses provider sends oversized `instructions` field, gets 400 Bad Request [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#57930Fetched 2026-04-08 01:56:01
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

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.

Error Message

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

Root Cause

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.

Fix Action

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.

Code Example

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"}

---

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
RAW_BUFFERClick to expand / collapse

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

  1. Configure an agent with workspace bootstrap files totaling ~80+ KB (after OpenClaw's per-file bootstrapMaxChars truncation at 20K)
  2. Set primary model to openai-codex/gpt-5.4
  3. Send any message via Telegram (or other channel)
  4. 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 input messages array (which has higher limits)
  • Compressed/summarized

Evidence

Ran a parallel test with two agents on the same gateway, same auth token, same model:

MetricBarnabyHendrix
Request body size172,502 bytes94,913 bytes
Result400 Bad RequestSuccess
Workspace total~87 KB~16 KB
MEMORY.md31,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

extent analysis

Fix Plan

To resolve the issue of the openai-codex provider sending oversized instructions fields, we need to enforce a cap on the instructions field. Here are the steps:

  • Truncate the instructions field: Implement a truncation mechanism in the openai-codex-responses provider to limit the instructions field to approximately 32 KiB.
  • Log a warning: Log a warning when truncation occurs to notify the user of potential data loss.

Example code snippet in Python:

import logging

# Define the maximum allowed size for the instructions field
MAX_INSTRUCTIONS_SIZE = 32 * 1024

def truncate_instructions(instructions):
    if len(instructions) > MAX_INSTRUCTIONS_SIZE:
        logging.warning("Instructions field exceeds maximum size. Truncating...")
        return instructions[:MAX_INSTRUCTIONS_SIZE]
    return instructions

# Usage
instructions = "## LCM Recall... "  # example instructions
truncated_instructions = truncate_instructions(instructions)

Verification

To verify that the fix worked:

  1. Test with large workspace: Configure an agent with a large workspace (~80+ KB) and send a message via Telegram.
  2. Check API response: Observe the API response from the Codex API. It should no longer return a 400 Bad Request error.
  3. Verify truncation: Check the logs for a warning message indicating that the instructions field was truncated.

Extra Tips

  • Consider implementing a more sophisticated truncation mechanism, such as compressing or summarizing the excess context, to minimize data loss.
  • Review the OpenAI Codex CLI documentation for any updates on the project_doc_max_bytes setting and adjust the truncation limit accordingly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix openai-codex-responses provider sends oversized `instructions` field, gets 400 Bad Request [1 participants]