Repository navigation
fix(web-fetch): keep code indentation when extracting Markdown as text - #172389
Conversation
|
🦞👀 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. What this changesThis PR preserves fenced-code whitespace when web_fetch converts Markdown responses to text. Example: Fetch a Markdown Python example with extractMode set to text.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a current Markdown extraction defect with a focused change and supplied Gateway proof; no actionable findings remain, and current-head CI is pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe shared Markdown-to-text converter receives fetched Markdown or rendered HTML and returns extracted text for the web_fetch result. flowchart TD
A[HTTP response] --> B[web_fetch extraction]
B --> C[Markdown text conversion]
C --> D[Protect code literals]
D --> E[Normalize prose]
E --> F[Restore code literals]
F --> G[Wrapped tool result]
Technical reviewBest possible solution: Merge the focused normalization-order correction once the existing current-head checks pass. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically collapses protected code whitespace after restoration; supplied Gateway before/after output demonstrates the reported failure without requiring a reviewer-side execution. Is this the best way to solve the issue? Moving the existing normalization before restoration fixes the responsible shared owner without introducing another parser, configuration option, or extraction path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7bf56c8aa502. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests +4, Docs +2. Total +7 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 16, 2026, 12:05 AM ET / 04:05 UTC (Revision 3). |
|
@clawsweeper re-review Added built-Gateway proof and actual before/after returned strings in the PR body's Real Behavior Proof section. The same product head Baseline remains red only for the two target defects; candidate is green with source/build custody and process/listener cleanup verified. Earlier harness failures remain recorded, not relabeled as green. Upstream READY CI and both required |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 42ff52b. Thanks @ly85206559. web_fetch now keeps code block whitespace intact. |
openclaw#172389) fix(web-fetch): keep whitespace inside fenced code when extracting page text When web_fetch converted a page to text, it collapsed whitespace before handling fenced Markdown code, so code blocks lost their indentation, repeated spaces, tabs and blank lines. Fenced code is now kept verbatim; prose whitespace is still normalized as before, and unclosed fences keep their existing handling. Proof: built Gateway, authenticated /tools/invoke calling web_fetch on a local Markdown page. On main the code block came back flattened (twice). With this change indentation, repeated spaces, tabs and blank lines inside the fence are preserved; prose and other Markdown controls are unchanged. Thanks @ly85206559. Co-authored-by: Ayaan Zaidi <[email protected]>
…n output (openclaw#176263) fix(web-fetch): keep HTML table cells and preformatted text intact web_fetch's HTML-to-Markdown rendering merged adjacent table cells, so separate values like "12" and "34" came out as a misleading "1234", and it flattened indentation in pre/code blocks. Cells now stay separated and preformatted blocks keep their indentation and the text that follows them. Proof: built Gateway, /tools/invoke web_fetch on a local page. On main, numeric cells merged and code indentation was lost (twice, separate URLs); a plain-prose page was unchanged. With this change cells stay separate, indentation is kept, and the following paragraph is intact. Production +95 (cut from the original proposal by 77 lines; reuses the code-whitespace handling from openclaw#172389). Fixes openclaw#176244. Thanks @sunlit-deng. Co-authored-by: Ayaan Zaidi <[email protected]>
…n output (openclaw#176263) fix(web-fetch): keep HTML table cells and preformatted text intact web_fetch's HTML-to-Markdown rendering merged adjacent table cells, so separate values like "12" and "34" came out as a misleading "1234", and it flattened indentation in pre/code blocks. Cells now stay separated and preformatted blocks keep their indentation and the text that follows them. Proof: built Gateway, /tools/invoke web_fetch on a local page. On main, numeric cells merged and code indentation was lost (twice, separate URLs); a plain-prose page was unchanged. With this change cells stay separate, indentation is kept, and the following paragraph is intact. Production +95 (cut from the original proposal by 77 lines; reuses the code-whitespace handling from openclaw#172389). Fixes openclaw#176244. Thanks @sunlit-deng. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes code indentation, repeated spaces, and blank lines being lost when
web_fetchextracts Markdown responses as text.User Impact
Agents receive usable code examples rather than whitespace-corrupted code. Markdown-mode output and prose normalization remain unchanged. No configuration or migration is needed.
Why This Change Was Made
Normalize prose before restoring protected code literals, instead of normalizing the restored code. This extends the literal protection from #164936 to preserve code whitespace as well.
The existing HTTP extraction tests cover closed and incomplete fences. The incomplete-fence regression now combines syntax and whitespace checks in one case instead of adding a second fixture. Production delta: +4/-3 lines; tests: +8/-4; documentation: +3/-1 against the merge base.
Original fix and report by @ly85206559; contributor commits are preserved.
Evidence
A secretless Linux container built current main
060a63ff446a05ec469d4d9197af74536681f884and the candidate separately, then invoked the registeredweb_fetchthrough an authenticated Gateway/tools/invokerequest against a local HTTP Markdown page. No model/provider was involved.Both baseline requests returned corrupted code:
Both candidate requests preserved the expected code (including the two blank lines and the tab before
return):Observed results:
The contributor's independent built-Gateway evidence also covers incomplete fences: baseline, candidate.
Merge danger: two-way door. Reverting restores the previous extraction behavior without changing persisted state. Blast radius is Markdown-to-text extraction by
web_fetch; HTML extraction can also use this shared converter, while Markdown-mode responses are unchanged.