Repository navigation
fix(adapters): bound each date-extraction model call (#42) - #59
Merged
Merged
Conversation
A provider that never answers held the mailbox watcher forever: nothing in Mastra, the AI SDK or Bun's fetch sets a whole-call deadline. dateExtractorLayer gains timeoutMs (default 120 s), enforced with Effect.timeoutOrElse, which interrupts the call and aborts its request; the call fails with a DateExtractionError naming the timeout, and the run fails as any other.
dVelopment
marked this pull request as ready for review
November 7, 2026 12:15
dVelopment
self-requested a review
November 7, 2026 12:15
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.
Closes #42
A DateExtractor model call that never answers no longer holds the mailbox watcher. Each
extractcall now has a deadline (default 2 minutes, retries included). A call that runs out of time is aborted, HTTP request included, and fails like any other failed run, so the watcher takes the next mail.Does the client have a default timeout?
No timeout bounds the whole call. The only one is Bun's socket idle timeout of 5 minutes, and every byte received restarts it.
@mastra/core@1.80.0,dist/agent-b2Y5GsZg.js):Agent.generateruns the loop'sexecute(~L34047), which callsmodel.doGeneratewithabortSignal: callAbortSignal(~L34146).createTimeoutAbortSignal({ parentSignal, timeoutMs: timeout?.stepMs })(~L34126).modelSettings.timeoutisundefinedunless the caller sets it. In that casecreateTimeoutAbortSignal(L796) returns the caller's signal as it is, with no timer.p-retrywithretries: modelSettings?.maxRetries ?? 2, and hex'sStreamErrorRetryProcessor(maxRetries: 2) adds retries of its own.dist/netlify-CGQcc7B9.js):createAnthropic({ apiKey, baseURL, headers })(L42185), with nofetchand no timeout.@ai-sdk/anthropic@3.0.133doGeneratepasses onlyoptions.abortSignaltopostJsonToApi(L14710–14720).@ai-sdk/provider-utils@4.0.61postToApi(L2347) callsglobalThis.fetch(url, { …, signal: abortSignal })and adds no timeout.fetch: seeBunFetchRequestInit.timeout(also inbun-types@1.4.4,globals.d.tsL2163). It is a socket idle timeout: "The timer is reset on every byte sent or received". Its default is 5 minutes (BUN_CONFIG_HTTP_IDLE_TIMEOUT, since Setfetchtimeout to 5 minutes oven-sh/bun#6217), and the docs say: "This is not a whole-request deadline; useAbortSignal.timeout(ms)for that."What changed
packages/adapters/src/date-extractor.ts: newDateExtractorOptions.timeoutMs, default120_000.Effect.timeoutOrElseon theEffect.tryPromisearoundagent.generate, so it covers Mastra's retries andStreamErrorRetryProcessor's.tryPromiseaborts the signal passed asabortSignal. Mastra checks that signal before retrying, and the provider'sfetchreceives it.DateExtractionError:reading the Document date of "<file>" with <model> timed out after <N> ms. The error type is unchanged and still carries no cause.MAX_FAILED_RUNS.packages/server/test/mock-model.ts: thebeforehook now wrapsdoGenerateas well asdoStream.agent.generatecallsdoGenerate, so before this change the hook never ran for the extractor.How it was proven
packages/adapters/test/date-extractor.test.ts: a mock model that never answers,timeoutMs: 50. The call fails with the timeout message in under 1 s, after one call, and the model's abort signal is aborted.timeoutMs: 100andretryDelayMs: 1000. The call fails with the timeout message in under 500 ms (about 100 ms in practice), after one model call. With a per-attempt deadline instead, the test fails: the retry waits out the backoff and succeeds after about 1037 ms.packages/server/test/mailbox-watcher.test.ts: end-to-end with the livedateExtractorLayerover a mock model whose first call hangs.failed run 1 of 5), and its mail stays in the watched folder.dateExtractorLayer("openai/gpt-5-mini", { timeoutMs: 1500 }), withOPENAI_BASE_URLpointing at a loopback server that accepts the request and never answers.DateExtractionError: reading the Document date of "smoke.pdf" with openai/gpt-5-mini timed out after 1500 ms.fetch.bun run checkpasses on43cb98615(format, lint, typecheck, manifests, licenses, tests): 1019 pass, 0 fail.43cb98615). A recheck found nothing above low.Action items
timeoutMsinpackages/eval-harness(recommended over raising the production default).bun run checkand the smoke ran on Bun 1.4.4, the local system Bun. CI covers 1.4.2.