Skip to content

fix: enforce BFS max_pages across each level - #2341

Closed
nightcityblade wants to merge 1 commit into
unclecode:mainfrom
nightcityblade:fix/issue-2338
Closed

nightcityblade wants to merge 1 commit into
unclecode:mainfrom
nightcityblade:fix/issue-2338

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

Summary

Fixes #2338

Count URLs already queued for the next BFS level against the remaining max_pages budget so sibling parent pages cannot oversubscribe it.

List of files changed and why

  • crawl4ai/deep_crawling/bfs_strategy.py - Subtract the current next-level queue length when calculating remaining capacity.
  • tests/deep_crawling/test_deep_crawl_resume.py - Add a regression test with two parents sharing the final two-page budget.

How Has This Been Tested?

  • uv run --with pytest --with pytest-asyncio pytest tests/deep_crawling/test_deep_crawl_resume.py -q (33 passed)
  • ruff check --select E9,F63,F7,F82 crawl4ai/deep_crawling/bfs_strategy.py tests/deep_crawling/test_deep_crawl_resume.py (passed)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My code is commented where needed — N/A; the capacity calculation and regression test are self-explanatory
  • I have made corresponding changes to the documentation — N/A; this corrects existing max_pages behavior without changing the public API
  • 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 Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for picking this up so quickly, @nightcityblade, and for adding a test!

#2339 fixed the same issue and is now merged. It includes your len(next_level) change and also caps each level before it is fetched, which the batch mode needed to stop at exactly max_pages. So I'm closing this one as a duplicate.

Thanks again for your effort, and we'd be happy to see more PRs from you.

@ntohidi ntohidi closed this Oct 12, 2026
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.

[Bug]: BFSDeepCrawlStrategy: max_pages is checked per parent page, so a depth level can exceed the limit by a lot

2 participants