Skip to content

fix(codex): preserve upstream error headers - #4635

Open
jroth1111 wants to merge 4 commits into
router-for-me:devfrom
jroth1111:agent/codex-error-headers
Open

fix(codex): preserve upstream error headers#4635
jroth1111 wants to merge 4 commits into
router-for-me:devfrom
jroth1111:agent/codex-error-headers

Conversation

@jroth1111

@jroth1111 jroth1111 commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Preserve upstream response headers on Codex HTTP errors and parse standard Retry-After values before returning the error to the auth/retry and API layers.

Fixes #4633.

Root cause

The Codex WebSocket error path already returns statusErrWithHeaders, but the HTTP execute, streaming bootstrap, and image endpoints called newCodexStatusErr(status, body). That constructor retained only the status and response body.

Consequently:

  • numeric or HTTP-date Retry-After headers could not influence retry scheduling;
  • safe correlation headers such as X-Request-Id were unavailable to optional downstream header passthrough;
  • HTTP and WebSocket Codex errors exposed inconsistent metadata.

Changes

  • Add newCodexStatusErrWithHeaders for Codex HTTP failures.
  • Preserve an immutable clone of the upstream headers.
  • Parse RFC-compatible Retry-After delta-seconds and HTTP-date values.
  • Keep body-derived usage reset metadata authoritative when both body and header hints exist.
  • Use the header-aware error at all Codex HTTP non-2xx call sites:
    • normal execute paths;
    • streaming bootstrap;
    • image generation/edit/variation paths.
  • Add constructor-level and real HTTP executor regression coverage for normal and streaming requests.

Downstream header exposure remains governed by the existing passthrough-headers setting and now passes through FilterUpstreamHeaders; Retry-After still participates in internal 408/5xx cooldown scheduling even when passthrough is disabled. Correlation headers are exposed only when passthrough is enabled.

Validation

  • go test ./internal/runtime/executor
  • go test ./sdk/cliproxy/auth ./sdk/api/handlers
  • go vet ./internal/runtime/executor ./sdk/cliproxy/auth ./sdk/api/handlers
  • go build ./...
  • go test ./...
  • git diff --check

All passed against current dev.

@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: 8bc6d6b320

ℹ️ 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 internal/runtime/executor/codex_executor_terminal.go
Comment thread internal/runtime/executor/codex_executor_terminal.go
@jroth1111
jroth1111 force-pushed the agent/codex-error-headers branch from 8bc6d6b to d530e39 Compare July 28, 2026 15:29

@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: d530e39a48

ℹ️ 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 sdk/cliproxy/auth/conductor_cooldown.go
Comment thread internal/runtime/executor/codex_executor_stream.go
Co-Authored-By: Claude <noreply@anthropic.com>

@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: 0dc8724902

ℹ️ 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 internal/runtime/executor/codex_executor_terminal.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant