Skip to content

[Bug]: Codex OAuth compaction falls back to direct OpenAI API and fails without OPENAI_API_KEY #86820

@kopl-blip

Description

@kopl-blip

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

A session using openai/gpt-5.5 with a valid OpenAI Codex OAuth profile fails during compaction with:

Missing API key for OpenAI on the gateway. Use openai/gpt-5.5 with the Codex OAuth profile, or set OPENAI_API_KEY for direct OpenAI API-key runs.

This is not limited to Slack. It appears to happen whenever compaction is triggered. The agent works normally before compaction, and openclaw models status reports Codex OAuth as usable.

The failure path appears to be:

  1. Session reaches the compaction threshold.
  2. Codex-native/app-server compaction cannot use the existing thread/session binding.
  3. OpenClaw falls back to a context-engine/direct provider path.
  4. That fallback path tries to use the direct OpenAI provider.
  5. Since the installation is intentionally using Codex OAuth and has no OPENAI_API_KEY, compaction fails and the user receives the missing API key warning.

Steps to reproduce

  1. Start OpenClaw 2026.5.22 with OpenAI Codex OAuth configured.

  2. Configure an agent with model openai/gpt-5.5.

  3. Do not set OPENAI_API_KEY; use Codex OAuth only.

  4. Confirm the agent auth is usable:

    openclaw models status --agent <agent-id>

    The output shows:

    • Runtime auth
    • openai via codex uses openai-codex ... status=usable
  5. Use the agent until the session reaches the compaction threshold, or otherwise trigger budget-based compaction.

  6. Observe that compaction fails and the user-visible response becomes:

    ⚠️ Missing API key for OpenAI on the gateway. Use openai/gpt-5.5 with the Codex OAuth profile, or set OPENAI_API_KEY for direct OpenAI API-key runs.

  7. Check gateway logs.

Expected behavior

Compacted without errors.

Actual behavior

When compaction is triggered, the session fails with a missing OPENAI_API_KEY warning, even though the active model is openai/gpt-5.5 and Codex OAuth auth is usable.

Observed gateway log:

[agent/embedded] codex app-server compaction could not use thread binding
[agent/embedded] native harness compaction could not use its session binding; falling back to context engine: no codex app-server thread binding
[agent/embedded] [compaction-diag] end runId=2a6dbce3-8204-4ce4-817d-ca3b533d600d sessionKey=agent:jenny:slack:channel:c0b1fnbny5p diagId=cmp-mpkmesl7-485csw trigger=budget provider=openai/gpt-5.5 attempt=1 maxAttempts=1 outcome=failed reason=unknown detail=No_API_key_found_for_provider_openai_._You_are_authenticated_with_OpenAI_Codex_OAuth_OpenAI_agent_mo durationMs=6739

⚠️ Missing API key for OpenAI on the gateway. Use openai/gpt-5.5 with the Codex OAuth profile, or set OPENAI_API_KEY for direct OpenAI API-key runs.

### OpenClaw version

2026.5.22 (a374c3a)

### Operating system

Ubuntu 24.04.4

### Install method

npm / pnpm package-manager install, not git checkout

### Model

openai/gpt-5.5

### Provider / routing chain

OpenClaw -> OpenAI Codex OAuth -> openai/gpt-5.5

### Additional provider/model setup details

_No response_

### Logs, screenshots, and evidence

```shell

Impact and severity

No response

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions