Conversation
Session.run() passed `{ signal }` as a third argument to fetch(), which
fetch ignores. The `timeout` option and a caller's `signal` never reached
the request, so a slow or hung inference host left run() pending until
the worker was killed.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Supabase.ai.Session.run()builds an abort signal fromopts.timeout(60s by default) andopts.signal, and then passes it as a third argument tofetch():fetch()only takes(input, init), so the signal never reaches the request. If the inference host (for example Ollama) is slow or hangs before it sends headers, then:run("…", { timeout: 2 })keeps waiting after 2 seconds.run("…", { signal })keeps waiting after the caller aborts.The signal is only checked later, between body reads in
parseJSON, which does nothing whilefetch()itself is still pending.I reproduced this on
supabase/edge-runtime:v1.77.1.AI_INFERENCE_API_HOSTpointed at a TCP server that accepts the connection and never answers:What is the new behavior?
The signal goes into the
fetch()init, so both the timeout and the caller's signal abort the request:Normal completions are unchanged. I checked an
ollamaand anopenaicompatiblenon-stream response against a fake host, and both still resolve.Tests
This adds
test_supabase_ai_inference_api_honors_timeout_and_signaland the test casescrates/base/test_cases/ai-inference-api/{main,abort}. The Rust test starts a listener that accepts and never answers, and passes its address to the user worker asAI_INFERENCE_API_HOST. The worker then checks thattimeout: 1rejects withTimeoutErrorand that an abortedsignalrejects with its reason.I didn't do a full local build of the runtime. Instead, I ran these exact test case files through the released binary:
v1.77.1as released{"timeout":"still pending","signal":"still pending"}, HTTP 500, after about 20sai.jssource{"timeout":"TimeoutError: Signal timed out.","signal":"Error: caller aborted"}, HTTP 200, after 1.7sThe changed files pass
dprint check. CI will run the Rust test itself.Additional context
The third-argument call has been there since
383dd52(2025-01-09).This PR was prepared with AI assistance (Claude). I reproduced the bug and checked the fix as described above.