Skip to content

Apply the webFetch timeout to the response body - #102

Open
RenKoya1 wants to merge 1 commit into
cloudflare:mainfrom
RenKoya1:fix/webfetch-body-timeout
Open

Apply the webFetch timeout to the response body#102
RenKoya1 wants to merge 1 commit into
cloudflare:mainfrom
RenKoya1:fix/webfetch-body-timeout

Conversation

@RenKoya1

@RenKoya1 RenKoya1 commented Aug 9, 2026

Copy link
Copy Markdown

webFetch arms a 30s abort timer, but clears it in the finally of the fetch() call — which resolves as soon as the response headers arrive. The body read that follows therefore runs with no deadline: a response whose headers arrive promptly and whose body then stalls holds the agent's webFetch tool call open until the Worker itself gives out. HARD_MAX_BYTES bounds the size, not the time.

The change keeps the timer armed across the body read and clears it in a single finally, so an abort mid-body surfaces as the same Fetch timed out after 30000ms error the header path already produces. The diff looks larger than it is — most of it is the existing final-URL / Content-Signal / readBodyCapped block moving inside the try unchanged.

Verification

Added a regression test that stubs fetch with a body that yields one chunk and then only ends on abort, and advances fake timers past the deadline.

  • Without the fix: the test hangs and fails on the 5s vitest timeout; the captured AbortSignal is still un-aborted after 60 simulated seconds.
  • With the fix: webFetch rejects with Fetch timed out after 30000ms.

pnpm exec tsc --noEmit clean, workshop-backend suite 280/280 passing, oxlint reports nothing new.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

The 30s timeout was cleared as soon as fetch() resolved, which is when
headers arrive. A response whose body then stalled was read with no
deadline at all, so the agent's webFetch tool call could hang until the
Worker itself gave out.

Keep the timer armed across the body read and clear it in one finally,
so an abort mid-body surfaces as the same "Fetch timed out" error.
@RenKoya1
RenKoya1 force-pushed the fix/webfetch-body-timeout branch from 4c064b0 to 7de89a2 Compare August 9, 2026 17:09
@RenKoya1

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant