Skip to content

Resume/handoff to third-party Responses providers fails: item type "compaction" is not supported #45393

Open

Description

@keleqnma

What version of Codex is running?

codex-cli 0.154.0 (also reproduced via Codex Desktop 0.154.0-alpha.6.2)

What issue are you seeing?

When a session that has gone through auto-compaction is resumed (or handed off) with a third-party model provider using wire_api = "responses", every request fails with:

{"error":{"code":"invalid_request_error","message":"invalid_request_error: invalid_request_error: input.12: item type \"compaction\" is not supported","type":"invalid_request_error"}}

The provider is Kimi for Coding (https://api.kimi.com/coding/v1), which implements a Responses-compatible endpoint. The same problem presumably affects any non-OpenAI Responses-compatible provider.

Root cause

On resume, Codex replays the persisted rollout history into input verbatim. Sessions that were compacted contain an item like:

{"type":"compaction","id":"cmp_...","encrypted_content":"gAAAAAB..."}

compaction is an OpenAI-private item type — the encrypted_content is only meaningful to OpenAI's backend. Third-party "Responses-compatible" endpoints implement the public item subset (message, function_call, reasoning, ...) and reject unknown item types, so the whole request is rejected and the thread can never be continued with that provider.

This makes switching an existing (compacted) thread between OpenAI models and third-party providers impossible. Note that wire_api = "chat" is no longer an escape hatch since it was removed (#7782).

Steps to reproduce

  1. Configure a third-party provider with wire_api = "responses" (e.g. Kimi for Coding).
  2. Have a session that went through auto-compaction with any model (the rollout contains a compacted record / a compaction response item).
  3. Resume the session with the third-party model (codex exec resume <id> "...", or switch the model of an existing thread in Codex Desktop).
  4. Every turn fails with item type "compaction" is not supported.

What is the expected behavior?

Codex should not send OpenAI-private item types to providers that can't understand them. When the active provider is not OpenAI, history replay should strip compaction items (or downgrade them to a plain text message such as "[earlier context was compacted]"), the same way the local summary bridge messages are already plain text.

Additional information

Verified workaround: a localhost proxy that rewrites input items of type: "compaction" into a placeholder message item makes resume work with the third-party provider (all requests return 200 and the thread continues normally), which confirms the only blocker is this item type being forwarded as-is.

Activity

  1. added
    bug
    CLI
    custom-model
    context
    session
    on Sep 14, 2026
  2. keleqnma commented on Sep 14, 2026

    @keleqnma
    Author

    I have a fix ready for this on a branch: https://github.com/keleqnma/codex/tree/fix/strip-compaction-for-third-party-providers (compare: main...keleqnma:codex:fix/strip-compaction-for-third-party-providers)

    I currently can't open the PR myself — GitHub rejects pull request creation from my account on this repo ("keleqnma does not have the correct permissions to execute CreatePullRequest" via API; the compare page says PRs are limited to collaborators). Happy to open it once that clears, or a maintainer can pull the branch directly.

    Fix summary

    In build_responses_request (codex-rs/core/src/client.rs), when the active provider is not OpenAI, drop ResponseItem::Compaction and ResponseItem::ContextCompaction items from the request input before sending:

    if !is_openai {
        input.retain(|item| {
            !matches!(
                item,
                ResponseItem::Compaction { .. } | ResponseItem::ContextCompaction { .. }
            )
        });
    }

    This is lossless for third-party providers: the compaction summary is already present in history as a regular plain-text user message, so no information visible to a non-OpenAI backend is removed. OpenAI providers keep receiving the items unchanged.

    Testing

    Added responses_request_strips_openai_private_compaction_items_for_third_party_providers in codex-rs/core/src/client_tests.rs, verifying:

    • a third-party (OSS) provider's request input contains the summary message and no compaction items;
    • an OpenAI provider's request input is unchanged.
    just test -p codex-core responses_request_strips_openai_private_compaction_items_for_third_party_providers
    # 1 test run: 1 passed, 4356 skipped
    

    just fmt and git diff --check pass.

  3. ChildOfAnAndroid commented on Oct 7, 2026

    @ChildOfAnAndroid

    Reproduced on Codex CLI 0.161.0 on macOS when cold-resuming an OpenAI-originated thread under Ollama/Qwen.

    Setup:

    • existing Codex thread had previously been compacted by an OpenAI-backed model
    • resume under --oss --local-provider ollama -m qwen3.6:27b-coding-mxfp8
    • first continued turn fails with:
      unsupported compaction item: encrypted_content is not an Ollama payload
      

    This is now especially clear from Ollama's current implementation. Ollama intentionally treats compaction.encrypted_content as provider-owned state: its payload must decode to {"type":"ollama_compaction","version":1,...}; foreign/OpenAI opaque compaction content is rejected with the exact error above in openai/responses_compact.go.

    Ollama's Codex Desktop proxy already has the reciprocal compatibility behavior in internal/proxy/codex_desktop_normalize.go: when routing to Ollama it retains only Ollama-owned compaction items and drops foreign ones; when routing to OpenAI it drops Ollama compaction state.

    The raw Codex CLI Ollama provider path does not go through that proxy, so Codex still forwards the persisted OpenAI compaction item verbatim.

    I also verified a recovery in the same thread: after a plaintext context checkpoint was established and a fresh local compaction completed, continuation under Ollama worked. So the local provider/compactor itself is fine; the poison is specifically the replayed foreign compaction payload.

    The request-boundary fix proposed above remains the minimal interoperability fix. For remote-v2 compactions, a stronger lossless approach would be to avoid selecting an incompatible persisted compaction checkpoint when the producer compaction_model_hash differs from the resumed model/provider, replay the retained rollout history instead, and let the new provider compact it into its own format. That avoids treating provider-specific encrypted state as portable.

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

    CLIbugcontextcustom-modelsession

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions