Skip to content

fix(web-fetch): keep code indentation when extracting Markdown as text - #172389

Merged
obviyus merged 3 commits into
openclaw:mainfrom
ly85206559:codex/fix-web-code-whitespace-20261015
Oct 16, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
ly85206559:codex/fix-web-code-whitespace-20261015

Conversation

@ly85206559

@ly85206559 ly85206559 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes code indentation, repeated spaces, and blank lines being lost when web_fetch extracts 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 060a63ff446a05ec469d4d9197af74536681f884 and the candidate separately, then invoked the registered web_fetch through an authenticated Gateway /tools/invoke request against a local HTTP Markdown page. No model/provider was involved.

Both baseline requests returned corrupted code:

 if enabled:
 print("two spaces")

	return True

Both candidate requests preserved the expected code (including the two blank lines and the tab before return):

    if enabled:
        print("two  spaces")


	return True

Observed results:

  • Current main: both code-preservation checks failed; prose and unchanged Markdown-output controls passed.
  • Candidate: both code-preservation checks and both controls passed.
  • Final consolidated HTTP extraction suite: 7 tests passed; targeted Oxfmt and Oxlint checks passed.
  • Earlier harness syntax failure was corrected before any Gateway execution; it is not counted as a product reproduction.

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.

@clawsweeper

clawsweeper Bot commented Oct 14, 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.

@ly85206559
ly85206559 marked this pull request as ready for review October 14, 2026 17:55
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Oct 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 14, 2026
@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves fenced-code whitespace when web_fetch converts Markdown responses to text.

Example: Fetch a Markdown Python example with extractMode set to text.

  • Before: Eight-space indentation becomes one space, print("two spaces") loses a space, and consecutive blank lines collapse.
  • After: The indentation, repeated spaces, tabs, and internal blank lines remain intact.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused correction with shipped-entry-point before/after evidence, useful HTTP regression coverage, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies actual output from a secretless Linux built Gateway invoking registered web_fetch through authenticated /tools/invoke against real HTTP Markdown: baseline code whitespace is corrupted and candidate output is preserved, with prose and Markdown-mode controls passing; contributor evidence additionally covers incomplete fences, and the production converter is unchanged since that proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Agents receive code examples with corrupted indentation and literal spacing when fetching Markdown as text.
Reason: The change restores usable code examples within the existing extraction contract and preserves ordinary prose conversion and Markdown mode.

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
Reviewed head: 975ccade7044ca86e30214d52166c49a63a2ba86

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Fenced-code whitespace normalization changes intended behavior with a stated reason (4a90ec6: The earlier literal-protection PR explicitly restored code before existing normalization and excluded exact whitespace preservation from its scope.)
  • Incomplete-fence regression coverage keeps the original intent (e9938e3: Protect incomplete code while retaining unmatched-inline-fence prose; the consolidated fixture preserves those checks and adds whitespace expectations.)
  • Extraction-mode documentation keeps the original intent (5f19e28: The parameter documentation describes extraction output; the addition explains the corrected text-mode contract.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ben.Li: Raw commit 4a90ec6 adds src/agents/tools/web-fetch-utils.ts:337 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4a90ec622ffa; files: src/agents/tools/web-fetch-utils.ts)
  • Peter Steinberger: Raw commit 568b8ee adds src/agents/tools/web-fetch-utils.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 568b8ee96ce2; files: src/agents/tools/web-fetch-utils.ts)
  • Yuval Dinodia: Raw commit f0a6317 adds src/agents/tools/web-fetch-utils.ts:363 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: f0a63179594d; files: src/agents/tools/web-fetch-utils.ts)

PR surface

Source +1, Tests +4, Docs +2. Total +7 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 3 +1
Tests 1 8 4 +4
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 15 8 +7

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Whitespace corruption makes fetched code examples unreliable, with impact limited to text extraction.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-14T18:13:59.992Z sha bbf6cff :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-14T18:54:26.181Z sha bbf6cff :: needs maintainer review before merge. :: none

Reviewed October 16, 2026, 12:05 AM ET / 04:05 UTC (Revision 3).

@ly85206559

Copy link
Copy Markdown
Contributor Author

@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 bbf6cff27aa4c4dede53e73919ba4d277fb3b179 passes the supported CLI → authenticated /tools/invoke → registered web_fetch → real HTTP fixture path, including closed/incomplete code whitespace, prose, Markdown-mode, and 401/404 controls.

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 openclaw/ci-gate contexts also succeeded. No product changes since the reviewed head; requesting review only, not merge or repair execution.

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 14, 2026
@obviyus

obviyus commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 16, 2026
@obviyus
obviyus merged commit 42ff52b into openclaw:main Oct 16, 2026
120 of 123 checks passed
@obviyus

obviyus commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Landed in 42ff52b. Thanks @ly85206559. web_fetch now keeps code block whitespace intact.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
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]>
MarMarLabs pushed a commit to MarMarLabs/openclaw that referenced this pull request Oct 20, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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