Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
priority/p2-mediumPriority P2: standard workscope/aiAI review pipeline, personas, prompts, LLM client, or RAGtype/bugType bug: the code does not do what it must
Description
Context & Rationale
#860 split the web_fetch hardening entry (docs/ROADMAP.md, at 308a71f line 878) into four PRs and delivered PR1, the per-hop egress veto, as a v0.2.24 critical fix. This is PR3. resp.text skips the WHATWG BOM and <meta charset> steps, so pages arrive as mojibake.
Scope & Deliverables
- Deliverable: a
default_encodingcallable (httpx2/_models.py:539,672-680) prescans 1024 bytes for<meta charset>, thencharset_normalizer, pinned inpyproject.toml; checkresp.contentfor a BOM and setresp.encodingfirst. Port vibestest_crawler.py:306-351,396-475ontohttpx2.MockTransport. - Acceptance criteria: every behaviour named above has a test that fails before the change; tests use
httpx2.MockTransportand never touch the network;uv run devops cipasses. - Constraint: the per-hop veto from fix(ai): web_fetch vetoes every redirect hop, reports failures as failures and renders pages as untrusted text #860 stays the only egress check, and a failure is never returned as page text.
Strategic Alignment
- Depends on: fix(ai): web_fetch vetoes every redirect hop, reports failures as failures and renders pages as untrusted text #860 (the per-hop veto, v0.2.24).
Proposed design
Problem statement
The web_fetch function in the AI module does not properly decode web pages by their BOM (Byte Order Mark) or declared charset, resulting in mojibake (garbled text) when pages are fetched. This issue affects the accuracy and usability of fetched content.
Acceptance criteria
- Criterion 1: The
default_encodingcallable correctly prescans 1024 bytes for `` declaration.
Verification: A test usinghttpx2.MockTransportverifies that the function identifies the charset from HTML meta tags within the first 1024 bytes. - Criterion 2: The
default_encodingcallable usescharset_normalizerto determine encoding when no meta charset is found.
Verification: A test usinghttpx2.MockTransportverifies that the function correctly identifies encoding usingcharset_normalizeron content without explicit charset. - Criterion 3: The
default_encodingcallable checks for BOM inresp.contentand setsresp.encodingaccordingly.
Verification: A test usinghttpx2.MockTransportverifies that the function correctly detects and applies BOM-based encoding from response content. - Criterion 4: All behaviors named above have tests that fail before the change and pass after the change.
Verification: Runninguv run devops cipasses with the new implementation, confirming all tests are working correctly.
Key questions
- What tools are used for charset detection?: The
charset_normalizerlibrary is used for charset detection, and it is pinned inpyproject.toml. [sources: pyproject.toml, uv.lock:471]
Open questions
- What is the purpose of the
default_encodingcallable in the context ofweb_fetch? (missing verified source) - What is the expected behavior of
resp.textin relation to BOM and `` steps? (missing verified source) - What tests are required to validate the fix? (missing verified source)
- What constraint is imposed on this fix? (missing verified source)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
priority/p2-mediumPriority P2: standard workscope/aiAI review pipeline, personas, prompts, LLM client, or RAGtype/bugType bug: the code does not do what it must
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(release): v0.2.24 (#905)
dan-petty commentedon Oct 20, 2026
Status set back to New at 2954109: refine found it not ready (see Key questions, Fit and Suspected block in the proposed design in the issue body).
dan-petty commentedon Oct 23, 2026
Not planned: #1854 deleted the
web_fetchtool, and its task file says this item no longer applies. A later fetch feature can usepydantic_ai.common_tools.web_fetch.