Repository navigation
Fix: BFS deep crawl refetches its start page and stream mode drops the last page - #2433
Open
workflowsdiy wants to merge 1 commit into
Open
workflowsdiy wants to merge 1 commit into
workflowsdiy wants to merge 1 commit into
Conversation
…e last page Batch mode never added the URLs of the level being fetched to `visited`, so a page that links to itself (e.g. a home page's logo link) was queued again at the next depth, fetched twice, and used up a max_pages slot. Both modes now add the level's URLs to `visited`, normalized the same way as discovered links, so `https://Example.com` and `https://example.com/` match. Stream mode counted the page that reached max_pages and then broke out of the loop before yielding it, so a crawl with max_pages=5 fetched 5 pages and returned 4. It now yields the page, then stops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Two bugs in
BFSDeepCrawlStrategy, both present onmain(0.9.5) anddevelop.1. Batch mode fetches the start page twice
_arun_batchnever adds the URLs of the level it is fetching tovisited(_arun_streamdoes). A page that links to itself, such as a home page's logo link, is queued again at the next depth, fetched a second time, and uses up amax_pagesslot.Repro with 0.9.5:
Fix: both modes add the level's URLs to
visited, normalized withnormalize_url_for_deep_crawllike discovered links, so a start URL ofhttps://Example.comalso matches a link tohttps://example.com/.2. Stream mode drops the page that reaches
max_pages_arun_streamcounts the page that reachesmax_pagesand thenbreaks before yielding it. Withmax_pages=5it fetches 5 pages and returns 4. It now yields the page, then stops (the same orderBestFirstCrawlingStrategyalready uses).Tests
Added to
tests/deep_crawling/test_bfs_max_pages_next_level.py:test_stream_crawl_yields_the_page_that_reaches_max_pagestest_crawl_does_not_refetch_start_url(batch and stream), on a site where every page links back to the home pageAll three fail before the change and pass after.
pytest tests/deep_crawling: 90 passed. Live check against docs.crawl4ai.com withmax_depth=1, max_pages=5: 5 unique pages in both batch and stream mode (0.9.5 returns the start page twice in batch mode and 4 pages in stream mode).🤖 Generated with Claude Code