Skip to content

feat: expose response headers on parsing and stream errors - #1285

Queued
dpiet-oai wants to merge 4 commits into
mainfrom
codex/java-690-response-headers
Queued

dpiet-oai wants to merge 4 commits into
mainfrom
codex/java-690-response-headers

Conversation

@dpiet-oai

@dpiet-oai dpiet-oai commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Preserve response headers, including x-request-id, when JSON body reads, JSON deserialization, SSE JSON parsing, or streaming reads fail. OpenAIInvalidDataException and OpenAIIoException now expose headers(): Optional<Headers>; failures without response context return an empty optional.

Existing constructors and Kotlin default-argument signatures remain unchanged. SSE parsing enriches the original exception, preserving its cause and stack trace. Consumer callback exceptions remain untouched, and headers are not added to exception messages. OpenAIServiceException.headers() and the base exception API remain unchanged.

Existing stream-close mocks now supply empty headers to satisfy the non-null HttpResponse.headers() contract.

The build also compiles Headers.kt in the runtime shard alongside the exceptions. No published artifact boundaries or generated-owned files change.

Validation:

  • Kotlin formatting and git diff --check pass.
  • Java and Kotlin consumers compiled against the baseline constructors run successfully against the updated exception classes without recompilation.
  • 49 handler and response-close tests pass via JUnit against the compiled SDK classes and Jackson 2.14, including body-read timeouts, stream-read timeouts, malformed JSON, SSE syntax/type errors, missing response context, and consumer exceptions.
  • The standard local Gradle test run was interrupted by a lost compiler daemon, then a shared cache lock held by another process. Hosted CI passes, including the SDK suite, Jackson/API compatibility, Java 8/25 runtime checks, and ProGuard/R8. One unrelated WebSocket send-queue failure passed on rerun without code changes.

Builds on the approach in #922 and adds SSE parsing coverage and the required compilation-shard adjustment.

Fixes #690.

@dpiet-oai dpiet-oai changed the title fix: retain response headers on parsing and stream failures feat: expose response headers on parsing and stream errors Oct 27, 2026

@markstuart-oai markstuart-oai 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.

Approved. JSON read failures, SSE decoding failures and streaming I/O failures retain the response headers through an explicit accessor. The existing constructor parameters and default arguments remain intact. SSE decoding enriches the original exception, while consumer exceptions and stream-close behavior stay unchanged. The private header field is not added to default exception messages.

Moving Headers into the runtime compilation shard satisfies the new dependency without changing the published artifact boundary. The changed files are outside the generated-file inventory. The focused tests cover missing response context, parsing and read failures, and consumer exception identity. No actionable findings after source review and an independent pass.

Current-head hosted checks passed, including API compatibility, Jackson compatibility, Java 8/25, the SDK suite, ProGuard and R8. No candidate code or tests ran locally. The reported baseline-compiled constructor tests were not independently rerun; this review makes no claim about Java object-serialization compatibility.

Reviewed head: 04b660ae40057ddb95d29efbda43935ab5479738; base: 4311dba26c34f5d813105f94f2a76ba9073561dc.

@dpiet-oai
dpiet-oai marked this pull request as ready for review October 27, 2026 18:42
@dpiet-oai
dpiet-oai requested a review from a team as a code owner October 27, 2026 18:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T20:06:21.719689Z 4a30e26 New commits
🔒 Security Review ✅ Completed 2026-10-27T20:06:58.581145Z 4a30e26 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbeckwith-oai jbeckwith-oai 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.

Approved after static review of all eight changed files and relevant streaming, SSE, header and compilation-shard code, with an independent second review. No actionable findings. Existing constructor and Kotlin default-argument signatures remain intact; response headers are retained on parsing/read failures without changing consumer exceptions or default exception messages. Hosted CI has 13 passed checks; OkTest remains in progress. No local code or tests were run.

Refresh review: approval retained at ffef365 after merging main 28dce99. All eight PR patches and resulting file blobs are identical to the prior review. Core production/test sources and compilation-shard sources are unchanged by the merge; Headers remains in the correct runtime shard. Independent second review found no actionable issues. Fresh hosted checks are in progress; the prior OkTest reporting failure is not evidence of this new commit passing. No candidate code or tests ran locally. Existing approval updated without a duplicate review.

Refresh at 4a30e26: retained approval after static review and an independent second review. This merges main e1bd0d3 containing the separately reviewed token-response change from PR #1289. All eight PR patches and resulting file blobs remain identical; incoming auth changes do not conflict with header retention or compilation shards. Fresh hosted CI and OkTest are still running. No local code or tests ran.

@dpiet-oai
dpiet-oai added this pull request to the merge queue Oct 27, 2026
Any commits made after this event will not be merged.

This branch has not been deployed

No deployments
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.

Make request/response info available in OpenAIException when available

3 participants