fix: correct deadline logic in _wait_for_finish by vdusek · Pull Request #749 · apify/apify-client-python · GitHub
Skip to content

fix: correct deadline logic in _wait_for_finish#749

Merged
vdusek merged 1 commit into
masterfrom
fix/wait-for-finish-deadline-logic
Apr 23, 2026
Merged

fix: correct deadline logic in _wait_for_finish#749
vdusek merged 1 commit into
masterfrom
fix/wait-for-finish-deadline-logic

Conversation

@vdusek

@vdusek vdusek commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

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.

@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Apr 22, 2026
@vdusek vdusek self-assigned this Apr 22, 2026
@github-actions github-actions Bot added this to the 139th sprint - Tooling team milestone Apr 22, 2026
@codecov

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

@vdusek vdusek requested a review from Pijukatel April 22, 2026 07:48
Make the not-found deadline lazy (starts on the first observed 404 and
resets after any successful response) and honor the user-provided
wait_duration in the 404 branch. This prevents a single transient 404
from aborting a long poll early, and prevents overruns when the user's
deadline is shorter than DEFAULT_WAIT_WHEN_JOB_NOT_EXIST.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vdusek vdusek force-pushed the fix/wait-for-finish-deadline-logic branch from b9a24dc to 122f101 Compare April 22, 2026 09:23
@vdusek vdusek merged commit fd0663e into master Apr 23, 2026
26 checks passed
@vdusek vdusek deleted the fix/wait-for-finish-deadline-logic branch April 23, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants