Skip to content

fix(config): make body visibility timeout configurable - #2131

Merged
ntohidi merged 2 commits into
unclecode:developfrom
nightcityblade:fix/issue-2129
Aug 17, 2026
Merged

fix(config): make body visibility timeout configurable#2131
ntohidi merged 2 commits into
unclecode:developfrom
nightcityblade:fix/issue-2129

Conversation

@nightcityblade

@nightcityblade nightcityblade commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2129.

Add CrawlerRunConfig.body_visibility_timeout, defaulting to the existing 30-second behavior, and use it for the body visibility check. This lets callers lower the ceiling for pages whose body remains hidden without changing the default crawl behavior. The value is included in config serialization and the untrusted-config allowlist, validated as a positive number, and capped at 60 seconds for untrusted Docker input.

List of files changed and why

  • crawl4ai/async_configs.py - define, document, serialize, validate, allow, and cap the new configuration field.
  • crawl4ai/async_crawler_strategy.py - pass the configured timeout to the body visibility wait.
  • docs/md_v2/api/parameters.md and docs/md_v2/complete-sdk-reference.md - document the new public option.
  • tests/test_config_defaults.py - cover the default and round trip, invalid values, the untrusted cap, and propagation into csp_compliant_wait.

How Has This Been Tested?

  • /tmp/crawl4ai-followup-venv/bin/python -m pytest tests/test_config_defaults.py -q — 40 passed, 1 existing warning.
  • /tmp/crawl4ai-followup-venv/bin/python -m pytest deploy/docker/tests/test_security_trust_boundary.py -q — 38 passed, 4 existing warnings.
  • /tmp/crawl4ai-followup-venv/bin/ruff check --isolated --select E9,F63,F7,F82 --ignore F821 crawl4ai/async_configs.py crawl4ai/async_crawler_strategy.py tests/test_config_defaults.py — passed. (F821 is excluded because of the existing VirtualScrollConfig forward-reference finding in async_crawler_strategy.py.)
  • /tmp/crawl4ai-followup-venv/bin/python -m compileall -q crawl4ai/async_configs.py crawl4ai/async_crawler_strategy.py tests/test_config_defaults.py — passed.
  • git diff --check — passed.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas — N/A; no complex logic was introduced.
  • I have made corresponding changes to the documentation
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@ntohidi

ntohidi commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

@nightcityblade Thanks — approach looks right. Default stays 30000 so nobody's existing crawls change, and I checked the plumbing: from_kwargs reads the __init__ signature so that path is covered automatically, and clone/dump/load all go through to_dict, which you updated. Allowlist entry is in the right set too.

Three things before merge:

  1. Docs. docs/md_v2/api/parameters.md and docs/md_v2/complete-sdk-reference.md both document ignore_body_visibility and should get the new option too. The docstring alone isn't enough.

  2. The timeout goes straight into JavaScript at async_crawler_strategy.py:324. Passing None renders > None and blows up as a RuntimeError. That's pre-existing, but this PR makes it reachable from user input, including over the Docker API now that it's allowlisted. Worth a basic check on the value.

  3. The test only checks the default and a dump/load round trip. Nothing verifies the value actually reaches csp_compliant_wait — the test would still pass if the call site kept using 30000. A mock asserting the timeout that gets passed would cover the real thing.

Separate from this PR: even after it lands, the default path still spends 30 silent seconds on these pages. csp_compliant_wait returns False on timeout instead of raising, so nothing is logged and the crawl reports success. @mvletter had to profile the pipeline to find it. A debug log when that wait times out would make this option discoverable — happy to do it as a follow-up rather than expand the scope here.

@nightcityblade

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Addressed in 64bf678:

  • documented body_visibility_timeout in both public parameter references;
  • reject non-numeric, boolean, zero, and negative values, and cap untrusted Docker input at 60 seconds;
  • added a mocked crawl-path test that verifies 1234 reaches csp_compliant_wait, alongside default/round-trip/validation coverage.

Focused validation passes: 40 config tests and 38 trust-boundary tests. I kept the separate timeout-debug logging idea out of this PR as suggested.

Aitosoft added a commit to Aitosoft/crawl4ai that referenced this pull request Aug 17, 2026
…se the harm was sized

MAS shipped their raw client logs for the sweep (49-data/: 61,937 timing rows,
5,511 refusal rows, terminal outcomes). Their capture table prices every defect
on our open list in the only unit that matters -- pages they lost:

  our 429s        29 captures    (0.05% of 60,874 attempts)
  our 500s       156 captures    (0.26%)
  render_defect   27 captures
  86.1% stored; 95% of all their failures were the origin

Across 175 hours, two requests failed hard at the wire.

That is the bar seven task files failed. Not because the diagnoses were wrong
-- most were right -- but because the thing being fixed is worth less than the
regression risk of fixing it, and in three cases upstream is fixing it for us.
Closed and moved to tasks/done/ unchanged, with the reasoning for each in
tasks/done/post-sweep-closure-2026-08-17.md:

- memory-guard-charges-reclaimable-page-cache: settled by two repos. Our `anon`
  moved +26 MB of 4,096 across 53 h; MAS's independent gauge +0.13 points. All
  three candidate fixes refuted or unsafe. max_browsers never refused once in
  186,178 requests.
- crawl-cost-is-idle-replicas-not-slow-renders: question answered. One config
  number took cost per 1,000 requests from $3.28 to $0.51. The fleet is at its
  floor and the remaining levers are MAS's.
- the patchright permanent-class retry: upstream PR unclecode#2131 fixes the 30 s
  wait_for_selector("body") it depends on. Do not build what upstream ships.
- static-mode-tls-impersonation, static-fallback-within-fence: static mode was
  used 0 times in 186,178 requests, confirmed from MAS's side.
- blocked-host-retry-economy: premise refuted. On the 590 hosts crawled in both
  regimes the block rate is identical (2.75 vs 2.73/1k) and zero hosts went
  clean-then-blocked. The rise is composition -- dead-DNS went 0.22% -> 1.78%/day.
- preflight-batch-endpoint: both sides already declined it.
- cleaned-html-collapse-guard part 2: recovery works -- 43 rescued (~1.6M chars)
  against 10 unrecovered. Root-causing the rest is prospective.

What survives is four items, each for a different reason, and none is a
performance optimisation: the capacity gate (MAS's one explicit ask, and their
49-... section 1 is the argument -- our gauge sat in their logs for a fortnight
because it was embedded in prose), the fixture-origin proxy gap (~12 lines,
makes 67 existing tests measure the path production uses), the upstream PRs
(reframed: our fork is +4,696 lines with ~2,375 on files upstream owns, and
upstream is now editing api.py and server.py), and a one-word render_mode fix.

tasks/README.md rewritten from scratch. Every item gives concern, evidence, why
it matters and what the author is least sure of -- and deliberately no ordered
checklist, because a step list narrows the implementing session's judgement and
a fresh context re-deriving the diagnosis is what has caught nine consecutive
task files being wrong.

Two standing rules added: size the harm before opening the investigation, and
research what is true this month. The consent problem turned out to be solved
by the wider ecosystem in a way we had not noticed -- every maintained system
hides rather than removes, and autoconsent's rule syntax has no remove() action
at all -- which is what the upstream PR should now argue.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ntohidi
ntohidi merged commit b2162c4 into unclecode:develop Aug 17, 2026
2 checks passed
@ntohidi

ntohidi commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

@nightcityblade thanks for your contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants