Commit 7fa7946
authored
fix(client): honor Retry-After delays up to two minutes (#3555)
## Summary
- honor positive, finite `Retry-After` delays up to 120 seconds
- treat longer server-directed delays as non-retryable instead of
substituting short exponential backoff
- keep exponential backoff for zero, negative, non-finite, missing, or
malformed values
- cover sync and async clients with numeric seconds, milliseconds, and
HTTP-date boundaries
## Motivation
The Python SDK currently ignores `Retry-After` values above 60 seconds
and falls back to a much shorter exponential delay. Historical
reset-header data shows that common minute-scale waits can land just
above 60 seconds, while extending the ceiling beyond two minutes adds
little coverage before waits jump to hours or days.
## Developer impact
Clients with automatic retries enabled will honor server-directed delays
through two minutes. If `Retry-After` exceeds two minutes, the SDK
surfaces the API error instead of blocking a synchronous worker for an
extended period or retrying before the requested time. Retry attempts
remain bounded by `max_retries`.
## Validation
- `.venv/bin/ruff format --check src/openai/_constants.py
src/openai/_base_client.py tests/test_client.py`
- `.venv/bin/ruff check src/openai/_constants.py
src/openai/_base_client.py tests/test_client.py`
- `.venv/bin/pytest -q tests/test_client.py` (198 passed, 2 skipped)1 parent 3844843 commit 7fa7946
3 files changed
Lines changed: 111 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| 90 | + | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| |||
781 | 783 | | |
782 | 784 | | |
783 | 785 | | |
784 | | - | |
785 | | - | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
786 | 793 | | |
787 | 794 | | |
788 | | - | |
789 | 795 | | |
790 | 796 | | |
791 | 797 | | |
| |||
796 | 802 | | |
797 | 803 | | |
798 | 804 | | |
799 | | - | |
| 805 | + | |
800 | 806 | | |
801 | | - | |
| 807 | + | |
802 | 808 | | |
803 | 809 | | |
804 | 810 | | |
| |||
813 | 819 | | |
814 | 820 | | |
815 | 821 | | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
816 | 831 | | |
817 | 832 | | |
818 | 833 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1083 | 1083 | | |
1084 | 1084 | | |
1085 | 1085 | | |
1086 | | - | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1087 | 1089 | | |
1088 | 1090 | | |
1089 | 1091 | | |
1090 | 1092 | | |
1091 | | - | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
1092 | 1096 | | |
| 1097 | + | |
| 1098 | + | |
1093 | 1099 | | |
| 1100 | + | |
1094 | 1101 | | |
1095 | 1102 | | |
1096 | 1103 | | |
| |||
1106 | 1113 | | |
1107 | 1114 | | |
1108 | 1115 | | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
1109 | 1158 | | |
1110 | 1159 | | |
1111 | 1160 | | |
| |||
2339 | 2388 | | |
2340 | 2389 | | |
2341 | 2390 | | |
2342 | | - | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
2343 | 2394 | | |
2344 | 2395 | | |
2345 | 2396 | | |
2346 | 2397 | | |
2347 | | - | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
2348 | 2401 | | |
| 2402 | + | |
| 2403 | + | |
2349 | 2404 | | |
| 2405 | + | |
2350 | 2406 | | |
2351 | 2407 | | |
2352 | 2408 | | |
| |||
2362 | 2418 | | |
2363 | 2419 | | |
2364 | 2420 | | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
2365 | 2451 | | |
2366 | 2452 | | |
2367 | 2453 | | |
| |||
0 commit comments