feat: transient-error retry policy with failure telemetry - #8
Merged
Conversation
- RetryPolicy (attempts >= 1, backoff >= 0, linear backoff) in ports.py - Crawl4AIBackend retries arun on raised exceptions AND unsuccessful results; exhaustion raises CrawlError (soft failures) or the original error (exceptions); no policy preserves single-attempt behaviour - Per-page failures in crawl results are recorded on backend.last_failed_pages instead of vanishing; run_pipeline aggregates them into PipelineResult.failed_pages via duck-typed getattr, so other backends are unaffected - CLI: --attempts/--backoff wired through build_backend - 8 retry scenarios executed in the sandbox (transient retry, soft-fail retry, exhaustion both modes, single-attempt default, telemetry, linear backoff [2.0, 4.0], validation)
- run.py: drop unused dataclasses.field import - test_retry_policy.py: drop unused CrawlOptions import and unused page assignment in the soft-fail retry test
The factory built a fresh FlakyCrawler with the full script per call, so the second crawl replayed the first script entry. One shared crawler advances the script as intended.
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.
Closes the last gap from the drift/retries review: previously there were no retries anywhere, and per-page crawl failures vanished silently. Follows on from #7.
What's included
ports.py—RetryPolicy(frozen, validated)attempts >= 1,backoff_seconds >= 0; linear backoff (backoff * attempt) — deliberate politeness towards a public NHS site, where exponential retries are the wrong posturebackends/crawl4ai_backend.py— retry engine_arun_with_retries: retriesarunon raised exceptions (transport/browser errors) and unsuccessful results (soft failures, e.g. timeouts)CrawlErrorwith the site's error message; transport errors → the original exception propagatessleeperinjection hook so tests record backoff delays without sleepingFailure telemetry
backend.last_failed_pages— URLs of unsuccessful page results, recorded per crawl and reset between calls; pages are still skipped (partial results kept) but no longer silentlyPipelineResult.failed_pages—run_pipelineaggregates telemetry via duck-typedgetattr(backend, "last_failed_pages", ()), so backends without the attribute are unaffectedCLI —
--attempts(default 3) /--backoff(default 2.0) wired throughbuild_backend.Tests (17 new + 2 adjusted) — policy validation; 6 scrape-retry scenarios (transient-then-success, soft-fail-then-success, exhaustion both modes, single-attempt default, recorded backoff
[2.0, 4.0]); crawl telemetry + reset; pipeline aggregation with partial results kept; no-telemetry backend; CLI flags. The twotest_preflight.pymonkeypatch lambdas were widened to*a, **kwfor the newbuild_backendsignature.Verification
8 scenarios executed in the sandbox before pushing — transient retry, soft-fail retry, exhaustion both modes, single-attempt default, telemetry, linear backoff, validation — all green.
Design decisions to review
success=Falsefrom the crawler is usually transient; aValueErrorfrom our own validation is deterministic.getattrconvention) over a port change — keeps the protocol minimal; a formalTelemetryBackendprotocol is a possible later refinement.