Skip to content

fix(web-fetch): preserve code literals in text extraction - #164936

Merged
obviyus merged 8 commits into
openclaw:mainfrom
ly85206559:codex/fix-web-fetch-code-literals-20261004
Oct 4, 2026
Merged

obviyus merged 8 commits into
openclaw:mainfrom
ly85206559:codex/fix-web-fetch-code-literals-20261004

Conversation

@ly85206559

@ly85206559 ly85206559 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: text-mode web_fetch removes comment markers, list syntax, links, and inline backticks from fenced code examples in Markdown responses.

Related: #164692, whose landing note identified this separate fenced-code issue. Thanks to @ly85206559 for reporting and implementing the follow-up; the contributor's commits are preserved.

User Impact

User impact: agents reading documentation in text mode retain literal syntax inside fenced code examples. Ordinary Markdown prose still converts to text; Markdown mode, existing fence recognition, whitespace normalization, and size limits remain unchanged.

Why This Change Was Made

Protect fenced literals while converting prose, then restore them before the existing whitespace normalization. Escaped input NULs cannot be mistaken for temporary code markers. The branch now includes current main and #164692's LF/CRLF list-boundary fix.

No overlap with Pash/Sarah changes.

Evidence

Validated merged head 746af80caca566d13542e288d1cce96bd1754e15 against frozen main bb5656bf89e230bb3d6c9040b1e9b86df0306439 in an isolated Docker container:

  • Real Gateway before/after: a scripted model called web_fetch with extractMode: "text" against a local text/markdown page. Main returned comment, item, ordered, link, and backticks from the fenced example. The candidate returned the literal # comment, - item, 1. ordered, [link](https://example.com), and inline backticks. Both kept surrounding prose and the paragraph/list blank line identical. The actual model-facing tool responses were compared, not a mocked converter result.
  • Corpus comparison: 14 representative paragraph, heading, LF/CRLF and nested-list, fenced-code, inline-code, and table cases. Exactly two changed: the fenced-code cases. All differences were inside the fences; prose was byte-identical. LF and CRLF list-boundary output from fix(web-fetch): keep blank lines before lists in text extraction #164692 remained intact.
  • Regression proof: the identical candidate tests against main's converter fail exactly the fenced-literal unit case and HTTP text-extraction case. The candidate passes all 109 tests across web-fetch-utils.test.ts, web-fetch-visibility.tool-extraction.test.ts, and web-fetch.cf-markdown.test.ts, including LF/CRLF boundaries and Markdown-mode controls. Command: node scripts/run-vitest.mjs <these three files> --maxWorkers=1 --retry=0; candidate wall time 22.05 seconds. Baseline stopped after the failing HTTP shard (21.49 seconds), then the converter file ran separately (2.25 seconds).
  • Both baseline and candidate completed pnpm build:docker; the candidate container's changed-source hashes match the worktree.
  • Live provider gate: one real gpt-5-mini request through a passive proxy on the exact candidate head, reasoning low, output budget 4096, HTTP 200, expected final reply received. No paid Firecrawl call.
  • The contributor's earlier matched baseline/candidate proof remains supporting evidence, not a substitute for the refreshed merged-head proof above. Fresh exact-head upstream CI and ClawSweeper review are required before landing.

Not claimed: broader CommonMark/fence grammar support or exact code whitespace preservation beyond the existing normalization.

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 11:07 AM ET / 15:07 UTC (Revision 3).

ClawSweeper review

What this changes

The PR preserves literal syntax inside fenced code examples when web_fetch converts Markdown responses to text, with regression coverage for extraction and surrounding prose.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still has the fenced-literal defect, and the refreshed Gateway before/after evidence supports the fix. No blocking correctness finding remains.

Priority: P2
Reviewed head: 746af80caca566d13542e288d1cce96bd1754e15

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, sound repair with strong refreshed production-boundary evidence and no blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured exact-head Docker Gateway before/after exercises web_fetch text mode against real HTTP Markdown and reports restored literal syntax in model-facing responses. The corpus comparison and failing-baseline regressions supplement that boundary proof; the provider smoke is separate. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured exact-head Docker Gateway before/after exercises web_fetch text mode against real HTTP Markdown and reports restored literal syntax in model-facing responses. The corpus comparison and failing-baseline regressions supplement that boundary proof; the provider smoke is separate. No stored-data contract changes.
Evidence reviewed 8 items Pinned introduced change: The merge-base-to-head diff protects fenced content during prose conversion and restores it before unchanged whitespace normalization; it introduces no configuration, dependency, or persistent-state changes.
Current main still needs the fix: Current main removes fences before stripping inline backticks, heading markers, and list markers, and strips links before fence extraction. Consequently fenced examples still lose literal syntax.
Production entrypoint and security boundary: A text/markdown response in text mode calls the changed converter. The resulting content still passes through the existing bounded external-content wrapper; network authorization and SSRF policy are unchanged.
Findings None None.
Security None None.

How this fits together

OpenClaw's web_fetch tool retrieves web content and extracts readable text for agents. This change affects Markdown-to-text conversion before the existing output limits and untrusted-content wrapping.

flowchart TD
 A[Agent requests a page] --> B[Guarded HTTP fetch]
 B --> C{Response format}
 C --> D[Markdown text extraction]
 D --> E[Protect code and convert prose]
 E --> F[Normalize and restore literals]
 F --> G[Limit and wrap external content]
 G --> H[Agent receives tool result]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +13, Tests +51. Total +64 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 26 13 +13
Tests 2 54 3 +51
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 80 16 +64

Review metrics

Metric Value Why it matters
Production versus test growth production +13 net lines; tests +51 net lines Production growth implements bounded literal protection in the existing owner, supported by converter and HTTP extraction regressions.

Technical review

Best possible solution:

Keep literal protection in the existing converter while preserving prose conversion, list separation, whitespace normalization, and output safety boundaries.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main source clearly strips literal markers after removing fences, and the supplied Gateway before/after reports that exact failure. This reviewer did not execute a reproduction.

Is this the best way to solve the issue?

Yes: protecting literals inside the existing converter is a focused repair, and the refreshed comparison supports unchanged prose and list-boundary behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ab57310b7e87.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs a limited text-extraction defect that alters documentation code examples returned to agents.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured exact-head Docker Gateway before/after exercises web_fetch text mode against real HTTP Markdown and reports restored literal syntax in model-facing responses. The corpus comparison and failing-baseline regressions supplement that boundary proof; the provider smoke is separate. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured exact-head Docker Gateway before/after exercises web_fetch text mode against real HTTP Markdown and reports restored literal syntax in model-facing responses. The corpus comparison and failing-baseline regressions supplement that boundary proof; the provider smoke is separate. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff protects fenced content during prose conversion and restores it before unchanged whitespace normalization; it introduces no configuration, dependency, or persistent-state changes. (src/agents/tools/web-fetch-utils.ts:336, 746af80caca5)
  • Current main still needs the fix: Current main removes fences before stripping inline backticks, heading markers, and list markers, and strips links before fence extraction. Consequently fenced examples still lose literal syntax. (src/agents/tools/web-fetch-utils.ts:336, ab57310b7e87)
  • Production entrypoint and security boundary: A text/markdown response in text mode calls the changed converter. The resulting content still passes through the existing bounded external-content wrapper; network authorization and SSRF policy are unchanged. (src/agents/tools/web-fetch.ts:691, 746af80caca5)
  • Refreshed real Gateway evidence: The captured PR body and fix(web-fetch): preserve code literals in text extraction #164936 (comment) describe isolated Docker Gateway turns using a scripted model and a real local HTTP Markdown response on the exact head. Baseline model-facing responses lost comment, list, link, and backtick syntax; candidate responses retained it. A 14-case comparison changed only the two fenced cases, preserving surrounding prose and LF/CRLF list boundaries. This evidence was supplied, not executed by this reviewer. (746af80caca5)
  • Regression coverage: The added cases cover fenced syntax, prose boundaries, incomplete fences, literal NUL handling, and HTTP extraction in both text and Markdown modes using the existing suite-level server. The PR records intended baseline failures and 109 passing candidate tests in 22.05 seconds; these tests were inspected but not rerun. (src/agents/tools/web-fetch-visibility.tool-extraction.test.ts:108, 746af80caca5)
  • Distinct merged sibling: fix(web-fetch): keep blank lines before lists in text extraction #164692 is merged and fixes LF/CRLF list separation. Its discussion explicitly reserves fenced-code preservation for separate work, and its source patch changes only list whitespace matching. (src/agents/tools/web-fetch-utils.ts:371, f0a63179594d)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-04T13:58:24.210Z sha 6c363f1 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-04T14:08:51.480Z sha 6c363f1 :: needs maintainer review before merge. :: none

@obviyus

obviyus commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

Please review merged head 746af80caca566d13542e288d1cce96bd1754e15. The PR body now records a real Gateway before/after, a 14-case model-output comparison limited to fenced-code literals, failing-baseline/passing-candidate regressions, composition with #164692 for LF and CRLF, and one successful real gpt-5-mini call on this exact head. Contributor commits are preserved.

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit 4a90ec6 into openclaw:main Oct 4, 2026
114 checks passed
@obviyus

obviyus commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Landed as 4a90ec6. Thanks @ly85206559! Maintainer note: a diagnostic command I ran by mistake performed the squash merge, so the commit on main has the placeholder subject and body x. The authorship is correct (you're the author), and main won't be rewritten for this. The intended message, for the record:

fix(web-fetch): preserve code literals in text extraction (#164936)

Related: #164692. Text-mode web_fetch ran its Markdown-to-text conversion over fenced code blocks too, stripping comment markers (#), list syntax, links and inline backticks from code examples. Fenced code is now kept literal while prose is still converted. Markdown mode and the #164692 list-boundary handling (LF and CRLF) are unchanged, and a 14-case corpus diff against main differs only in fenced code. Proven with a real Gateway web_fetch (stripped on base, preserved here) and regression tests that fail on base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants