Skip to content

fix(auth): recover after synchronous refresh startup failure - #1246

Merged
dpiet-oai merged 1 commit into
mainfrom
castiron/promotions/pr-194
Oct 20, 2026
Merged

dpiet-oai merged 1 commit into
mainfrom
castiron/promotions/pr-194

Conversation

@dpiet-oai

Copy link
Copy Markdown
Contributor

When SubjectTokenProvider.getTokenAsync() throws before returning a future, workload-identity authentication can leave a refresh pending indefinitely. Settle the failed refresh and clear its shared state so waiting callers receive the failure and subsequent calls can refresh successfully. Background callers continue to receive their still-valid cached token.

Addresses #852. Adapted from #877.

The change is limited to WorkloadIdentityAuth and regression tests for repeated failures, foreground and background recovery, cached-token use during a pending refresh, and three concurrent waiters. Public APIs and token-expiry behavior remain unchanged.

Validation before promotion:

  • 24 focused authentication and HTTP-wrapper tests passed, including six regression cases.
  • All five synchronous-failure cases failed with the unfixed implementation and passed with the fix; the asynchronous-failure control passed in both runs.
  • Formatting and CI passed on the reviewed patch.
./scripts/gradle :openai-java-core:test \
  --tests 'com.openai.auth.WorkloadIdentityAuth*' \
  --tests 'com.openai.core.http.WorkloadIdentityHttpClientTest'

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

chatgpt-codex-connector Bot commented Oct 20, 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-20T20:06:38.505859Z e64e234 New commits
🔒 Security Review ✅ Completed 2026-10-20T20:07:25.007981Z e64e234 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.

@openai-sdks

openai-sdks Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

OkTest Summary

✅ 236/236 SDK tests passed in 16.21s for Java SDK PR #1246.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 275ms
tests/chat-completions-create.test.ts ✅ Passed 661ms
tests/chat-completions-stream.test.ts ✅ Passed 950ms
tests/files-content-binary.test.ts ✅ Passed 386ms
tests/files-create-multipart.test.ts ✅ Passed 467ms
tests/files-list-pagination.test.ts ✅ Passed 301ms
tests/initialize-config.test.ts ✅ Passed 267ms
tests/instance-isolation.test.ts ✅ Passed 206ms
tests/models-list.test.ts ✅ Passed 206ms
tests/responses-background-lifecycle.test.ts ✅ Passed 343ms
tests/responses-body-method-errors.test.ts ✅ Passed 628ms
tests/responses-cancel-timeout.test.ts ✅ Passed 271ms
tests/responses-cancel.test.ts ✅ Passed 281ms
tests/responses-compact-retries.test.ts ✅ Passed 413ms
tests/responses-compact.test.ts ✅ Passed 367ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 379ms
tests/responses-create-advanced.test.ts ✅ Passed 1.696s
tests/responses-create-disconnect.test.ts ✅ Passed 1.102s
tests/responses-create-errors.test.ts ✅ Passed 375ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 396ms
tests/responses-create-retries.test.ts ✅ Passed 310ms
tests/responses-create-stream-failures.test.ts ✅ Passed 295ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 238ms
tests/responses-create-stream-wire.test.ts ✅ Passed 5.522s
tests/responses-create-stream.test.ts ✅ Passed 474ms
tests/responses-create-terminal-states.test.ts ✅ Passed 467ms
tests/responses-create-timeout.test.ts ✅ Passed 243ms
tests/responses-create.test.ts ✅ Passed 259ms
tests/responses-delete.test.ts ✅ Passed 308ms
tests/responses-input-items-errors.test.ts ✅ Passed 327ms
tests/responses-input-items-list.test.ts ✅ Passed 383ms
tests/responses-input-items-options.test.ts ✅ Passed 240ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 297ms
tests/responses-input-tokens-count.test.ts ✅ Passed 392ms
tests/responses-malformed-inputs.test.ts ✅ Passed 4.39s
tests/responses-not-found-errors.test.ts ✅ Passed 479ms
tests/responses-parse.test.ts ✅ Passed 794ms
tests/responses-retrieve-retries.test.ts ✅ Passed 1.005s
tests/responses-retrieve.test.ts ✅ Passed 276ms
tests/responses-stored-method-errors.test.ts ✅ Passed 943ms
tests/retry-behavior.test.ts ✅ Passed 3.357s
tests/sdk-error-shape.test.ts ✅ Passed 451ms

View OkTest run #39488873657

SDK merge (98037fe583a3) · head (e64e234cca53) · base (1e54d93d6d1c) · OkTest (29c8150fa2c4)

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Castiron custom code

Evaluated main: 1e54d93d6d1c68bbd8529b0327aa06bdea0abdb9.

Trusted main policy: 1e54d93d6d1c68bbd8529b0327aa06bdea0abdb9.

✅ No new custom-code files detected.

97 mixed files remain; 0 existing customizations changed.

Compared 1e54d93d6d1c → e64e234cca53. Generated baselines verified.

