Fix blocked webpage fetches with a requests fallback - #38
Open
LIMINGNING wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves resilience of fetch_page_content_async by adding a non-blocking (threaded) synchronous requests fallback when the aiohttp path fails (HTTP errors, blocked/short responses, or exceptions), and by selecting request headers per-domain (notably a Wikimedia-specific user agent).
Changes:
- Added
request_headers_for_url()and a Wikimedia-specificUser-Agent. - Implemented
fetch_with_requests_fallback()usingasyncio.to_thread()and wired it intoextract_text_from_url_async()error paths. - Added unit tests covering header selection and fallback behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/search/bing_search.py | Adds per-URL header selection, and introduces a threaded synchronous fallback for async fetch failures/blocked responses. |
| scripts/tests/test_web_fetch_fallback.py | Adds tests for Wikimedia vs non-Wikimedia headers and for async-to-sync fallback execution. |
馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
Problem
fetch_page_content_asynccan fail on pages that remain reachable through the synchronousrequestsextractor. In the reproduced Wikipedia case, the aiohttp path timed out or received a blocked response whilerequestsreturned HTTP 200. WhenWebParserClient_urlwas not configured, the async path had no second retrieval channel and downstream code received only a search-result snippet. The short/empty-response branch also referenced an undefined exception variable.Changes
asyncio.to_threadso it does not block the event loop.The fallback is generic and contains no task-, domain-content-, or answer-specific logic.
Verification
python -m unittest discover -s scripts/tests -p "test_*.py": 4 tests passed.https://en.wikipedia.org/wiki/Mercedes_Sosa: retrieved 20,000 characters and found the expectedStudio albumssection and its 2000-2009 entries.mainrevision (db387eb).Scope
This PR changes only
scripts/search/bing_search.pyand addsscripts/tests/test_web_fetch_fallback.py. It does not modify model prompts, search-query generation, API configuration, or answer logic.