Skip to content

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

Merged
steipete merged 8 commits into
openclaw:mainfrom
lilesjtu:codex/context-tokens-consistency
May 6, 2026
Merged

fix(codex): honor OAuth contextTokens in native harness#77861
steipete merged 8 commits into
openclaw:mainfrom
lilesjtu:codex/context-tokens-consistency

Conversation

@lilesjtu

@lilesjtu lilesjtu commented May 5, 2026

Copy link
Copy Markdown
Contributor

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

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 5, 2026
@clawsweeper

clawsweeper Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR maps native Codex openai/* context lookups to openai-codex, preserves catalog contextTokens, updates status/directive context cap handling, and adds focused tests plus a changelog entry.

Reproducibility: yes. As a source-level reproduction, configure models.providers.openai-codex.models[].contextTokens for gpt-5.5, then run openai/gpt-5.5 through agentRuntime.id: "codex"; current main resolves the runtime context provider as openai.

Real behavior proof
Sufficient (live_output): The PR body includes copied after-fix live /status output from a real macOS OpenClaw 2026.5.4 native Codex setup showing the configured 1.0m context cap.

Next step before merge
No repair lane: I found no PR-introduced code defect to patch, and the remaining blocker is ordinary CI/merge handling for failures outside the touched diff.

Security
Cleared: The diff changes TypeScript context/status/catalog logic, tests, and changelog only; it does not alter dependencies, workflows, scripts, secrets, permissions, or package resolution.

Review details

Best possible solution:

Land the revised consistency fix once exact-head checks are green or the unrelated gateway-test failures are resolved outside this PR.

Do we have a high-confidence way to reproduce the issue?

Yes. As a source-level reproduction, configure models.providers.openai-codex.models[].contextTokens for gpt-5.5, then run openai/gpt-5.5 through agentRuntime.id: "codex"; current main resolves the runtime context provider as openai.

Is this the best way to solve the issue?

Yes. The PR keeps the public openai/gpt-* model route intact and only redirects context-config lookup to openai-codex across run, status, and directive persistence paths, which is the narrowest maintainable fix I found.

What I checked:

  • Current-main bug path: On current main, resolveEffectiveRuntimeModel() resolves resolveContextWindowInfo() against params.provider, and runEmbeddedPiAgent() passes the selected provider without a Codex context-config override, so native openai/gpt-* Codex runs look under openai rather than openai-codex. (src/agents/pi-embedded-runner/run/setup.ts:126, c5fcfa1b56e1)
  • Documented route contract: The provider docs define the native Codex route as model ref openai/gpt-5.5 with agentRuntime.id: "codex", while auth/profile commands keep using provider id openai-codex. Public docs: docs/providers/openai.md. (docs/providers/openai.md:216, c5fcfa1b56e1)
  • PR run-path fix: The PR diff adds resolveHarnessContextConfigProvider() and passes openai-codex as contextConfigProvider for provider=openai on the codex harness. (src/agents/pi-embedded-runner/run.ts:181, 850369b608e6)
  • Earlier review blockers addressed: The revised diff adds the active changelog entry and changes directive persistence to call shared resolveContextTokens() with a Codex-aware context provider, addressing the prior ClawSweeper findings. (src/auto-reply/reply/directive-handling.persist.ts:67, 850369b608e6)
  • Real behavior proof: The PR body supplies copied live output from macOS OpenClaw 2026.5.4 after applying the patch, showing /status with Context: 0/1.0m and agentMeta.contextTokens: 1000000 for native Codex openai/gpt-5.5. (850369b608e6)
  • Exact-head CI state: GitHub check annotations show check-lint and check-test-types failing in src/gateway/server.cron.test.ts, which is not part of this PR diff; other touched-surface checks and the real behavior proof check are green. (src/gateway/server.cron.test.ts:194, 850369b608e6)

Likely related people:

  • steipete: Recent history includes runtime context cap work, status runtime metadata, and model-selection maintenance on the same context/status surfaces. (role: recent maintainer / context-status owner; confidence: high; commits: 58d2b9dd46cc, e5dc0e6d15ea, 59fb9e5ca7fe; files: src/agents/context-window-guard.ts, src/status/status-message.ts, src/auto-reply/reply/model-selection.ts)
  • vincentkoc: Recent commits touch status rendering, provider/runtime type boundaries, and embedded runner adjacent files that the PR changes. (role: recent status/harness maintainer; confidence: medium; commits: 46c99cff0b2f, a17d4371d101, 61da711b1a7e; files: src/status/status-message.ts, src/status/status-text.ts, src/agents/pi-embedded-runner/run/setup.ts)
  • pashpashpash: Recent docs and runtime work clarified the Codex subscription/native route that defines the user-facing contract this PR repairs. (role: adjacent Codex route/docs owner; confidence: medium; commits: 9fb90f3d2921, 8adbee3a686a, 401ae38f13a3; files: docs/providers/openai.md)

Remaining risk / open question:

  • Exact-head CI currently has failing check-lint and check-test-types annotations in untouched src/gateway/server.cron.test.ts; this looks unrelated to the PR diff but still needs CI resolution before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against c5fcfa1b56e1.

@lilesjtu lilesjtu changed the title Keep agent contextTokens from inflating reported model context Honor Codex context overrides in native harness May 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M and removed size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 5, 2026
@lilesjtu lilesjtu changed the title Honor Codex context overrides in native harness Honor Codex OAuth contextTokens in native Codex harness May 5, 2026
@lilesjtu lilesjtu changed the title Honor Codex OAuth contextTokens in native Codex harness fix(codex): honor OAuth contextTokens in native harness May 5, 2026
@steipete steipete force-pushed the codex/context-tokens-consistency branch from a129bd6 to 850369b Compare May 6, 2026 07:33
@openclaw-barnacle openclaw-barnacle Bot added the proof: supplied External PR includes structured after-fix real behavior proof. label May 6, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@steipete steipete force-pushed the codex/context-tokens-consistency branch from 850369b to 36e3527 Compare May 6, 2026 07:45
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels May 6, 2026
@steipete steipete force-pushed the codex/context-tokens-consistency branch from 36e3527 to c9f158e Compare May 6, 2026 07:49
@steipete steipete merged commit 58f81b0 into openclaw:main May 6, 2026
109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime proof: supplied External PR includes structured after-fix real behavior proof. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Honor Codex OAuth contextTokens in native Codex harness

2 participants