Skip to content

[codex] fix OpenAI Codex OAuth transport#75111

Merged
steipete merged 3 commits into
openclaw:mainfrom
keshavbotagent:codex/fix-openai-codex-oauth-transport
Apr 30, 2026
Merged

[codex] fix OpenAI Codex OAuth transport#75111
steipete merged 3 commits into
openclaw:mainfrom
keshavbotagent:codex/fix-openai-codex-oauth-transport

Conversation

@keshavbotagent

@keshavbotagent keshavbotagent commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve the embedded runner OAuth/auth-injection stream when adding OpenAI attribution for openai-codex traffic
  • sanitize native ChatGPT Codex Responses payloads by removing fields rejected by that backend while preserving custom/proxy Codex-compatible routes
  • persist Codex OAuth account metadata from the access-token identity so refreshed profiles keep account/plan context

Root Cause

Commit d1b2d81 switched openai-codex traffic through createOpenAIResponsesTransportStreamFn() inside the attribution wrapper. In the embedded runner path that created a fresh transport and bypassed the existing auth-injection wrapper, so the OAuth bearer was not passed into the Codex Responses request and the backend returned 401 status code (no body).

Fix

  • only create a Codex native transport in the attribution wrapper when no wrapped stream has already been provided
  • keep already-wrapped Codex streams intact so runtime OAuth injection reaches the transport
  • strip unsupported request fields only for the native ChatGPT Codex backend before calling client.responses.create
  • preserve caller controls such as max_output_tokens, temperature, and metadata for custom/proxy Codex-compatible endpoints
  • carry accountId and chatgptPlanType through Codex OAuth login/refresh profile storage

Validation

  • node scripts/test-projects.mjs src/agents/pi-embedded-runner/openai-stream-wrappers.test.ts src/agents/pi-embedded-runner/stream-resolution.test.ts src/agents/openai-transport-stream.test.ts extensions/openai/openai-codex-provider.test.ts extensions/openai/openai-codex-auth-identity.test.ts
  • pnpm build
  • local smoke: openclaw agent --agent main --message "Reply with exactly: OK" --json --timeout 180 returned OK with provider openai-codex and model gpt-5.5

@keshavbotagent keshavbotagent marked this pull request as ready for review April 30, 2026 14:26
@keshavbotagent keshavbotagent requested a review from a team as a code owner April 30, 2026 14:26
@clawsweeper

clawsweeper Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes:

The PR updates OpenAI Codex transport wrapping, native ChatGPT Codex Responses payload sanitization, and Codex OAuth credential metadata persistence with regression tests.

Maintainer follow-up before merge:

This is an active implementation PR that appears narrowly targeted; the remaining action is maintainer review, CI completion, and optional live OAuth validation rather than an automated replacement fix PR.

Security review:

Security review cleared: The diff touches OAuth metadata and request shaping but adds no dependency, workflow, script, package-resolution, secret-broadening, or new code-execution surface.

Review details

Best possible solution:

Land a targeted provider/transport fix after maintainer review and green relevant checks, keeping the OAuth injection wrapper intact for embedded openai-codex runs while stripping only fields rejected by the native ChatGPT Codex backend.

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

Yes. The high-confidence static reproduction path is current main resolving a boundary-aware OAuth-injecting Codex stream, then the attribution wrapper replacing that stream with a fresh Responses transport before the request is sent.

Is this the best way to solve the issue?

Yes. The PR appears to be the narrowest maintainable fix because it preserves an existing wrapped stream, creates a native Codex transport only for the no-wrapper case, and limits payload sanitization to recognized native ChatGPT Codex URLs.

Acceptance criteria:

  • node scripts/test-projects.mjs src/agents/pi-embedded-runner/openai-stream-wrappers.test.ts src/agents/pi-embedded-runner/stream-resolution.test.ts src/agents/openai-transport-stream.test.ts extensions/openai/openai-codex-provider.test.ts extensions/openai/openai-codex-auth-identity.test.ts
  • pnpm build
  • Optional live smoke with an OpenAI Codex OAuth profile: openclaw agent --agent main --message "Reply with exactly: OK" --json --timeout 180