97 existing customizations unchanged
  • openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/models/admin/organization/projects/apikeys/ApiKeyUpdateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/audio/AudioResponseFormat.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/agents/environments/EnvironmentCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/agents/vaults/credentials/CredentialAuth.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/agents/vaults/credentials/CredentialAuthCreateParam.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/agents/vaults/credentials/CredentialAuthRotateParam.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponse.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponseError.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponseInjectEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponseInjectFailedEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponseStreamEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponseToolSearchOutputItemParam.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponsesServerEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionMessageFunctionToolCall.kt
  • openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionToolMessageParam.kt
  • openai-java-core/src/main/kotlin/com/openai/models/conversations/ConversationCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ItemCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/embeddings/Embedding.kt
  • openai-java-core/src/main/kotlin/com/openai/models/embeddings/EmbeddingCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/live/ResponseItemCreateEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/realtime/RealtimeResponseStatus.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/Response.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseError.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionToolCall.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseStreamEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseTextConfig.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseToolSearchOutputItemParam.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponsesServerEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/VectorStoreFileBatch.kt
  • openai-java-core/src/main/kotlin/com/openai/models/videos/Video.kt
  • openai-java-core/src/main/kotlin/com/openai/models/videos/VideoCreateError.kt
  • openai-java-core/src/main/kotlin/com/openai/models/webhooks/UnwrapWebhookEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/webhooks/WebhookEndpointWithSecret.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/BetaServiceAsync.kt

57 more in the full report.

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 39488998613 --repo openai/openai-java \
  --name castiron-custom-code-39488998613-1 --dir /tmp/castiron-custom-code-39488998613-1
git apply --stat /tmp/castiron-custom-code-39488998613-1/custom-code.patch
cat /tmp/castiron-custom-code-39488998613-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin 1e54d93d6d1c68bbd8529b0327aa06bdea0abdb9 e64e234cca534051c2e26cd29cf3a33f571e8380
python3 scripts/castiron/custom_code_report.py report \
  --base 1e54d93d6d1c68bbd8529b0327aa06bdea0abdb9 \
  --head e64e234cca534051c2e26cd29cf3a33f571e8380 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-e64e234cca53
cat /tmp/castiron-custom-code-e64e234cca53/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@dpiet-oai
dpiet-oai force-pushed the castiron/promotions/pr-194 branch from 410c2a5 to b0cbd9c Compare October 20, 2026 15:07

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

Reviewed b0cbd9c. No actionable findings. The shared refresh is settled and cleared when the provider throws synchronously, concurrent waiters receive the failure, subsequent calls can retry, and background callers retain a valid cached token. Checked regression coverage and existing async completion paths. Hosted SDK CI passed; separate OkTest run 39445509465 is still running. Static review only; no local tests executed.

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

Reviewed b0cbd9c826bfabdc15733e46670de2e74fc21d50. No actionable findings.

The shared refresh helper clears the pending refresh and settles waiting callers when a provider throws synchronously. Background failures preserve the valid cached token, and subsequent calls can refresh again. The regression tests cover repeated failure, recovery, and concurrent waiters without changing token expiry or exchange behavior.

Validation: source review and exact-head hosted CI. The observed build, SDK tests, compatibility checks and lint passed. I did not run the candidate code locally; the focused test counts in the description are author-reported.

@dpiet-oai
dpiet-oai force-pushed the castiron/promotions/pr-194 branch from b0cbd9c to a8fd55b Compare October 20, 2026 19:20
@dpiet-oai
dpiet-oai enabled auto-merge October 20, 2026 19:20
@dpiet-oai

Copy link
Copy Markdown
Contributor Author

Resolved the .castiron.stats.yml conflict by refreshing from current main and rerunning promotion to rebuild the public snapshot pointer. The authentication implementation and regression tests are unchanged from the approved patch.

All 24 focused authentication and HTTP-wrapper tests passed on the refreshed branch. Hosted CI is running on a8fd55b7c44d03caab4df6d5689dd32e9a94cf8b; auto-merge is enabled through the repository's merge queue once required checks pass.

@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 at a8fd55b. Re-reviewed the refreshed head. Authentication implementation and regression tests are byte-identical to the previously approved change; the additional changes come from upstream and the regenerated snapshot pointer.

Coordinator and independent static reviews found no actionable issues. Hosted repository checks passed or were intentionally skipped. External OkTest is still running and will be followed up. No candidate code or tests were run locally.

@dpiet-oai
dpiet-oai added this pull request to the merge queue Oct 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 20, 2026
@dpiet-oai
dpiet-oai added this pull request to the merge queue Oct 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 20, 2026
Castiron-Internal-PR: openai/openai-java-internal#194
Castiron-Source-SHA: 6e1f7349e35cac87c326879431ceec55b7f87508
Castiron-Public-Base-SHA: 1e54d93
@dpiet-oai
dpiet-oai force-pushed the castiron/promotions/pr-194 branch from a8fd55b to e64e234 Compare October 20, 2026 20:04
@dpiet-oai
dpiet-oai enabled auto-merge October 20, 2026 20:05

@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 at e64e234. Authentication code/tests are unchanged; incremental differences incorporate upstream and regenerated snapshot metadata.

Coordinator and independent static reviews found no actionable issues. Current-head build and external OkTest remain pending; follow-up retained. No candidate code or tests ran locally.

@dpiet-oai
dpiet-oai added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit efe5b95 Oct 20, 2026
17 checks passed
@openai-sdks openai-sdks Bot mentioned this pull request Oct 20, 2026
@dpiet-oai
dpiet-oai deleted the castiron/promotions/pr-194 branch October 20, 2026 22:02
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.

3 participants