Skip to content

fix(client): stop retries when server delay exceeds maximum — SDK-235 - #609

Open
markstuart-oai wants to merge 15 commits into
mainfrom
markstuart/sdk-235-retry-after
Open

fix(client): stop retries when server delay exceeds maximum — SDK-235#609
markstuart-oai wants to merge 15 commits into
mainfrom
markstuart/sdk-235-retry-after

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Valid server retry delays above max_retry_delay were shortened, allowing requests before the server’s minimum. Authentication replay could also bypass finite API or issuer hints.

Preserve the server minimum across normal retries, credential refresh, and cached-token fallback. Return the original error when that minimum exceeds the cap, including numeric overflow. Shared-refresh participants retain their strongest observed issuer minimum without delaying independent callers. A short request deadline takes precedence over refusing an excessive 401 replay, and delayed authentication replays emit the standard retry callback and log event.

Validation on the final bytes: full suite 1,659 tests / 16,025 assertions (one skip); Bedrock 44 tests / 390 assertions (one opt-in live-test skip); focused authentication regressions, formatting, RuboCop, Sorbet, and RBS passed. Two consecutive independent adversarial-review rounds were clean. Signed commit 22b67c6ee236a4f21921941a0b6f2032b6dbad3d passes the trusted-current-main custom-code budget at 3,434 / 4,000 lines.

The shipped RBI/RBS signatures include the optional retry_state keyword. Retained stronger refusals take effect before another notification or wait; delayed 401 callbacks report the reachable attempt limit. Early test setup failures preserve their original errors during cleanup. The focused suite passes 81 tests / 1,647 assertions, and all 1,279 RBS checks pass.

@markstuart-oai
markstuart-oai requested a review from a team as a code owner September 4, 2026 05:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 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-09-04T23:15:23.060363Z b45cbc1 New commits
🔒 Security Review Completed 2026-09-04T23:18:07.982375Z b45cbc1 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 Sep 4, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

237/237 SDK tests passed in 10.307s for Ruby SDK PR #609.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 190ms
tests/chat-completions-create.test.ts ✅ Passed 259ms
tests/chat-completions-stream.test.ts ✅ Passed 137ms
tests/files-content-binary.test.ts ✅ Passed 132ms
tests/files-create-multipart.test.ts ✅ Passed 137ms
tests/files-list-pagination.test.ts ✅ Passed 170ms
tests/initialize-config.test.ts ✅ Passed 195ms
tests/instance-isolation.test.ts ✅ Passed 259ms
tests/models-list.test.ts ✅ Passed 242ms
tests/responses-background-lifecycle.test.ts ✅ Passed 269ms
tests/responses-body-method-errors.test.ts ✅ Passed 378ms
tests/responses-cancel-timeout.test.ts ✅ Passed 291ms
tests/responses-cancel.test.ts ✅ Passed 206ms
tests/responses-compact-retries.test.ts ✅ Passed 288ms
tests/responses-compact.test.ts ✅ Passed 300ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 133ms
tests/responses-create-advanced.test.ts ✅ Passed 197ms
tests/responses-create-disconnect.test.ts ✅ Passed 993ms
tests/responses-create-errors.test.ts ✅ Passed 199ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 162ms
tests/responses-create-retries.test.ts ✅ Passed 360ms
tests/responses-create-stream-failures.test.ts ✅ Passed 173ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 242ms
tests/responses-create-stream-wire.test.ts ✅ Passed 2.521s
tests/responses-create-stream.test.ts ✅ Passed 180ms
tests/responses-create-terminal-states.test.ts ✅ Passed 290ms
tests/responses-create-timeout.test.ts ✅ Passed 296ms
tests/responses-create.test.ts ✅ Passed 296ms
tests/responses-delete.test.ts ✅ Passed 239ms
tests/responses-input-items-errors.test.ts ✅ Passed 195ms
tests/responses-input-items-list.test.ts ✅ Passed 224ms
tests/responses-input-items-options.test.ts ✅ Passed 177ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 264ms
tests/responses-input-tokens-count.test.ts ✅ Passed 229ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.141s
tests/responses-not-found-errors.test.ts ✅ Passed 348ms
tests/responses-parse.test.ts ✅ Passed 169ms
tests/responses-retrieve-retries.test.ts ✅ Passed 300ms
tests/responses-retrieve.test.ts ✅ Passed 250ms
tests/responses-stored-method-errors.test.ts ✅ Passed 881ms
tests/retry-behavior.test.ts ✅ Passed 3.389s
tests/sdk-error-shape.test.ts ✅ Passed 339ms

View OkTest run #33928619483

SDK merge (95ce826abac7) · head (b45cbc121381) · base (06e2c91dc349) · OkTest (2b1bdfd25e98)

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

47 mixed files remain; 1 existing customization changed.

Compared 1560da0107303b65e696ff7c. Generated baselines verified.

