Skip to content

Azure /responses/compact 5xx should fall back to local auto compaction #25534

Closed

Description

@hueifeng

Azure /responses/compact 5xx should fall back to local auto compaction

Summary

Azure Responses remote compaction can return transient 5xx / high-demand errors for long-running Codex sessions. When this happens, Codex currently exhausts the remote retry budget and aborts the turn instead of falling back to local compaction.

I think Codex should degrade gracefully:

remote auto compaction succeeds -> keep current behavior
remote auto compaction fails with transient 5xx/high-demand/stream/transport error -> fall back to local auto compaction
auth/usage/cancel/context-window/4xx errors -> keep current error behavior

Environment

  • Codex CLI: 0.135.0
  • Provider: Azure Responses
  • Region observed: East US 2
  • Models observed:
    • gpt-5.4-mini
    • gpt-5.4
    • gpt-5.5
  • model_context_window: 258400
  • model_auto_compact_token_limit: tested with 80000 and 100000

No API keys, bearer tokens, or secrets are included in this report.

Observed behavior

For long-running / large-context sessions, Codex attempts remote compaction:

endpoint="/responses/compact"

The Azure backend returns:

http.response.status_code=500
error.message="http 500"
compact_error="We're currently experiencing high demand, which may cause temporary errors."

Example request IDs:

x-request-id: 3dbc52a9-f643-44eb-84e3-796e18daa354
apim-request-id: d1533a38-3ccb-4b04-85c9-7e5d87876d15

x-request-id: ec518e5c-b095-4db1-b08a-49b2893af1f7
apim-request-id: d1329d8d-c723-475b-aa36-1246e86eb4a3

The turn fails after remote retry attempts.

Expected behavior

If remote auto compaction fails with a transient backend/transport error, Codex should fall back to local auto compaction and continue the turn.

It should not fall back for non-transient failures such as:

  • auth failures
  • usage/quota failures
  • cancellation/interruption
  • context window exceeded
  • 4xx invalid request errors

Related context

This is related to Azure remote compaction support added after:

That issue fixed Azure providers not using remote compaction. This issue is about the next failure mode: Azure remote compaction is used, but transient /responses/compact failures abort the turn instead of falling back.

Azure's Responses API docs also describe server-side compaction via context_management, but Codex currently calls the separate /responses/compact endpoint.

Proposed fix

I have a candidate patch here:

https://github.com/hueifeng/codex/tree/fix/remote-compaction-local-fallback

The patch:

  • adds a compaction-specific transient fallback predicate
  • falls back from remote auto compaction to local auto compaction for transient errors
  • preserves current behavior for auth/usage/cancel/context-window/4xx errors
  • includes unit tests for fallback classification
  • includes an integration test where /responses/compact returns repeated 500 responses and the turn continues via local compaction

Commits:

8e760da Fall back to local compaction on transient remote failures
9c481fd Cover remote compaction fallback integration

Tests run

just fmt
just test -p codex-core remote_pre_turn_compaction_5xx_falls_back_to_local_compaction falls_back_to_local_compact does_not_fallback_to_local_compact

Result:

3 tests run: 3 passed

Why this matters

For long-running Codex sessions, a transient Azure /responses/compact failure currently makes the whole session unusable. Falling back to local compaction gives Codex a safe degradation path without provider-name hacks or user config changes.

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    azureIssues related to the Azure-hosted OpenAI models
    contextIssues related to context management (including compaction)
    connectivityIssues involving networking or endpoint connectivity problems (disconnections)
    on Jun 1, 2026
  2. hueifeng commented on Jun 1, 2026

    @hueifeng
    Author

    I understand that external PRs are by invitation only. I have prepared a focused candidate patch with tests in my fork:

    https://github.com/hueifeng/codex/tree/fix/remote-compaction-local-fallback

    If the Codex team agrees with this direction and would like an external PR, I’m happy to submit it following the contribution guidelines, including CLA signing and any additional changes requested by maintainers.

  3. etraut-openai commented on Jun 29, 2026

    @etraut-openai
    Contributor

    Thanks for reporting this problem. Until recently, Codex used a separate endpoint and server-side logic for compaction. We recently switched to a more robust approach where the compaction logic is moved locally using the same endpoint as normal turns. This eliminates "remote compaction" errors and increases the stability and reliability of compaction operations. If you see further problems with compaction, please use /feedback and open a new bug report.

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

    CLIIssues related to the Codex CLIazureIssues related to the Azure-hosted OpenAI modelsbugSomething isn't workingconnectivityIssues involving networking or endpoint connectivity problems (disconnections)contextIssues related to context management (including compaction)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions