Repository navigation
fix(agents): web_fetch text mode distorts Markdown inside inline code - #184411
Conversation
…ext mode Inline code spans were flattened into prose before link and heading/list formatting ran, so Markdown-looking text inside backticks was reinterpreted: `` was dropped as an image and ``[label](url)`` collapsed to its label. Hide inline code spans behind the existing code placeholder before prose formatting, and restore them verbatim afterwards. Runs of N backticks close only on a matching run of exactly N backticks; unmatched runs keep their previous behavior.
|
🦞👀 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 changesPreserve Markdown-looking inline code when web_fetch converts Markdown responses to text. Example: Fetch a Markdown response containing Use Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a current extraction bug, resolves both earlier findings, and has convincing exact-head Gateway proof; no actionable code defects remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe web_fetch extraction layer receives downloaded Markdown, converts prose to plain text while protecting code literals, and returns wrapped content to the agent. flowchart LR
A[HTTP Markdown response] --> B[web_fetch extraction]
B --> C[Shared code region parser]
C --> D[Protect inline and fenced literals]
D --> E[Convert prose to text]
E --> F[Restore literals]
F --> G[Agent tool result]
Technical reviewBest possible solution: Preserve original inline-code ranges through the existing parser and literal-restoration owner, as this PR does. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the reported ordering defect, and supplied built-Gateway A/B captures demonstrate the same failure and repaired output; this review executed no target code. Is this the best way to solve the issue? The patch fixes literal ownership before prose conversion, reuses the canonical parser and existing restoration store, and resolves the earlier nested-placeholder and destination-backtick defects without replacing established fence handling. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dc90c458ac03. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +63, Tests +18. Total +81 across 2 files. Added test files: 0. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 HistoryReview history (4 earlier review cycles)
Reviewed October 26, 2026, 7:36 AM ET / 11:36 UTC (Revision 5). |
Address review findings on the previous revision: - Inline ranges now come from findMarkdownCodeRegions on the original Markdown instead of a second backtick scanner over the post-fence prose. A fence-looking run inside a code span therefore stays one literal span (no nested placeholders), and a backtick inside a link or image destination no longer pairs with a real code delimiter. - Fence scanning skips runs the parser places inside inline code, so the two recognisers cannot disagree. - Regression tests cover the fence-in-span and destination-backtick inputs.
|
@clawsweeper re-review Both review findings are addressed in 236dbcc, and the PR body now carries shipped-entry proof: the real
Controls from the same real-tool run: |
|
🦞👀 Re-review progress:
|
|
The PR body now carries tool-level shipped-entry output from this branch: the real Both review findings are fixed at On the remaining agent-level item: it is not reproducible in this environment. It has no model provider configured, and the tree cannot be built into |
|
@clawsweeper re-review The PR body now carries the agent-level proof that was outstanding: an isolated embedded agent turn with The same agent turn on the base commit returns the corrupted text instead: The body also shows identical prose controls (image omitted, link label kept) before and after, and an unchanged |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review The PR body now carries the Gateway-scoped proof: an isolated Gateway (loopback, token auth) started from this tree, with the CLI connected over the WebSocket as At this revision the agent receives: The same Gateway and document on the base commit produce the corrupted text ( Both earlier findings remain fixed, and the regression tests fail on the base and pass at this head. |
|
🦞👀 Re-review progress:
|
Shipped-Gateway A/B proof on exact head
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 7639f53. Thanks @yy19971996. web_fetch now keeps Markdown-looking inline code literal. |
…openclaw#184411) fix(web-fetch): keep Markdown-looking text inside inline code literal web_fetch text extraction treated Markdown-looking text inside inline code as prose, so literal image examples like `` were deleted and literal links were flattened. Inline code content is now kept as written; prose links, fenced code, Markdown mode and HTML extraction are unchanged. Evidence: real OpenAI turns (ChatGPT login, no API key) through both the native Codex runtime and OpenClaw's own harness, fetching a page from a local HTTP fixture. On main the web_fetch result the model received had the inline-code image example removed and the literal link flattened; with this change both arrived intact. Twelve more Gateway turns with a local provider fixture repeated the result and confirmed prose, fenced-code, Markdown-mode and HTML controls are unchanged. Details: openclaw#184411 (comment). Production about 73 lines. Thanks @yy19971996. Co-authored-by: Ayaan Zaidi <[email protected]>

Fixes #184362
What Problem This Solves
When
web_fetchextracts a Markdown document in text mode, Markdown-looking text inside inline code spans is reinterpreted as prose:``disappears as an image and``[label](https://example.com)``collapses to its label. Inline code is literal text, so readers lose the example they were meant to see.markdownToText()ranstripInlineLinks()before inline code spans were protected, so link and image syntax between backticks was flattened like prose.findMarkdownCodeRegions()on the original Markdown, and those ranges are hidden behind the same literal store fenced blocks already use, before prose formatting runs.src/agents/tools/web-fetch-utils.tsplus regression tests insrc/agents/tools/web-fetch-utils.test.ts.User Impact
Users who
web_fetcha Markdown page in text mode now see inline-code examples intact instead of losing image examples and link labels.Why This Change Was Made
Follow-up to the review on the previous revision (both findings fixed):
xin`before ```x``` after`.behind marker 0, then a second inline pass stored the surrounding span (including marker 0) behind marker 1; the non-recursive restore then exposed the raw marker. Inline ranges are now resolved on the original Markdown, and fence scanning skips any run the parser places inside inline code. andcode.hid the image's closing parenthesis.findMarkdownCodeRegions()` already distinguishes code from link and image resources, so this change reuses it instead of adding a second recogniser.Best fix: reuse the existing parser in
packages/markdown-core/src/markdown-code-regions.ts. Alternative: keep the post-fence scanner (previous revision) — it produced both findings above. Non-goals: no new abstraction, no change to fence or HTML paths.Evidence
Exact shipped-Gateway A/B captures and real model answers, on candidate
236dbccb8975135918e6e0a7de740ac6c907f0a0versus main4575e7cfb655a1cf9cf956fec21eaab99fd93914.node:24.22.1containers:pnpm buildpassed on both refs. All proof used emitted artifacts and actual Gateway agent turns.web_fetchresult: main loses inline image/link literals and rewrites heading/list/fence-looking code; candidate preserves those literals. Both actual model answers and the independent fixture GET ledger are captured.Read guide., no NUL markers leak.Earlier contributor source-Gateway evidence and focused tests also reproduced the same before/after; the emitted-artifact proof above replaces its former build limitation. Contributor reported 56 focused tests passing and changed-file lint/format passing; those checks were not rerun in this proof-only pass.
AI Assistance
This PR is AI-assisted. Used grep, git diff and node --import tsx to analyze issue #184362, locate the root cause in src/agents/tools/web-fetch-utils.ts, and implement the fix. The implementer understands the code: inline code ranges come from the shared Markdown parser and are hidden before prose formatting so their content stays literal. All evidence above is from real local runtime execution.