Skip to content

fix: honor Codex auth order for OpenAI PI - #82605

Merged
steipete merged 2 commits into
mainfrom
fix/openai-pi-codex-auth-order-82521
May 16, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/openai-pi-codex-auth-order-82521

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Summary

  • Honor Codex-first auth.order.openai entries for explicit OpenAI PI runs while keeping OpenAI-compatible custom base URLs on the OpenAI provider path.
  • Preserve the PI harness when explicit Codex auth routing changes the runtime provider to openai-codex.
  • Accept openclaw models auth login --provider openai-codex --device-code for headless Codex OAuth sign-in.

Fixes #82521.

Verification

  • node scripts/run-vitest.mjs src/agents/openai-codex-routing.test.ts src/agents/pi-embedded-runner.e2e.test.ts src/agents/auth-profiles/order.test.ts src/cli/models-cli.test.ts src/auto-reply/reply/commands-status.test.ts
    • 5 files passed, 71 tests passed
  • git diff --check
  • /Users/steipete/Projects/agent-scripts/skills/codex-review/scripts/codex-review --full-access
    • clean after accepted findings were fixed
  • pnpm check:changed via Testbox run tbx_01krre2mywy5h4wp2mtwen8z33

Real behavior proof

Behavior addressed: Explicit OpenAI PI runs now respect a Codex-first auth.order.openai list, so openai-codex:* OAuth profiles are tried before OpenAI API-key backups when the selected harness is PI.

Real environment tested: Local OpenClaw source checkout with focused Vitest coverage plus Codex review; broader check:changed was attempted on Testbox and hit unrelated current-main type errors outside this patch.

Exact steps or command run after this patch: node scripts/run-vitest.mjs src/agents/openai-codex-routing.test.ts src/agents/pi-embedded-runner.e2e.test.ts src/agents/auth-profiles/order.test.ts src/cli/models-cli.test.ts src/auto-reply/reply/commands-status.test.ts

Evidence after fix: The embedded PI regression test resolves the original OpenAI model config first, then activates the openai-codex runtime provider only when that runtime model exists, and the status test reports the Codex OAuth profile instead of the OpenAI API-key backup.

Observed result after fix: 5 focused test files passed, 71 tests passed; Codex review completed with no accepted/actionable findings remaining.

What was not tested: No live OpenAI/Codex OAuth run was executed in this checkout; pnpm check:changed did not complete because of unrelated current-main typecheck failures listed above.

@steipete
steipete requested a review from a team as a code owner May 16, 2026 13:35
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes commands Command implementations agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels May 16, 2026
@clawsweeper

clawsweeper Bot commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR updates OpenAI/Codex auth routing, PI embedded runner/status auth selection, models auth login --device-code, regression tests, and the changelog so explicit OpenAI PI runs honor Codex-first auth.order.openai entries.

Reproducibility: yes. Configure openai/gpt-5.5 with provider/model agentRuntime.id: "pi" and auth.order.openai listing openai-codex:* before openai:*; current main source orders/validates the generic OpenAI provider first, matching the linked issue's /status evidence.

Real behavior proof
Needs real behavior proof before merge: The PR body provides focused tests and a Testbox attempt but explicitly says no live OpenAI/Codex OAuth run was executed; the contributor should add redacted terminal output, logs, screenshots, recording, or linked artifact showing the real fixed path before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
This is an active protected-label PR with no narrow automation repair finding; the next action is human maintainer review plus contributor real-behavior proof, not a cleanup close or repair-lane PR.

Security
Cleared: The diff touches TypeScript routing, CLI option parsing, tests, and changelog only; I found no new dependency, workflow, secret, or supply-chain concern.

Review details

Best possible solution:

Land this PR or an equivalent maintainer-approved fix once it has redacted live proof that documented auth.order.openai drives explicit PI Codex OAuth before OpenAI backups and that the documented device-code login path works as intended.

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

Yes. Configure openai/gpt-5.5 with provider/model agentRuntime.id: "pi" and auth.order.openai listing openai-codex:* before openai:*; current main source orders/validates the generic OpenAI provider first, matching the linked issue's /status evidence.

Is this the best way to solve the issue?

Likely yes. The patch moves the PI runtime-provider choice and auth-label ordering to the existing OpenAI/Codex routing helpers with focused regression coverage; maintainer review should confirm the documented --device-code semantics and live behavior proof before merge.

What I checked:

  • Protected label: The live PR labels include maintainer, so this cleanup workflow must keep the PR open for explicit human handling even if the patch is otherwise acceptable. (3bba9d94e564)
  • Current-main source contract mismatch: Current main lists OpenAI before OpenAI Codex for explicit PI runtime, while resolveAuthProfileOrder validates profiles against the requested provider, which makes a Codex-first auth.order.openai entry lose priority for the reported setup. (src/agents/openai-codex-routing.ts:111, b9921e21b93d)
  • Documented expected behavior: The docs say openai/gpt-* stays on the Codex harness while auth may rotate between openai-codex:* subscription auth and an openai:* API-key backup under auth.order.openai; the OpenAI provider page also documents --device-code for callback-hostile sign-in. Public docs: docs/concepts/model-failover.md. (docs/concepts/model-failover.md:129, b9921e21b93d)
  • PR patch surface: The patch adds config-aware OpenAI auth-provider ordering, selected PI runtime-provider resolution, status auth-label handling, a --device-code CLI option, and focused regression tests across agent routing, embedded PI runner, auth order, status, and models CLI. (src/agents/openai-codex-routing.ts:78, 3bba9d94e564)
  • Linked issue discussion: The linked issue includes a live reporter comparison: the documented openai/gpt-5.5 plus Codex-first auth.order.openai path showed /status using the OpenAI API-key backup, while an explicit openai-codex/gpt-5.5 primary used the Codex OAuth profile.
  • Real behavior proof gap: The PR body reports focused Vitest coverage and a Testbox check:changed attempt, but explicitly says no live OpenAI/Codex OAuth run was executed; that is useful test proof but not after-fix real behavior proof for this external PR gate. (3bba9d94e564)