File Result Current custom patch
lib/openai/client.rb Existing customization changed +580 / −20
46 existing customizations unchanged
  • lib/openai.rb
  • lib/openai/models/chat/chat_completion_message.rb
  • lib/openai/models/chat/chat_completion_message_function_tool_call.rb
  • lib/openai/models/chat/completion_create_params.rb
  • lib/openai/models/response_format_json_schema.rb
  • lib/openai/models/responses/function_tool.rb
  • lib/openai/models/responses/response.rb
  • lib/openai/models/responses/response_create_params.rb
  • lib/openai/models/responses/response_format_text_config.rb
  • lib/openai/models/responses/response_format_text_json_schema_config.rb
  • lib/openai/models/responses/response_function_tool_call.rb
  • lib/openai/models/responses/response_function_web_search.rb
  • lib/openai/models/responses/response_output_text.rb
  • lib/openai/models/responses/tool.rb
  • lib/openai/resources/beta/threads.rb
  • lib/openai/resources/chat/completions.rb
  • lib/openai/resources/files.rb
  • lib/openai/resources/responses.rb
  • lib/openai/resources/vector_stores/file_batches.rb
  • lib/openai/resources/vector_stores/files.rb
  • lib/openai/resources/webhooks.rb
  • rbi/openai/client.rbi
  • rbi/openai/models/chat/chat_completion_message.rbi
  • rbi/openai/models/chat/chat_completion_message_function_tool_call.rbi
  • rbi/openai/models/chat/completion_create_params.rbi
  • rbi/openai/models/response_format_json_schema.rbi
  • rbi/openai/models/responses/response.rbi
  • rbi/openai/models/responses/response_create_params.rbi
  • rbi/openai/models/responses/response_function_tool_call.rbi
  • rbi/openai/models/responses/response_function_web_search.rbi
  • rbi/openai/models/responses/response_output_text.rbi
  • rbi/openai/resources/chat/completions.rbi
  • rbi/openai/resources/files.rbi
  • rbi/openai/resources/responses.rbi
  • rbi/openai/resources/vector_stores/file_batches.rbi
  • rbi/openai/resources/vector_stores/files.rbi
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py
  • sig/openai/client.rbs

6 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 33847219377 --repo openai/openai-ruby \
  --name castiron-custom-code-33847219377-1 --dir /tmp/castiron-custom-code-33847219377-1
git apply --stat /tmp/castiron-custom-code-33847219377-1/custom-code.patch
cat /tmp/castiron-custom-code-33847219377-1/custom-code.patch

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

git fetch --no-tags origin 1560da01073061cc0a0dadc853f7dbc6e688a4d4 3b65e696ff7cc0dbadc8c54eb0bb67d9696bf3eb
python3 scripts/castiron/custom_code_report.py report \
  --base 1560da01073061cc0a0dadc853f7dbc6e688a4d4 \
  --head 3b65e696ff7cc0dbadc8c54eb0bb67d9696bf3eb --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-3b65e696ff7c
cat /tmp/castiron-custom-code-3b65e696ff7c/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

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

ℹ️ 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 lib/openai/internal/transport/base_client.rb

@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: 61b0327a79

ℹ️ 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 lib/openai/internal/transport/base_client.rb Outdated

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

Blocking: lib/openai/internal/transport/base_client.rb:518 still treats positive numeric overflow as an invalid hint. Ruby parses both Retry-After: 1e999 and a standards-valid 400-digit delay-seconds value as Infinity; the finite? filter drops them and falls back to short jittered backoff, so the client retries earlier than the server minimum. Preserve positive numeric overflow as an excessive delay (while keeping literal infinity and negative overflow invalid), and cover both Retry-After and Retry-After-Ms plus the authentication replay path. Reviewed exact head 3b65e69.

@markstuart-oai

Copy link
Copy Markdown
Contributor Author

Fixed positive numeric overflow for both Retry-After and Retry-After-Ms, including legacy and X.509 authentication paths. An overflowing positive numeric value now exceeds the existing cap and returns the original error; it cannot select a short fallback. Existing numeric grammar and header precedence are preserved.

The same pass closes two related authentication paths: finite 401 minima are honored before replay, and issuer minima survive cached-token fallback through subsequent API retries. Timing is captured before response cleanup and remains local to the logical request.

The public regressions fail before the fixes and pass afterward, including concurrent callers whose shared issuer response body fails. Published in f068fa7c76445056853060816b797567ada2f607. Final native validation passes 1,633 tests (15,544 assertions, one existing skip), Bedrock 44 tests (390 assertions, one opt-in live skip), focused regression/polling tests, formatting and type checks. Two consecutive independent reviews are clean; trusted-main custom-code budget passes at 3,416 / 4,000.

Comment thread test/openai/auth/x509_proactive_refresh_test.rb
Comment thread test/openai/auth/x509_proactive_refresh_test.rb

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

The current head closes the important overflow case rather than merely clamping it: positive numeric overflow remains an excessive server minimum, while literal/negative invalid values still fall back through the normal policy. Capturing issuer retry timing before response cleanup is also necessary for workload-identity replay, otherwise authentication can silently shorten the same minimum. The deadline and cached-token precedence look appropriately preserved.

@markstuart-oai markstuart-oai changed the title fix(client): stop retries when server delay exceeds maximum fix(client): stop retries when server delay exceeds maximum — SDK-235 Sep 4, 2026
Comment thread lib/openai/client.rb Fixed
Comment thread lib/openai/client.rb Fixed
Comment thread test/openai/auth/x509_proactive_refresh_test.rb Fixed
Comment thread test/openai/auth/x509_proactive_refresh_test.rb Fixed
Comment thread test/openai/auth/x509_proactive_refresh_test.rb Fixed
Comment thread test/openai/auth/x509_proactive_refresh_test.rb Fixed

@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: 6449ab3db7

ℹ️ 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 lib/openai/client.rb Outdated
Comment thread lib/openai/client.rb Outdated

@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: 22b67c6ee2

ℹ️ 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 lib/openai/client.rb
Comment thread lib/openai/client.rb
Comment thread lib/openai/client.rb

@HAYDEN-OAI HAYDEN-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 all 18 changed files at b45cbc1 against 06e2c91, including the prior review discussions. Positive numeric overflow now remains an excessive minimum for both retry headers; invalid literal and negative values retain fallback behavior. Authentication replay, issuer minima across cached/shared refresh, deadline precedence, retry notifications, and RBI/RBS signatures are consistent with the added regressions. No new actionable findings. Static review only; Ruby is unavailable in this environment, so I did not run tests.

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.

4 participants