Repository navigation
fix(webfetch): drain fallback response bodies - #1094
Merged
Merged
Conversation
Adapt the lifecycle hardening proposed by @Indosaram in code-yeongyu/pi-webfetch#7 while preserving Senpi's bounded Undici dump path. Bodies without dump() are drained before quiet destruction, and discard-time stream errors are guarded from escaping the process.
Record why the vendored cleanup cannot be implemented through extension hooks and attach machine-readable credit for the lifecycle design adapted from pi-webfetch PR #7. Ultraworked with [omo](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Indosaram <47408490+Indosaram@users.noreply.github.com> Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
Attach stream error handling before discard begins, thread the request abort signal through cleanup, and stop fallback iteration when the size bound is crossed. Add regressions for listener ordering, stalled iterators, and bounded iteration. Ultraworked with [omo](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Indosaram <47408490+Indosaram@users.noreply.github.com> Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
undicibody does not exposedump()dump({ limit: 1024 })pathUpstream credit
This adapts the lifecycle hardening proposed by @Indosaram in code-yeongyu/pi-webfetch#7. The upstream PR identified that immediate destruction leaves the no-
dump()body undrained and that discard-time stream errors need an attached listener before destruction.Verification
dump()body was drained and that an error listener was attached before destructionnpm test -- test/suite/regressions/1089-webfetch-bun-body-discard.test.ts test/extensions-webfetch.test.ts— 2 files, 6 tests passednpm run check— passed200 https://httpbingo.org/get, exit 0, no uncaught exceptionfetcher.ts236,response-body.ts30, regression test 101Follow-up to #1091.
Summary by cubic
Drains Bun-compatible webfetch response bodies, guards discard-time stream errors, and makes cleanup abort-aware. Previously, bodies without
dump()were destroyed immediately and could remain undrained or emit unhandled errors; now we attach an error listener before discard begins, drain up to the 5MB limit or until aborted, usedump({ limit: 1024, signal })when available, and always destroy afterward.response-body.tswithdiscardBody(body, maxBytes, signal)andtoUint8Array;fetcher.tsimports these and passesMAX_RESPONSE_SIZE_BYTESfor redirects and oversizedcontent-length.dump()exists, calldump({ limit: 1024, signal })then destroy; otherwise, bounded, abort-aware async drain then destroy; drain failures are swallowed.errorlistener before discard starts so stream errors during best-effort cleanup do not surface as uncaught process errors.webfetch/changes.mdto credit upstreampi-webfetchfix(coding-agent): avoid fork-only pi-ai imports #7 and note why extension hooks cannot replace this vendored cleanup.Written for commit 3d3d049. Summary will update on new commits.