Skip to content

fix: keep the Gateway responsive while extracting web pages - #200925

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-web-readability-off-main-20260919
Nov 18, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-web-readability-off-main-20260919

Conversation

@steipete

@steipete steipete commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fetching a large HTML page can stall unrelated Gateway work while Readability parses and renders it. The existing async extractor still performed that CPU work on the Gateway thread.

User Impact

Readability extraction runs in a worker while preserving text, Markdown, titles, and the existing sanitized HTML size/depth limits. Cancellation and the existing HTTP request deadline stop the caller's wait; late extraction results cannot trigger fallback or enter the fetch cache.

Why This Change Was Made

The plugin uses the existing SDK worker transport, compute sizing, shared admission, and pending task/byte limits. The extraction request contract is unchanged. Sanitization, cap checks, DOM parsing, Readability, and rendering move together; there was no redundant DOM parse or defensive clone to delete.

Accepted cancellation tradeoff: extraction already admitted to a worker continues to completion after a rare caller abort or timeout, and its result is discarded. Work retains the existing HTML limits. Core owns the race against the HTTP guard's existing composed signal; the plugin does not receive cancellation or create another timeout.

The production delta is +67 lines: +62 source lines for the offload and lifetime boundary, plus five lines declaring the package-owned worker entry. There are no new dependencies, configuration options, caches, or schemas.

Evidence

Acceptance requires identical output and lower warm main-thread CPU/longest-callback p95. Any total-cost or first-use regression requires explicit owner acceptance.

The synthetic corpus has 20 pages across five article/document shapes and four sizes (50 KB, 250 KB, 900 KB, 2 MB), tested in text and Markdown modes. Five interleaved A1/A2/B rounds yielded 600 exact serialized-output matches in each of the source and packaged runs (1,200 comparisons total); all hashes also match the original checkout. The 2 MB cases preserve the existing null result after sanitization and the size cap.

Warm packaged metric per extraction Inline A1 Inline A2 Worker B
Main-thread CPU median 24.03 ms 23.85 ms 0.30 ms
Main-thread CPU p95 220.21 ms 226.68 ms 0.42 ms
Longest main callback median 23.17 ms 23.43 ms 0.11 ms
Longest main callback p95 208.29 ms 214.68 ms 0.20 ms
Total process CPU median 27.31 ms 25.99 ms 38.00 ms
Total process CPU p95 248.87 ms 255.87 ms 307.12 ms
Extraction wall time median 24.11 ms 23.93 ms 27.80 ms
Extraction wall time p95 223.30 ms 227.37 ms 235.64 ms

Node 26.12.1, 32 logical CPUs, 200 warmed samples per phase. Packaged-run host load fell from 32 to 24. Main-thread CPU uses threadCpuUsage; longest callbacks use async hooks without a spinning probe. Separate V8 sampling passes include collected objects: main allocation per 40 extractions was 2143.06/2131.89/9.81 MiB; total allocation was 2143.06/2131.89/2214.54 MiB. Retained RSS was not measured in isolated processes. This is extractor-owner proof, not a whole-Gateway surge benchmark.

The packaged first-use samples were 33 ms inline and 442 ms via the worker, including a 332 ms main callback in B. These are single first-use samples; A2 reused loaded dependencies and is not another cold control. The earlier source run measured 41/2,100 ms, with higher host load. The performance owner explicitly accepted the packaged total-CPU p95 increase of 20–23% and one-time first-use cost on November 17, 2026, in exchange for the measured warm main-thread responsiveness improvement. The measured median CPU increase remains 39–46%. The owner decision is posted verbatim in a PR comment.

Reproduce source: nice -n 10 node --import ./scripts/tsx.mjs extensions/web-readability/test/web-content-extractor.bench.ts <output.json>. For packaged proof, run pnpm build, copy the identical committed benchmark to dist/extensions/web-readability/test/web-content-extractor.bench.ts, and run that file with plain Node and an output JSON path. Remove the copied proof file afterward.

Focused proof covers the real worker's extraction output and real guarded HTTP abort/timeout flows, including discarded late results and no fallback/cache publication. The final candidate passed 51 focused tests across the extraction bridge, real HTTP abort/timeout and cache behavior, real worker extraction, and runtime process packaging. Both new cancellation regressions fail on the original bridge. pnpm check:changed completed: every gate passed except the moved assertion allowance and benchmark lint; both were corrected and passed focused reruns. The assertion baseline only shrinks, and benchmark cleanup adds braces, uses a nonmutating sort and removes a synchronous await. Core/UI/plugin/script/test typechecks, formatting, boundary checks, runtime import cycles and dead-export scans passed. Final git diff --check is clean.

The full local pnpm build passed in 6m 19s and the packaged-worker benchmark passed. Initial-head CI 44222426669 skipped build-artifacts; no build success is inferred from that skip. It caught the missing package workerEntries declaration, now fixed at its metadata owner: production/full-tree unused-file scans and 19 build-entry tests pass.

The remaining initial-run UI failure is proven inherited: ui/src/e2e/chat-heartbeat-activity-rollup.e2e.test.ts:61 expects “Heartbeat Respond” but renders “Used tools”. The same focused browser test fails on both the candidate and exact main parent fd2949d747c11a671676a1697232d67a6614772d, using a clean detached checkout and its own frozen dependency installation. Commit 18136c960eaf7 / PR #198133 introduced that assertion. This was a main regression, now repaired on newer main by 375daf6d3c3de / #200897. This lane does not duplicate that repair or treat the failure as noise. Final-head CI 44225226137, attempt 1 at 9d07b6fec8286783180905d197d87caf66d21087, completed with a different failure: boot-module-boundaries.e2e.test.ts / “keeps pending Inbox intent current across navigation”, at native-module-boundaries.test-support.ts:136 (dialog count remains 1 after Escape). Focused browser replays passed on both the exact parent and candidate. That does not prove a fix or establish inherited attribution; the CI failure remains unresolved and is not eligible for the inherited-red exception. The lead classified this as a hosted intermittent and authorized one failed-job-only rerun. Attempt 2 passed, including UI job134547388653 and the aggregate CI gate, on the unchanged exact head 9d07b6fec8286783180905d197d87caf66d21087. No inherited-red exception is used; the first failed attempt remains recorded.

Codex autoreview of the local candidate against fd2949d747c11a671676a1697232d67a6614772d: scoped clean through P2, no accepted/actionable findings. A fresh Codex review of the five-line worker-entry declaration is also clean through P2. Performance acceptance is not implied by either correctness review.

Final-head ClawSweeper reported no actionable code findings; its performance-cost decision is now explicitly accepted by the owner. Re-review is requested to reconcile that item. No merge has been submitted.

@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: web-readability size: L labels Nov 18, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please review the worker extraction and caller-owned abort/timeout boundary at e5a678f. The intentional tradeoff is that admitted worker work finishes after cancellation, while the caller promptly stops awaiting and discards the result. The public extraction request remains unchanged. The PR records the output-equality proof and the separate, pending performance-cost acceptance decision.

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Moves Readability extraction into the existing worker pool and stops awaiting extraction when the fetch is canceled or times out.

Example: Extract a 900 KB HTML article while the Gateway handles other requests.

  • Before: DOM parsing, Readability, and rendering occupy the Gateway thread.
  • After: The worker performs extraction, while cancellation or timeout rejects the waiting call and discards its late result.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused and useful, with sufficient owner-boundary proof and accepted performance costs; validation remains below shipped Gateway end-to-end coverage.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): The reported source and packaged benchmark exercises the production plugin and real worker with exact output comparisons, supported by real guarded-HTTP cancellation coverage; this establishes the accepted extractor-owner scope rather than whole-Gateway surge behavior, and the inspected screenshots concern the linked UI PR.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Fetching a large HTML page can stall unrelated Gateway requests during local extraction.
Reason: The measured warm responsiveness benefit addresses the reported problem, and the owner explicitly accepted the adverse CPU and first-use measurements.

Merge readiness

✅ Ready for maintainer review

This PR addresses a current main-thread bottleneck without actionable code findings. The recorded owner acceptance resolves the previous performance decision; exact-head CI remains incomplete.

Priority: P2
Reviewed head: 9d07b6fec8286783180905d197d87caf66d21087

Before merge

None.

Findings

None.

Agent review details

How this fits together

The web_fetch tool downloads guarded HTTP content, dispatches HTML to plugin-owned extractors, and publishes readable text through its existing fallback and cache owners.

flowchart LR
  A[web_fetch request] --> B[Guarded HTTP fetch]
  B --> C[Extractor bridge]
  C --> D[Shared compute worker pool]
  D --> E[Readability and rendering]
  E --> F[Result publication]
  B --> G[Caller and deadline signal]
  G --> C
Loading

Technical review

Best possible solution:

Retain plugin-owned extraction, the shared SDK worker pool, and caller-owned cancellation with the recorded performance tradeoff.

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

Current main visibly performs CPU-heavy parsing and rendering on the calling thread; this read-only review did not execute target code.

Is this the best way to solve the issue?

The change uses existing transport, admission, sizing, and cancellation owners while preserving the extraction algorithm, making it a focused fix rather than a parallel implementation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Plugin-owned extraction and output keeps the original intent (86099ec: Keep DOM/Readability dependencies in the enabled bundled plugin while preserving default web-fetch behavior.)
  • Lazy DOM dependency loading changes intended behavior with a stated reason (7e55839: Reduce first-extraction loading work through LinkeDOM's public bundled entry without changing extraction contracts.)
  • Best-effort extractor fallback changes intended behavior with a stated reason (0b8aabe: One failing extractor must not prevent later plugins from processing the page; this PR preserves ordinary fallback while making caller cancellation terminal.)
  • Bun response abort propagation keeps the original intent (58253d1: Propagate post-header aborts through foreign Undici response streams under Bun; the response wrapper remains behaviorally unchanged.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit 86099ec adds src/web-fetch/content-extractors.runtime.ts:45 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 86099ec62a41; files: src/web-fetch/content-extractors.runtime.ts)

PR surface

Source +62, Tests +331, Docs +5, Config +5, Generated 0, Other -1. Total +402 across 16 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 8 225 163 +62
Tests 3 331 0 +331
Docs 1 6 1 +5
Config 1 5 0 +5
Generated 2 2 2 0
Other 1 0 1 -1
Total 16 569 167 +402

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus proof growth Production +67 lines; regression tests +89; benchmark +242 Excludes generated outputs and docs; growth supports worker packaging, the cancellation boundary, and a rerunnable performance comparison.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove merge-risk: 🚨 compatibility: Current PR review merge-risk labels are merge-risk: 🚨 availability.
  • remove status: ⏳ waiting on maintainer: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Large-page extraction can delay unrelated Gateway work, making this a useful bounded performance repair.
  • merge-risk: 🚨 availability: Worker execution increases total CPU and first-use latency; the owner explicitly accepted these measured costs for improved warm Gateway responsiveness.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • 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 (3 earlier review cycles)
  • reviewed 2026-11-18T02:27:22.152Z sha e5a678f :: blocked before merge. :: none
  • reviewed 2026-11-18T02:49:16.570Z sha 9d07b6f :: blocked before merge. :: none
  • reviewed 2026-11-18T02:55:33.810Z sha 9d07b6f :: blocked before merge. :: none

Reviewed November 17, 2026, 10:15 PM ET / November 18, 2026, 03:15 UTC (Revision 4).

@steipete
steipete marked this pull request as ready for review November 18, 2026 02:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T02:45:01.385113Z 9d07b6f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete

Copy link
Copy Markdown
Contributor Author

Addressing the latest review’s open item against 9d07b6fec8286783180905d197d87caf66d21087:

  1. Resolve merge risk / attribute check-dependencies — fixed as a PR defect. The failed log identified web-content-extractor.worker.ts and its imported runtime as unused. The package was missing its worker declaration. package.json lines 15–19 now declare that real entrypoint through the existing openclaw.build.workerEntries owner. No lint ignore or baseline exception was added. pnpm deadcode:unused-files now passes both production and full-tree scans; all 19 build-entry tests pass. Fresh scoped Codex review is clean through P2.

The other initial-run failure is separately proven inherited: the heartbeat-rollup browser test expects “Heartbeat Respond” but renders “Used tools”. The same focused test fails on both this candidate and exact main parent fd2949d747c11a671676a1697232d67a6614772d with an isolated frozen install. 18136c960eaf7 / #198133 introduced the assertion at test line 61. This is a main regression requiring repair, not an ignored failure. No UI code changed here.

The body now includes the successful full local build and another 600 exact comparisons through the built worker. The original extraction/HTTP/packaging proof has 51 passing tests. The requested owner-level corpus proof is complete; no whole-Gateway surge proof is claimed. Packaged measurements refine the adverse costs to +20–23% total CPU p95 and a 442 ms first-use sample (332 ms main callback). Explicit performance-cost acceptance remains pending. Normal CI is being attached to the final head; neither prior-head CI nor review is being called final-head green.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 18, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Lead (owner) decision for #200925, recorded for the PR per the performance skill:

ACCEPTED: +20–23% total CPU p95 per extraction, plus a one-time first-use cost of 442 ms (332 ms main callback) per process for the worker/module load, in exchange for main-thread CPU p95 dropping 220–227 ms → 0.42 ms and longest callback p95 208–215 ms → 0.20 ms with byte-equal output. Rationale: on Team the Gateway main thread is the scarce resource (ELU pinned at 1.0 for long stretches today, 16+ cores mostly idle), so moving parse work to a worker at some extra total CPU is the right trade. The first-use cost is once per Gateway process.

  1. Acceptance item addressed by the explicit owner decision above. The worker transport and accepted abort behavior remain at extensions/web-readability/web-content-extractor-worker.runtime.ts:11; the measured cost and byte-equality proof remain in the PR body. No source changes since reviewed head 9d07b6fec8286783180905d197d87caf66d21087.

The lead classifies the Inbox UI CI failure as a hosted intermittent after passing candidate and parent replays, and authorizes one failed-job-only rerun. A repeated failure will be diagnosed rather than waived as inherited.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 18, 2026
@steipete
steipete merged commit a2c1b0e into main Nov 18, 2026
377 of 381 checks passed
@steipete
steipete deleted the steipete/perf-micro-web-readability-off-main-20260919 branch November 18, 2026 03:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…#200925)

* perf(web-fetch): offload readability extraction through SDK workers

* fix(web-readability): declare the worker build entry
RomneyDa added a commit that referenced this pull request Nov 19, 2026
* perf(web-fetch): offload readability extraction through SDK workers

* fix(web-readability): declare the worker build entry

(cherry picked from commit a2c1b0e)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…#200925)

* perf(web-fetch): offload readability extraction through SDK workers

* fix(web-readability): declare the worker build entry

Release adaptation: Reviewed readability worker and unchanged redirect helper extraction; shrink-only assertion baseline preserved.

(cherry picked from commit a2c1b0e)

Co-authored-by: RomneyDa <[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 extensions: web-readability merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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.

1 participant