SIGN IN SIGN UP

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>
V
Vlada Dusek committed
fd0663e22b31ddd289325146c9750ff07c068d6b
Parent: 1dd70b8
Committed by GitHub <noreply@github.com> on 4/23/2026, 11:04:52 AM