Commit fd0663e
fix: correct deadline logic in _wait_for_finish (#749)
## Summary
Fixes two bugs in `ResourceClient._wait_for_finish` /
`ResourceClientAsync._wait_for_finish`:
1. **`not_found_deadline` anchored at function entry.** The 3-second
"job not found" grace window was computed once at entry and never reset.
A single transient 404 (e.g. replica lag) during a long poll could
terminate the wait and return `None` even though the job was live. The
deadline is now lazy — it starts on the first observed 404 and resets
after any successful response, so each run of 404s gets its own fresh
window.
2. **User `wait_duration` not checked on 404.** When `wait_duration` was
shorter than `DEFAULT_WAIT_WHEN_JOB_NOT_EXIST` (3s) and the API returned
persistent 404s, the loop could overrun the documented contract by up to
~3s. The 404 branch now checks the user deadline first.
Applied symmetrically to the sync and async mirrors.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1dd70b8 commit fd0663e
1 file changed
Lines changed: 22 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | | - | |
312 | | - | |
313 | | - | |
| 311 | + | |
| 312 | + | |
314 | 313 | | |
315 | 314 | | |
316 | 315 | | |
| |||
331 | 330 | | |
332 | 331 | | |
333 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
334 | 336 | | |
335 | 337 | | |
336 | 338 | | |
| |||
340 | 342 | | |
341 | 343 | | |
342 | 344 | | |
343 | | - | |
344 | | - | |
345 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
346 | 351 | | |
347 | 352 | | |
348 | 353 | | |
| |||
496 | 501 | | |
497 | 502 | | |
498 | 503 | | |
499 | | - | |
500 | | - | |
501 | | - | |
| 504 | + | |
| 505 | + | |
502 | 506 | | |
503 | 507 | | |
504 | 508 | | |
| |||
519 | 523 | | |
520 | 524 | | |
521 | 525 | | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
522 | 529 | | |
523 | 530 | | |
524 | 531 | | |
| |||
528 | 535 | | |
529 | 536 | | |
530 | 537 | | |
531 | | - | |
532 | | - | |
533 | | - | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
534 | 544 | | |
535 | 545 | | |
536 | 546 | | |
| |||
0 commit comments