What I checked:

  • Current main bypasses the wrapped Codex stream: On current main, openai-codex attribution always selects a native Responses transport instead of the supplied underlying stream, matching the reported OAuth wrapper bypass path. (src/agents/pi-embedded-runner/openai-stream-wrappers.ts:501, 46888f5afbe9)
  • Current main relies on a wrapped boundary-aware stream for OAuth: The embedded runner wraps boundary-aware transports so resolved runtime auth reaches options.apiKey; the comment explicitly calls out openai-codex/gpt-5.5 failing with missing bearer auth when that wrap is absent. (src/agents/pi-embedded-runner/stream-resolution.ts:107, 46888f5afbe9)
  • PR preserves existing wrapped streams: The PR diff changes the attribution wrapper to create the native Codex transport only when the base stream is absent or streamSimple, and adds a regression test that the OAuth apiKey reaches the existing stream. (src/agents/pi-embedded-runner/openai-stream-wrappers.ts:498, 8f6606abbdef)
  • Prior review concern was addressed: The current PR diff scopes unsupported-parameter stripping to recognized chatgpt.com/backend-api Codex URLs and includes tests preserving custom/proxy Codex-compatible params after payload hooks. (src/agents/openai-transport-stream.ts:876, 8f6606abbdef)
  • Credential metadata matches an existing consumer: The Codex app-server auth bridge already reads accountId and chatgptPlanType from auth profile credentials, so persisting those non-secret JWT-derived fields fits the current auth handoff contract. (extensions/codex/src/app-server/auth-bridge.ts:260, 46888f5afbe9)
  • Latest head checks are not all complete: Public check-runs for head 8f6606abbdef showed many successes, but build, lint, type, selected fast shards, and several security/quality checks were still queued or in progress during review. (8f6606abbdef)

Likely related people:

  • steipete: GitHub commit history shows steipete authored the attribution change named by the PR root cause and most recent OpenAI Codex provider/auth route changes. (role: introduced behavior and recent OpenAI/Codex maintainer; confidence: high; commits: d1b2d81752b8, 3766bbb6745f, e6cd90e3fd9c; files: src/agents/pi-embedded-runner/openai-stream-wrappers.ts, src/agents/openai-transport-stream.ts, extensions/openai/openai-codex-provider.ts)
  • @openclaw/openclaw-secops: CODEOWNERS routes src/agents auth-profile and auth-related surfaces to the secops owner group, and this PR changes OAuth credential metadata storage. (role: required adjacent reviewer; confidence: medium; files: .github/CODEOWNERS, src/agents/auth-profiles/types.ts, extensions/openai/openai-codex-provider.ts)
  • pashpashpash: Recent history for the Codex app-server auth bridge includes several pashpashpash commits on fallback auth and effective env handoff, which is adjacent to the account metadata consumed by that bridge. (role: adjacent Codex auth maintainer; confidence: medium; commits: a412603bad53, 401ae38f13a3, 20ff49f7c82d; files: extensions/codex/src/app-server/auth-bridge.ts)

Remaining risk / open question:

  • Latest PR head still needs completion of queued/in-progress CI before merge.
  • The author-reported live OAuth smoke is useful, but this read-only review did not independently run a live OpenAI Codex OAuth request.

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

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

Copy link
Copy Markdown

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: debfb6d8f0

ℹ️ 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 thread src/agents/openai-transport-stream.ts Outdated
@keshavbotagent keshavbotagent force-pushed the codex/fix-openai-codex-oauth-transport branch from cdc6c35 to b70bd31 Compare April 30, 2026 14:54
@steipete steipete force-pushed the codex/fix-openai-codex-oauth-transport branch from 8f6606a to e764439 Compare April 30, 2026 16:55
@steipete steipete merged commit 388019f into openclaw:main Apr 30, 2026
98 checks passed
steipete pushed a commit that referenced this pull request Apr 30, 2026
Preserve the existing wrapped OpenAI Codex stream so PI OAuth bearer injection reaches ChatGPT/Codex Responses, and scope native Codex payload sanitization to the ChatGPT backend.\n\nThanks @keshavbotagent.
lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
Preserve the existing wrapped OpenAI Codex stream so PI OAuth bearer injection reaches ChatGPT/Codex Responses, and scope native Codex payload sanitization to the ChatGPT backend.\n\nThanks @keshavbotagent.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Preserve the existing wrapped OpenAI Codex stream so PI OAuth bearer injection reaches ChatGPT/Codex Responses, and scope native Codex payload sanitization to the ChatGPT backend.\n\nThanks @keshavbotagent.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Preserve the existing wrapped OpenAI Codex stream so PI OAuth bearer injection reaches ChatGPT/Codex Responses, and scope native Codex payload sanitization to the ChatGPT backend.\n\nThanks @keshavbotagent.
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
Preserve the existing wrapped OpenAI Codex stream so PI OAuth bearer injection reaches ChatGPT/Codex Responses, and scope native Codex payload sanitization to the ChatGPT backend.\n\nThanks @keshavbotagent.
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Preserve the existing wrapped OpenAI Codex stream so PI OAuth bearer injection reaches ChatGPT/Codex Responses, and scope native Codex payload sanitization to the ChatGPT backend.\n\nThanks @keshavbotagent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants