Skip to content

Bug: Codex session resume fails with Invalid 'input[x].content': array too long due to incompatible reasoning items in rollout JSONL #36551

Open

Description

@lamugu

What version of the Codex App are you using (From “About Codex” dialog)?

26.721.81911

What subscription do you have?

plus

What platform is your computer?

No response

What issue are you seeing?

Bug: Codex session resume fails with Invalid 'input[x].content': array too long due to incompatible reasoning items in rollout JSONL

Description

When resuming an existing Codex session, Codex fails with the following error:


Invalid 'input[7].content': array too long.
Expected an array with maximum length 0, but got an array with length 1 instead.

This is not caused by exceeding the context window or token limit.

The issue appears to be caused by incompatible reasoning items written into the local session history (rollout-*.jsonl) by a third-party Responses API compatible provider.

After switching back to the official OpenAI API endpoint, Codex reloads the existing session history and sends the persisted items for replay. The official Responses API rejects the stored reasoning.content format because reasoning items should not contain a content array.


Environment

  • Codex CLI version: <version>
  • OS: <OS>
  • API provider:
    • Created session with: third-party OpenAI-compatible Responses API provider
    • Resumed session with: official OpenAI API

Steps to reproduce

  1. Configure Codex to use a third-party OpenAI-compatible API provider.
  2. Start a Codex session.
  3. Generate responses that contain reasoning items.
  4. Allow Codex to save the session locally.
  5. Switch the configuration back to the official OpenAI API endpoint.
  6. Resume the previous session.

Expected:

  • Codex should either migrate incompatible history entries or skip unsupported fields.

Actual:

Codex fails while replaying the stored history:


Invalid 'input[7].content': array too long.
Expected an array with maximum length 0, but got an array with length 1 instead.


Root cause

The affected rollout-*.jsonl contains entries like:

{
  "type": "response_item",
  "payload": {
    "type": "reasoning",
    "content": [
      {
        "type": "reasoning_text",
        "text": "..."
      }
    ]
  }
}

The third-party provider writes reasoning.content as an array.

However, when the official Responses API validates the replayed history, reasoning items do not accept content arrays:

Expected:

{
  "type": "response_item",
  "payload": {
    "type": "reasoning",
    "content": null
  }
}

Received:

{
  "type": "response_item",
  "payload": {
    "type": "reasoning",
    "content": [...]
  }
}

The API validation fails because:

Expected an array with maximum length 0
Got an array with length 1

Temporary workaround

Manually edit the affected session file:

~/.codex/sessions/**/rollout-*.jsonl

First create a backup.

Then only modify entries where:

type == "response_item"

AND

payload.type == "reasoning"

AND

payload.content is an array

Change:

{
  "type": "response_item",
  "payload": {
    "type": "reasoning",
    "content": [...]
  }
}

to:

{
  "type": "response_item",
  "payload": {
    "type": "reasoning",
    "content": null
  }
}

After this change, the session can resume normally.


Expected behavior

Codex should handle incompatible persisted session records more gracefully.

Possible solutions:

  1. Ignore invalid reasoning.content fields when loading old sessions.
  2. Sanitize/migrate rollout JSONL before sending history to the Responses API.
  3. Detect incompatible provider-generated session records and show a clear migration error.
  4. Avoid persisting provider-specific fields that are not compatible with the official Responses API schema.

Additional notes

This issue is easy to confuse with context length problems because it happens during session resume.

However, this is a schema validation error:

  • Not related to token count.
  • Not related to context window size.
  • Not related to prompt length.

The failure occurs because persisted local session data contains a reasoning.content structure that is rejected by the official Responses API.


What steps can reproduce the bug?

Steps to reproduce

  1. Configure Codex CLI to use a third-party OpenAI-compatible Responses API provider.

  2. Start a new Codex session and have a normal conversation. The provider writes response items into the local Codex session history.

  3. Check the generated session file:


~/.codex/sessions/<session-id>/rollout-*.jsonl

The file contains entries similar to:

{
  "type": "response_item",
  "payload": {
    "type": "reasoning",
    "content": [
      {
        "type": "reasoning_text",
        "text": "..."
      }
    ]
  }
}
  1. Switch Codex configuration back to the official OpenAI API endpoint.

  2. Resume the previous session using the same session id.

  3. Codex attempts to replay the stored history and fails with:

Invalid 'input[7].content': array too long.
Expected an array with maximum length 0, but got an array with length 1 instead.

Session information

Session id:

<insert affected session id here>

Rollout file:

~/.codex/sessions/<session-id>/rollout-<timestamp>.jsonl

Context/token information

This issue is not related to context length.

