Repository navigation
fix: enforce Cloudflare binding timeout for non-streaming calls - #132
stackbilt-admin merged 4 commits into
Conversation
stackbilt-admin
left a comment
There was a problem hiding this comment.
Thanks. The binding path ignoring timeout was a real gap, and the approach looks right:
- the timer is cleared in
.finallyon both success and error; - the losing side of the race is handled;
- a timeout raises the same
TimeoutError/TIMEOUTthe HTTP providers use; - streaming opts out with
enforceTimeout: false, so its open timer doesn't run twice; - zero and negative timeout values disable this deadline; an omitted setting uses the existing 30-second default.
The first test (a binding call that never resolves) is a real regression test.
Changes requested:
-
Make the cleanup test prove cleanup. "clears the non-streaming timeout after a binding response" resolves the request and then advances time, but it would pass without
clearTimeout, and it also passes onmain. Please recordvi.getTimerCount()before the call and check it returns to that baseline after the response resolves. Please also add an error-path case: whenai.runrejects, the timer is cleared and the original error is surfaced, not aTimeoutError. -
Restore real timers in
afterEach.vi.useRealTimers()currently runs at the end of each test body. If an assertion fails or the test hangs, fake timers leak into later tests. The pattern instream-lifecycle.test.ts/resilience-context.test.tsis what we use elsewhere. -
Document the behavior change in the CHANGELOG and with a short README note:
BaseProviderdefaultstimeoutto 30000 ms, so non-streaming Workers AI calls that had no deadline are now limited to 30s by default.- The timeout applies per attempt, not to the whole operation.
TimeoutErroris retryable and the default allows 3 retries, so one logical request can take four attempts plus backoff. The factory can also fall back to another provider onTIMEOUT. - The Workers AI binding takes no abort signal, so
Promise.racestops waiting but does not cancel the call. A timed-out call may keep running alongside retries and may still incur charges. - For long generations, raise
timeout, lowermaxRetries, or use streaming.
A short code comment at the race site explaining the abandon-not-abort behavior would also help.
Optional, not blocking:
- Treat non-finite or > 2^31−1 timeouts as "no timeout".
setTimeoutclamps those values and fires almost immediately, sotimeout: Infinitywould now fail at once.makeRequesthas the same latent issue, so this could also be a follow-up. healthCheck()still calls the binding with no deadline. That's fine as a follow-up.
We plan to ship this as a patch release, since it makes an existing setting work. CI is waiting on maintainer approval for fork PRs. We'll require normal CI to pass on the final commit before merging. The failing supply-chain check is a known repo-level problem unrelated to this PR, tracked in #137.
|
Addressed the review feedback on the timeout change:\n\n- Added timer-count assertions for successful binding responses and a rejection-path regression test that preserves the original error.\n- Moved fake-timer cleanup into |
|
Thanks, the updates cover everything from the review. Before we can review it again, it needs a rebase: #139 (released as 1.24.0) changed |
a7d2a51 to
e207228
Compare
|
Thanks for the rebase and the updates. The cleanup tests now catch a missing Blocking
Please fix in the same round
Follow-up, not needed here: |
e207228 to
28a9100
Compare
|
Thanks for the update. This covers everything from the last review: only finite timeouts in Two small documentation fixes before we merge:
Optional: the first new test still calls |
Resolve the CHANGELOG conflict with 1.26.0 and Stackbilt-dev#147, describe the timeout behaviour without naming a release (it ships in the next one), and restore the blank line before ## [1.24.1]. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks again for this. To get it into the next release, we finished the last two docs items ourselves in one merge commit (559c36b) on your branch:
We didn't change any code or tests; the optional |
* chore: release 1.27.0 - Opt-in context-window routing and a better input estimate (#147) - Workers AI non-streaming binding timeout (#132) - Checkpoint and README version references updated Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs: 1.27.0 upgrade note for the Workers AI timeout and review fixes Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Kurt Overmier <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Fixes #131
Issue: #131
Cloudflare Workers AI binding calls made through non-streaming
generateResponsenow honor the providertimeoutsetting. Slow calls reject with the library'sTimeoutError, while successful calls clear their timer; streaming keeps its existing open-timeout handling.Tests:
npm testnpm run typechecknpm run buildnpm run test:worker-importgit diff --check