Skip to content

fix(agents): web_fetch leaves body open after provider fallback - #111332

Closed
nocodet888-arch wants to merge 1 commit into
openclaw:mainfrom
nocodet888-arch:fix/web-fetch-cancel-fallback-body
Closed

nocodet888-arch wants to merge 1 commit into
openclaw:mainfrom
nocodet888-arch:fix/web-fetch-cancel-fallback-body

Conversation

@nocodet888-arch

@nocodet888-arch nocodet888-arch commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where web_fetch could leave an upstream response body open when a non-OK (or extraction-failed) response was abandoned after a successful provider fallback return. finally only called release(); the unread (or abandoned) body was never cancelled.

Why This Change Was Made

Before returning a provider-fallback payload that abandons the direct fetch response, cancel the response body best-effort (void body?.cancel().catch(...)), matching the cancel-before-release campaign used elsewhere in core. Cancellation is fire-and-forget so a never-settling cancel() cannot hang a successful fallback. Covers both the non-OK early-return path and the readability-disabled HTML fallback return path.

User Impact

Before: Successful provider fallback after a non-OK upstream (or after skipping local HTML extraction) could retain an abandoned response stream until GC. An awaited cancel could also stall the fallback return.

After: The abandoned upstream body is cancelled without awaiting before returning the fallback payload; dispatcher release still runs in finally.

Evidence

Proof (exit 0)

node scripts/run-vitest.mjs src/agents/tools/web-fetch.provider-fallback.test.ts -t "cancels an unread non-OK|cancels the response body when readability|does not block provider fallback|cancels unread non-OK body over real" --reporter=verbose
[web-fetch non-ok fallback cancel proof] cancelled=true extractor=custom-provider
[web-fetch readability-off fallback cancel proof] cancel_invoked=true extractor=custom-provider
[web-fetch never-settling cancel proof] returned=true elapsed_ms=1 extractor=custom-provider
[web-fetch live guarded HTTP cancel proof] url_host=127.0.0.1 cancel_invoked=1 server_closed=true extractor=custom-provider elapsed_ms=192

 ✓ cancels an unread non-OK response body when provider fallback succeeds
 ✓ cancels the response body when readability-disabled fallback succeeds
 ✓ does not block provider fallback when body cancel never settles
 ✓ cancels unread non-OK body over real guarded HTTP when provider fallback succeeds

 Test Files  2 passed (2)
 Tests  8 passed | 10 skipped (18)

Live log: /tmp/proof-111332-live.txt

Real behavior proof

  • Behavior or issue addressed: Non-OK and readability-disabled HTML upstream bodies are cancelled when provider fallback succeeds and returns early; never-settling cancel() cannot block the return.

  • Canonical reachability path: createWebFetchTool → guarded fetch → maybeFetchProviderWebFetchPayload success → cancelUnreadWebFetchBody(res) (fire-and-forget) → return payload → release().

  • Boundary crossed: Abandoned upstream HTTP body stream → body.cancel() before fallback return; real node:http 503 upstream closed (server_closed=true) after cancel.

  • Shared helper / provider constraint check: Local cancelUnreadWebFetchBody uses void body?.cancel().catch(() => undefined) (same best-effort pattern as readResponseText in web-shared.ts).

  • Observed result after fix: cancel_invoked=1 server_closed=true extractor=custom-provider on real guarded loopback HTTP; never-settling cancel returns in ~1ms.

  • Fix classification: Root cause fix

  • AI-assisted (Cursor)

  • I understand what the code does

  • Change is focused and does not mix unrelated concerns

@nocodet888-arch
nocodet888-arch marked this pull request as ready for review July 19, 2026 09:09
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jul 19, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 19, 2026
@clawsweeper

clawsweeper Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 19, 2026, 10:56 AM ET / 14:56 UTC.

Summary
The PR cancels unread upstream response bodies before three successful provider-fallback early returns in web_fetch and adds regressions for non-OK, readability-disabled, non-settling, and guarded HTTP paths.

PR surface: Source +10, Tests +289. Total +299 across 2 files.

Reproducibility: yes. from source and supplied terminal evidence: a guarded non-OK response whose provider fallback succeeds reaches an early return with an unread body, and the added loopback HTTP regression verifies cancellation and server closure.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Refresh the merge result and required checks against current main before landing.

Risk before merge

  • [P1] GitHub reports the branch as behind main; refresh the merge result and required checks against the current base before landing.

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused cancellation helper and regressions once the current-head merge/check gate is refreshed, preserving the non-blocking cancellation behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] No repair lane is needed: the previous awaited-cancel blocker is addressed and the remaining action is routine maintainer merge review on the refreshed base.

Security
Cleared: The patch changes response-stream cleanup and tests only; no concrete security or supply-chain concern is visible in the supplied diff.

Review details

Best possible solution:

Land the focused cancellation helper and regressions once the current-head merge/check gate is refreshed, preserving the non-blocking cancellation behavior.

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

Yes, from source and supplied terminal evidence: a guarded non-OK response whose provider fallback succeeds reaches an early return with an unread body, and the added loopback HTTP regression verifies cancellation and server closure.

Is this the best way to solve the issue?

Yes. Cancelling only the response body that is abandoned by a successful fallback, while retaining finally-based dispatcher release and avoiding an awaited cancellation, is the narrowest root-cause repair.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6dc6d5efeeb7.

Label changes

Label justifications:

  • P2: This is a bounded agent web-fetch resource-cleanup fix with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides after-fix terminal output from a guarded real loopback HTTP path showing cancellation and server closure, as well as a non-settling cancellation check that preserves fallback availability.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix terminal output from a guarded real loopback HTTP path showing cancellation and server closure, as well as a non-settling cancellation check that preserves fallback availability.
Evidence reviewed

PR surface:

Source +10, Tests +289. Total +299 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 0 +10
Tests 1 289 0 +289
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 299 0 +299

What I checked:

  • Root-cause patch: The PR adds cancelUnreadWebFetchBody, using void response.body?.cancel().catch(() => undefined), then calls it immediately before each provider-fallback return that abandons the original response body. (src/agents/tools/web-fetch.ts:565, 578466dfcebc)
  • Previous finding addressed: The prior review identified an unbounded awaited cancellation; the current patch uses a non-awaited cancellation and adds a regression where cancellation never settles while fallback returns promptly. (src/agents/tools/web-fetch.provider-fallback.test.ts, 578466dfcebc)
  • After-fix behavior proof: The PR body includes terminal output for a guarded loopback HTTP 503 path reporting cancel_invoked=1, server_closed=true, and a successful provider fallback, plus a non-settling cancellation returning in approximately 1 ms. (src/agents/tools/web-fetch.provider-fallback.test.ts, 578466dfcebc)
  • Scope and security pass: The supplied diff is limited to web_fetch resource cleanup and its focused tests; it does not add dependencies, workflow changes, credentials handling, permissions, or artifact execution. (src/agents/tools/web-fetch.ts:565, 578466dfcebc)

Likely related people:

  • unresolved: The available review evidence identifies the proposed head but does not provide sufficient current-main blame or feature-history provenance to route this cleanup path to a specific person without guessing. (role: current-main history owner not established; confidence: low; files: src/agents/tools/web-fetch.ts, src/agents/tools/web-fetch.provider-fallback.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (4 earlier review cycles)
  • reviewed 2026-07-19T09:13:14.539Z sha 986cb02339e6753c83548fd860bfc83da0ac2102 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-19T11:30:23.027Z sha 4e29b1245c1d99312e09966058718b2bda09706b :: needs real behavior proof before merge. :: [P2] Do not await an unbounded response-body cancellation
  • reviewed 2026-07-19T12:12:48.182Z sha 4e29b1245c1d99312e09966058718b2bda09706b :: needs real behavior proof before merge. :: [P2] Do not await an unbounded response-body cancellation
  • reviewed 2026-07-19T14:13:51.505Z sha 578466d :: needs maintainer review before merge. :: none

@nocodet888-arch
nocodet888-arch force-pushed the fix/web-fetch-cancel-fallback-body branch from 986cb02 to 4e29b12 Compare July 19, 2026 11:26
@nocodet888-arch

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Strengthened proof: added second cancel-path test for readability-disabled HTML provider fallback (cancel_invoked=true). Both cancel paths covered with verbatim logs. Rebased onto latest main.

@clawsweeper

clawsweeper Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 19, 2026
Fire-and-forget cancel abandoned upstream bodies before provider-fallback
early returns so release() does not leave streams open, without awaiting
cancel() (never-settling streams must not hang a successful fallback).

Co-authored-by: Cursor <[email protected]>
@nocodet888-arch
nocodet888-arch force-pushed the fix/web-fetch-cancel-fallback-body branch from 4e29b12 to 578466d Compare July 19, 2026 14:10
@nocodet888-arch

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the awaited-cancel availability risk (fire-and-forget void body?.cancel().catch(...)) and added:

  • never-settling cancel regression (fallback returns in ~1ms)
  • real node:http guarded HTTP proof: cancel_invoked=1 server_closed=true extractor=custom-provider

Updated PR body + log at /tmp/proof-111332-live.txt on the proof host.

@clawsweeper

clawsweeper Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for identifying the unread web-fetch response-body leak. The canonical fix is now merged in #115759 and credits your original contribution as a commit co-author. It closes the response in one guarded cleanup for both successful and failing provider fallbacks; 184 focused tests and real guarded HTTP socket cleanup pass.

@steipete steipete closed this Jul 29, 2026
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. 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