openclaw - ✅(Solved) Fix Honor Codex OAuth contextTokens in native Codex harness [1 pull requests, 1 comments, 2 participants]

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…
GitHub stats
openclaw/openclaw#77858Fetched 2026-05-06 06:20:14
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Author
Timeline (top)
commented ×1cross-referenced ×1renamed ×1

The native Codex route uses an openai/gpt-* model ref plus agents.defaults.agentRuntime.id: "codex", but the Codex OAuth/runtime context metadata and user overrides are exposed under the openai-codex provider.

That creates a confusing split for context configuration. A user can configure:

{
  models: {
    providers: {
      "openai-codex": {
        models: [
          {
            id: "gpt-5.5",
            contextWindow: 1050000,
            contextTokens: 1000000,
          },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: { primary: "openai/gpt-5.5" },
      agentRuntime: { id: "codex" },
    },
  },
}

but the native harness context calculation still resolves against provider openai, so it can keep the runtime model's default contextTokens value such as 272000. In practice, /status may show a larger configured/catalog window while agentMeta.contextTokens reports the smaller default runtime cap.

Root Cause

The native Codex route uses an openai/gpt-* model ref plus agents.defaults.agentRuntime.id: "codex", but the Codex OAuth/runtime context metadata and user overrides are exposed under the openai-codex provider.

That creates a confusing split for context configuration. A user can configure:

{
  models: {
    providers: {
      "openai-codex": {
        models: [
          {
            id: "gpt-5.5",
            contextWindow: 1050000,
            contextTokens: 1000000,
          },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: { primary: "openai/gpt-5.5" },
      agentRuntime: { id: "codex" },
    },
  },
}

but the native harness context calculation still resolves against provider openai, so it can keep the runtime model's default contextTokens value such as 272000. In practice, /status may show a larger configured/catalog window while agentMeta.contextTokens reports the smaller default runtime cap.

Fix Action

Fixed

PR fix notes

PR #77861: fix(codex): honor OAuth contextTokens in native harness

Description (problem / solution / changelog)

Summary

Fixes #77858.

Native Codex runs use openai/gpt-* as the model ref, but Codex OAuth runtime context metadata and user overrides live under the openai-codex provider. Before this PR, the native harness resolved context limits against openai, so an override like models.providers.openai-codex.models[].contextTokens could be ignored and the run would keep the default Codex runtime cap, for example 272000.

This PR aligns the run and status paths:

  • Add an explicit contextConfigProvider to effective runtime model resolution.
  • Map openai/* running on the codex harness to openai-codex for context config lookup.
  • Use the same mapping in /status, so rendered context and agentMeta.contextTokens agree.
  • Keep /status context lookup lightweight by using config/cache lookup only, avoiding full model catalog discovery during status rendering.
  • Preserve contextTokens in model catalog entries so runtime/catalog consumers and plugin boundary types stay consistent.
  • Keep agent-level contextTokens as a cap over known model/runtime windows instead of letting it inflate reporting above the effective model window.

Real behavior proof

  • Behavior or issue addressed: A real native Codex harness run configured as openai/gpt-5.5 with agentRuntime.id: codex should honor the openai-codex/gpt-5.5 context override instead of staying at the default 272k-ish runtime cap.
  • Real environment tested: macOS local OpenClaw install, openclaw 2026.5.4 (325df3e), native Codex route, main agent configured with openai/gpt-5.5, agentRuntime.id: codex, and models.providers.openai-codex.models[].contextTokens: 1000000.
  • Exact steps or command run after this patch:
openclaw agent --agent main --session-id codex-context-cap-smoke-20260505f --message "/status" --json --timeout 120
  • Evidence after fix: Copied live output from the real OpenClaw setup after applying the patch locally:
Context: 0/1.0m
agentMeta.contextTokens: 1000000
provider: openai
model: gpt-5.5
promptTokens: 31233
  • Observed result after fix: /status reported Context: 0/1.0m, and the response metadata reported contextTokens: 1000000, confirming the native Codex run used the Codex OAuth context override while keeping the canonical openai/gpt-5.5 model ref.
  • What was not tested: No known gaps.

Tests

pnpm vitest run src/auto-reply/reply/commands-status.test.ts src/auto-reply/reply/commands-status.thinking-default.test.ts
pnpm vitest run src/agents/pi-embedded-runner/run/setup.test.ts src/auto-reply/reply/commands-status.test.ts src/auto-reply/reply/model-selection.test.ts src/auto-reply/status.test.ts src/agents/context-window-guard.test.ts src/agents/command/session-store.test.ts
pnpm build:plugin-sdk:strict-smoke
pnpm run test:extensions:package-boundary:compile
pnpm run lint:extensions:channels
pnpm run lint:extensions:bundled
git diff --check

Changed files

  • src/agents/model-catalog.ts (modified, +40/-2)
  • src/agents/model-catalog.types.ts (modified, +1/-0)
  • src/agents/model-selection-shared.ts (modified, +9/-0)
  • src/agents/pi-embedded-runner/run.ts (modified, +14/-0)
  • src/agents/pi-embedded-runner/run/setup.test.ts (modified, +87/-1)
  • src/agents/pi-embedded-runner/run/setup.ts (modified, +2/-1)
  • src/auto-reply/reply/commands-status.test.ts (modified, +51/-0)
  • src/auto-reply/reply/model-selection.test.ts (modified, +26/-0)
  • src/auto-reply/reply/model-selection.ts (modified, +18/-10)
  • src/auto-reply/status.test.ts (modified, +48/-0)
  • src/status/status-message.ts (modified, +24/-15)
  • src/status/status-text.ts (modified, +24/-0)

Code Example

{
  models: {
    providers: {
      "openai-codex": {
        models: [
          {
            id: "gpt-5.5",
            contextWindow: 1050000,
            contextTokens: 1000000,
          },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: { primary: "openai/gpt-5.5" },
      agentRuntime: { id: "codex" },
    },
  },
}
RAW_BUFFERClick to expand / collapse

Summary

The native Codex route uses an openai/gpt-* model ref plus agents.defaults.agentRuntime.id: "codex", but the Codex OAuth/runtime context metadata and user overrides are exposed under the openai-codex provider.

That creates a confusing split for context configuration. A user can configure:

{
  models: {
    providers: {
      "openai-codex": {
        models: [
          {
            id: "gpt-5.5",
            contextWindow: 1050000,
            contextTokens: 1000000,
          },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: { primary: "openai/gpt-5.5" },
      agentRuntime: { id: "codex" },
    },
  },
}

but the native harness context calculation still resolves against provider openai, so it can keep the runtime model's default contextTokens value such as 272000. In practice, /status may show a larger configured/catalog window while agentMeta.contextTokens reports the smaller default runtime cap.

Expected behavior

For openai/gpt-* running through the codex harness, context-window resolution should use openai-codex as the context config provider. That lets models.providers.openai-codex.models[].contextTokens override the Codex runtime cap consistently for the actual run and for /status.

Impact

Users following the recommended native Codex route can otherwise see contradictory context numbers and have no obvious way to make their configured Codex OAuth context cap affect the actual run.

extent analysis

TL;DR

To resolve the context configuration split, update the native Codex route to use the openai-codex provider for context-window resolution.

Guidance

  • Verify that the openai-codex provider is correctly configured with the desired contextTokens value.
  • Update the native Codex route to use the openai-codex provider for context configuration, ensuring consistency between the actual run and the /status endpoint.
  • Check the agentMeta.contextTokens value to confirm that it reflects the configured contextTokens value from the openai-codex provider.
  • Review the documentation to ensure that users are aware of the correct configuration procedure for the native Codex route.

Example

{
  models: {
    providers: {
      "openai-codex": {
        models: [
          {
            id: "gpt-5.5",
            contextWindow: 1050000,
            contextTokens: 1000000,
          },
        ],
      },
    },
  },
  agents: {
    defaults: {
      model: { primary: "openai/gpt-5.5" },
      agentRuntime: { id: "codex" },
    },
  },
}

Note that the openai-codex provider should be used for context configuration to ensure consistency.

Notes

This solution assumes that the openai-codex provider is correctly configured and that the native Codex route is updated to use this provider for context-window resolution.

Recommendation

Apply workaround: Update the native Codex route to use the openai-codex provider for context configuration to ensure consistency between the actual run and the /status endpoint. This will allow users to configure the context cap consistently for the actual run and for /status.

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…

FAQ

Expected behavior

For openai/gpt-* running through the codex harness, context-window resolution should use openai-codex as the context config provider. That lets models.providers.openai-codex.models[].contextTokens override the Codex runtime cap consistently for the actual run and for /status.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Honor Codex OAuth contextTokens in native Codex harness [1 pull requests, 1 comments, 2 participants]