Repository navigation
fix(agents): web_fetch leaves body open after provider fallback - #111332
nocodet888-arch wants to merge 1 commit into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 19, 2026, 10:56 AM ET / 14:56 UTC. Summary 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 follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest 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 AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6dc6d5efeeb7. Label changesLabel justifications:
Evidence reviewedPR surface: Source +10, Tests +289. Total +299 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (4 earlier review cycles)
|
986cb02 to
4e29b12
Compare
|
@clawsweeper re-review Strengthened proof: added second cancel-path test for readability-disabled HTML provider fallback ( |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
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]>
4e29b12 to
578466d
Compare
|
@clawsweeper re-review Addressed the awaited-cancel availability risk (fire-and-forget
Updated PR body + log at |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
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. |
What Problem This Solves
Fixes an issue where
web_fetchcould leave an upstream response body open when a non-OK (or extraction-failed) response was abandoned after a successful provider fallback return.finallyonly calledrelease(); 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-settlingcancel()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=verboseLive log:
/tmp/proof-111332-live.txtReal 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 →maybeFetchProviderWebFetchPayloadsuccess →cancelUnreadWebFetchBody(res)(fire-and-forget) → return payload →release().Boundary crossed: Abandoned upstream HTTP body stream →
body.cancel()before fallback return; realnode:http503 upstream closed (server_closed=true) after cancel.Shared helper / provider constraint check: Local
cancelUnreadWebFetchBodyusesvoid body?.cancel().catch(() => undefined)(same best-effort pattern asreadResponseTextinweb-shared.ts).Observed result after fix:
cancel_invoked=1 server_closed=true extractor=custom-provideron 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