Skip to content

[Bug]: doctor --fix silently migrates intentional openai-codex/ config to openai/, breaking PI+OAuth runtime and causing 3-4x token inflation #84038

@danielsan1

Description

@danielsan1

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

The native Codex runtime produces 3–4× higher token usage compared to the
OpenClaw PI runtime for the same GPT-5.x requests. This is a known upstream
issue that OpenClaw cannot fix — but doctor --fix silently forces users onto
the broken runtime by migrating intentional openai-codex/ configs to
openai/, removing the agentRuntime: { id: "pi" } override in the process.
Users have no way to opt out of this migration short of manually reverting
after every doctor run.

Steps to reproduce

  1. Configure an explicit PI-runtime setup to avoid the broken Codex runtime:
    {
      "agents": {
        "defaults": {
          "model": {
            "primary": "openai-codex/gpt-5.4"
          },
          "models": {
            "openai-codex/gpt-5.4": {
              "agentRuntime": { "id": "pi" }
            }
          }
        }
      },
      "auth": {
        "order": {
          "openai-codex": ["openai-codex:user@example.com"]
        }
      },
      "plugins": {
        "entries": { "codex": { "enabled": false } }
      }
    }
  2. Run openclaw doctor --fix (e.g. as part of a version update)
  3. Observe doctor output:
    Repaired Codex model routes:
  • agents.defaults.model.primary: openai-codex/gpt-5.4 -> openai/gpt-5.4
  • agents.defaults.models.openai-codex/gpt-5.4: openai-codex/gpt-5.4 -> openai/gpt-5.4
  1. Restart the gateway
  2. Send any message to the agent and observe token usage or check
    openclaw models status

Expected behavior

- Doctor respects an explicitly configured openai-codex/ primary and
agentRuntime: { id: "pi" } override. If the user has deliberately opted
out of the native Codex runtime (because buggy/token-burn), doctor should not re-enroll them.

  • If doctor must migrate model references, it should at minimum preserve the
    agentRuntime config from the old entry and copy it to the new one.
  • Ideally: doctor warns and asks before applying breaking model-route changes,
    similar to how it already shows interactive summaries for other migrations.

Actual behavior

  • primary is silently changed to openai/gpt-5.4
  • The models["openai-codex/gpt-5.4"] entry — including agentRuntime: { id: "pi" } —
    is removed entirely
  • All model aliases pointing to openai-codex/gpt-5.4 are dropped
  • The gateway starts with the native Codex runtime active
  • Token usage per turn is 3–4× higher than before the migration
    (observed with GPT-5.4; even worse with GPT-5.5)
  • openclaw models status shows openai/gpt-5.4 · api-key (env: OPENAI_API_KEY)
    instead of openai-codex/gpt-5.4 · oauth — auth path also silently switched

OpenClaw version

from 2026.5.12 onwards

Operating system

macOS 26.5

Install method

No response

Model

openai-codex/gpt-5.x

Provider / routing chain

Desired (PI runtime, working): User message → openai-codex/gpt-5.4 → auth: oauth (openai-codex:user@example.com) → runtime: OpenClaw PI → tokens_prompt: baseline (1×)

Additional provider/model setup details

Provider / Routing Chain

Desired (PI runtime, working):
User message
→ openai-codex/gpt-5.4
→ auth: oauth (openai-codex:user@example.com)
→ runtime: OpenClaw PI
→ tokens_prompt: baseline (1×)

Actual after doctor (native Codex runtime, broken):
User message
→ openai/gpt-5.4
→ auth: api-key (env: OPENAI_API_KEY) ← wrong auth path
→ runtime: native Codex harness ← broken runtime
→ tokens_prompt: 3–4× baseline ← token inflation

The OPENAI_API_KEY is present in this environment for unrelated features
(Talk/Voice). With primary: openai/gpt-5.4, OpenClaw silently prefers the
direct API key path even when auth.order.openai-codex is configured — this
auth-path ambiguity is the original reason for adopting the explicit
openai-codex/ namespace

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

Proposed Fix / Feature Request

The root issue is the native Codex runtime itself — it is producing
significantly inflated token counts compared to the PI runtime for equivalent
workloads. This appears to be an upstream Codex issue that OpenClaw cannot
directly fix at the provider level.

Until that is resolved, users need a stable way to opt out. Specifically:

  1. Respect agentRuntime: { id: "pi" } as an explicit opt-out signal.
    Doctor should not overwrite a model entry that carries this key without
    at minimum a warning.
  2. Surface the Codex runtime as experimental / opt-in, not the default
    path that doctor steers users toward. Users should be able to choose
    whether they want the native Codex harness or the PI runtime — and that
    choice should survive doctor --fix.
  3. If migration is unavoidable, carry agentRuntime and alias config
    forward to the new model ref automatically.

Workaround

Manually reapply after every doctor --fix:

openclaw config set agents.defaults.model.primary "openai-codex/gpt-5.4"
openclaw config set agents.defaults.models["openai-codex/gpt-5.4"].agentRuntime.id "pi"
openclaw gateway restart --force

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    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