At the time of failure:

  • Context window usage: not exceeded
  • Token limit: not exceeded
  • Failure occurs during session history validation before model execution

The error is caused by invalid persisted history format, specifically:

payload.type = "reasoning"
payload.content = [...]

which is rejected by the official Responses API schema.


Minimal reproduction

A minimal corrupted rollout entry is:

{
  "type": "response_item",
  "payload": {
    "type": "reasoning",
    "content": [
      {
        "type": "reasoning_text",
        "text": "example"
      }
    ]
  }
}

When this entry is loaded and replayed through the official Responses API, it produces:

Invalid 'input[x].content':
array too long.
Expected an array with maximum length 0, but got an array with length 1 instead.

Changing:

"content": [...]

to:

"content": null

allows the session to resume normally.

What is the expected behavior?

No response

Additional information

No response

Activity

  1. added
    app
    on Aug 2, 2026
  2. added
    bug
    CLI
    custom-model
    session
    on Aug 2, 2026
  3. thom-at-redhat commented on Oct 9, 2026

    @thom-at-redhat

    Additional confirmation on Linux with Codex CLI 0.162.0, observed on 2026-10-09.

    The affected thread began with a third-party Responses-compatible provider (EnMaas), model rits/zai-org/glm-5-3. After an unrelated provider authentication failure, its model/provider settings were changed to gpt-6.1-sol on the official OpenAI API through a named CLI profile. Persisted thread_settings_applied events confirm that the provider change took effect, while the thread ID remained the same.

    The next two continuation attempts failed at 20:13:39 UTC and 20:15:04 UTC with:

    Invalid 'input[7].content': array too long. Expected an array with maximum length 0, but got an array with length 1 instead.
    type: invalid_request_error
    param: input[7].content
    code: array_above_max_length
    

    A read-only structural inspection found 62 retained reasoning items, each with an empty summary, one reasoning_text content entry, and encrypted_content: null. The following is an illustrative shape; the text is synthetic:

    {
      "type": "reasoning",
      "summary": [],
      "content": [{"type": "reasoning_text", "text": "synthetic example"}],
      "encrypted_content": null
    }

    This corroborates the reported cross-provider replay incompatibility on CLI 0.162.0. The actual outgoing request was not captured, so the exact mapping from input[7] to a stored item remains unverified. No isolated reproduction or history-editing workaround was tested, and the original rollout was left unchanged.

    This report contains metadata and a synthetic item shape only; no private prompts, reasoning text, credentials, internal hostnames, paths, or session identifiers are included. Graceful handling of incompatible provider history, or a clear compatibility message before continuation, would make this failure easier to recover from.

  4. telemetrya2018-dotcom commented on Oct 20, 2026

    @telemetrya2018-dotcom

    Windows follow-up observed2026-10-20 through an OpenMausBot app-server integration (related report: milind-soni/OpenMausBot#3148). An already-existing native session resumed and then failed before tools with HTTP400 invalid_request_error, array_above_max_length, param input[102].content, maximum0 versus length1. This is not the earlier max_output_tokens failure in that conversation.

    Read-only structure inspection of the exact rollout returned by thread/resume found85 reasoning records, including2 with nonempty reasoning_text content, empty summary, and no encrypted_content. The original session metadata records CLI0.163.0, while a separate present-day shell command resolution returns0.150.1; neither is being presented as proof of the failed app-server executable version. That version/route provenance remains part of the investigation.

    The exact outbound HTTP item102 has not been captured, so the stored shapes corroborate a compatibility hypothesis but do not conclusively identify that rejected item. No original rollout was edited, no history dropped, no model or credentials changed, and the failed assignment was not resubmitted. Is there a supported request-time compatibility/repair path which preserves the original session history?

    No user prompts, private reasoning text, credentials, native session IDs or local paths included. Marker: OMB-installed0453-resume-shape.

  5. CieveMe commented on Oct 22, 2026

    @CieveMe

    Additional affected case on Windows, observed October 23, 2026 (UTC+8).

    Desktop logs identify client version 26.1016.51333; the model manager reports client version 0.163.0 (these are different version fields).

    An existing chat contains turns previously generated with deepseek-flash. Continuing with gpt-6.1-sol fails twice, at 00:26:42 and 00:26:57 UTC+8, with HTTP 400, invalid_request_error, code array_above_max_length:

    Invalid 'input[422].content': array too long. Expected an array with maximum length 0, but got an array with length 1 instead.
    

    Read-only reconstruction from the latest local replacement history plus subsequent response items yields 541 items. Zero-based item 422 is a reasoning item with one reasoning_text content entry and a non-null encrypted_content field. There are 36 reasoning items with nonempty content in that reconstructed history. Their original turn contexts identify deepseek-flash. No reasoning text or encrypted payload is included here.

    This is evidence from an affected chat, not an independent reproduction in a fresh chat. The full outbound request was not captured, so the matching local index is diagnostic evidence rather than proof of the exact wire payload. The third-party integration details and responsible conversion layer remain unverified. No session/database/configuration was edited and no repair was tested.

    Is there a supported way to resume an affected chat while preserving user/assistant messages, and should incompatible foreign reasoning items be handled during replay or reported with an actionable recovery path?

    Disclosure: AI assistance was used to prepare this comment; the reported metadata was checked against local files and logs.

  6. billy-enrizky commented on Nov 5, 2026

    @billy-enrizky

    Confirmed on Codex CLI 0.166.0 (macOS) with a wire-level reproduction and a proposed fix.

    Environment

    • Thread started on deepseek-ai/DeepSeek-V4.1-Flash-1017 through a Responses-compatible LiteLLM gateway.
    • Same thread switched to gpt-6-luna, also through the gateway.
    • Resuming and /compact both fail with HTTP 400, array_above_max_length.

    Exact item and index, proven

    The thread has 236 response_item entries of type reasoning, all with summary: [], content: [{"type":"reasoning_text", ...}], and encrypted_content: null.

    gpt-6-luna has use_responses_lite: true, so build_responses_request prepends an additional_tools input item. The normal turn request is:

    0 additional_tools
    1 developer message (skills, permissions, collaboration mode, plugins)
    2 user message (AGENTS.md and environment context)
    3 user message (first task)
    4 first stored reasoning item
    

    Replaying exactly those first five items to the same endpoint:

    • as stored: HTTP 400 Invalid 'input[4].content': array too long. Expected an array with maximum length 0, but got an array with length 1 instead.
    • with that item's content set to null: HTTP 200

    /compact fails one index earlier, at input[3].content, because the compaction prompt has no tools and therefore no additional_tools prefix. This confirms the rejected item is the stored reasoning item, not a token or context-length problem.

    Model matrix for the same item at index 4:

    model content: [reasoning_text] content: null
    gpt-6-luna 400 array_above_max_length 200
    gpt-6.1-sol 400 array_above_max_length 200
    gpt-5.6-terra 400 array_above_max_length 200
    DeepSeek V4.1 Flash 200 200
    GLM-5.3 200 200

    Dropping inline reasoning text on replay is therefore safe for the OpenAI models and the two third-party models tested.

    Why compaction does not recover the thread

    run_inline_auto_compact_task builds turn_input from history.clone().for_prompt(...) and sends it through build_responses_request. The validator rejects the history before a summary can be produced, so compaction cannot repair the thread.

    Code path

    • codex-rs/protocol/src/models.rs, should_serialize_reasoning_content: keeps ReasoningItemContent::ReasoningText in the serialized reasoning item, so content is sent as a non-empty array.
    • codex-rs/core/src/client.rs, build_responses_request: copies prompt.get_formatted_input_for_request(model_info) into input and does not clear foreign reasoning.content. The !is_openai branch clears metadata and encrypted content, but not reasoning content.

    Proposed fix

    Request-time only, persisted history unchanged:

    // codex-rs/core/src/client.rs, in build_responses_request
    // Foreign providers persist inline `reasoning_text`. OpenAI Responses models
    // reject replayed reasoning items with non-empty `content` (maxItems 0).
    // The raw text is not needed to continue a thread; summary and
    // encrypted_content are enough.
    for item in &mut input {
        if let ResponseItem::Reasoning { content, .. } = item {
            *content = None;
        }
    }

    Optional cleanup so the field is omitted instead of sent as null:

    // codex-rs/protocol/src/models.rs
    fn should_serialize_reasoning_content(content: &Option<Vec<ReasoningItemContent>>) -> bool {
        match content {
            Some(content) => !content
                .iter()
                .any(|c| matches!(c, ReasoningItemContent::ReasoningText { .. })),
            None => true, // skip null
        }
    }

    If keeping inline reasoning for models that accept it matters, gate the clear behind a new ModelInfo capability (default false) and opt in DeepSeek/GLM. An unconditional clear is simpler and matched every model tested.

    Workaround verified today

    With a full backup, rewrite every response_item where payload.type == "reasoning" and payload.content is a non-empty array, setting payload.content = null. Keep the reasoning items themselves, including summary and encrypted_content. After clearing 236 items, the first five request items replayed with HTTP 200 and the thread became resumable. Compaction then passes the same validator, because the rejected item no longer carries content.

    Related: #56155 (GLM, compaction), #36704 (stale encrypted reasoning).

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

    CLIappbugcustom-modelsession

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions