Repository navigation
Description
Summary
A Codex CLI session became impossible to resume because the persisted transcript contained a function_call.name with embedded NUL bytes. When Codex replayed that history to the Responses API, the API rejected the request with a 400 validation error.
Version
codex-cli 0.133.0
Error
{
"error": {
"message": "Invalid 'input[646].name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.",
"type": "invalid_request_error",
"param": "input[646].name",
"code": "invalid_value"
}
}Feedback / thread id
019e55fb-87ff-7a30-9d52-010b48f14964
Redacted session evidence
The persisted JSONL session contained a response item like this:
{
"type": "response_item",
"payload": {
"type": "function_call",
"name": "apply\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000",
"call_id": "call_EizYvzgC5R9tmVUJj17m5aDA"
}
}The same item's arguments also contained many \\u0000 sequences, so this appears to be a corrupted persisted tool call, not only a legacy/namespaced tool name.
The following output item was also persisted:
unsupported call: apply\u0000\u0000\u0000\u0000\u0000\u0000
Manual recovery
I backed up the session JSONL and changed only that persisted function_call.name from:
apply\u0000\u0000\u0000\u0000\u0000\u0000
to:
apply_patch
After that, the session JSONL parsed successfully and no function_call.name values violated ^[a-zA-Z0-9_-]+$.
Related issues / prior work
This appears related to:
- Streamable MCP run normally and return results, but soon get unexpected status 400 Bad Request error #6540
- Session resume can fail: invalid function_call.name like 'functions.exec_command' #10563
- Normalize tool call names for Responses API #9447
However, this case is slightly different from namespace normalization such as functions.exec_command: the stored transcript contains embedded NUL bytes and should be treated as corrupted history.
Expected behavior
Codex should not replay invalid historical function_call.name values to the Responses API.
Before sending replayed history or compaction payloads, Codex should validate historical function_call.name values and either:
- sanitize control characters / invalid characters,
- map known corrupted names to valid tool names when safe,
- or drop/convert corrupted historical tool call items so one bad persisted item does not make the whole session impossible to resume.
Suggested regression test
A persisted history item with:
{
"type": "function_call",
"name": "apply\\u0000\\u0000",
"call_id": "call_test",
"arguments": "{}"
}should not cause a Responses API request containing an invalid input[*].name.
Activity
cratexnet commentedon May 24, 2026
I pushed a candidate fix branch here:
What it changes:
ResponseItem::FunctionCall.namevalues during context normalization before prompt construction.[a-zA-Z0-9_-]and falls back tounknown_toolif the sanitized name is empty.Validation:
just test -p codex-core normalize_sanitizes_function_call_names_for_prompt"apply\0\0"and"\0\0".1 passed, 2549 skipped; the recipe'sbench-smokestep also exited 0.cargo fmt -- --config imports_granularity=Item --checkexited 0.I attempted to open a draft PR from
cratexnet:codex/sanitize-replayed-function-call-namestoopenai/codex:main, but GitHub rejected PR creation for this account:gh pr create:GraphQL: cratexnet does not have the correct permissions to execute CreatePullRequestPOST /repos/openai/codex/pulls:404 Not Found403 Resource not accessible by integrationThe branch and compare link above should still make the proposed patch reviewable.
cratexnet commentedon May 24, 2026
Update: I amended the candidate fix commit message to English for the upstream branch.