openclaw - 💡(How to fix) Fix [Bug]: ChatGPT-OAuth compact path hits Cloudflare 300s idle-timeout on large contexts; no clean config knob to force local compaction

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

OpenClaw sessions on ChatGPT-OAuth fail with Error running remote compact task: stream disconnected before completion around 300-320s into compact, on contexts that have grown large (~1 MB compact-payload, ~250k tokens). Error shows up in ~/.openclaw/agents/main/agent/codex-home/logs_2.sqlite as repeated POST to https://chatgpt.com/backend-api/codex/responses/compact failing.

Root Cause

Root cause (as best we can determine)

Fix Action

Fix / Workaround

The workaround we ended up using

Code Example

model_provider = "openai-custom"

[model_providers.openai-custom]
name = "OpenAI-Custom"
base_url = "https://chatgpt.com/backend-api/codex"
wire_api = "responses"
requires_openai_auth = true

---

{
  "agents": {
    "defaults": {
      "compaction": {
        "forceLocal": true,    // <-- new
        "mode": "default",
        ...
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Symptom

OpenClaw sessions on ChatGPT-OAuth fail with Error running remote compact task: stream disconnected before completion around 300-320s into compact, on contexts that have grown large (~1 MB compact-payload, ~250k tokens). Error shows up in ~/.openclaw/agents/main/agent/codex-home/logs_2.sqlite as repeated POST to https://chatgpt.com/backend-api/codex/responses/compact failing.

User-facing: Telegram replies stop landing, agent eventually surfaces "Something went wrong" or just goes quiet for minutes at a time.

Root cause (as best we can determine)

  1. The /responses/compact endpoint on chatgpt.com/backend-api/codex/ is unary — the server computes the full compaction then returns the response in one go.
  2. chatgpt.com sits behind Cloudflare, which has a documented 300s edge idle-timeout on connections that don't stream chunks.
  3. On large compact inputs (~1 MB), the server-side compute exceeds 300s before any byte returns → Cloudflare kills the connection.
  4. Codex's ApiRetryConfig.max_attempts retries 4×, total ~317s = 300s (Cloudflare cap) + ~17s overhead before erroring out.
  5. The OPENCLAW_CODEX_COMPACTION_WAIT_TIMEOUT_MS env var (which I see in compact-*.js) only controls OC's outer waiter — it never fires because the inner Codex retry chain errors first.

The workaround we ended up using

In ~/.openclaw/agents/main/agent/codex-home/config.toml:

model_provider = "openai-custom"

[model_providers.openai-custom]
name = "OpenAI-Custom"
base_url = "https://chatgpt.com/backend-api/codex"
wire_api = "responses"
requires_openai_auth = true

This works because Codex's compact.rs::should_use_remote_compact_task only enters the remote-compact path if provider.supports_remote_compaction() is true, and that check is is_openai() || is_azure_responses_provider(). is_openai() literal-compares the provider name to "OpenAI", so spoofing the name flips the routing off and Codex falls back to local compaction via the streaming /responses endpoint, which doesn't get Cloudflare-killed.

Ask

Could OC expose a clean config knob to force local compaction? Something like:

{
  "agents": {
    "defaults": {
      "compaction": {
        "forceLocal": true,    // <-- new
        "mode": "default",
        ...
      }
    }
  }
}

Or alternatively a documented env var OPENCLAW_FORCE_LOCAL_COMPACTION=1 that propagates to Codex via CODEX_FORCE_LOCAL_COMPACTION=1 or similar.

The provider-name spoof works but is fragile: any future change to OC's config-validation, Codex's is_openai() definition, or the [model_providers.*] schema will silently break it.

Affected

  • ChatGPT-OAuth users only (API-key users route via api.openai.com, not Cloudflare-fronted, so don't hit this)
  • Sessions with large accumulated context (1 MB+ compact payload — easy to hit on long sessions with browser + computer-use plugins)

Environment

  • OC version: 2026.5.19
  • Codex: v0.125.0
  • macOS 26.4.1 arm64
  • ChatGPT-OAuth mode

References

  • Source: compact.rs::should_use_remote_compact_task (Codex Rust)
  • Source: compact-*.js (OC's outer waiter — OPENCLAW_CODEX_COMPACTION_WAIT_TIMEOUT_MS)
  • Cloudflare docs on edge idle timeouts

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING