Repository navigation
fix(web-fetch): keep blank lines before lists in text extraction - #164692
Conversation
markdownToText stripped list and heading markers with multiline regexes whose leading and trailing \s also matched newlines, so the blank line between a paragraph or heading and the following list was consumed. Restrict those regexes to horizontal whitespace.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 3:40 AM ET / 07:40 UTC (Revision 3). ClawSweeper reviewWhat this changesPreserves blank lines before lists in web-fetch plain-text results and adds regressions for Markdown, fallback HTML, and Windows line endings. Merge readiness✅ Ready for maintainer review Keep open: current main and v2026.9.8 retain the defect. The focused repair has sufficient Gateway behavior proof and no blocking findings. Priority: P2 Review scores
Verification
How this fits togetherThe web-fetch tool retrieves page content and returns readable content to agents. Its shared plain-text converter handles Markdown responses, fallback HTML extraction, and Firecrawl output. flowchart TD
A[Fetched page] --> B{Content format}
B --> C[Markdown response]
B --> D[Fallback HTML extraction]
C --> E[Shared plain-text converter]
D --> E
E --> F[Content wrapping and limits]
F --> G[Agent tool result]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0, Tests +16. Total +16 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep list separation in the existing shared converter while preserving public signatures, heading behavior, and Markdown-mode output. Do we have a high-confidence way to reproduce the issue? Yes: current-main list expressions consume preceding line breaks, and the supplied base/candidate Gateway output demonstrates the exact failure through real HTTP extraction. This reviewer did not execute target code. Is this the best way to solve the issue? Yes: narrowing the leading list-marker match repairs the shared producer without adding a competing converter or changing public APIs. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3e8edffc4313. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
…nclaw#164692) `web_fetch` with `extractMode: "text"` dropped the blank line between a paragraph or heading and the list after it, so the intro line read as the first list item. With CRLF input, list items also ran together (`Install steps:DownloadRun`). This affected text/markdown responses, the raw-HTML fallback, Firecrawl text mode and HTML error details, which all go through `markdownToText`. The converter now keeps that boundary for LF and CRLF input. The heading and marker-stripping behavior is otherwise unchanged, and a corpus diff confirms the only output change is the restored list separation. Proof: in a real Gateway `web_fetch` against local Markdown and HTML pages, the blank line was missing on base and present with this change. The regression tests fail on base and pass here. A live gpt-5-mini call passed. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fix
web_fetchtext extraction losing the separation between a paragraph or heading and a following list. The list-marker regexes inmarkdownToTextallowed their leading whitespace match to consume preceding line breaks.User Impact
Agents receive readable paragraph, heading, and list boundaries in
web_fetchtext results. No configuration or migration is required.Why This Change Was Made
Keep yetval's original fix and regression, with a small follow-up that limits the behavior change to list separation: exclude LF from leading list whitespace, but preserve the existing heading regex, trailing marker whitespace, and Unicode indentation semantics. Extend the HTML regression to a heading followed by an ordered list and add a CRLF regression.
No overlap with Pash/Sarah changes.
Output compatibility
Compared the actual base and candidate
markdownToTextfunctions in an isolated Node 24 container across 12 fixtures: paragraphs, headings, nested lists, fenced code, a table, standalone markers, Unicode indentation, CRLF, and tab-indented lists.The only observed changes in that corpus are:
Install steps:,Download, andRunintoInstall steps:DownloadRun; the candidate keeps the paragraph separation and separate item lines. This is the same list-separation defect with CRLF input.Paragraphs, nested lists without a preceding blank line, tables, Unicode indentation, standalone markers, and fenced code otherwise match the base byte-for-byte. Markdown mode is untouched.
A separate existing defect found while checking scope: main strips a standalone
#inside a fenced code block after removing the fence. The original proposal also changed that output. This PR deliberately leaves that behavior unchanged; code-block marker preservation deserves its own fix.Evidence
pnpm test src/agents/tools/web-fetch-utils.test.ts --maxWorkers=1, Linux arm64, Node 24.21.0, isolated Docker:Install steps:DownloadRun.No paid Firecrawl requests were made. Firecrawl text mode and HTML error details use the same converter but were not exercised through their external entry points.
Real Gateway behavior proof
Built the base and candidate with
pnpm build:dockerin a secretless Node 24 container. Base production source is commit91e9b93bcebd821474415d3daa8e9de4a566e1c3; candidate isde9bbef1e89da8e86b6ddda032f76560e71c490b. The touched files have no intervening main changes through920820b202b.Ran a real isolated Gateway agent turn using a scripted streaming model. It calls the real
web_fetchtool twice withextractMode: "text"against a local HTTP server: once fortext/markdown, once for equivalent HTML. The fixture explicitly allows only the local hostname, disables Tool Search to exposeweb_fetchdirectly, and disables extractor plugins while keeping the readability fallback route enabled. The returned extractors arecf-markdownandraw-html; both tools succeed.For both content types, the base tool result contains:
For both content types, the candidate tool result contains:
The extracted content diff is exactly those two added blank lines. The real tool's untrusted-content wrapping remains in place; timestamps, timing, wrapper IDs, and lengths are normal per-call metadata, not content comparisons.
A separate exact-head live Gateway turn made one real
gpt-5-minirequest through a passive proxy: HTTP 200, reasoning effortlow, maximum output budget 4096, and the expected final reply. That live smoke did not fetch a page; the deterministic Gateway turns above prove the changed fetch behavior.