Likely related people:

  • pashpashpash: Auth/runtime routing history includes Route OpenAI agents through Codex by default and Keep OpenAI Codex migrations on automatic runtime routing, which introduced much of the OpenAI/Codex provider-runtime boundary involved here. (role: feature-history owner; confidence: high; commits: 1c3399010815, 02fe0d8978db, 517566e39a10; files: src/agents/openai-codex-routing.ts, src/agents/auth-profiles/order.ts, docs/concepts/agent-runtimes.md)
  • steipete: Recent auth-order and PI runner work includes Codex auth-order preservation, fallback blocking, and model-picker/runtime-choice changes; this PR author also appears in prior merged history for the affected surfaces. (role: recent area contributor; confidence: high; commits: 3f05165c47d7, 6ee0c9a69654, 6171b4254d41; files: src/agents/auth-profiles/order.ts, src/agents/pi-embedded-runner/run.ts, src/agents/openai-codex-routing.ts)
  • jalehman: Recent OpenAI runtime work adjusted Codex context windows and touched the same routing and embedded runner surfaces that this PR modifies. (role: adjacent runtime contributor; confidence: medium; commits: 4004c9342d7d; files: src/agents/openai-codex-routing.ts, src/agents/pi-embedded-runner/run.ts)
  • vincentkoc: Recent commits touched the embedded runner and models CLI lazy-loading/runtime surface, including files affected by the device-code CLI option and PI runner path. (role: recent CLI/agent contributor; confidence: medium; commits: 310c8530eb81, babd25c6b7ff; files: src/agents/pi-embedded-runner/run.ts, src/cli/models-cli.ts)

Remaining risk / open question:

  • The PR body does not include live OpenAI/Codex OAuth or explicit PI runtime proof after the patch; focused tests are not enough for the external PR real-behavior gate.
  • The broad pnpm check:changed attempt did not complete; the PR attributes failures to unrelated current-main type errors, which a maintainer should verify before landing.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3bba9d94e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +605 to +606
provider = selectedPiRuntimeProvider;
modelResolution = runtimeModelResolution;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep OpenAI config auth lookup on original provider

Switching provider to openai-codex here makes later auth resolution treat the run as Codex-owned, so explicit OpenAI API-key configuration can be skipped. In a PI run with auth.order.openai starting with openai-codex:* and models.providers.openai.auth/apiKey configured, this reassignment causes downstream checks like shouldPreferExplicitConfigApiKeyAuth and key lookup to use openai-codex instead of openai, which can lead to selecting the wrong profile or failing with missing credentials even though OpenAI auth is configured. Keep credential/config resolution keyed to the original OpenAI provider when only the runtime transport changes.

Useful? React with 👍 / 👎.

@steipete steipete added the proof: override Maintainer override for the external PR real behavior proof gate. label May 16, 2026
@steipete
steipete force-pushed the fix/openai-pi-codex-auth-order-82521 branch from 3bba9d9 to a2b614a Compare May 16, 2026 14:21
@steipete
steipete merged commit 9dedc4d into main May 16, 2026
114 checks passed
@steipete
steipete deleted the fix/openai-pi-codex-auth-order-82521 branch May 16, 2026 14:26
@steipete

Copy link
Copy Markdown
Contributor Author

Landed via rebase onto current main and squash merge.

  • Gate: focused node scripts/run-vitest.mjs src/agents/openai-codex-routing.test.ts src/agents/pi-embedded-runner.e2e.test.ts src/agents/auth-profiles/order.test.ts src/cli/models-cli.test.ts src/auto-reply/reply/commands-status.test.ts plus full GitHub PR checks on a2b614a30b7503a5897e98e50f20f7cfc186eee5
  • Proof gate: maintainer proof: override label applied; Real behavior proof check passed
  • PR head: a2b614a30b7503a5897e98e50f20f7cfc186eee5
  • Merge commit: 9dedc4d95cfb8b5fee3019a073d19ac65fc11367

jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix: honor Codex auth order for OpenAI PI

* docs: add PR reference for OpenAI PI auth fix
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix: honor Codex auth order for OpenAI PI

* docs: add PR reference for OpenAI PI auth fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations maintainer Maintainer-authored PR proof: override Maintainer override for the external PR real behavior proof gate. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Documented openai/* + openai-codex:* auth.order cross-namespace routing does not engage Codex CLI fallback on v2026.5.16-beta.1 (post-#82117)

1 participant