feat(engine): WorkLease reclaim and fail-closed challenge_block - #53
Merged
Conversation
Replace Future.cancel theater and ScrapeProgress with a single lease that admits per-host, kills the session driver on deadline, and builds the timeout envelope from one phase snapshot (SCRAPE_MAX_PER_HOST).
Delete soft-retry (may_retry_strategies) and prefer-challenge continue paths so unclean or unreadable hung pages always emit challenge_block.
Own Cloudflare/DataDome/Vercel HTML under tests/fixtures/challenge, trim one-sided detector markers, and document the shared corpus home.
Close idempotently by clearing the driver handle (not a pre-assign flag), retain a strong ref to shielded executor work, and cover early reclaim.
Set lease.aborted on reclaim so workers exit without booting after host gate release; treat unreadable mid-wait probes as challenge_block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
WorkLease(app/engine/work_lease.py) as sole owner of admit, deadline, and Chromium reclaim; delete softfuture.cancel()-as-reclaim andScrapeProgress.challenge_block(no soft-retry budget burn).SCRAPE_MAX_PER_HOST; abort flag skips Chromium after host-gate release on reclaim.tests/fixtures/challenge/for detector corpus tests.error_category+timeout_phase.Why
Root cause
Hostile hosts (e.g. SoundCloud-class) burned ~45s as
timeout/work, held executor slots after outer cancel, starved the pool (timeout/queue), and mapped to retryableGATEWAY_TIMEOUT(“took too long”) instead ofBLOCKED_SURFACE.Intent
Reclaim workers on lease end and emit
challenge_blockwhen the surface is blocked/hostile so gem → web Decision already yields honest non-retryable UX.Risk
timeout_phase:queuedrop /scrape.challenge_blockrise.Review map
app/engine/work_lease.py— admit / deadline / reclaim / abortapp/domain/scrape_service.py+app/engine/session.py— lease wiring and cold-boot reclaim raceapp/engine/browser_tier.py+app/infra/detector.py+app/engine/strategies.py— fail-closed challenge, soft-retry removedtests/domain/test_work_lease_reclaim.py+tests/engine/test_session_reclaim.py+ challenge corpus testsValidation
make check/make ready— exit 0 (189 tests)837bf85