Skip to content

Resume fails with Responses API 400 when persisted function_call.name contains NUL bytes #24369

Open

Description

@cratexnet

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:

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

  1. added
    bug
    CLI
    session
    tool-calls
    on May 24, 2026
  2. cratexnet commented on May 24, 2026

    @cratexnet
    Author

    I pushed a candidate fix branch here:

    What it changes:

    • Sanitizes replayed ResponseItem::FunctionCall.name values during context normalization before prompt construction.
    • Preserves the stored rollout/session history unchanged.
    • Strips characters outside [a-zA-Z0-9_-] and falls back to unknown_tool if the sanitized name is empty.
    • Adds a regression test for null-padded and fully invalid function call names.

    Validation:

    • just test -p codex-core normalize_sanitizes_function_call_names_for_prompt
      • Before the fix: failed because names remained "apply\0\0" and "\0\0".
      • After the fix: passed, 1 passed, 2549 skipped; the recipe's bench-smoke step also exited 0.
    • cargo fmt -- --config imports_granularity=Item --check exited 0.

    I attempted to open a draft PR from cratexnet:codex/sanitize-replayed-function-call-names to openai/codex:main, but GitHub rejected PR creation for this account:

    • gh pr create: GraphQL: cratexnet does not have the correct permissions to execute CreatePullRequest
    • REST POST /repos/openai/codex/pulls: 404 Not Found
    • GitHub App connector: 403 Resource not accessible by integration

    The branch and compare link above should still make the proposed patch reviewable.

  3. cratexnet commented on May 24, 2026

    @cratexnet
    Author

    Update: I amended the candidate fix commit message to English for the upstream branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugsessiontool-calls

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions