Repository navigation
feat(api): add CompletePromptOptions parameter to completePrompt method - #901
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthrough
ChangesComplete prompt options
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/api/providers/base-openai-compatible-provider.ts (1)
215-229: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftThread
CompletePromptOptionsinto these completion requests.
abortSignalandtimeoutMsare defined onCompletePromptOptions, but everycompletePrompthere dropsoptions, so caller cancellation and per-call timeouts never reach the SDK request.
src/api/providers/base-openai-compatible-provider.ts#L215-L229src/api/providers/opencode-go.ts#L488-L537src/api/providers/openrouter.ts#L577-L606src/api/providers/poe.ts#L141-L147src/api/providers/qwen-code.ts#L330-L341src/api/providers/requesty.ts#L207-L221src/api/providers/unbound.ts#L195-L209src/api/providers/vercel-ai-gateway.ts#L120-L136🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/api/providers/base-openai-compatible-provider.ts` around lines 215 - 229, Thread CompletePromptOptions through each completePrompt implementation so abortSignal and timeoutMs reach the underlying SDK completion request. Update the request construction or invocation in src/api/providers/base-openai-compatible-provider.ts lines 215-229, src/api/providers/opencode-go.ts lines 488-537, src/api/providers/openrouter.ts lines 577-606, src/api/providers/poe.ts lines 141-147, src/api/providers/qwen-code.ts lines 330-341, src/api/providers/requesty.ts lines 207-221, src/api/providers/unbound.ts lines 195-209, and src/api/providers/vercel-ai-gateway.ts lines 120-136, reusing each provider’s existing request options and preserving current completion behavior.
🧹 Nitpick comments (1)
src/core/task/__tests__/Task.spec.ts (1)
2235-2252: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSimplify the mock stream factory.
The custom mock implementation manually overrides the async iterator protocol, but
for awaitloops rely exclusively on the[Symbol.asyncIterator]()method. Since that method returns a native generator, your customnext(),return(), andthrow()methods are bypassed as dead code, andcallCountis never actually incremented here.You can safely simplify this to a standard async generator function, which naturally fulfills the
AsyncGeneratorcontract and correctly increments your counter as intended:♻️ Proposed refactor
- const mockStreamFactory = () => { - return { - async *[Symbol.asyncIterator]() { - yield { type: "text", text: `response ${callCount}` } - }, - async next() { - callCount++ - return { done: true, value: { type: "text", text: `response ${callCount - 1}` } } - }, - async return() { - return { done: true, value: undefined } - }, - async throw(e: any) { - throw e - }, - [Symbol.asyncDispose]: async () => {}, - } as AsyncGenerator<ApiStreamChunk> - } + const mockStreamFactory = async function* (): AsyncGenerator<ApiStreamChunk> { + yield { type: "text", text: `response ${callCount}` } + callCount++ + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/core/task/__tests__/Task.spec.ts` around lines 2235 - 2252, Replace the custom object returned by mockStreamFactory with a standard async generator function. Move the callCount increment into the generator execution before yielding the response, remove the manually defined next, return, throw, and async iterator members, and preserve the existing response text and AsyncGenerator<ApiStreamChunk> contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/api/providers/gemini.ts`:
- Line 579: All completePrompt implementations accept CompletePromptOptions but
do not propagate cancellation or timeout settings to their requests. Update
src/api/providers/gemini.ts:579 in completePrompt to pass abortSignal to
generateContent; src/api/providers/minimax.ts:292-295 in completePrompt to pass
the signal to client.messages.create; src/api/providers/mistral.ts:195 in
completePrompt to pass abortSignal and timeoutMs to client.chat.complete;
src/api/providers/native-ollama.ts:553-579 in completePrompt to pass abortSignal
to client.chat; src/api/providers/openai-codex.ts:1157 in completePrompt to use
options?.abortSignal for fetch, preserving the existing controller as fallback;
src/api/providers/openai-compatible.ts:200 in completePrompt to pass abortSignal
to generateText; and src/api/providers/openai-native.ts:1487-1585 in
completePrompt to use options?.abortSignal for responses.create instead of
relying solely on the shared controller.
---
Outside diff comments:
In `@src/api/providers/base-openai-compatible-provider.ts`:
- Around line 215-229: Thread CompletePromptOptions through each completePrompt
implementation so abortSignal and timeoutMs reach the underlying SDK completion
request. Update the request construction or invocation in
src/api/providers/base-openai-compatible-provider.ts lines 215-229,
src/api/providers/opencode-go.ts lines 488-537, src/api/providers/openrouter.ts
lines 577-606, src/api/providers/poe.ts lines 141-147,
src/api/providers/qwen-code.ts lines 330-341, src/api/providers/requesty.ts
lines 207-221, src/api/providers/unbound.ts lines 195-209, and
src/api/providers/vercel-ai-gateway.ts lines 120-136, reusing each provider’s
existing request options and preserving current completion behavior.
---
Nitpick comments:
In `@src/core/task/__tests__/Task.spec.ts`:
- Around line 2235-2252: Replace the custom object returned by mockStreamFactory
with a standard async generator function. Move the callCount increment into the
generator execution before yielding the response, remove the manually defined
next, return, throw, and async iterator members, and preserve the existing
response text and AsyncGenerator<ApiStreamChunk> contract.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 098310bc-c298-461e-b612-f08806baff20
📒 Files selected for processing (30)
src/api/index.tssrc/api/providers/anthropic-vertex.tssrc/api/providers/anthropic.tssrc/api/providers/base-openai-compatible-provider.tssrc/api/providers/bedrock.tssrc/api/providers/fake-ai.tssrc/api/providers/gemini.tssrc/api/providers/kenari.tssrc/api/providers/lite-llm.tssrc/api/providers/lm-studio.tssrc/api/providers/minimax.tssrc/api/providers/mistral.tssrc/api/providers/native-ollama.tssrc/api/providers/openai-codex.tssrc/api/providers/openai-compatible.tssrc/api/providers/openai-native.tssrc/api/providers/openai.tssrc/api/providers/opencode-go.tssrc/api/providers/openrouter.tssrc/api/providers/poe.tssrc/api/providers/qwen-code.tssrc/api/providers/requesty.tssrc/api/providers/unbound.tssrc/api/providers/vercel-ai-gateway.tssrc/api/providers/vscode-lm.tssrc/api/providers/xai.tssrc/api/providers/zoo-gateway.tssrc/core/task/__tests__/Task.spec.tssrc/utils/__tests__/enhance-prompt.spec.tssrc/utils/single-completion-handler.ts
37133de to
62ed671
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/api/providers/base-openai-compatible-provider.ts (1)
215-243: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winUnused
optionsparameter incompletePromptimplementations.Although the
optionsparameter (containingabortSignalandtimeoutMs) is now included in thecompletePromptsignature across all providers, it is never forwarded to the underlying SDK clients (e.g., OpenAI or Anthropic). As a result, network requests will not actually be aborted when the cancellation signal is triggered, defeating the objective of stopping requests after cancellation.
src/api/providers/base-openai-compatible-provider.ts#L215-L243: Pass the options to the OpenAI client call:await this.client.chat.completions.create(params, { signal: options?.abortSignal, timeout: options?.timeoutMs }).src/api/providers/opencode-go.ts#L488-L545: Pass the options to both the Anthropic and OpenAI client calls.src/api/providers/requesty.ts#L207-L226: Pass the options to the OpenAI client call.src/api/providers/vercel-ai-gateway.ts#L120-L144: Pass the options to the OpenAI client call.src/api/providers/xai.ts#L145-L163: Pass the options to the Responses API client call.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/api/providers/base-openai-compatible-provider.ts` around lines 215 - 243, Forward CompletePromptOptions.abortSignal and timeoutMs to every underlying SDK request: update completePrompt in src/api/providers/base-openai-compatible-provider.ts (215-243), both Anthropic and OpenAI calls in src/api/providers/opencode-go.ts (488-545), the OpenAI call in src/api/providers/requesty.ts (207-226), the OpenAI call in src/api/providers/vercel-ai-gateway.ts (120-144), and the Responses API call in src/api/providers/xai.ts (145-163). Use each client’s request options so cancellation and timeouts are applied.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/api/providers/base-openai-compatible-provider.ts`:
- Around line 215-243: Forward CompletePromptOptions.abortSignal and timeoutMs
to every underlying SDK request: update completePrompt in
src/api/providers/base-openai-compatible-provider.ts (215-243), both Anthropic
and OpenAI calls in src/api/providers/opencode-go.ts (488-545), the OpenAI call
in src/api/providers/requesty.ts (207-226), the OpenAI call in
src/api/providers/vercel-ai-gateway.ts (120-144), and the Responses API call in
src/api/providers/xai.ts (145-163). Use each client’s request options so
cancellation and timeouts are applied.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9e539678-aff9-4a10-a391-e6ceb6abf6a6
📒 Files selected for processing (31)
src/api/index.tssrc/api/providers/__tests__/fake-ai.spec.tssrc/api/providers/anthropic-vertex.tssrc/api/providers/anthropic.tssrc/api/providers/base-openai-compatible-provider.tssrc/api/providers/bedrock.tssrc/api/providers/fake-ai.tssrc/api/providers/gemini.tssrc/api/providers/kenari.tssrc/api/providers/lite-llm.tssrc/api/providers/lm-studio.tssrc/api/providers/minimax.tssrc/api/providers/mistral.tssrc/api/providers/native-ollama.tssrc/api/providers/openai-codex.tssrc/api/providers/openai-compatible.tssrc/api/providers/openai-native.tssrc/api/providers/openai.tssrc/api/providers/opencode-go.tssrc/api/providers/openrouter.tssrc/api/providers/poe.tssrc/api/providers/qwen-code.tssrc/api/providers/requesty.tssrc/api/providers/unbound.tssrc/api/providers/vercel-ai-gateway.tssrc/api/providers/vscode-lm.tssrc/api/providers/xai.tssrc/api/providers/zoo-gateway.tssrc/core/task/__tests__/Task.spec.tssrc/utils/__tests__/enhance-prompt.spec.tssrc/utils/single-completion-handler.ts
🚧 Files skipped from review as they are similar to previous changes (17)
- src/utils/single-completion-handler.ts
- src/api/providers/bedrock.ts
- src/api/providers/qwen-code.ts
- src/api/providers/vscode-lm.ts
- src/api/providers/openai-codex.ts
- src/api/providers/mistral.ts
- src/api/providers/zoo-gateway.ts
- src/api/providers/openai.ts
- src/api/providers/openrouter.ts
- src/api/providers/minimax.ts
- src/api/providers/anthropic-vertex.ts
- src/api/providers/kenari.ts
- src/api/providers/unbound.ts
- src/api/providers/openai-compatible.ts
- src/api/providers/native-ollama.ts
- src/core/task/tests/Task.spec.ts
- src/api/providers/openai-native.ts
edelauna
left a comment
There was a problem hiding this comment.
to minor comments about consistency, but otherwise looks good.
Add optional second parameter to all provider completePrompt methods for future abort signal and timeout support. - Add CompletePromptOptions interface with abortSignal and timeoutMs fields - Update 25+ provider implementations to accept options?: CompletePromptOptions parameter - Simplify providers to use basic request calls without signal/timeout logic
Co-authored-by: edelauna <54631123+edelauna@users.noreply.github.com>
6d67b5c to
98201f4
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/api/providers/base-openai-compatible-provider.ts`:
- Line 215: Forward the received CompletePromptOptions from completePrompt
through each provider’s SDK request so abortSignal and timeoutMs are applied.
Update the implementations in
src/api/providers/base-openai-compatible-provider.ts:215-215,
src/api/providers/lm-studio.ts:190-190, src/api/providers/minimax.ts:292-292,
and src/api/providers/requesty.ts:207-207; preserve existing request behavior
while passing the options to the underlying completion call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c572da25-8110-4ac2-a5a7-23dba23165c3
📒 Files selected for processing (31)
src/api/index.tssrc/api/providers/__tests__/fake-ai.spec.tssrc/api/providers/anthropic-vertex.tssrc/api/providers/anthropic.tssrc/api/providers/base-openai-compatible-provider.tssrc/api/providers/bedrock.tssrc/api/providers/fake-ai.tssrc/api/providers/gemini.tssrc/api/providers/kenari.tssrc/api/providers/lite-llm.tssrc/api/providers/lm-studio.tssrc/api/providers/minimax.tssrc/api/providers/mistral.tssrc/api/providers/native-ollama.tssrc/api/providers/openai-codex.tssrc/api/providers/openai-compatible.tssrc/api/providers/openai-native.tssrc/api/providers/openai.tssrc/api/providers/opencode-go.tssrc/api/providers/openrouter.tssrc/api/providers/poe.tssrc/api/providers/qwen-code.tssrc/api/providers/requesty.tssrc/api/providers/unbound.tssrc/api/providers/vercel-ai-gateway.tssrc/api/providers/vscode-lm.tssrc/api/providers/xai.tssrc/api/providers/zoo-gateway.tssrc/core/task/__tests__/Task.spec.tssrc/utils/__tests__/enhance-prompt.spec.tssrc/utils/single-completion-handler.ts
🚧 Files skipped from review as they are similar to previous changes (27)
- src/utils/tests/enhance-prompt.spec.ts
- src/api/providers/kenari.ts
- src/api/providers/xai.ts
- src/api/index.ts
- src/api/providers/openai-compatible.ts
- src/api/providers/openrouter.ts
- src/api/providers/opencode-go.ts
- src/api/providers/anthropic-vertex.ts
- src/api/providers/poe.ts
- src/api/providers/gemini.ts
- src/api/providers/lite-llm.ts
- src/api/providers/qwen-code.ts
- src/api/providers/tests/fake-ai.spec.ts
- src/api/providers/openai-codex.ts
- src/api/providers/anthropic.ts
- src/api/providers/openai-native.ts
- src/api/providers/vercel-ai-gateway.ts
- src/api/providers/unbound.ts
- src/api/providers/native-ollama.ts
- src/api/providers/zoo-gateway.ts
- src/api/providers/mistral.ts
- src/api/providers/vscode-lm.ts
- src/api/providers/openai.ts
- src/utils/single-completion-handler.ts
- src/core/task/tests/Task.spec.ts
- src/api/providers/fake-ai.ts
- src/api/providers/bedrock.ts
Co-authored-by: edelauna <54631123+edelauna@users.noreply.github.com>
824a196 to
73054a4
Compare
edelauna
left a comment
There was a problem hiding this comment.
Thanks for your contribution and all the reviews you went through.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The two inner pre-stream guard mutants (the abort-normalization condition and its provider-name literal) are documented as provably equivalent with mutator-specific Stryker directives: createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested). The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404.
…ssion tests (Zoo-Code-Org#1288) * feat(api): add throwIfAborted helper and completePrompt options regression tests Add a fast-fail throwIfAborted guard to the shared abort-signal utilities and regression tests for the CompletePromptOptions interface (added by Zoo-Code-Org#901). * feat(api): add shared isRequestAborted and createAbortError helpers to abort-signal utils The OpenAI-family provider PRs (Zoo-Code-Org#1309, Zoo-Code-Org#1311) carry per-provider copies of the same abort-detection helper (isRequestAborted) and the same abort-error constructor (createAbortError); only the provider name in the message differs. Per the CodeRabbit maintainability finding on Zoo-Code-Org#1309 (extract the shared abort helpers into utils/abort-signal.ts), these are now shared in the foundation utility: - isRequestAborted(error, signal?) - true when the caller signal fired, a native AbortError / OpenAI SDK APIUserAbortError was raised, or the message is exactly "Request was aborted." (exact match; a substring match would misclassify unrelated errors that merely mention aborting) - createAbortError(providerName) - fresh error with name === "AbortError" and message "The <providerName> request was aborted", satisfying the Task.ts abort contract - exported OpenAiRequestOptions type 7 new tests (isRequestAborted 4, createAbortError 3). * test(abort-signal): assert throwIfAborted error message The mutation-diff gate reports a surviving StringLiteral mutant on the throwIfAborted message literal. Assert the exact message so a blanked literal fails the suite. --------- Co-authored-by: Eason Liang <easonliang28@gmail.com> Co-authored-by: easonLiangWorldedtech <easonliangworldedtech@users.noreply.github.com> Co-authored-by: edelauna <54631123+edelauna@users.noreply.github.com>
…rg#1651) * feat(api): add abort-signal cancellation-scope helpers to the shared utils Extend src/api/providers/utils/abort-signal.ts with the abort-signal series helpers used by the gateway providers: - isRequestAborted(error, signal): wider abort detection - an aborted signal, a DOM AbortError, the OpenAI/Anthropic SDK APIUserAbortError (name check), or the exact SDK abort message "Request was aborted." - trusting name/message only on real Error instances so a plain object that merely looks like an abort propagates unchanged - createAbortError(providerName): fresh error satisfying the Task.ts abort contract (name "AbortError", message ending in "aborted") - rejectOnAbort(pending, signal, providerName): settle a signal-less async phase (model discovery) on the provider AbortError when the signal fires first; the abort listener detaches when pending settles - resolveModelWithAbort(fetchModel, signal, providerName): run model resolution inside a cancellation scope - entry fast-fail for a pre-aborted signal, the rejectOnAbort race while the lookup is pending, and normalization of abort-flavored lookup failures; any other resolution failure propagates unchanged Includes direct unit tests for the resolveModelWithAbort cancellation scope (pre-aborted fast-fail, no-signal pass-through, mid-resolution race, abort normalization, non-abort propagation), the isRequestAborted instanceof tightening tests, and the settle-guard test utility. Unit 1/3 of the Zoo-Code-Org#1295 split (content source: 62f596c). Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. * fix: restore throwIfAborted export dropped by the util rewrite (+ tests) * fix(abort-r1): handle a rejecting pending promise in rejectOnAbort's pre-aborted branch * test(abort-r1): remove the process listener on every exit path * chore: trigger CodeRabbit re-review (findings already addressed) --------- Co-authored-by: Eason Liang <easonliang28@gmail.com> Co-authored-by: easonLiangWorldedtech <eason.liang@worldedtech.com>
…eMessage) (Zoo-Code-Org#1300) * feat(api): abort signal support for vscode-lm + fake-ai completion tests - completePrompt: bridge CompletePromptOptions.abortSignal and timeoutMs into a request-local vscode.CancellationTokenSource (the VS Code LanguageModelChat API only accepts a CancellationToken, not an AbortSignal); apply timeoutMs only when it is a positive value - completePrompt: report aborted requests (external signal, timeout, or host cancellation) as errors with name = "AbortError" on both the error and success paths; remove the abort listener and dispose the token source in finally - createMessage: bridge metadata.abortSignal into the internal request CancellationTokenSource (Bedrock pattern: pre-aborted guard + { once: true } listener stored in a named const), fail fast with an AbortError when the signal is already aborted, surface host CancellationError with name = "AbortError", and detach the listener / dispose the source in finally - vscode-lm.spec.ts: add pre-aborted and mid-flight abort, timeout, listener attach/detach, and backward-compatibility tests - fake-ai.spec.ts: option pass-through tests already merged on main via Zoo-Code-Org#901; verified green without changes * fix(api): address CodeRabbit review on vscode-lm abort handling - createMessage: sendRequest now uses the request-local cancellation source, the finally block disposes that local source and clears the shared field only when it still points at this request, and the error path no longer calls ensureCleanState (prevents an older finishing request from cancelling/disposing a newer request's token) - completePrompt: a pre-aborted signal now fails fast before getClient() and again before sendRequest(), so a cancelled request never initializes or invokes the host - completePrompt: a host vscode.CancellationError is normalized to an AbortError alongside isAborted() - spec: the timeout test now expects an AbortError (the cancelled token aborts the completion); the pre-abort test asserts sendRequest is never called; added a CancellationError -> AbortError rejection test; the mock CancellationTokenSource cancel() now flips isCancellationRequested to match the real API * fix(api): handle vscode-lm createMessage aborts during client init and streaming - createMessage re-checks the external abort signal after client initialization (and before sendRequest), cancelling the local token source and throwing an AbortError when the signal aborted while getClient() was pending - createMessage re-checks the external abort signal at the top of the stream consumption loop so a late abort stops the stream instead of yielding stale chunks (the bridged listener still covers the normal mid-flight case) - spec: the mid-flight abort test now expects the stream to stop with an AbortError; added a regression test where client initialization is gated on a release promise and the signal aborts in that window - the generator rejects with AbortError and sendRequest is never called * fix(api): start vscode-lm request cancellation before client initialization * fix(api): cancel vscode-lm request on premature generator closure + fix pre-abort test comment * test(vscode-lm): assert abort/timeout edge paths for the mutation-diff gate Adds focused assertions for the remaining mutation-diff mutants on the abort-signal and timeoutMs paths: external-abort pre-checks and the in-stream abort re-throw, cancellation listener cleanup, timeout timer scheduling and clearing, and host CancellationError wrapping. * test(vscode-lm): assert exact abort error messages and listener cleanup Close the 18 surviving mutants of the PR Zoo-Code-Org#1300 mutation-diff gate on vscode-lm.ts: - assert the exact canonical abort error message at every abort path in both createMessage and completePrompt - rewrite the finally listener-detach guards to if (externalAbortSignal && handler) so the guard only runs when the signal exists, and direct the correlated LogicalOperator mutant - direct the StringLiteral mutants on the guard/bridge abort errors: the catch re-throws its own canonical abort error, so those literals are unobservable - add a test where the external signal aborts while the host cancellation token was not cancelled, exercising the right-hand operand of isAborted() - strengthen the listener-spy tests to assert removeEventListener is called with the same listener reference, and clear the timeout timer unconditionally * fix(vscode-lm): check request-local cancellation in createMessage and cover negative timeout * fix(vscode-lm): re-check request-local token after client init Address CodeRabbit findings on the abort-signal series: - Re-check the request-local token immediately after getClient() so a request superseded while client initialization is pending aborts before token counting or host invocation. - Drive the counting-abort regression through the public path by mocking countTokens on the host chat mock, removing the @ts-ignore private-method suppression. - Add a gated-initialization supersession regression covering the new post-init guard. * fix: normalize superseded createMessage client-init failures to AbortError * fix(vscode-lm): reject quiet stream end after abort in createMessage The in-loop cancellation check only fires when the host delivers another chunk: if the external signal aborts (or a newer request supersedes this one) while the host stream is parked and the stream then ends normally, createMessage counted output tokens and yielded a usage chunk for the partial text instead of rejecting. completePrompt already guards this with its post-loop isAborted() check; createMessage now mirrors it with the same token/signal check after the stream loop and before output-token counting. Regression tests cover both cancellation sources (external signal abort and supersession via ensureCleanState) with a gated stream that ends quietly, asserting the canonical AbortError and no usage chunk. * test(vscode-lm): pin budget-gate edges and disable unobservable guard strings Preflight on the unit delta flagged the context-window budget gate and the refusal message: the gate condition (non-positive window disables trimming), the raw-budget arithmetic, the strict > admission boundary, and the refusal message's budget figure and pairing warning were all covered only by looser regex assertions. Add three tests that pin each edge (zero window sends an oversized request untouched; the refusal message is asserted in full, including the raw budget figure; a conversation exactly at the raw budget is sent, which the >= mutant refuses). The post-loop quiet-end guard's own error strings are never observed: the catch's abort branch intercepts the throw and re-throws its own canonical abort error with identical message and name, so those StringLiteral mutants are disabled with a concrete reason, matching the in-loop guard's existing directives. * test(vscode-lm): pin the raw-budget tool-schema subtraction With no tools in the request the -toolSchemaChars operator in the raw-budget arithmetic is equivalent to +toolSchemaChars (0 both ways), so the mutant was unobservable. Add a refusal test with a non-empty tool schema that asserts the exact budget figure: the mutant that flips the operator inflates the reported budget by twice the schema size and fails the assertion. * fix(api): reject non-finite and cap overflowing completePrompt timeouts CodeRabbit: the timeoutMs guard let Infinity and values above 2^31-1 through to setTimeout, which Node coerces to a 1ms delay - completePrompt could then cancel almost immediately with an AbortError. Non-finite values now mean "no timeout" and finite delays are capped at 2^31-1 ms. Regression tests: Infinity schedules no timer and completes; 2^31 ms schedules a capped timer that does not fire within the first second. Negative controls: reverting the guard fails each test in isolation (1 red per control). * fix(api): harden mergeAbortSignalAndTimeout against invalid delays Port of the timeout guard finding (CodeRabbit, Zoo-Code-Org#1300 thread wave): Node's AbortSignal.timeout validates its delay as uint32 - Infinity and finite fractions (1500.5, 0.5) throw ERR_OUT_OF_RANGE, and delays above 2^31-1 ms clamp to 1 ms (immediate abort). The helper now treats non-finite values as "no timeout", rounds fractional delays up (never down to 0), and caps the rest at 2^31-1 ms. vscode-lm's own setTimeout guard is unaffected: setTimeout accepts fractional delays (verified). Regression tests for non-finite, overflowing, and fractional values; each revert fails exactly one test. * test(api): assert the rounded delay reaching AbortSignal.timeout CodeRabbit: the fractional-timeout test only proved the call did not throw and eventually aborted - a round-down mutation (1.5 -> 1) would still pass. The test now spies AbortSignal.timeout and pins the received delay: 2 for 1.5 and 1 for 0.5 (never 0). Negative control: mutating Math.ceil to Math.floor fails exactly this test. * fix(api): round fractional completion timeouts up before scheduling CodeRabbit: the raw setTimeout path passed 1500.5 through and Node truncates non-integer delays, cancelling at 1500 ms - inconsistent with the PR objective and mergeAbortSignalAndTimeout's 1501. The guard now applies Math.ceil before the cap. New test pins the delay handed to setTimeout (1501 for 1500.5); negative control (reverting the ceil) fails exactly that test. * fix(api): reconcile Copilot cancellation tests with the merged abort contract The merge brought in main's GitHubCopilotHandler cancellation tests, which were written against main's vscode-lm internals. Two reconciliations: - createMessage now also records the caller's abort in an abortedByCaller flag set synchronously by the bridge listener, and the post-getClient / post-count re-checks consult it in addition to the token flag. The token flag alone cannot be the sole signal: cleanup cancels the token too, and a host token's flag is not observable before its cancel settles (main's own implementation used the same flag for this reason). - github-copilot.spec.ts: cancellation assertions now expect this unit's canonical abort error (createAbortError -> "The VS Code LM request was aborted", name AbortError) instead of main's interim strings, and the mid-stream completePrompt test asserts the contract that content racing a cancellation is not surfaced (rejects instead of resolving with late text), matching the pinned vscode-lm behavior. Full api suite green (3220 passed / 2 skipped); tsc, eslint, prettier clean. * test(vscode-lm): pin the bridged token in the completePrompt abort test createMessage already asserts sendRequest received the bridged token; completePrompt only checked that the token source was disposed, so a fresh token passed to sendRequest would have gone unnoticed. * style: apply repo Prettier to the merge resolution * test(api): pin the abort-bridge listener identity in the cleanup assertion The initialization-abort test only counted removeEventListener calls. Spy on addEventListener too and assert the removed listener is the exact callback the bridge registered, so a wrong-listener cleanup cannot pass. * fix(vscode-lm): cancel in-flight completions on handler disposal Review follow-ups: completePrompt token sources are tracked on the handler and cancelled in dispose() (removed from the set in finally), so tearing the handler down stops completion requests as well as streaming ones. completePrompt also adopts the shared hasUsableTimeout/toSdkTimeoutMs helpers instead of inlining ceil/cap. Adds two focused tests: an external abort landing while getClient() is pending rejects with the contract AbortError without a host request, and disposal during client initialization cancels the active completion token. vscode-lm.spec.ts 382 passed; tsc clean for the file. * fix(vscode-lm): reject a cancellation that lands inside the final token count Review follow-ups: internalCountTokens returns 0 on cancellation, so the generator re-checks the request cancellation before yielding the usage chunk instead of completing normally with a zero-output chunk. The boundary test now pins a window whose 0.8*3 character budget is an exact integer (2.4 is exact for a 128k-token window), so the equality case is representable and the >= mutant is detectable; a focused test aborts during the output count and asserts the contract AbortError. vscode-lm.spec.ts 382 passed (new count-abort test included). * test(vscode-lm): abort from the host count instead of spying a private method The platform-unit coverage run reported 19 downstream failures: spying on the private internalCountTokens made the abort land differently under coverage instrumentation. The test now aborts from the host countTokens mock (the output count is the call carrying the streamed text) and restores the original implementation, so the suite passes with and without coverage (383 passed in both). * fix(vscode-lm): surface the shared canonical abort for host cancellation Human review follow-up: replace the remaining hand-built AbortError for a host CancellationError with createAbortError(this.providerName); update the two assertions that pinned the old branded message to the canonical text. vscode-lm.spec.ts 383 passed; tsc clean. * test(vscode-lm): pin signal-only aborts and completion token disposal Review follow-ups: a createMessage test neutralises the bridged token cancel so only the external signal aborts (canonical AbortError); dispose tests cover a streaming completion, two concurrent completions, and a finished completion (which must not be cancelled again). vscode-lm.spec 387 passed; tsc clean. * test(vscode-lm): yield-empty generators in the signal-only abort test Lint follow-up: the quiet stream stubs must be generators, so they yield an empty iterable instead of only awaiting the gate. vscode-lm.spec 387 passed; eslint 0. --------- Co-authored-by: Eason Liang <easonliang28@gmail.com> Co-authored-by: edelauna <54631123+edelauna@users.noreply.github.com> Co-authored-by: easonLiangWorldedtech <eason.liang@worldedtech.com> Co-authored-by: dsh-agent <dsh@local>
…oo-Code-Org#1309) * feat(api): add throwIfAborted helper and completePrompt options regression tests Add a fast-fail throwIfAborted guard to the shared abort-signal utilities and regression tests for the CompletePromptOptions interface (added by Zoo-Code-Org#901). * feat(api): abort-signal wiring for lm-studio and qwen-code (round 2) * fix(api): align lm-studio specs with abort-signal call shape and address review CI: platform-unit-test (ubuntu-latest) was failing on four LM Studio spec assertions that still expected the pre-PR single-argument SDK call shape. createMessage now calls chat.completions.create(params, { signal }) with the request-local AbortSignal, and completePrompt passes no options when no signal/timeout is configured. Update the two existing specs to the same two-argument assertions used by the new qwen-code-native-tools.spec.ts (expect.any(AbortSignal) for createMessage, undefined second argument for the no-signal completePrompt case). Review: (1) narrow isRequestAborted to an exact match on the OpenAI SDK abort error text ("Request was aborted.") instead of a substring scan, so unrelated errors that merely mention "abort" are no longer normalized as user cancellations; (2) abort the request-local controller in the createMessage finally block so early stream termination (break/return) cancels the in-flight SDK request. * test(api): cover LM Studio reasoning_content delta in abort-signal spec Changed-line coverage verification against the full PR diff (git diff origin/main...HEAD) found two executable added lines in lm-studio.ts uncovered by the PR's spec files: the reasoning_content/reasoning delta branch of createMessage (upstream main had since re-based that block into the PR diff). Add a focused streaming regression test to lm-studio-timeout.spec.ts that exercises the branch, restoring 100% changed-line coverage on both provider files (lm-studio.ts 35/35, qwen-code.ts 65/65 executable added lines). * test(api): cover qwen-code degenerate stream shapes for full branch coverage Codecov's patch report on the previous head flagged 5 partial-coverage lines in qwen-code.ts (lines 328, 338, 344, 398, 399): the defensive branches of the createMessage stream loop — a chunk with no choice (choices[0] ?? fallback), a delta that repeats the previous full content (empty after trimming), a think block that starts the text (empty leading split segment), and a zeroed usage payload (prompt_tokens || 0, completion_tokens || 0). Add one focused degenerate-stream-shapes test to qwen-code-native-tools spec covering all five branches in a single stream. Branch-level lcov cross-reference on the PR's added lines now reports zero partial-coverage added lines in both provider files, and line-level changed-line coverage stays 100% (lm-studio.ts 35/35, qwen-code.ts 65/65 executable added lines). * feat(api): add shared isRequestAborted and createAbortError helpers to abort-signal utils The OpenAI-family provider PRs (Zoo-Code-Org#1309, Zoo-Code-Org#1311) carry per-provider copies of the same abort-detection helper (isRequestAborted) and the same abort-error constructor (createAbortError); only the provider name in the message differs. Per the CodeRabbit maintainability finding on Zoo-Code-Org#1309 (extract the shared abort helpers into utils/abort-signal.ts), these are now shared in the foundation utility: - isRequestAborted(error, signal?) - true when the caller signal fired, a native AbortError / OpenAI SDK APIUserAbortError was raised, or the message is exactly "Request was aborted." (exact match; a substring match would misclassify unrelated errors that merely mention aborting) - createAbortError(providerName) - fresh error with name === "AbortError" and message "The <providerName> request was aborted", satisfying the Task.ts abort contract - exported OpenAiRequestOptions type 7 new tests (isRequestAborted 4, createAbortError 3). * refactor(api): use shared abort helpers from foundation utils in lm-studio and qwen-code The per-provider copies of isRequestAborted / createAbortError / OpenAiRequestOptions were extracted into src/api/providers/utils/abort-signal.ts by foundation PR Zoo-Code-Org#1288 (commit a0117fb) following the CodeRabbit maintainability finding on this PR; the providers now import the shared helpers. createAbortError takes the provider name as a parameter; provider behavior and abort messages are unchanged. * fix(api): normalize aborts during qwen-code 401 retry and lm-studio token counting CodeRabbit follow-ups on the abort-signal series: an abort landing while the qwen-code 401 retry request is in flight escaped callApiWithRetry as the raw SDK abort error instead of the normalized 'The Qwen Code request was aborted'; the retried apiCall now goes through the same isRequestAborted normalization. In lm-studio createMessage, an abort landing while input token counting is pending was silently dropped (a listener added to an already-aborted signal never fires), so the aborted state is bridged into the request-local controller and throwIfAborted fast-fails before the request is issued. Regression tests cover both paths. * test(api): cover the non-abort path of the qwen-code 401 retry Closes the remaining changed-line gap in qwen-code.ts: a 401 whose retry fails with a non-abort error must be rethrown unchanged (the abort check's false branch). * fix(ci): declare vitest as a root devDependency so the mutation gate resolves its bin * test(api): strengthen focused tests for the changed-code mutation gate * test(api): harden abort-wiring tests against hanging mutants * test(api): exclude proven-equivalent Stryker mutants from the changed-code gate * test(api): exclude unobservable inner-abort provider-name literals from the gate The two inner throw createAbortError("LM Studio") sites in createMessage and completePrompt always produce an error whose name is AbortError. isRequestAborted treats name AbortError as an aborted request, so the outer catch re-normalizes those failures into the same contract error. The provider-name StringLiteral at the inner sites is therefore unobservable and the StringLiteral mutants are provably equivalent. * fix(api): settle lm-studio and qwen-code wait points against the abort signal - add settleOnAbort helper: await pending work but reject with the request abort error the moment the signal aborts; the underlying work keeps running (a shared deduped token refresh is never cancelled by one request's signal) and the listener is removed on either outcome - lm-studio: race the input and output token counts against the request-local signal so a Stop during a pending count settles the generator promptly; skip usage reporting if a stop lands in the microtask gap before the usage yield - qwen-code: race ensureAuthenticated (credential load and token refresh) against the request signal in createMessage and completePrompt; read the OpenAI SDK status through a narrow shape instead of catch (error: any) - specs: pending-count and pending-auth abort contract tests plus settleOnAbort unit tests - eslint-suppressions: drop the qwen-code no-explicit-any entry consumed by the catch-clause fix * test(api): add abort kill-tests for lm-studio and qwen-code * Adapt qwen-code spec to per-scope NativeToolCallParser API * fix(deps): repair pnpm-lock.yaml broken by merge conflict resolution The merge of main into this branch resolved the lockfile conflict by taking main's lockfile plus only the PR-side importers hunk, leaving the root importer's vitest 4.1.9 reference without a matching packages/snapshots entry. pnpm install --frozen-lockfile failed with ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY in every CI job. Regenerated the lockfile with pnpm install --no-frozen-lockfile at the merge head: adds the vitest@4.1.9 package/snapshot entries and the new peer resolutions. Verified: pnpm install --frozen-lockfile passes, lint 11/11, check-types 11/11, code-qa workflow, lifecycle model-check 7/7, mcp integration check, translations, knip, and the 7 PR-affected vitest suites (143 tests). * fix(deps): align root vitest with the 4.1.11 security bump GitHub dependency review flagged vitest 4.1.9 (the root devDependency this branch introduced) as vulnerable; the repo already moved the per-package vitest pins to 4.1.11 in Zoo-Code-Org#1582 (security). Set the root pin to 4.1.11 and regenerated pnpm-lock.yaml, which drops the now-unused vitest@4.1.9 package/snapshot entries. Verified: pnpm install --frozen-lockfile passes, knip, and the 7 PR-affected vitest suites (143 tests). * fix(api): race the Qwen 401 refresh wait against the abort signal and tighten listener-identity assertions Address the CodeRabbit findings on the 401 refresh path: - callApiWithRetry now races the refresh wait against the caller's signal (settleOnAbort), so a stop settles promptly instead of blocking on the token endpoint; the shared refresh keeps running and only this wait is cut. - The abort-during-401-refresh spec now keeps the token endpoint pending forever, proving the wait is cut by the abort (a post-hoc aborted check alone would hang). - settleOnAbort listener-cleanup specs assert the exact registered listener reference is removed, not just that some function was removed. * fix(qwen-code): keep in-memory credentials current after a cancelled 401 wait (CodeRabbit, R2, Zoo-Code-Org#1309) doRefreshAccessToken persisted the refreshed token but left the in-memory credentials to the waiting caller's assignment. When settleOnAbort rejected on abort before the shared refresh settled, that assignment was skipped: the background refresh had already saved the new token, yet the handler kept the stale one in memory, so the next request reused it and triggered a second 401 refresh. Assign this.credentials in the shared refresh itself, and restructure the refresh-wait test so the abort lands after settleOnAbort has registered its listener (the old mock aborted synchronously inside the fetch, only exercising the already-aborted fast path). New regression test: abort cuts the established wait, the refresh settles in the background, and the in-memory credentials carry the refreshed token. 28/28 specs pass; eslint clean (suppressions unchanged). * chore: trigger label reconcile (CI green + CR approved, cron stalled) * Assert the abort bridge while the request is in flight Both tests asserted after the call had already finished, so they passed even with a broken bridge: the provider's finally block aborts the request signal on its own, and releasing the count gate lets counting finish normally. - the signal test now keeps the mocked stream open, aborts the caller signal and checks the captured request signal before the stream is released; - the cancellation test now asserts the pending count rejects while the gate is still closed, and releases the gate in a finally block. 54 tests green across the two suites; prettier, eslint and tsc clean. * Re-trigger review at the current head Every review thread on this PR is resolved and CI is green at this head; the review decision still points at an older commit. This empty commit re-runs the review so the decision and the label reflect the current head. * Address pre-merge checks: detach settleOnAbort's listener on abort; pin completePrompt fast-fail settleOnAbort registered an abort listener that its onAbort callback never removed: when the pending promise never settled (e.g. a wedged shared token refresh), the listener stayed attached to the caller's signal for the signal's whole life. A single cleanup function now detaches the exact registered listener at most once, called from the abort callback and from the pending promise's fulfillment/rejection handlers. New test aborts with a never-settling pending promise and asserts the listener is removed by the abort callback itself (negative control: removing the cleanup call from onAbort fails exactly that test). Also adds the missing focused test for LmStudioHandler.completePrompt's pre-aborted-signal fast-fail: an already-aborted signal rejects with the contract AbortError and chat.completions.create is never called (negative control: removing the throwIfAborted guard fails exactly that test). Verification at this head: 67/67 green across abort-signal.spec.ts and lm-studio.spec.ts; tsc --noEmit 0 errors; eslint --max-warnings=0 clean on touched files with suppression counts unchanged; prettier clean. * Address review: pin listener removal by function reference Both listener-removal tests accepted any function in the removeSpy assertion, so removing a different function than the one registered would still pass. Per the path instruction (and CR suggestions): the lm-studio createMessage test now captures the registered listener from addSpy and asserts removeSpy was called with that exact reference; the settleOnAbort rejection-propagation test now uses the same addSpy.mock.calls[0]?.[1] pattern as the other cleanup tests in the file. Verification at this head: 67/67 green across abort-signal.spec.ts and lm-studio.spec.ts; tsc --noEmit 0 errors; eslint --max-warnings=0 clean on touched files; prettier clean. * Address pre-merge warnings: guard settleOnAbort's early return; share Qwen credential loads settleOnAbort's already-aborted early return handed the caller the abort error without attaching a rejection handler to the pending promise, exposing a rejecting pending promise as an unhandled rejection. A no-op rejection guard now runs before the early return (same shape as rejectOnAbort's existing guard). New test aborts with a rejecting pending promise and asserts no unhandledRejection fires while the abort error surfaces (negative control: removing the guard fails exactly that test). QwenCodeHandler duplicated credential loading after cancellation: createMessage/completePrompt race ensureAuthenticated() with settleOnAbort, so a cancelled first request left its load running and a second request started a fresh credential read. ensureAuthenticated now shares the in-flight load promise the same way refreshAccessToken shares its refresh, cleared in a finally once the load settles, so a failed load is retried by the next request. New tests: concurrent cancel+retry reuses one credential read; success and failure both clear the shared promise (negative control: breaking the reuse guard fails exactly the reuse test; the test releases the hung read in a finally so a failing run cannot leak the pending load into later tests). Review test-fidelity threads: the two qwen-code-native-tools 401 refresh tests now abort only after the refresh wait is established (fetch never settles; drain until the fetch starts) instead of aborting synchronously inside the fetch mock, which exercised only the already-aborted fast path; the two qwen-code listener tests now assert the exact registered listener reference is removed instead of expect.any(Function). Verification at this head: 128/128 green across abort-signal, qwen-code, qwen-code-native-tools and lm-studio specs; tsc --noEmit 0 errors; eslint --max-warnings=0 clean with suppression counts unchanged; prettier clean. * Address review: cover LM Studio early consumer termination createMessage's finally block cancels the request-local SDK signal and detaches the external abort listener, but no test pinned the early consumer exit (break/return while the SDK stream is still pending): the existing coverage only exercised normal completion and external-signal aborts. New test consumes one chunk from a stream that then stays pending, calls stream.return(), and asserts the request-local SDK signal becomes aborted and the exact registered external listener is removed (by reference, per the established pattern). Negative control: removing the finally-block abort fails exactly this test (isolated run). Verification at this head: 27/27 green in lm-studio.spec.ts; tsc --noEmit 0 errors; eslint --max-warnings=0 clean with suppression counts unchanged; prettier clean. * Address review: pin no premature abort before early termination The early-termination test only observed the request-local signal after stream.return(), so a premature abort (one landing while the consumer is still iterating) would also pass. The test now captures the SDK request options after the first chunk and asserts the request-local signal is still live (aborted === false) before the early return, retaining the post-return aborted assertion. Negative control: aborting the request-local controller right after the SDK create call fails exactly this test (isolated run: the new false assertion reddens). Verification at this head: 27/27 green in lm-studio.spec.ts; tsc --noEmit 0 errors; eslint --max-warnings=0 clean with suppression counts unchanged; prettier clean. * chore(api): remove Stryker suppression comments from touched files Per repo policy (AGENTS.md: Stryker suppression comments are banned; the mutation gate rejects them in touched files). Equivalence arguments for the resulting mutants are recorded in the PR body. * fix(api): reject non-finite and cap overflowing mergeAbortSignalAndTimeout delays Port of the Zoo-Code-Org#1300 timeout guard finding (CodeRabbit): Node's AbortSignal.timeout throws ERR_OUT_OF_RANGE for non-integer delays (Infinity) and clamps delays above 2^31-1 ms to 1 ms, so a non-finite timeoutMs threw a RangeError instead of running the request, and an overflowing one aborted almost immediately. The helper now treats non-finite values as "no timeout" and caps finite delays at 2^31-1 ms. Regression tests added; negative controls (reverting the guard) fail exactly the two new tests. * fix(api): round fractional timeouts before AbortSignal.timeout CodeRabbit follow-up on the timeout guard: Node validates AbortSignal.timeout delays as uint32, so finite fractions (1500.5, 0.5) threw ERR_OUT_OF_RANGE just like Infinity did. The helper now rounds delays up (a positive fraction never becomes 0 ms) before capping at 2^31-1 ms. Regression test mergeAbortSignalAndTimeout (undefined, 1.5); negative control (reverting the rounding) fails exactly that test. * test(api): assert the rounded delay reaching AbortSignal.timeout CodeRabbit: the fractional-timeout test only proved the call did not throw and eventually aborted - a round-down mutation (1.5 -> 1) would still pass. The test now spies AbortSignal.timeout and pins the received delay: 2 for 1.5 and 1 for 0.5 (never 0). Negative control: mutating Math.ceil to Math.floor fails exactly this test. * fix(api): restore the OpenAiRequestOptions type the abort wiring imports upstream/main removed the type in its knip dead-code pass; lm-studio.ts and qwen-code.ts still import it, so the merge has to re-add it. * fix(api): report an elapsed per-request timeout as TimeoutError completePrompt merged the caller signal with the timeout and mapped every abort-shaped failure to AbortError, so a deadline expiry looked like a user stop. Distinguish them via the merged signal reason: TimeoutError when the timer fired while the caller signal stayed live, AbortError for a real cancellation. Applied to both lm-studio and qwen-code (same PR, same contract) with regression tests whose negative controls fail with expected AbortError to be TimeoutError. * refactor(providers): share the timeout-vs-abort helpers and dedupe the LM Studio catch selection Review follow-ups: createTimeoutError/isTimeoutAbort move from qwen-code.ts and lm-studio.ts into utils/abort-signal.ts (providerName stays a createTimeoutError parameter; behavior unchanged) and both providers import them. LM Studio completePrompt selects TimeoutError vs the contract AbortError through one private helper used by the inner create catch and the outer completion catch. The qwen elapsed-timeout test now passes a live caller signal alongside timeoutMs and asserts TimeoutError, and uses mockImplementationOnce so the signal-waiting mock cannot leak into later tests. Contract tests for the shared helpers live in abort-signal.spec.ts. qwen-code + lm-studio + abort-signal suites 111 passed; abort-signal 58 passed; tsc clean. * fix(abort-signal): classify timeout aborts by the merged signal reason Review follow-ups: isTimeoutAbort takes only the merged requestSignal and keys on its retained abort reason, so a timeout that fires before a later caller abort stays a TimeoutError (and a caller-first abort stays a cancellation); both providers updated. Tests cover both abort orders. The elapsed-timeout completePrompt test moved into the completePrompt suite. abort-signal + qwen-code + lm-studio specs 116 passed; tsc clean. * chore(lm-studio): drop the unused caller signal parameter Follow-up to the isTimeoutAbort signature change: toCompletionAbortError only needs the merged request signal. tsc clean; eslint on the touched providers exits 0. * test(lmstudio): wait for the request instead of a fixed sleep * fix(api): settle qwen-code streams that end quietly on abort Review threads on Zoo-Code-Org#1309: - qwen-code.ts: the OpenAI SDK iterator returns without throwing when its controller aborts (openai/core/streaming.js: isAbortError -> return), so a stop mid-stream left the generator looking like a completed turn with no usage chunk. Re-check the request-local signal after the stream loop, as lm-studio.ts already does. Regression test included; negative control: the test fails with the guard removed. - lm-studio.ts: drop the unreachable already-aborted branch - nothing is awaited between throwIfAborted and the listener registration - and fix the comment that justified it. - abort-signal.ts: settleOnAbort delegates to rejectOnAbort/raceAbort instead of maintaining a second copy of the race. raceAbort now detaches its listener exactly once from whichever side settles first (the abort callback included), so both helper suites keep their leak guards; three assertions that pinned the addEventListener argument count now assert only that the registration happened once. - abort-signal.ts: comments describe what the helpers do instead of referring to a PR series. - specs: replace fixed 10 ms sleeps and fixed-depth promise ticks with vi.waitFor on the observable condition, and add concurrent-request tests for both providers (aborting one request must not cancel the other's signal). Local verification: api/providers + api/transform 3716 tests green, tsc --noEmit clean, eslint --max-warnings=0 clean with no suppression changes, prettier clean, knip strict clean. * test(api): poll instead of assuming await depth, and exercise the merged signal for real,,Three review findings on the abort-signal tests:,,- qwen-code-native-tools.spec.ts: the two 401-refresh tests drained up to 50 microtasks with, 'await Promise.resolve()' before asserting the refresh fetch had started, and waitForCreateCall, re-implemented vi.waitFor with a setTimeout loop. Both replaced by vi.waitFor polls, matching, qwen-code.spec.ts. Control: a 2-deep microtask drain fails with 'expected "vi.fn()" to be called, 1 times, but got 0 times' at spec:796 while the poll passes. Honest note: on the SDK-call wait a, 2-deep drain still happened to pass today, so that half is a latent trap rather than a present, failure - the helper is gone either way.,- abort-signal.spec.ts: the isTimeoutAbort order tests built two unlinked controllers (and copied, the reason by hand), so they passed regardless of what the merge actually preserves. Both now, build the signal with the real mergeAbortSignals. Control: swapping the two abort calls in the, timeout-first test now fails with "AssertionError: expected false to be true" - the test tracks, the merge semantics it describes.,- abort-signal.spec.ts: added the null abort-reason case. Control: removing the optional chain on, requestSignal.reason at abort-signal.ts:320 fails the new test with 'TypeError: Cannot read, properties of null (reading name)' at abort-signal.ts:320:85, which is the surviving, OptionalChaining mutant mutation-diff reported on that line.,,Verification: api/providers/__tests__/qwen-code-native-tools.spec.ts +,api/providers/utils/__tests__/abort-signal.spec.ts -> 2 files, 99 tests passed. tsc --noEmit: 0,errors. eslint --max-warnings=0 exit 0 on both files with src/eslint-suppressions.json untouched.,prettier --check clean. * test(api): ban setTimeout in provider specs, use waitFor and shared helpers --------- Co-authored-by: Eason Liang <easonliang28@gmail.com> Co-authored-by: easonLiangWorldedtech <easonliangworldedtech@users.noreply.github.com> Co-authored-by: easonLiangWorldedtech <eason.liang@worldedtech.com> Co-authored-by: Elliott de Launay <edelauna@gmail.com>
…ssion tests (Zoo-Code-Org#1288) * feat(api): add throwIfAborted helper and completePrompt options regression tests Add a fast-fail throwIfAborted guard to the shared abort-signal utilities and regression tests for the CompletePromptOptions interface (added by Zoo-Code-Org#901). * feat(api): add shared isRequestAborted and createAbortError helpers to abort-signal utils The OpenAI-family provider PRs (Zoo-Code-Org#1309, Zoo-Code-Org#1311) carry per-provider copies of the same abort-detection helper (isRequestAborted) and the same abort-error constructor (createAbortError); only the provider name in the message differs. Per the CodeRabbit maintainability finding on Zoo-Code-Org#1309 (extract the shared abort helpers into utils/abort-signal.ts), these are now shared in the foundation utility: - isRequestAborted(error, signal?) - true when the caller signal fired, a native AbortError / OpenAI SDK APIUserAbortError was raised, or the message is exactly "Request was aborted." (exact match; a substring match would misclassify unrelated errors that merely mention aborting) - createAbortError(providerName) - fresh error with name === "AbortError" and message "The <providerName> request was aborted", satisfying the Task.ts abort contract - exported OpenAiRequestOptions type 7 new tests (isRequestAborted 4, createAbortError 3). * test(abort-signal): assert throwIfAborted error message The mutation-diff gate reports a surviving StringLiteral mutant on the throwIfAborted message literal. Assert the exact message so a blanked literal fails the suite. --------- Co-authored-by: Eason Liang <easonliang28@gmail.com> Co-authored-by: easonLiangWorldedtech <easonliangworldedtech@users.noreply.github.com> Co-authored-by: edelauna <54631123+edelauna@users.noreply.github.com> (cherry picked from commit e12a42e)
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The two inner pre-stream guard mutants (the abort-normalization condition and its provider-name literal) are documented as provably equivalent with mutator-specific Stryker directives: createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested). The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 196 passed (196) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `8efbbc5315c5aededc008f119c06e17a5acefe75`, spec `04c0528ccda0a8f655a16e6900ef5c627beb23ad`; `git diff eb162c4 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 393 passed (393) in declaration order and 393 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The inner pre-stream provider-name literal is provably equivalent and documented as such in the PR body; no Stryker disable directive is added anywhere in the tree. createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes the error, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested), and the abort-normalization condition beside that literal is killed by a live-signal delivery added in the second review round. The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Review round 2 (CodeRabbit pre-merge checks): completePrompt gained a parameterized timeout-option test per wire format (Anthropic messages, Responses, chat completions) that proves each call site applies the shared hasUsableTimeout/toSdkTimeoutMs contract rather than only testing the helper: NaN, Infinity and -5 leave no timeout key, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and every row also asserts the caller's signal reached the SDK options, so dropping the budget can never drop the cancel. Controls: deleting the forward arm fails two rows per format, forcing it to always forward fails the three disabled-budget rows, and replacing toSdkTimeoutMs(timeoutMs) with the raw value fails exactly the two forwarding rows. The five provider-name literals on the abort paths were re-measured at this head: all five survive the full 211-test suite, which is the measured half of the equivalence argument in the PR body. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 211 passed (211) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `8efbbc5315c5aededc008f119c06e17a5acefe75`, spec `4654b728043f9c7ed2e30f46e8543a1a29bfe6cf`; `git diff e88d290 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Review round 2 (CodeRabbit pre-merge checks): each gateway completePrompt now pins the disabled-budget boundary at -5 — the SDK options carry no timeout key and the bridged per-request signal is still handed over (the zoo variant is one of the tests that also catches a dropped signal arm). The ported Opencode Go spec brings its own parameterized timeout-option test per wire format: NaN, Infinity and -5 omit the option, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and the caller signal is asserted on every row. Those rows kill the forward arms at opencode-go.ts:886/944/1027 in both directions (deleting the arm fails two rows per format, forcing it always-forward fails the three disabled-budget rows) and the toSdkTimeoutMs call sites; forcing the gateway arms to always forward fails the new -5 rows on all three providers.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 411 passed (411) in declaration order and 411 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The inner pre-stream provider-name literal is provably equivalent and documented as such in the PR body; no Stryker disable directive is added anywhere in the tree. createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes the error, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested), and the abort-normalization condition beside that literal is killed by a live-signal delivery added in the second review round. The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Review round 2 (CodeRabbit pre-merge checks): completePrompt gained a parameterized timeout-option test per wire format (Anthropic messages, Responses, chat completions) that proves each call site applies the shared hasUsableTimeout/toSdkTimeoutMs contract rather than only testing the helper: NaN, Infinity and -5 leave no timeout key, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and every row also asserts the caller's signal reached the SDK options, so dropping the budget can never drop the cancel. Controls: deleting the forward arm fails two rows per format, forcing it to always forward fails the three disabled-budget rows, and replacing toSdkTimeoutMs(timeoutMs) with the raw value fails exactly the two forwarding rows. The five provider-name literals on the abort paths were re-measured at this head: all five survive the full 211-test suite, which is the measured half of the equivalence argument in the PR body. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 211 passed (211) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false. Review round 3 (CodeRabbit pre-merge checks, six Minor rows): the Chat Completions streaming loop now re-checks the request signal in front of every buffered item of a frame — the text item after a reasoning item, each tool-call partial inside the per-item loop, and the usage item — because a consumer that takes the first item, cancels and pulls the next one resumes this generator inside the same iteration, where the top-of-loop guard has already run. The three stream-open awaits (Anthropic /v1/messages, Responses /v1/responses and chat completions) now go through settleOnAbort with the signal still handed to the SDK, so a 429 with Retry-After plus a caller cancel no longer holds the pending first next() and the bridge cleanup until the sleep ends. Regression evidence: one parameterized test for the three stream-open races plus three manual-iteration tests that abort between two items of one frame (the buffered-text variant also asserts the bridge listener is detached by reference). Negative controls: removing each open wrapper fails exactly that format's row (1 failed | 216 passed each), disabling each buffered-item guard fails exactly that item's test, and reverting the OpenAI-path fixture key from opencodeGoModelId to the ignored apiModelId fails the five assertions that now pin model "glm-5.1" instead of expect.any(String). The parked-lookup test releases its gate in a finally so an assertion throw cannot strand the promise the provider awaits; measured with a probe: a release placed after the throwing assertion leaves the promise unresolved, the same release in a finally settles it. Verification on this round: vitest 217 passed (217) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files reported zero count decreases); prettier 3.9.10 --check: clean.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `23348a501e9f31d0c72bffa6eefb6030bb6149a3`, spec `5dbe3382d1f1d6af8d22e7637a088c546988ef18`; `git diff df29307 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Review round 2 (CodeRabbit pre-merge checks): each gateway completePrompt now pins the disabled-budget boundary at -5 — the SDK options carry no timeout key and the bridged per-request signal is still handed over (the zoo variant is one of the tests that also catches a dropped signal arm). The ported Opencode Go spec brings its own parameterized timeout-option test per wire format: NaN, Infinity and -5 omit the option, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and the caller signal is asserted on every row. Those rows kill the forward arms at opencode-go.ts:886/944/1027 in both directions (deleting the arm fails two rows per format, forcing it always-forward fails the three disabled-budget rows) and the toSdkTimeoutMs call sites; forcing the gateway arms to always forward fails the new -5 rows on all three providers.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 411 passed (411) in declaration order and 411 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
Review round 3: the mutation-diff report at 313cf0e listed 20 blocking rows (21 survived mutants plus one uncovered arm) over 338 changed executable lines. Five of them are now killed by four tests added here: unbound.ts:349 and vercel-ai-gateway.ts:280 (detachExternalAbortSignal() -> ; in the completePrompt finally) by a detach test per provider that identifies the bridge listener by the { once: true } registration and asserts its removal by reference; zoo-gateway.ts:337 (classification gate -> false) by a streaming test that feeds a name-only AbortError with a live-but-not-aborted caller signal and asserts the contract identity, that the add-credits notification never ran, and that nothing was logged; zoo-gateway.ts:346 in both directions by a streaming test where the notification itself rejects while the caller signal is live (the log must name the surfacing failure and the original 402 must still reach the caller) plus the existing cancel-while-prompt-open test, which also puts that line under coverage. Each of those four mutants was applied alone and restored: 1 failed | 414 passed, killed by the named test in every case. The remaining sixteen rows are all StringLiteral -> "" on a provider-name label inside createAbortError/settleOnAbort/rejectOnAbort; each one sits inside a catch or race whose enclosing handler re-throws with its own unmutated literal, so the provider-visible error name and message are identical through the public API and no assertion can distinguish the mutant from the code (measured: full suite green with each mutant in place). No Stryker directive was added; the equivalence is argued in the PR discussion for a maintainer to weigh.
Verification on this tree: vitest 421 passed (421) across the four provider specs in declaration order and with --sequence.shuffle (the six new opencode-go tests arrive with the re-ported blobs); tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical; prettier 3.9.10 --check on the touched files: clean. The opencode-go blobs are re-ported from df29307 and remain byte-identical to that head (git diff --quiet against it for those two paths: exit 0), so after a maintainer merges Zoo-Code-Org#1652 these lines drop out of this diff on rebase.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The inner pre-stream provider-name literal is provably equivalent and documented as such in the PR body; no Stryker disable directive is added anywhere in the tree. createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes the error, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested), and the abort-normalization condition beside that literal is killed by a live-signal delivery added in the second review round. The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Review round 2 (CodeRabbit pre-merge checks): completePrompt gained a parameterized timeout-option test per wire format (Anthropic messages, Responses, chat completions) that proves each call site applies the shared hasUsableTimeout/toSdkTimeoutMs contract rather than only testing the helper: NaN, Infinity and -5 leave no timeout key, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and every row also asserts the caller's signal reached the SDK options, so dropping the budget can never drop the cancel. Controls: deleting the forward arm fails two rows per format, forcing it to always forward fails the three disabled-budget rows, and replacing toSdkTimeoutMs(timeoutMs) with the raw value fails exactly the two forwarding rows. The five provider-name literals on the abort paths were re-measured at this head: all five survive the full 211-test suite, which is the measured half of the equivalence argument in the PR body. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 211 passed (211) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false. Review round 3 (CodeRabbit pre-merge checks, six Minor rows): the Chat Completions streaming loop now re-checks the request signal in front of every buffered item of a frame — the text item after a reasoning item, each tool-call partial inside the per-item loop, and the usage item — because a consumer that takes the first item, cancels and pulls the next one resumes this generator inside the same iteration, where the top-of-loop guard has already run. The three stream-open awaits (Anthropic /v1/messages, Responses /v1/responses and chat completions) now go through settleOnAbort with the signal still handed to the SDK, so a 429 with Retry-After plus a caller cancel no longer holds the pending first next() and the bridge cleanup until the sleep ends. Regression evidence: one parameterized test for the three stream-open races plus three manual-iteration tests that abort between two items of one frame (the buffered-text variant also asserts the bridge listener is detached by reference). Negative controls: removing each open wrapper fails exactly that format's row (1 failed | 216 passed each), disabling each buffered-item guard fails exactly that item's test, and reverting the OpenAI-path fixture key from opencodeGoModelId to the ignored apiModelId fails the five assertions that now pin model "glm-5.1" instead of expect.any(String). The parked-lookup test releases its gate in a finally so an assertion throw cannot strand the promise the provider awaits; measured with a probe: a release placed after the throwing assertion leaves the promise unresolved, the same release in a finally settles it. Verification on this round: vitest 217 passed (217) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files reported zero count decreases); prettier 3.9.10 --check: clean. Review round 4 (CodeRabbit pre-merge checks, one Major and nine Minor rows, handled in a single pass): the Responses and Anthropic helpers no longer let a normally-ending SDK iterator read as a completed turn. The Responses helper re-checks the bridged signal after processResponsesApiStream returns; the Anthropic helper re-checks it at the top of each event dispatch, between the separator item and the block body of an indexed content_block_start, and after the loop before the terminal cost chunk, so a cancel cannot emit the rest of an event or bill a turn the caller already cancelled. Four tests drive the shape the pinned SDKs actually produce - hand the consumer one item, cancel, then let the mock iterator report done instead of throwing - and each one also runs the identical fixture with a live caller signal, which still delivers its text and its terminal cost. Negative controls, each against the full suite: the Responses post-stream check (1 failed | 223 passed), the Anthropic after-loop check (killed by the test that cancels after the last event was delivered), the event-dispatch check (killed by the quiet-close test) and the separator checks (killed by the two-yields-of-one-event test) each fail their own test and nothing else that matters. The Responses pre-stream abort test no longer certifies itself through the provider's own catch: the mock captures the signal the SDK actually received and then throws a plain failure, so the only evidence left is that the captured signal is an AbortSignal that had already flipped; handing the SDK an unrelated signal instead of the bridge fails seven tests, including that one. The timeout matrix now pins signal identity rather than signal type - with no usable budget the SDK must hold the caller's own signal, with a usable one it must hold the merged deadline - and a new parameterized test parks each format's request under a 5000 ms budget, cancels the caller long before the deadline and requires the merged signal to flip and the completion to reject with the contract AbortError; replacing the merged deadline with the caller's own signal on the chat-completions completion fails 26 tests, including those rows. Three tests that polled for readiness before observing the rejection now attach the handler when the promise is created, so a model lookup or stream open that rejects during the poll cannot go unobserved. Verification on this round: vitest 224 passed (224) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files found zero decreases, so the rewritten file was reverted); prettier 3.9.10 --check: clean.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `23348a501e9f31d0c72bffa6eefb6030bb6149a3`, spec `5dbe3382d1f1d6af8d22e7637a088c546988ef18`; `git diff df29307 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Review round 2 (CodeRabbit pre-merge checks): each gateway completePrompt now pins the disabled-budget boundary at -5 — the SDK options carry no timeout key and the bridged per-request signal is still handed over (the zoo variant is one of the tests that also catches a dropped signal arm). The ported Opencode Go spec brings its own parameterized timeout-option test per wire format: NaN, Infinity and -5 omit the option, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and the caller signal is asserted on every row. Those rows kill the forward arms at opencode-go.ts:886/944/1027 in both directions (deleting the arm fails two rows per format, forcing it always-forward fails the three disabled-budget rows) and the toSdkTimeoutMs call sites; forcing the gateway arms to always forward fails the new -5 rows on all three providers.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 411 passed (411) in declaration order and 411 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
Review round 3: the mutation-diff report at 313cf0e listed 20 blocking rows (21 survived mutants plus one uncovered arm) over 338 changed executable lines. Five of them are now killed by four tests added here: unbound.ts:349 and vercel-ai-gateway.ts:280 (detachExternalAbortSignal() -> ; in the completePrompt finally) by a detach test per provider that identifies the bridge listener by the { once: true } registration and asserts its removal by reference; zoo-gateway.ts:337 (classification gate -> false) by a streaming test that feeds a name-only AbortError with a live-but-not-aborted caller signal and asserts the contract identity, that the add-credits notification never ran, and that nothing was logged; zoo-gateway.ts:346 in both directions by a streaming test where the notification itself rejects while the caller signal is live (the log must name the surfacing failure and the original 402 must still reach the caller) plus the existing cancel-while-prompt-open test, which also puts that line under coverage. Each of those four mutants was applied alone and restored: 1 failed | 414 passed, killed by the named test in every case. The remaining sixteen rows are all StringLiteral -> "" on a provider-name label inside createAbortError/settleOnAbort/rejectOnAbort; each one sits inside a catch or race whose enclosing handler re-throws with its own unmutated literal, so the provider-visible error name and message are identical through the public API and no assertion can distinguish the mutant from the code (measured: full suite green with each mutant in place). No Stryker directive was added; the equivalence is argued in the PR discussion for a maintainer to weigh.
Verification on this tree: vitest 421 passed (421) across the four provider specs in declaration order and with --sequence.shuffle (the six new opencode-go tests arrive with the re-ported blobs); tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical; prettier 3.9.10 --check on the touched files: clean. The opencode-go blobs are re-ported from df29307 and remain byte-identical to that head (git diff --quiet against it for those two paths: exit 0), so after a maintainer merges Zoo-Code-Org#1652 these lines drop out of this diff on rebase.
Review round 4 (CodeRabbit pre-merge checks, six Major and 26 Minor rows, handled in one pass): three sibling
stream loops no longer hand a cancelled turn their last item - Unbound re-checks the caller signal in front of
the text item of a frame whose reasoning item was already delivered, and both Vercel AI Gateway and Zoo Gateway
re-check it in front of the usage item of a frame whose text was already delivered, so a cancel between the two
items of one chunk rejects instead of emitting or billing the remainder. The three "does not emit the rest of a
tool-call chunk" tests are now consumer-driven (take the first partial, cancel, require the next call to reject
without building the second one) because the getter variant aborted before either partial existed and could not
tell a per-partial check from a per-frame check. Unbound's retained usage is typed as
OpenAI.Completions.CompletionUsage | undefined, which drops its @typescript-eslint/no-explicit-any suppression
from 3 to 2 (the only suppression change in this unit). The non-array tool_calls fixture now carries a truthy
value instead of null, so the Array.isArray check is what the test pins. The Zoo Gateway SDK-timeout
classification test no longer carries a 50 ms provider deadline, and the deadline test's mock refuses to run
without the per-request signal, so a provider that stops forwarding the deadline fails loudly instead of
throwing immediately. The two add-credits streaming tests wrap their whole body in a try/finally so the console
spy is restored even when an early assertion throws. The opencode-go provider and spec are the byte-identical
blobs from Zoo-Code-Org#1652 at d4ce1ce (opencode-go.ts 970de27, opencode-go.spec.ts 8c34bbb), which carry
the Responses/Anthropic quiet-close guards, the terminal-usage guard, the captured-SDK-signal assertions and
the merged-deadline cancel rows that close this unit's opencode-go rows; on rebase over the merged Zoo-Code-Org#1652 those
lines drop out.
Not changed in this unit, with the reasoning recorded on the threads: Unbound's timeout is enforced through the
merged deadline signal rather than response-body consumption (helper-side, tracked on Zoo-Code-Org#2486), the completion
races still return a response that won the race before the cancel, and the completion paths keep using the
shared mergeAbortSignalAndTimeout signal rather than a request-local bridge.
Verification on this round: vitest 431 passed (431) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0
without --prune-suppressions: exit 0, with src/eslint-suppressions.json updated only for the unbound.ts decrease
(3 -> 2) that the prune run reported; prettier 3.9.10 --check: clean. Negative controls against the suite, each
disabling one guard: the Unbound text-item guard, the Vercel usage-item guard and the Zoo usage-item guard each
fail exactly their own new test (1 failed | 45, 56 and 103 passed respectively), the three per-partial guards
each fail exactly their rewritten tool-call test, dropping the Zoo completion's per-request signal arm fails the
seven timeout and abort-delivery tests that read it, and dropping the timeout arm fails the two option-forwarding
tests.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The inner pre-stream provider-name literal is provably equivalent and documented as such in the PR body; no Stryker disable directive is added anywhere in the tree. createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes the error, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested), and the abort-normalization condition beside that literal is killed by a live-signal delivery added in the second review round. The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Review round 2 (CodeRabbit pre-merge checks): completePrompt gained a parameterized timeout-option test per wire format (Anthropic messages, Responses, chat completions) that proves each call site applies the shared hasUsableTimeout/toSdkTimeoutMs contract rather than only testing the helper: NaN, Infinity and -5 leave no timeout key, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and every row also asserts the caller's signal reached the SDK options, so dropping the budget can never drop the cancel. Controls: deleting the forward arm fails two rows per format, forcing it to always forward fails the three disabled-budget rows, and replacing toSdkTimeoutMs(timeoutMs) with the raw value fails exactly the two forwarding rows. The five provider-name literals on the abort paths were re-measured at this head: all five survive the full 211-test suite, which is the measured half of the equivalence argument in the PR body. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 211 passed (211) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false. Review round 3 (CodeRabbit pre-merge checks, six Minor rows): the Chat Completions streaming loop now re-checks the request signal in front of every buffered item of a frame — the text item after a reasoning item, each tool-call partial inside the per-item loop, and the usage item — because a consumer that takes the first item, cancels and pulls the next one resumes this generator inside the same iteration, where the top-of-loop guard has already run. The three stream-open awaits (Anthropic /v1/messages, Responses /v1/responses and chat completions) now go through settleOnAbort with the signal still handed to the SDK, so a 429 with Retry-After plus a caller cancel no longer holds the pending first next() and the bridge cleanup until the sleep ends. Regression evidence: one parameterized test for the three stream-open races plus three manual-iteration tests that abort between two items of one frame (the buffered-text variant also asserts the bridge listener is detached by reference). Negative controls: removing each open wrapper fails exactly that format's row (1 failed | 216 passed each), disabling each buffered-item guard fails exactly that item's test, and reverting the OpenAI-path fixture key from opencodeGoModelId to the ignored apiModelId fails the five assertions that now pin model "glm-5.1" instead of expect.any(String). The parked-lookup test releases its gate in a finally so an assertion throw cannot strand the promise the provider awaits; measured with a probe: a release placed after the throwing assertion leaves the promise unresolved, the same release in a finally settles it. Verification on this round: vitest 217 passed (217) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files reported zero count decreases); prettier 3.9.10 --check: clean. Review round 4 (CodeRabbit pre-merge checks, one Major and nine Minor rows, handled in a single pass): the Responses and Anthropic helpers no longer let a normally-ending SDK iterator read as a completed turn. The Responses helper re-checks the bridged signal after processResponsesApiStream returns; the Anthropic helper re-checks it at the top of each event dispatch, between the separator item and the block body of an indexed content_block_start, and after the loop before the terminal cost chunk, so a cancel cannot emit the rest of an event or bill a turn the caller already cancelled. Four tests drive the shape the pinned SDKs actually produce - hand the consumer one item, cancel, then let the mock iterator report done instead of throwing - and each one also runs the identical fixture with a live caller signal, which still delivers its text and its terminal cost. Negative controls, each against the full suite: the Responses post-stream check (1 failed | 223 passed), the Anthropic after-loop check (killed by the test that cancels after the last event was delivered), the event-dispatch check (killed by the quiet-close test) and the separator checks (killed by the two-yields-of-one-event test) each fail their own test and nothing else that matters. The Responses pre-stream abort test no longer certifies itself through the provider's own catch: the mock captures the signal the SDK actually received and then throws a plain failure, so the only evidence left is that the captured signal is an AbortSignal that had already flipped; handing the SDK an unrelated signal instead of the bridge fails seven tests, including that one. The timeout matrix now pins signal identity rather than signal type - with no usable budget the SDK must hold the caller's own signal, with a usable one it must hold the merged deadline - and a new parameterized test parks each format's request under a 5000 ms budget, cancels the caller long before the deadline and requires the merged signal to flip and the completion to reject with the contract AbortError; replacing the merged deadline with the caller's own signal on the chat-completions completion fails 26 tests, including those rows. Three tests that polled for readiness before observing the rejection now attach the handler when the promise is created, so a model lookup or stream open that rejects during the poll cannot go unobserved. Verification on this round: vitest 224 passed (224) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files found zero decreases, so the rewritten file was reverted); prettier 3.9.10 --check: clean. Review round 5 (mutation sticky at d4ce1ce: blocking 23, advisories 0): this round adds no production lines. Three tests were added, each aimed at a variant the sticky lists: a cancel between the separator and the body of an indexed thinking block (kills the ConditionalExpression -> false variant at opencode-go.ts:796 and puts line 797 under coverage), and one run per streaming format that passes no abort signal at all, so every guard in the helper is exercised with an absent caller signal. Measured against the suite: each of the 17 StringLiteral -> "" rows (357, 380, 391, 407, 424, 567, 574, 626, 717, 725, 743, 797, 809, 858, 976, 1046, 1104) leaves 227/227 green, and each of the 5 OptionalChaining rows (625, 742, 796, 808, 857) leaves 227/227 green. The reason is structural, not a matter of unasserted detail: at the OptionalChaining lines the operand is the request-local signal that bridgeExternalAbortSignal/mergeAbortSignalAndTimeout always hand to the SDK, so it is never nullish there, and an inner createAbortError is replaced by the enclosing catch's own unmutated literal (for example the stream-open catch at 719 re-throwing at 725, and the completion catch at 981 re-throwing at 992), so the tests that do assert the exact contract message still see "The Opencode Go request was aborted". The one variant that is observably different is now killed: ConditionalExpression -> false at 796 fails the new thinking test (1 failed | 226 skipped) where it left the previous suite green. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0, with eslint-suppressions.json unchanged because --prune-suppressions on the two unit files reported no count change; prettier 3.9.10 --check: clean.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `23348a501e9f31d0c72bffa6eefb6030bb6149a3`, spec `5dbe3382d1f1d6af8d22e7637a088c546988ef18`; `git diff df29307 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Review round 2 (CodeRabbit pre-merge checks): each gateway completePrompt now pins the disabled-budget boundary at -5 — the SDK options carry no timeout key and the bridged per-request signal is still handed over (the zoo variant is one of the tests that also catches a dropped signal arm). The ported Opencode Go spec brings its own parameterized timeout-option test per wire format: NaN, Infinity and -5 omit the option, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and the caller signal is asserted on every row. Those rows kill the forward arms at opencode-go.ts:886/944/1027 in both directions (deleting the arm fails two rows per format, forcing it always-forward fails the three disabled-budget rows) and the toSdkTimeoutMs call sites; forcing the gateway arms to always forward fails the new -5 rows on all three providers.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 411 passed (411) in declaration order and 411 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
Review round 3: the mutation-diff report at 313cf0e listed 20 blocking rows (21 survived mutants plus one uncovered arm) over 338 changed executable lines. Five of them are now killed by four tests added here: unbound.ts:349 and vercel-ai-gateway.ts:280 (detachExternalAbortSignal() -> ; in the completePrompt finally) by a detach test per provider that identifies the bridge listener by the { once: true } registration and asserts its removal by reference; zoo-gateway.ts:337 (classification gate -> false) by a streaming test that feeds a name-only AbortError with a live-but-not-aborted caller signal and asserts the contract identity, that the add-credits notification never ran, and that nothing was logged; zoo-gateway.ts:346 in both directions by a streaming test where the notification itself rejects while the caller signal is live (the log must name the surfacing failure and the original 402 must still reach the caller) plus the existing cancel-while-prompt-open test, which also puts that line under coverage. Each of those four mutants was applied alone and restored: 1 failed | 414 passed, killed by the named test in every case. The remaining sixteen rows are all StringLiteral -> "" on a provider-name label inside createAbortError/settleOnAbort/rejectOnAbort; each one sits inside a catch or race whose enclosing handler re-throws with its own unmutated literal, so the provider-visible error name and message are identical through the public API and no assertion can distinguish the mutant from the code (measured: full suite green with each mutant in place). No Stryker directive was added; the equivalence is argued in the PR discussion for a maintainer to weigh.
Verification on this tree: vitest 421 passed (421) across the four provider specs in declaration order and with --sequence.shuffle (the six new opencode-go tests arrive with the re-ported blobs); tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical; prettier 3.9.10 --check on the touched files: clean. The opencode-go blobs are re-ported from df29307 and remain byte-identical to that head (git diff --quiet against it for those two paths: exit 0), so after a maintainer merges Zoo-Code-Org#1652 these lines drop out of this diff on rebase.
Review round 4 (CodeRabbit pre-merge checks, six Major and 26 Minor rows, handled in one pass): three sibling
stream loops no longer hand a cancelled turn their last item - Unbound re-checks the caller signal in front of
the text item of a frame whose reasoning item was already delivered, and both Vercel AI Gateway and Zoo Gateway
re-check it in front of the usage item of a frame whose text was already delivered, so a cancel between the two
items of one chunk rejects instead of emitting or billing the remainder. The three "does not emit the rest of a
tool-call chunk" tests are now consumer-driven (take the first partial, cancel, require the next call to reject
without building the second one) because the getter variant aborted before either partial existed and could not
tell a per-partial check from a per-frame check. Unbound's retained usage is typed as
OpenAI.Completions.CompletionUsage | undefined, which drops its @typescript-eslint/no-explicit-any suppression
from 3 to 2 (the only suppression change in this unit). The non-array tool_calls fixture now carries a truthy
value instead of null, so the Array.isArray check is what the test pins. The Zoo Gateway SDK-timeout
classification test no longer carries a 50 ms provider deadline, and the deadline test's mock refuses to run
without the per-request signal, so a provider that stops forwarding the deadline fails loudly instead of
throwing immediately. The two add-credits streaming tests wrap their whole body in a try/finally so the console
spy is restored even when an early assertion throws. The opencode-go provider and spec are the byte-identical
blobs from Zoo-Code-Org#1652 at d4ce1ce (opencode-go.ts 970de27, opencode-go.spec.ts 8c34bbb), which carry
the Responses/Anthropic quiet-close guards, the terminal-usage guard, the captured-SDK-signal assertions and
the merged-deadline cancel rows that close this unit's opencode-go rows; on rebase over the merged Zoo-Code-Org#1652 those
lines drop out.
Not changed in this unit, with the reasoning recorded on the threads: Unbound's timeout is enforced through the
merged deadline signal rather than response-body consumption (helper-side, tracked on Zoo-Code-Org#2486), the completion
races still return a response that won the race before the cancel, and the completion paths keep using the
shared mergeAbortSignalAndTimeout signal rather than a request-local bridge.
Verification on this round: vitest 431 passed (431) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0
without --prune-suppressions: exit 0, with src/eslint-suppressions.json updated only for the unbound.ts decrease
(3 -> 2) that the prune run reported; prettier 3.9.10 --check: clean. Negative controls against the suite, each
disabling one guard: the Unbound text-item guard, the Vercel usage-item guard and the Zoo usage-item guard each
fail exactly their own new test (1 failed | 45, 56 and 103 passed respectively), the three per-partial guards
each fail exactly their rewritten tool-call test, dropping the Zoo completion's per-request signal arm fails the
seven timeout and abort-delivery tests that read it, and dropping the timeout arm fails the two option-forwarding
tests.
Review round 5 (mutation sticky at 41ba1fe: blocking 23, advisories 0): no production line was added or changed in
this round. The opencode-go provider and spec are re-ported byte-identical from Zoo-Code-Org#1652 at 40456d8 (blobs
970de27 and 4afc3ee), which carry the thinking-separator cancel test and the two no-abort-signal runs that
kill and explain the structural variants on that file. Every sibling row was measured by hand in this worktree: the label
mutants at unbound.ts:218/247/257/278/338 and vercel-ai-gateway.ts:136/168/185/267 leave their whole spec green
(46/46 and 57/57) because each inner createAbortError is replaced by the enclosing catch's own unmutated literal, while
mutating those catches' own labels (unbound.ts:224, 289, 349 and vercel-ai-gateway.ts:204, 213, 279) fails 3, 6, 5, 4, 1
and 5 tests - which is what proves the message the tests assert comes from the catch, not from the inner label. The zoo
labels (280, 308, 344) are killed outright by the abort-identity tests, and the zoo console-guard optional chain is
killed by two existing tests.
Verification on this round: vitest 434 passed (434) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without
--prune-suppressions: exit 0 with eslint-suppressions.json carrying only the round-4 unbound.ts decrease (3 -> 2);
prettier 3.9.10 --check: clean across all eight unit files.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The inner pre-stream provider-name literal is provably equivalent and documented as such in the PR body; no Stryker disable directive is added anywhere in the tree. createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes the error, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested), and the abort-normalization condition beside that literal is killed by a live-signal delivery added in the second review round. The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Review round 2 (CodeRabbit pre-merge checks): completePrompt gained a parameterized timeout-option test per wire format (Anthropic messages, Responses, chat completions) that proves each call site applies the shared hasUsableTimeout/toSdkTimeoutMs contract rather than only testing the helper: NaN, Infinity and -5 leave no timeout key, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and every row also asserts the caller's signal reached the SDK options, so dropping the budget can never drop the cancel. Controls: deleting the forward arm fails two rows per format, forcing it to always forward fails the three disabled-budget rows, and replacing toSdkTimeoutMs(timeoutMs) with the raw value fails exactly the two forwarding rows. The five provider-name literals on the abort paths were re-measured at this head: all five survive the full 211-test suite, which is the measured half of the equivalence argument in the PR body. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 211 passed (211) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false. Review round 3 (CodeRabbit pre-merge checks, six Minor rows): the Chat Completions streaming loop now re-checks the request signal in front of every buffered item of a frame — the text item after a reasoning item, each tool-call partial inside the per-item loop, and the usage item — because a consumer that takes the first item, cancels and pulls the next one resumes this generator inside the same iteration, where the top-of-loop guard has already run. The three stream-open awaits (Anthropic /v1/messages, Responses /v1/responses and chat completions) now go through settleOnAbort with the signal still handed to the SDK, so a 429 with Retry-After plus a caller cancel no longer holds the pending first next() and the bridge cleanup until the sleep ends. Regression evidence: one parameterized test for the three stream-open races plus three manual-iteration tests that abort between two items of one frame (the buffered-text variant also asserts the bridge listener is detached by reference). Negative controls: removing each open wrapper fails exactly that format's row (1 failed | 216 passed each), disabling each buffered-item guard fails exactly that item's test, and reverting the OpenAI-path fixture key from opencodeGoModelId to the ignored apiModelId fails the five assertions that now pin model "glm-5.1" instead of expect.any(String). The parked-lookup test releases its gate in a finally so an assertion throw cannot strand the promise the provider awaits; measured with a probe: a release placed after the throwing assertion leaves the promise unresolved, the same release in a finally settles it. Verification on this round: vitest 217 passed (217) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files reported zero count decreases); prettier 3.9.10 --check: clean. Review round 4 (CodeRabbit pre-merge checks, one Major and nine Minor rows, handled in a single pass): the Responses and Anthropic helpers no longer let a normally-ending SDK iterator read as a completed turn. The Responses helper re-checks the bridged signal after processResponsesApiStream returns; the Anthropic helper re-checks it at the top of each event dispatch, between the separator item and the block body of an indexed content_block_start, and after the loop before the terminal cost chunk, so a cancel cannot emit the rest of an event or bill a turn the caller already cancelled. Four tests drive the shape the pinned SDKs actually produce - hand the consumer one item, cancel, then let the mock iterator report done instead of throwing - and each one also runs the identical fixture with a live caller signal, which still delivers its text and its terminal cost. Negative controls, each against the full suite: the Responses post-stream check (1 failed | 223 passed), the Anthropic after-loop check (killed by the test that cancels after the last event was delivered), the event-dispatch check (killed by the quiet-close test) and the separator checks (killed by the two-yields-of-one-event test) each fail their own test and nothing else that matters. The Responses pre-stream abort test no longer certifies itself through the provider's own catch: the mock captures the signal the SDK actually received and then throws a plain failure, so the only evidence left is that the captured signal is an AbortSignal that had already flipped; handing the SDK an unrelated signal instead of the bridge fails seven tests, including that one. The timeout matrix now pins signal identity rather than signal type - with no usable budget the SDK must hold the caller's own signal, with a usable one it must hold the merged deadline - and a new parameterized test parks each format's request under a 5000 ms budget, cancels the caller long before the deadline and requires the merged signal to flip and the completion to reject with the contract AbortError; replacing the merged deadline with the caller's own signal on the chat-completions completion fails 26 tests, including those rows. Three tests that polled for readiness before observing the rejection now attach the handler when the promise is created, so a model lookup or stream open that rejects during the poll cannot go unobserved. Verification on this round: vitest 224 passed (224) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files found zero decreases, so the rewritten file was reverted); prettier 3.9.10 --check: clean. Review round 5 (mutation sticky at d4ce1ce: blocking 23, advisories 0): this round adds no production lines. Three tests were added, each aimed at a variant the sticky lists: a cancel between the separator and the body of an indexed thinking block (kills the ConditionalExpression -> false variant at opencode-go.ts:796 and puts line 797 under coverage), and one run per streaming format that passes no abort signal at all, so every guard in the helper is exercised with an absent caller signal. Measured against the suite: each of the 17 StringLiteral -> "" rows (357, 380, 391, 407, 424, 567, 574, 626, 717, 725, 743, 797, 809, 858, 976, 1046, 1104) leaves 227/227 green, and each of the 5 OptionalChaining rows (625, 742, 796, 808, 857) leaves 227/227 green. The reason is structural, not a matter of unasserted detail: at the OptionalChaining lines the operand is the request-local signal that bridgeExternalAbortSignal/mergeAbortSignalAndTimeout always hand to the SDK, so it is never nullish there, and an inner createAbortError is replaced by the enclosing catch's own unmutated literal (for example the stream-open catch at 719 re-throwing at 725, and the completion catch at 981 re-throwing at 992), so the tests that do assert the exact contract message still see "The Opencode Go request was aborted". The one variant that is observably different is now killed: ConditionalExpression -> false at 796 fails the new thinking test (1 failed | 226 skipped) where it left the previous suite green. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0, with eslint-suppressions.json unchanged because --prune-suppressions on the two unit files reported no count change; prettier 3.9.10 --check: clean. Review round 6 (ask: kill the StringLiteral family with test-side message assertions before anything else, no new production code). The spec's two remaining name-only assertions now pin the message too (spec:3824 and spec:3867, in the two "bounds %s model resolution by the request timeout" groups), so every name assertion in the file carries the contract message. That changed no survivor, and the reason is worth recording: with the message pinned everywhere, each of the 17 StringLiteral -> "" rows still leaves 227/227 green, because the message those tests read is produced by an enclosing catch that throws its own unmutated createAbortError("Opencode Go") - the createMessage-level catch at :279 and the Chat Completions stream helper's catch at :431 - and blanking either of those two literals fails 8 and 7 tests respectively, while blanking any guard or race label fails none. The five OptionalChaining rows are equivalent for a separate reason: the streaming helpers are always handed bridgedSignal ?? new AbortController().signal at :260, so their operand is never nullish; with all five optional chains removed at once the suite is still 227/227, including the two runs that pass no caller signal at all. No production line changed in either of the last two rounds; the provider blob is unchanged at 970de27. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with eslint-suppressions.json unchanged; prettier 3.9.10 --check: clean.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `23348a501e9f31d0c72bffa6eefb6030bb6149a3`, spec `5dbe3382d1f1d6af8d22e7637a088c546988ef18`; `git diff df29307 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Review round 2 (CodeRabbit pre-merge checks): each gateway completePrompt now pins the disabled-budget boundary at -5 — the SDK options carry no timeout key and the bridged per-request signal is still handed over (the zoo variant is one of the tests that also catches a dropped signal arm). The ported Opencode Go spec brings its own parameterized timeout-option test per wire format: NaN, Infinity and -5 omit the option, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and the caller signal is asserted on every row. Those rows kill the forward arms at opencode-go.ts:886/944/1027 in both directions (deleting the arm fails two rows per format, forcing it always-forward fails the three disabled-budget rows) and the toSdkTimeoutMs call sites; forcing the gateway arms to always forward fails the new -5 rows on all three providers.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 411 passed (411) in declaration order and 411 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
Review round 3: the mutation-diff report at 313cf0e listed 20 blocking rows (21 survived mutants plus one uncovered arm) over 338 changed executable lines. Five of them are now killed by four tests added here: unbound.ts:349 and vercel-ai-gateway.ts:280 (detachExternalAbortSignal() -> ; in the completePrompt finally) by a detach test per provider that identifies the bridge listener by the { once: true } registration and asserts its removal by reference; zoo-gateway.ts:337 (classification gate -> false) by a streaming test that feeds a name-only AbortError with a live-but-not-aborted caller signal and asserts the contract identity, that the add-credits notification never ran, and that nothing was logged; zoo-gateway.ts:346 in both directions by a streaming test where the notification itself rejects while the caller signal is live (the log must name the surfacing failure and the original 402 must still reach the caller) plus the existing cancel-while-prompt-open test, which also puts that line under coverage. Each of those four mutants was applied alone and restored: 1 failed | 414 passed, killed by the named test in every case. The remaining sixteen rows are all StringLiteral -> "" on a provider-name label inside createAbortError/settleOnAbort/rejectOnAbort; each one sits inside a catch or race whose enclosing handler re-throws with its own unmutated literal, so the provider-visible error name and message are identical through the public API and no assertion can distinguish the mutant from the code (measured: full suite green with each mutant in place). No Stryker directive was added; the equivalence is argued in the PR discussion for a maintainer to weigh.
Verification on this tree: vitest 421 passed (421) across the four provider specs in declaration order and with --sequence.shuffle (the six new opencode-go tests arrive with the re-ported blobs); tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical; prettier 3.9.10 --check on the touched files: clean. The opencode-go blobs are re-ported from df29307 and remain byte-identical to that head (git diff --quiet against it for those two paths: exit 0), so after a maintainer merges Zoo-Code-Org#1652 these lines drop out of this diff on rebase.
Review round 4 (CodeRabbit pre-merge checks, six Major and 26 Minor rows, handled in one pass): three sibling
stream loops no longer hand a cancelled turn their last item - Unbound re-checks the caller signal in front of
the text item of a frame whose reasoning item was already delivered, and both Vercel AI Gateway and Zoo Gateway
re-check it in front of the usage item of a frame whose text was already delivered, so a cancel between the two
items of one chunk rejects instead of emitting or billing the remainder. The three "does not emit the rest of a
tool-call chunk" tests are now consumer-driven (take the first partial, cancel, require the next call to reject
without building the second one) because the getter variant aborted before either partial existed and could not
tell a per-partial check from a per-frame check. Unbound's retained usage is typed as
OpenAI.Completions.CompletionUsage | undefined, which drops its @typescript-eslint/no-explicit-any suppression
from 3 to 2 (the only suppression change in this unit). The non-array tool_calls fixture now carries a truthy
value instead of null, so the Array.isArray check is what the test pins. The Zoo Gateway SDK-timeout
classification test no longer carries a 50 ms provider deadline, and the deadline test's mock refuses to run
without the per-request signal, so a provider that stops forwarding the deadline fails loudly instead of
throwing immediately. The two add-credits streaming tests wrap their whole body in a try/finally so the console
spy is restored even when an early assertion throws. The opencode-go provider and spec are the byte-identical
blobs from Zoo-Code-Org#1652 at d4ce1ce (opencode-go.ts 970de27, opencode-go.spec.ts 8c34bbb), which carry
the Responses/Anthropic quiet-close guards, the terminal-usage guard, the captured-SDK-signal assertions and
the merged-deadline cancel rows that close this unit's opencode-go rows; on rebase over the merged Zoo-Code-Org#1652 those
lines drop out.
Not changed in this unit, with the reasoning recorded on the threads: Unbound's timeout is enforced through the
merged deadline signal rather than response-body consumption (helper-side, tracked on Zoo-Code-Org#2486), the completion
races still return a response that won the race before the cancel, and the completion paths keep using the
shared mergeAbortSignalAndTimeout signal rather than a request-local bridge.
Verification on this round: vitest 431 passed (431) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0
without --prune-suppressions: exit 0, with src/eslint-suppressions.json updated only for the unbound.ts decrease
(3 -> 2) that the prune run reported; prettier 3.9.10 --check: clean. Negative controls against the suite, each
disabling one guard: the Unbound text-item guard, the Vercel usage-item guard and the Zoo usage-item guard each
fail exactly their own new test (1 failed | 45, 56 and 103 passed respectively), the three per-partial guards
each fail exactly their rewritten tool-call test, dropping the Zoo completion's per-request signal arm fails the
seven timeout and abort-delivery tests that read it, and dropping the timeout arm fails the two option-forwarding
tests.
Review round 5 (mutation sticky at 41ba1fe: blocking 23, advisories 0): no production line was added or changed in
this round. The opencode-go provider and spec are re-ported byte-identical from Zoo-Code-Org#1652 at 40456d8 (blobs
970de27 and 4afc3ee), which carry the thinking-separator cancel test and the two no-abort-signal runs that
kill and explain the structural variants on that file. Every sibling row was measured by hand in this worktree: the label
mutants at unbound.ts:218/247/257/278/338 and vercel-ai-gateway.ts:136/168/185/267 leave their whole spec green
(46/46 and 57/57) because each inner createAbortError is replaced by the enclosing catch's own unmutated literal, while
mutating those catches' own labels (unbound.ts:224, 289, 349 and vercel-ai-gateway.ts:204, 213, 279) fails 3, 6, 5, 4, 1
and 5 tests - which is what proves the message the tests assert comes from the catch, not from the inner label. The zoo
labels (280, 308, 344) are killed outright by the abort-identity tests, and the zoo console-guard optional chain is
killed by two existing tests.
Verification on this round: vitest 434 passed (434) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without
--prune-suppressions: exit 0 with eslint-suppressions.json carrying only the round-4 unbound.ts decrease (3 -> 2);
prettier 3.9.10 --check: clean across all eight unit files.
Review round 6: the two opencode-go files are re-ported byte-identical from Zoo-Code-Org#1652 at b51323d (blobs 970de27 and
2163ff1), which adds the two message assertions described there and no production line. Verification on this round:
vitest 434 passed (434) across the four provider specs in declaration order and with --sequence.shuffle; tsc --noEmit -p
tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with only the
round-4 unbound.ts decrease (3 -> 2) in eslint-suppressions.json; prettier 3.9.10 --check: clean across the eight unit
files. The unit's own content (excluding the 2847 a+d carried byte-identically from Zoo-Code-Org#1652, which drops out on merge plus
rebase) is 3198 a+d.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The inner pre-stream provider-name literal is provably equivalent and documented as such in the PR body; no Stryker disable directive is added anywhere in the tree. createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes the error, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested), and the abort-normalization condition beside that literal is killed by a live-signal delivery added in the second review round. The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Review round 2 (CodeRabbit pre-merge checks): completePrompt gained a parameterized timeout-option test per wire format (Anthropic messages, Responses, chat completions) that proves each call site applies the shared hasUsableTimeout/toSdkTimeoutMs contract rather than only testing the helper: NaN, Infinity and -5 leave no timeout key, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and every row also asserts the caller's signal reached the SDK options, so dropping the budget can never drop the cancel. Controls: deleting the forward arm fails two rows per format, forcing it to always forward fails the three disabled-budget rows, and replacing toSdkTimeoutMs(timeoutMs) with the raw value fails exactly the two forwarding rows. The five provider-name literals on the abort paths were re-measured at this head: all five survive the full 211-test suite, which is the measured half of the equivalence argument in the PR body. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 211 passed (211) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false. Review round 3 (CodeRabbit pre-merge checks, six Minor rows): the Chat Completions streaming loop now re-checks the request signal in front of every buffered item of a frame — the text item after a reasoning item, each tool-call partial inside the per-item loop, and the usage item — because a consumer that takes the first item, cancels and pulls the next one resumes this generator inside the same iteration, where the top-of-loop guard has already run. The three stream-open awaits (Anthropic /v1/messages, Responses /v1/responses and chat completions) now go through settleOnAbort with the signal still handed to the SDK, so a 429 with Retry-After plus a caller cancel no longer holds the pending first next() and the bridge cleanup until the sleep ends. Regression evidence: one parameterized test for the three stream-open races plus three manual-iteration tests that abort between two items of one frame (the buffered-text variant also asserts the bridge listener is detached by reference). Negative controls: removing each open wrapper fails exactly that format's row (1 failed | 216 passed each), disabling each buffered-item guard fails exactly that item's test, and reverting the OpenAI-path fixture key from opencodeGoModelId to the ignored apiModelId fails the five assertions that now pin model "glm-5.1" instead of expect.any(String). The parked-lookup test releases its gate in a finally so an assertion throw cannot strand the promise the provider awaits; measured with a probe: a release placed after the throwing assertion leaves the promise unresolved, the same release in a finally settles it. Verification on this round: vitest 217 passed (217) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files reported zero count decreases); prettier 3.9.10 --check: clean. Review round 4 (CodeRabbit pre-merge checks, one Major and nine Minor rows, handled in a single pass): the Responses and Anthropic helpers no longer let a normally-ending SDK iterator read as a completed turn. The Responses helper re-checks the bridged signal after processResponsesApiStream returns; the Anthropic helper re-checks it at the top of each event dispatch, between the separator item and the block body of an indexed content_block_start, and after the loop before the terminal cost chunk, so a cancel cannot emit the rest of an event or bill a turn the caller already cancelled. Four tests drive the shape the pinned SDKs actually produce - hand the consumer one item, cancel, then let the mock iterator report done instead of throwing - and each one also runs the identical fixture with a live caller signal, which still delivers its text and its terminal cost. Negative controls, each against the full suite: the Responses post-stream check (1 failed | 223 passed), the Anthropic after-loop check (killed by the test that cancels after the last event was delivered), the event-dispatch check (killed by the quiet-close test) and the separator checks (killed by the two-yields-of-one-event test) each fail their own test and nothing else that matters. The Responses pre-stream abort test no longer certifies itself through the provider's own catch: the mock captures the signal the SDK actually received and then throws a plain failure, so the only evidence left is that the captured signal is an AbortSignal that had already flipped; handing the SDK an unrelated signal instead of the bridge fails seven tests, including that one. The timeout matrix now pins signal identity rather than signal type - with no usable budget the SDK must hold the caller's own signal, with a usable one it must hold the merged deadline - and a new parameterized test parks each format's request under a 5000 ms budget, cancels the caller long before the deadline and requires the merged signal to flip and the completion to reject with the contract AbortError; replacing the merged deadline with the caller's own signal on the chat-completions completion fails 26 tests, including those rows. Three tests that polled for readiness before observing the rejection now attach the handler when the promise is created, so a model lookup or stream open that rejects during the poll cannot go unobserved. Verification on this round: vitest 224 passed (224) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files found zero decreases, so the rewritten file was reverted); prettier 3.9.10 --check: clean. Review round 5 (mutation sticky at d4ce1ce: blocking 23, advisories 0): this round adds no production lines. Three tests were added, each aimed at a variant the sticky lists: a cancel between the separator and the body of an indexed thinking block (kills the ConditionalExpression -> false variant at opencode-go.ts:796 and puts line 797 under coverage), and one run per streaming format that passes no abort signal at all, so every guard in the helper is exercised with an absent caller signal. Measured against the suite: each of the 17 StringLiteral -> "" rows (357, 380, 391, 407, 424, 567, 574, 626, 717, 725, 743, 797, 809, 858, 976, 1046, 1104) leaves 227/227 green, and each of the 5 OptionalChaining rows (625, 742, 796, 808, 857) leaves 227/227 green. The reason is structural, not a matter of unasserted detail: at the OptionalChaining lines the operand is the request-local signal that bridgeExternalAbortSignal/mergeAbortSignalAndTimeout always hand to the SDK, so it is never nullish there, and an inner createAbortError is replaced by the enclosing catch's own unmutated literal (for example the stream-open catch at 719 re-throwing at 725, and the completion catch at 981 re-throwing at 992), so the tests that do assert the exact contract message still see "The Opencode Go request was aborted". The one variant that is observably different is now killed: ConditionalExpression -> false at 796 fails the new thinking test (1 failed | 226 skipped) where it left the previous suite green. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0, with eslint-suppressions.json unchanged because --prune-suppressions on the two unit files reported no count change; prettier 3.9.10 --check: clean. Review round 6 (ask: kill the StringLiteral family with test-side message assertions before anything else, no new production code). The spec's two remaining name-only assertions now pin the message too (spec:3824 and spec:3867, in the two "bounds %s model resolution by the request timeout" groups), so every name assertion in the file carries the contract message. That changed no survivor, and the reason is worth recording: with the message pinned everywhere, each of the 17 StringLiteral -> "" rows still leaves 227/227 green, because the message those tests read is produced by an enclosing catch that throws its own unmutated createAbortError("Opencode Go") - the createMessage-level catch at :279 and the Chat Completions stream helper's catch at :431 - and blanking either of those two literals fails 8 and 7 tests respectively, while blanking any guard or race label fails none. The five OptionalChaining rows are equivalent for a separate reason: the streaming helpers are always handed bridgedSignal ?? new AbortController().signal at :260, so their operand is never nullish; with all five optional chains removed at once the suite is still 227/227, including the two runs that pass no caller signal at all. No production line changed in either of the last two rounds; the provider blob is unchanged at 970de27. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with eslint-suppressions.json unchanged; prettier 3.9.10 --check: clean. Review round 7 (authorized: the pre-yield cancel check on the Responses path - one guard, one helper, one push, no gateway propagation). `streamResponsesMessage` now hands the shared transform an iterator whose `next()` reports the stream ended when the bridged signal is already aborted, so a pull that lands after the caller cancelled can no longer deliver the event the pinned decoder had already buffered; the after-loop guard then produces the contract AbortError. The helper's cleanup forward (`return: streamIterator.return?.bind(streamIterator)`) preserves the previous delegation behaviour - an early consumer exit still closes the SDK iterator twice, as the pre-existing cleanup test asserts - and stays callable when the source iterator implements no `return` at all. This helper's signal parameter is now typed `AbortSignal` (`createMessage` supplies `bridgedSignal ?? new AbortController().signal`), which is why the after-loop guard no longer needs its optional chain. Nothing was added to the three gateway helpers, as instructed. Two tests carry it: the buffered-completion fixture (text delta and `response.completed` from one read, take the delta, cancel, require the rejection and no usage item) and a next-only source iterator, which proves the cleanup forward must not assume `return` exists. Controls: against the pre-change provider the buffered fixture fails with 'expected undefined to match object { name: AbortError }' - today the usage chunk is delivered - so this was an uncovered gap, not a restatement of covered behaviour. For the new code: the pull guard's `ConditionalExpression -> false` fails exactly the two new tests and `-> true` fails 15; the `OptionalChaining` on the cleanup forward fails the next-only test; neutering the after-loop guard now fails 3 tests including the buffered fixture, which is the variant that fixture kills. Verification on this round: vitest 229 passed (229) in declaration order and with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` from `src`: zero errors;`eslint . --ext=ts --max-warnings=0` without `--prune-suppressions`: exit 0 with `eslint-suppressions.json` unchanged and`--prune-suppressions` reporting no decrease; prettier 3.9.10 `--check`: clean. Against merge-base `75a93a9d9acc`: opencode-go.spec.ts +2543/-200=2743, opencode-go.ts +390/-91=481 = 3224 a+d.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `23348a501e9f31d0c72bffa6eefb6030bb6149a3`, spec `5dbe3382d1f1d6af8d22e7637a088c546988ef18`; `git diff df29307 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Review round 2 (CodeRabbit pre-merge checks): each gateway completePrompt now pins the disabled-budget boundary at -5 — the SDK options carry no timeout key and the bridged per-request signal is still handed over (the zoo variant is one of the tests that also catches a dropped signal arm). The ported Opencode Go spec brings its own parameterized timeout-option test per wire format: NaN, Infinity and -5 omit the option, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and the caller signal is asserted on every row. Those rows kill the forward arms at opencode-go.ts:886/944/1027 in both directions (deleting the arm fails two rows per format, forcing it always-forward fails the three disabled-budget rows) and the toSdkTimeoutMs call sites; forcing the gateway arms to always forward fails the new -5 rows on all three providers.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 411 passed (411) in declaration order and 411 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
Review round 3: the mutation-diff report at 313cf0e listed 20 blocking rows (21 survived mutants plus one uncovered arm) over 338 changed executable lines. Five of them are now killed by four tests added here: unbound.ts:349 and vercel-ai-gateway.ts:280 (detachExternalAbortSignal() -> ; in the completePrompt finally) by a detach test per provider that identifies the bridge listener by the { once: true } registration and asserts its removal by reference; zoo-gateway.ts:337 (classification gate -> false) by a streaming test that feeds a name-only AbortError with a live-but-not-aborted caller signal and asserts the contract identity, that the add-credits notification never ran, and that nothing was logged; zoo-gateway.ts:346 in both directions by a streaming test where the notification itself rejects while the caller signal is live (the log must name the surfacing failure and the original 402 must still reach the caller) plus the existing cancel-while-prompt-open test, which also puts that line under coverage. Each of those four mutants was applied alone and restored: 1 failed | 414 passed, killed by the named test in every case. The remaining sixteen rows are all StringLiteral -> "" on a provider-name label inside createAbortError/settleOnAbort/rejectOnAbort; each one sits inside a catch or race whose enclosing handler re-throws with its own unmutated literal, so the provider-visible error name and message are identical through the public API and no assertion can distinguish the mutant from the code (measured: full suite green with each mutant in place). No Stryker directive was added; the equivalence is argued in the PR discussion for a maintainer to weigh.
Verification on this tree: vitest 421 passed (421) across the four provider specs in declaration order and with --sequence.shuffle (the six new opencode-go tests arrive with the re-ported blobs); tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical; prettier 3.9.10 --check on the touched files: clean. The opencode-go blobs are re-ported from df29307 and remain byte-identical to that head (git diff --quiet against it for those two paths: exit 0), so after a maintainer merges Zoo-Code-Org#1652 these lines drop out of this diff on rebase.
Review round 4 (CodeRabbit pre-merge checks, six Major and 26 Minor rows, handled in one pass): three sibling
stream loops no longer hand a cancelled turn their last item - Unbound re-checks the caller signal in front of
the text item of a frame whose reasoning item was already delivered, and both Vercel AI Gateway and Zoo Gateway
re-check it in front of the usage item of a frame whose text was already delivered, so a cancel between the two
items of one chunk rejects instead of emitting or billing the remainder. The three "does not emit the rest of a
tool-call chunk" tests are now consumer-driven (take the first partial, cancel, require the next call to reject
without building the second one) because the getter variant aborted before either partial existed and could not
tell a per-partial check from a per-frame check. Unbound's retained usage is typed as
OpenAI.Completions.CompletionUsage | undefined, which drops its @typescript-eslint/no-explicit-any suppression
from 3 to 2 (the only suppression change in this unit). The non-array tool_calls fixture now carries a truthy
value instead of null, so the Array.isArray check is what the test pins. The Zoo Gateway SDK-timeout
classification test no longer carries a 50 ms provider deadline, and the deadline test's mock refuses to run
without the per-request signal, so a provider that stops forwarding the deadline fails loudly instead of
throwing immediately. The two add-credits streaming tests wrap their whole body in a try/finally so the console
spy is restored even when an early assertion throws. The opencode-go provider and spec are the byte-identical
blobs from Zoo-Code-Org#1652 at d4ce1ce (opencode-go.ts 970de27, opencode-go.spec.ts 8c34bbb), which carry
the Responses/Anthropic quiet-close guards, the terminal-usage guard, the captured-SDK-signal assertions and
the merged-deadline cancel rows that close this unit's opencode-go rows; on rebase over the merged Zoo-Code-Org#1652 those
lines drop out.
Not changed in this unit, with the reasoning recorded on the threads: Unbound's timeout is enforced through the
merged deadline signal rather than response-body consumption (helper-side, tracked on Zoo-Code-Org#2486), the completion
races still return a response that won the race before the cancel, and the completion paths keep using the
shared mergeAbortSignalAndTimeout signal rather than a request-local bridge.
Verification on this round: vitest 431 passed (431) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0
without --prune-suppressions: exit 0, with src/eslint-suppressions.json updated only for the unbound.ts decrease
(3 -> 2) that the prune run reported; prettier 3.9.10 --check: clean. Negative controls against the suite, each
disabling one guard: the Unbound text-item guard, the Vercel usage-item guard and the Zoo usage-item guard each
fail exactly their own new test (1 failed | 45, 56 and 103 passed respectively), the three per-partial guards
each fail exactly their rewritten tool-call test, dropping the Zoo completion's per-request signal arm fails the
seven timeout and abort-delivery tests that read it, and dropping the timeout arm fails the two option-forwarding
tests.
Review round 5 (mutation sticky at 41ba1fe: blocking 23, advisories 0): no production line was added or changed in
this round. The opencode-go provider and spec are re-ported byte-identical from Zoo-Code-Org#1652 at 40456d8 (blobs
970de27 and 4afc3ee), which carry the thinking-separator cancel test and the two no-abort-signal runs that
kill and explain the structural variants on that file. Every sibling row was measured by hand in this worktree: the label
mutants at unbound.ts:218/247/257/278/338 and vercel-ai-gateway.ts:136/168/185/267 leave their whole spec green
(46/46 and 57/57) because each inner createAbortError is replaced by the enclosing catch's own unmutated literal, while
mutating those catches' own labels (unbound.ts:224, 289, 349 and vercel-ai-gateway.ts:204, 213, 279) fails 3, 6, 5, 4, 1
and 5 tests - which is what proves the message the tests assert comes from the catch, not from the inner label. The zoo
labels (280, 308, 344) are killed outright by the abort-identity tests, and the zoo console-guard optional chain is
killed by two existing tests.
Verification on this round: vitest 434 passed (434) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without
--prune-suppressions: exit 0 with eslint-suppressions.json carrying only the round-4 unbound.ts decrease (3 -> 2);
prettier 3.9.10 --check: clean across all eight unit files.
Review round 6: the two opencode-go files are re-ported byte-identical from Zoo-Code-Org#1652 at b51323d (blobs 970de27 and
2163ff1), which adds the two message assertions described there and no production line. Verification on this round:
vitest 434 passed (434) across the four provider specs in declaration order and with --sequence.shuffle; tsc --noEmit -p
tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with only the
round-4 unbound.ts decrease (3 -> 2) in eslint-suppressions.json; prettier 3.9.10 --check: clean across the eight unit
files. The unit's own content (excluding the 2847 a+d carried byte-identically from Zoo-Code-Org#1652, which drops out on merge plus
rebase) is 3198 a+d.
Review round 7: re-ported the two opencode-go blobs byte-identically from `371445df813b` (Zoo-Code-Org#1652 round 7), which
adds the authorized pre-yield cancel check on the Responses path and the two tests that carry it - the
buffered-completion fixture (text delta and `response.completed` from one read, take the delta, cancel, require
the rejection and no usage item) and the next-only source iterator that proves the cleanup forward must not assume
`return` exists. The three gateway helpers are untouched by that check, as instructed; series consistency of
the check is recorded as a follow-up on Zoo-Code-Org#2486 rather than folded into this unit.
Preflight reading (advisory, run incomplete, no scoring): the local Stryker preflight of the unit delta generated 402
mutants against the 400-mutant preflight limit in the previous round's run, and the added lines push that figure
higher; the run was therefore not scored, and `blocking:0` on the last completed report is an artifact of the
aborted preflight, not a clean mutation result - Zoo-Code-Org#1653's earlier completed head `41ba1fea0524` listed the same
12 `opencode-go.ts` StringLiteral rows as surviving with all three gateway specs present. No scored mutant of
this unit's own gateway code has been left without a disposition.
Decision requested (author/maintainer): either (a) split this unit further so each branch stays under the 400-mutant
preflight limit and the run can be scored, or (b) accept a reasoned narrow exclusion of the carried `opencode-go.ts`
rows from this unit's scoring on the ground that Zoo-Code-Org#1652 owns and scores those lines. Nothing here churns either unit to
force the count under 400.
Verification on this round: vitest 436 passed (436) across the four specs in declaration order and with
`--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` from `src`: zero errors;`eslint . --ext=ts --max-warnings=0`
without `--prune-suppressions`: exit 0 with `eslint-suppressions.json` unchanged from this unit's own
`-1` decrease and `--prune-suppressions` reporting no further decrease; prettier 3.9.10 `--check`: clean.
Against merge-base `75a93a9d9acc`: opencode-go.spec.ts +2543/-200=2743, unbound.spec.ts +1138/-4=1142, vercel-ai-gateway.spec.ts +771/-2=773, zoo-gateway.spec.ts +820/-1=821, opencode-go.ts +390/-91=481, unbound.ts +142/-36=178, vercel-ai-gateway.ts +144/-42=186, zoo-gateway.ts +87/-9=96, eslint-suppressions.json +1/-1=2 = 6422 a+d, of which 3224 is the
byte-identical carry of Zoo-Code-Org#1652's diff, leaving 3198 this unit's own.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The inner pre-stream provider-name literal is provably equivalent and documented as such in the PR body; no Stryker disable directive is added anywhere in the tree. createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes the error, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested), and the abort-normalization condition beside that literal is killed by a live-signal delivery added in the second review round. The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Review round 2 (CodeRabbit pre-merge checks): completePrompt gained a parameterized timeout-option test per wire format (Anthropic messages, Responses, chat completions) that proves each call site applies the shared hasUsableTimeout/toSdkTimeoutMs contract rather than only testing the helper: NaN, Infinity and -5 leave no timeout key, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and every row also asserts the caller's signal reached the SDK options, so dropping the budget can never drop the cancel. Controls: deleting the forward arm fails two rows per format, forcing it to always forward fails the three disabled-budget rows, and replacing toSdkTimeoutMs(timeoutMs) with the raw value fails exactly the two forwarding rows. The five provider-name literals on the abort paths were re-measured at this head: all five survive the full 211-test suite, which is the measured half of the equivalence argument in the PR body. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 211 passed (211) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false. Review round 3 (CodeRabbit pre-merge checks, six Minor rows): the Chat Completions streaming loop now re-checks the request signal in front of every buffered item of a frame — the text item after a reasoning item, each tool-call partial inside the per-item loop, and the usage item — because a consumer that takes the first item, cancels and pulls the next one resumes this generator inside the same iteration, where the top-of-loop guard has already run. The three stream-open awaits (Anthropic /v1/messages, Responses /v1/responses and chat completions) now go through settleOnAbort with the signal still handed to the SDK, so a 429 with Retry-After plus a caller cancel no longer holds the pending first next() and the bridge cleanup until the sleep ends. Regression evidence: one parameterized test for the three stream-open races plus three manual-iteration tests that abort between two items of one frame (the buffered-text variant also asserts the bridge listener is detached by reference). Negative controls: removing each open wrapper fails exactly that format's row (1 failed | 216 passed each), disabling each buffered-item guard fails exactly that item's test, and reverting the OpenAI-path fixture key from opencodeGoModelId to the ignored apiModelId fails the five assertions that now pin model "glm-5.1" instead of expect.any(String). The parked-lookup test releases its gate in a finally so an assertion throw cannot strand the promise the provider awaits; measured with a probe: a release placed after the throwing assertion leaves the promise unresolved, the same release in a finally settles it. Verification on this round: vitest 217 passed (217) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files reported zero count decreases); prettier 3.9.10 --check: clean. Review round 4 (CodeRabbit pre-merge checks, one Major and nine Minor rows, handled in a single pass): the Responses and Anthropic helpers no longer let a normally-ending SDK iterator read as a completed turn. The Responses helper re-checks the bridged signal after processResponsesApiStream returns; the Anthropic helper re-checks it at the top of each event dispatch, between the separator item and the block body of an indexed content_block_start, and after the loop before the terminal cost chunk, so a cancel cannot emit the rest of an event or bill a turn the caller already cancelled. Four tests drive the shape the pinned SDKs actually produce - hand the consumer one item, cancel, then let the mock iterator report done instead of throwing - and each one also runs the identical fixture with a live caller signal, which still delivers its text and its terminal cost. Negative controls, each against the full suite: the Responses post-stream check (1 failed | 223 passed), the Anthropic after-loop check (killed by the test that cancels after the last event was delivered), the event-dispatch check (killed by the quiet-close test) and the separator checks (killed by the two-yields-of-one-event test) each fail their own test and nothing else that matters. The Responses pre-stream abort test no longer certifies itself through the provider's own catch: the mock captures the signal the SDK actually received and then throws a plain failure, so the only evidence left is that the captured signal is an AbortSignal that had already flipped; handing the SDK an unrelated signal instead of the bridge fails seven tests, including that one. The timeout matrix now pins signal identity rather than signal type - with no usable budget the SDK must hold the caller's own signal, with a usable one it must hold the merged deadline - and a new parameterized test parks each format's request under a 5000 ms budget, cancels the caller long before the deadline and requires the merged signal to flip and the completion to reject with the contract AbortError; replacing the merged deadline with the caller's own signal on the chat-completions completion fails 26 tests, including those rows. Three tests that polled for readiness before observing the rejection now attach the handler when the promise is created, so a model lookup or stream open that rejects during the poll cannot go unobserved. Verification on this round: vitest 224 passed (224) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files found zero decreases, so the rewritten file was reverted); prettier 3.9.10 --check: clean. Review round 5 (mutation sticky at d4ce1ce: blocking 23, advisories 0): this round adds no production lines. Three tests were added, each aimed at a variant the sticky lists: a cancel between the separator and the body of an indexed thinking block (kills the ConditionalExpression -> false variant at opencode-go.ts:796 and puts line 797 under coverage), and one run per streaming format that passes no abort signal at all, so every guard in the helper is exercised with an absent caller signal. Measured against the suite: each of the 17 StringLiteral -> "" rows (357, 380, 391, 407, 424, 567, 574, 626, 717, 725, 743, 797, 809, 858, 976, 1046, 1104) leaves 227/227 green, and each of the 5 OptionalChaining rows (625, 742, 796, 808, 857) leaves 227/227 green. The reason is structural, not a matter of unasserted detail: at the OptionalChaining lines the operand is the request-local signal that bridgeExternalAbortSignal/mergeAbortSignalAndTimeout always hand to the SDK, so it is never nullish there, and an inner createAbortError is replaced by the enclosing catch's own unmutated literal (for example the stream-open catch at 719 re-throwing at 725, and the completion catch at 981 re-throwing at 992), so the tests that do assert the exact contract message still see "The Opencode Go request was aborted". The one variant that is observably different is now killed: ConditionalExpression -> false at 796 fails the new thinking test (1 failed | 226 skipped) where it left the previous suite green. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0, with eslint-suppressions.json unchanged because --prune-suppressions on the two unit files reported no count change; prettier 3.9.10 --check: clean. Review round 6 (ask: kill the StringLiteral family with test-side message assertions before anything else, no new production code). The spec's two remaining name-only assertions now pin the message too (spec:3824 and spec:3867, in the two "bounds %s model resolution by the request timeout" groups), so every name assertion in the file carries the contract message. That changed no survivor, and the reason is worth recording: with the message pinned everywhere, each of the 17 StringLiteral -> "" rows still leaves 227/227 green, because the message those tests read is produced by an enclosing catch that throws its own unmutated createAbortError("Opencode Go") - the createMessage-level catch at :279 and the Chat Completions stream helper's catch at :431 - and blanking either of those two literals fails 8 and 7 tests respectively, while blanking any guard or race label fails none. The five OptionalChaining rows are equivalent for a separate reason: the streaming helpers are always handed bridgedSignal ?? new AbortController().signal at :260, so their operand is never nullish; with all five optional chains removed at once the suite is still 227/227, including the two runs that pass no caller signal at all. No production line changed in either of the last two rounds; the provider blob is unchanged at 970de27. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with eslint-suppressions.json unchanged; prettier 3.9.10 --check: clean. Review round 7 (authorized: the pre-yield cancel check on the Responses path - one guard, one helper, one push, no gateway propagation). `streamResponsesMessage` now hands the shared transform an iterator whose `next()` reports the stream ended when the bridged signal is already aborted, so a pull that lands after the caller cancelled can no longer deliver the event the pinned decoder had already buffered; the after-loop guard then produces the contract AbortError. The helper's cleanup forward (`return: streamIterator.return?.bind(streamIterator)`) preserves the previous delegation behaviour - an early consumer exit still closes the SDK iterator twice, as the pre-existing cleanup test asserts - and stays callable when the source iterator implements no `return` at all. This helper's signal parameter is now typed `AbortSignal` (`createMessage` supplies `bridgedSignal ?? new AbortController().signal`), which is why the after-loop guard no longer needs its optional chain. Nothing was added to the three gateway helpers, as instructed. Two tests carry it: the buffered-completion fixture (text delta and `response.completed` from one read, take the delta, cancel, require the rejection and no usage item) and a next-only source iterator, which proves the cleanup forward must not assume `return` exists. Controls: against the pre-change provider the buffered fixture fails with 'expected undefined to match object { name: AbortError }' - today the usage chunk is delivered - so this was an uncovered gap, not a restatement of covered behaviour. For the new code: the pull guard's `ConditionalExpression -> false` fails exactly the two new tests and `-> true` fails 15; the `OptionalChaining` on the cleanup forward fails the next-only test; neutering the after-loop guard now fails 3 tests including the buffered fixture, which is the variant that fixture kills. Verification on this round: vitest 229 passed (229) in declaration order and with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` from `src`: zero errors;`eslint . --ext=ts --max-warnings=0` without `--prune-suppressions`: exit 0 with `eslint-suppressions.json` unchanged and`--prune-suppressions` reporting no decrease; prettier 3.9.10 `--check`: clean. Against merge-base `75a93a9d9acc`: opencode-go.spec.ts +2543/-200=2743, opencode-go.ts +390/-91=481 = 3224 a+d. Review round 8 (CodeRabbit review 5982073495, line 3872 wall-clock row): the deadline test no longer measures elapsed time. It parks the SDK promise so it never settles, then asserts the observed abort reason (name AbortError plus the exact contract message), that the signal handed to the SDK really is an AbortSignal and had already flipped, and that a settled-flag attached to the parked promise is still false, so the rejection can only come from the provider's race; the 1s bound is gone (it was the assertion a stalled worker could fail) and the duplicated message assertion was deduplicated. The caller-cancel-under- budget test now reads the SDK-facing signal immediately before controller.abort() and immediately after it, with no await between the two reads, and the redundant post-settlement read was removed. Shared-deadline row: a new test parks the catalog fetcher, releases it, waits for the dispatch, and then asserts by reference identity that the dispatched request runs on the caller's own cancellation scope (with no timeoutMs, mergeAbortSignalAndTimeout returns the caller's signal unchanged at utils/abort-signal.ts:42-44), flips it, requires the flip on the SDK-facing signal with no await in between, and requires the completion to reject with the contract AbortError while the parked SDK promise is still unsettled. Controls: replacing signal: resolutionAbortSignal in the chat-completions dispatch with a fresh controller fails exactly that test (AssertionError: expected AbortSignal { aborted: false } to be AbortSignal { aborted: false }, 1 failed | 229 skipped), and forcing the merge's timeout arm off fails all three rows of the deadline test (3 failed). Signal identity for the timeout shapes was already pinned by assertTimeoutOption (spec:4056), which requires the caller's own object with no usable budget and a merged deadline distinct from it with a usable one. Verification on this round: vitest 230 passed (230) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with eslint-suppressions.json unchanged (--prune-suppressions on the spec reported no count decrease, so the rewritten file was reverted); prettier 3.9.10 --check: clean. No production line changed in this round; the provider blob is unchanged at bb1acfe. Against merge-base 75a93a9: opencode-go.spec.ts +2597/-191=2788, opencode-go.ts +390/-91=481 = 3269 a+d.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `23348a501e9f31d0c72bffa6eefb6030bb6149a3`, spec `5dbe3382d1f1d6af8d22e7637a088c546988ef18`; `git diff df29307 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Review round 2 (CodeRabbit pre-merge checks): each gateway completePrompt now pins the disabled-budget boundary at -5 — the SDK options carry no timeout key and the bridged per-request signal is still handed over (the zoo variant is one of the tests that also catches a dropped signal arm). The ported Opencode Go spec brings its own parameterized timeout-option test per wire format: NaN, Infinity and -5 omit the option, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and the caller signal is asserted on every row. Those rows kill the forward arms at opencode-go.ts:886/944/1027 in both directions (deleting the arm fails two rows per format, forcing it always-forward fails the three disabled-budget rows) and the toSdkTimeoutMs call sites; forcing the gateway arms to always forward fails the new -5 rows on all three providers.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 411 passed (411) in declaration order and 411 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
Review round 3: the mutation-diff report at 313cf0e listed 20 blocking rows (21 survived mutants plus one uncovered arm) over 338 changed executable lines. Five of them are now killed by four tests added here: unbound.ts:349 and vercel-ai-gateway.ts:280 (detachExternalAbortSignal() -> ; in the completePrompt finally) by a detach test per provider that identifies the bridge listener by the { once: true } registration and asserts its removal by reference; zoo-gateway.ts:337 (classification gate -> false) by a streaming test that feeds a name-only AbortError with a live-but-not-aborted caller signal and asserts the contract identity, that the add-credits notification never ran, and that nothing was logged; zoo-gateway.ts:346 in both directions by a streaming test where the notification itself rejects while the caller signal is live (the log must name the surfacing failure and the original 402 must still reach the caller) plus the existing cancel-while-prompt-open test, which also puts that line under coverage. Each of those four mutants was applied alone and restored: 1 failed | 414 passed, killed by the named test in every case. The remaining sixteen rows are all StringLiteral -> "" on a provider-name label inside createAbortError/settleOnAbort/rejectOnAbort; each one sits inside a catch or race whose enclosing handler re-throws with its own unmutated literal, so the provider-visible error name and message are identical through the public API and no assertion can distinguish the mutant from the code (measured: full suite green with each mutant in place). No Stryker directive was added; the equivalence is argued in the PR discussion for a maintainer to weigh.
Verification on this tree: vitest 421 passed (421) across the four provider specs in declaration order and with --sequence.shuffle (the six new opencode-go tests arrive with the re-ported blobs); tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical; prettier 3.9.10 --check on the touched files: clean. The opencode-go blobs are re-ported from df29307 and remain byte-identical to that head (git diff --quiet against it for those two paths: exit 0), so after a maintainer merges Zoo-Code-Org#1652 these lines drop out of this diff on rebase.
Review round 4 (CodeRabbit pre-merge checks, six Major and 26 Minor rows, handled in one pass): three sibling
stream loops no longer hand a cancelled turn their last item - Unbound re-checks the caller signal in front of
the text item of a frame whose reasoning item was already delivered, and both Vercel AI Gateway and Zoo Gateway
re-check it in front of the usage item of a frame whose text was already delivered, so a cancel between the two
items of one chunk rejects instead of emitting or billing the remainder. The three "does not emit the rest of a
tool-call chunk" tests are now consumer-driven (take the first partial, cancel, require the next call to reject
without building the second one) because the getter variant aborted before either partial existed and could not
tell a per-partial check from a per-frame check. Unbound's retained usage is typed as
OpenAI.Completions.CompletionUsage | undefined, which drops its @typescript-eslint/no-explicit-any suppression
from 3 to 2 (the only suppression change in this unit). The non-array tool_calls fixture now carries a truthy
value instead of null, so the Array.isArray check is what the test pins. The Zoo Gateway SDK-timeout
classification test no longer carries a 50 ms provider deadline, and the deadline test's mock refuses to run
without the per-request signal, so a provider that stops forwarding the deadline fails loudly instead of
throwing immediately. The two add-credits streaming tests wrap their whole body in a try/finally so the console
spy is restored even when an early assertion throws. The opencode-go provider and spec are the byte-identical
blobs from Zoo-Code-Org#1652 at d4ce1ce (opencode-go.ts 970de27, opencode-go.spec.ts 8c34bbb), which carry
the Responses/Anthropic quiet-close guards, the terminal-usage guard, the captured-SDK-signal assertions and
the merged-deadline cancel rows that close this unit's opencode-go rows; on rebase over the merged Zoo-Code-Org#1652 those
lines drop out.
Not changed in this unit, with the reasoning recorded on the threads: Unbound's timeout is enforced through the
merged deadline signal rather than response-body consumption (helper-side, tracked on Zoo-Code-Org#2486), the completion
races still return a response that won the race before the cancel, and the completion paths keep using the
shared mergeAbortSignalAndTimeout signal rather than a request-local bridge.
Verification on this round: vitest 431 passed (431) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0
without --prune-suppressions: exit 0, with src/eslint-suppressions.json updated only for the unbound.ts decrease
(3 -> 2) that the prune run reported; prettier 3.9.10 --check: clean. Negative controls against the suite, each
disabling one guard: the Unbound text-item guard, the Vercel usage-item guard and the Zoo usage-item guard each
fail exactly their own new test (1 failed | 45, 56 and 103 passed respectively), the three per-partial guards
each fail exactly their rewritten tool-call test, dropping the Zoo completion's per-request signal arm fails the
seven timeout and abort-delivery tests that read it, and dropping the timeout arm fails the two option-forwarding
tests.
Review round 5 (mutation sticky at 41ba1fe: blocking 23, advisories 0): no production line was added or changed in
this round. The opencode-go provider and spec are re-ported byte-identical from Zoo-Code-Org#1652 at 40456d8 (blobs
970de27 and 4afc3ee), which carry the thinking-separator cancel test and the two no-abort-signal runs that
kill and explain the structural variants on that file. Every sibling row was measured by hand in this worktree: the label
mutants at unbound.ts:218/247/257/278/338 and vercel-ai-gateway.ts:136/168/185/267 leave their whole spec green
(46/46 and 57/57) because each inner createAbortError is replaced by the enclosing catch's own unmutated literal, while
mutating those catches' own labels (unbound.ts:224, 289, 349 and vercel-ai-gateway.ts:204, 213, 279) fails 3, 6, 5, 4, 1
and 5 tests - which is what proves the message the tests assert comes from the catch, not from the inner label. The zoo
labels (280, 308, 344) are killed outright by the abort-identity tests, and the zoo console-guard optional chain is
killed by two existing tests.
Verification on this round: vitest 434 passed (434) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without
--prune-suppressions: exit 0 with eslint-suppressions.json carrying only the round-4 unbound.ts decrease (3 -> 2);
prettier 3.9.10 --check: clean across all eight unit files.
Review round 6: the two opencode-go files are re-ported byte-identical from Zoo-Code-Org#1652 at b51323d (blobs 970de27 and
2163ff1), which adds the two message assertions described there and no production line. Verification on this round:
vitest 434 passed (434) across the four provider specs in declaration order and with --sequence.shuffle; tsc --noEmit -p
tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with only the
round-4 unbound.ts decrease (3 -> 2) in eslint-suppressions.json; prettier 3.9.10 --check: clean across the eight unit
files. The unit's own content (excluding the 2847 a+d carried byte-identically from Zoo-Code-Org#1652, which drops out on merge plus
rebase) is 3198 a+d.
Review round 7: re-ported the two opencode-go blobs byte-identically from `371445df813b` (Zoo-Code-Org#1652 round 7), which
adds the authorized pre-yield cancel check on the Responses path and the two tests that carry it - the
buffered-completion fixture (text delta and `response.completed` from one read, take the delta, cancel, require
the rejection and no usage item) and the next-only source iterator that proves the cleanup forward must not assume
`return` exists. The three gateway helpers are untouched by that check, as instructed; series consistency of
the check is recorded as a follow-up on Zoo-Code-Org#2486 rather than folded into this unit.
Preflight reading (advisory, run incomplete, no scoring): the local Stryker preflight of the unit delta generated 402
mutants against the 400-mutant preflight limit in the previous round's run, and the added lines push that figure
higher; the run was therefore not scored, and `blocking:0` on the last completed report is an artifact of the
aborted preflight, not a clean mutation result - Zoo-Code-Org#1653's earlier completed head `41ba1fea0524` listed the same
12 `opencode-go.ts` StringLiteral rows as surviving with all three gateway specs present. No scored mutant of
this unit's own gateway code has been left without a disposition.
Decision requested (author/maintainer): either (a) split this unit further so each branch stays under the 400-mutant
preflight limit and the run can be scored, or (b) accept a reasoned narrow exclusion of the carried `opencode-go.ts`
rows from this unit's scoring on the ground that Zoo-Code-Org#1652 owns and scores those lines. Nothing here churns either unit to
force the count under 400.
Verification on this round: vitest 436 passed (436) across the four specs in declaration order and with
`--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` from `src`: zero errors;`eslint . --ext=ts --max-warnings=0`
without `--prune-suppressions`: exit 0 with `eslint-suppressions.json` unchanged from this unit's own
`-1` decrease and `--prune-suppressions` reporting no further decrease; prettier 3.9.10 `--check`: clean.
Against merge-base `75a93a9d9acc`: opencode-go.spec.ts +2543/-200=2743, unbound.spec.ts +1138/-4=1142, vercel-ai-gateway.spec.ts +771/-2=773, zoo-gateway.spec.ts +820/-1=821, opencode-go.ts +390/-91=481, unbound.ts +142/-36=178, vercel-ai-gateway.ts +144/-42=186, zoo-gateway.ts +87/-9=96, eslint-suppressions.json +1/-1=2 = 6422 a+d, of which 3224 is the
byte-identical carry of Zoo-Code-Org#1652's diff, leaving 3198 this unit's own.
Review round 8 (carried from Zoo-Code-Org#1652 head 18eea83, spec blob b60a3da byte-identical): the deadline test drops its
elapsed-time bound - a stalled worker could fail it while the behaviour was correct - and now asserts the observed abort
reason (name + exact contract message), that the signal handed to the SDK is an AbortSignal that had already flipped, and
that a settled-flag attached to the parked SDK promise is still false, so the rejection can only come from the provider's
race. The caller-cancel-under-budget test reads the SDK-facing signal immediately before controller.abort() and immediately
after it, with no await between. A new test parks the catalog fetcher, releases it, waits for the dispatch and asserts by
reference identity that the dispatched request runs on the caller's own cancellation scope (no timeoutMs ->
mergeAbortSignalAndTimeout returns the caller's signal unchanged, utils/abort-signal.ts:42-44), then requires the cancel to
flip that same object with no await in between and the completion to reject while the SDK promise is still unsettled.
Controls: swapping signal: resolutionAbortSignal for a fresh controller in the chat-completions dispatch fails exactly that
test (1 failed | 229 skipped); disabling the merge's timeout arm fails all three rows of the deadline test (3 failed).
No gateway helper changed in this round; the four unit specs' own elapsed-time assertions were zero, and they remain zero.
Pre-merge rows answered without a production change: Lifecycle Resource Cleanup - completePrompt already builds one scope at
opencode-go.ts:951 via mergeAbortSignalAndTimeout(options?.abortSignal, options?.timeoutMs) and passes that merged signal to
the Anthropic, Responses and chat-completions SDK calls (:969, :1027, :1110) and to the races (:995, :1065, :1123); the raw
caller signal appears only in isRequestAborted classification. The helper registers no listener on the caller's signal -
utils/abort-signal.ts:42-44 returns it unchanged with no usable budget, :48-50 returns AbortSignal.timeout() alone, :52
returns mergeAbortSignals(external, timeout) which at :62-68 is AbortSignal.any([primary, secondary]) - so there is nothing
for the provider to detach, and the composite leaves with the request scope. The path that does attach a listener is the
streaming bridge at :256, whose dispose runs at :283, :309 and :435. Regression Evidence - the quiet-close tests the row
names already exist: spec:2376 (Anthropic streamAnthropicMessage), spec:2741 (Responses), spec:2785 (buffered completion
event delivered after the cancel), driven by the guards at opencode-go.ts:630, :644, :761 and :877.
Verification on this round: vitest 437 passed (437) across opencode-go.spec.ts, unbound.spec.ts, vercel-ai-gateway.spec.ts
and zoo-gateway.spec.ts in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero
errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with eslint-suppressions.json unchanged
(--prune-suppressions over the eight unit files reported no count decrease); prettier 3.9.10 --check: clean on all eight
unit files. Against merge-base 75a93a9 the unit totals are 6467 a+d.
- createMessage: bridge metadata.abortSignal to a per-request AbortController (Bedrock pattern: pre-aborted guard, once-listener, detached on completion so a task-scoped signal does not accumulate listeners); model resolution runs inside the shared resolveModelWithAbort cancellation scope (pre-aborted fast-fail, mid-resolution race) - aborted/timeout requests normalize to the provider AbortError on all three wire formats (anthropic /v1/messages, responses /v1/responses, openai chat completions), both pre-stream and mid-stream; non-abort failures keep the wrapped "Opencode Go completion error:" identity - the OpenAI branch runs message conversion and request construction inside the same cleanup scope as the Anthropic and Responses branches, so a conversion failure (e.g. an unstringifiable tool input) still detaches the bridged abort listener (CodeRabbit fix on this PR) - completePrompt: forwards abortSignal/timeoutMs to all three SDK paths (timeoutMs <= 0 omits the SDK timeout option, since the SDK treats timeout: 0 as an immediate abort); aborted completions and APIConnectionTimeoutError/APITimeoutError normalize to the provider AbortError (series standard) The inner pre-stream provider-name literal is provably equivalent and documented as such in the PR body; no Stryker disable directive is added anywhere in the tree. createMessage's outer catch applies the identical isRequestAborted check to the same controller signal and re-standardizes the error, so the inner layer's only unique behavior is the non-abort completion-error wrap (stays kill-tested), and the abort-normalization condition beside that literal is killed by a live-signal delivery added in the second review round. The cleanup-scope re-indentation made the gate instrument pre-existing request-construction lines for the first time; their previously unobservable mutants are kill-tested: R1 tool-result merge shape for preserveReasoning models and the plain shape for non-preserveReasoning models, the includeMaxTokens on/off branches with a ceiling-bounded model, and the parallel_tool_calls default/explicit-false. Unit 2/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the shared-util unit. Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008. Addresses Zoo-Code-Org#404. Review round (CodeRabbit threads on 41ef0e0): the Chat Completions stream loop now breaks on the request signal at the top of each iteration and re-checks that signal after the loop, so an SDK that swallows the body-read abort and closes the iterator normally cannot report a cancelled turn as completed. The new test parks the iterator after the first chunk, hands back a getter-counting chunk once the caller cancels, and asserts both the standardized AbortError and zero post-cancel chunk reads; flipping either guard to a false condition fails exactly that test (1 failed | 195 passed). The Responses pre-stream abort arm had no live-signal delivery, so one is added: with no caller signal nothing aborts, only the error-name arm can normalize, and the ConditionalExpression mutant dies with it (same control). The provider-name literals at the two stream catches and at the three completePrompt races were re-measured: each survives the full 196-test suite, which matches the equivalence argument above. The detach tests now require exactly two abort registrations on the caller's signal, name the bridge's by position, require it to differ from the model-resolution race's callback, and assert both removals by reference in that order. The SDK abort and timeout deliveries now reject from inside the SDK mock with no caller signal (the automocked openai module's error classes are not Error instances, so the name/message arm is exercised with the real class taken from the actual module), a caller cancel landing inside the SDK call is classified across all three formats, and the parked-lookup gate is the typed getModels fetcher rather than a spy on the private resolveModel. Review round 2 (CodeRabbit pre-merge checks): completePrompt gained a parameterized timeout-option test per wire format (Anthropic messages, Responses, chat completions) that proves each call site applies the shared hasUsableTimeout/toSdkTimeoutMs contract rather than only testing the helper: NaN, Infinity and -5 leave no timeout key, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and every row also asserts the caller's signal reached the SDK options, so dropping the budget can never drop the cancel. Controls: deleting the forward arm fails two rows per format, forcing it to always forward fails the three disabled-budget rows, and replacing toSdkTimeoutMs(timeoutMs) with the raw value fails exactly the two forwarding rows. The five provider-name literals on the abort paths were re-measured at this head: all five survive the full 211-test suite, which is the measured half of the equivalence argument in the PR body. Verification on this tree: src tsc --noEmit exit 0 apart from the two known donor-store integrations/misc/export-markdown.ts rows; vitest 211 passed (211) in declaration order and in shuffled order; eslint . --ext=ts --max-warnings=0 without --prune-suppressions exit 0 with src/eslint-suppressions.json byte-identical (a prune run found zero decreases for this unit); prettier 3.9.10 --check clean on the staged blobs extracted with core.autocrlf=false. Review round 3 (CodeRabbit pre-merge checks, six Minor rows): the Chat Completions streaming loop now re-checks the request signal in front of every buffered item of a frame — the text item after a reasoning item, each tool-call partial inside the per-item loop, and the usage item — because a consumer that takes the first item, cancels and pulls the next one resumes this generator inside the same iteration, where the top-of-loop guard has already run. The three stream-open awaits (Anthropic /v1/messages, Responses /v1/responses and chat completions) now go through settleOnAbort with the signal still handed to the SDK, so a 429 with Retry-After plus a caller cancel no longer holds the pending first next() and the bridge cleanup until the sleep ends. Regression evidence: one parameterized test for the three stream-open races plus three manual-iteration tests that abort between two items of one frame (the buffered-text variant also asserts the bridge listener is detached by reference). Negative controls: removing each open wrapper fails exactly that format's row (1 failed | 216 passed each), disabling each buffered-item guard fails exactly that item's test, and reverting the OpenAI-path fixture key from opencodeGoModelId to the ignored apiModelId fails the five assertions that now pin model "glm-5.1" instead of expect.any(String). The parked-lookup test releases its gate in a finally so an assertion throw cannot strand the promise the provider awaits; measured with a probe: a release placed after the throwing assertion leaves the promise unresolved, the same release in a finally settles it. Verification on this round: vitest 217 passed (217) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files reported zero count decreases); prettier 3.9.10 --check: clean. Review round 4 (CodeRabbit pre-merge checks, one Major and nine Minor rows, handled in a single pass): the Responses and Anthropic helpers no longer let a normally-ending SDK iterator read as a completed turn. The Responses helper re-checks the bridged signal after processResponsesApiStream returns; the Anthropic helper re-checks it at the top of each event dispatch, between the separator item and the block body of an indexed content_block_start, and after the loop before the terminal cost chunk, so a cancel cannot emit the rest of an event or bill a turn the caller already cancelled. Four tests drive the shape the pinned SDKs actually produce - hand the consumer one item, cancel, then let the mock iterator report done instead of throwing - and each one also runs the identical fixture with a live caller signal, which still delivers its text and its terminal cost. Negative controls, each against the full suite: the Responses post-stream check (1 failed | 223 passed), the Anthropic after-loop check (killed by the test that cancels after the last event was delivered), the event-dispatch check (killed by the quiet-close test) and the separator checks (killed by the two-yields-of-one-event test) each fail their own test and nothing else that matters. The Responses pre-stream abort test no longer certifies itself through the provider's own catch: the mock captures the signal the SDK actually received and then throws a plain failure, so the only evidence left is that the captured signal is an AbortSignal that had already flipped; handing the SDK an unrelated signal instead of the bridge fails seven tests, including that one. The timeout matrix now pins signal identity rather than signal type - with no usable budget the SDK must hold the caller's own signal, with a usable one it must hold the merged deadline - and a new parameterized test parks each format's request under a 5000 ms budget, cancels the caller long before the deadline and requires the merged signal to flip and the completion to reject with the contract AbortError; replacing the merged deadline with the caller's own signal on the chat-completions completion fails 26 tests, including those rows. Three tests that polled for readiness before observing the rejection now attach the handler when the promise is created, so a model lookup or stream open that rejects during the poll cannot go unobserved. Verification on this round: vitest 224 passed (224) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical (a prune run over the two unit files found zero decreases, so the rewritten file was reverted); prettier 3.9.10 --check: clean. Review round 5 (mutation sticky at d4ce1ce: blocking 23, advisories 0): this round adds no production lines. Three tests were added, each aimed at a variant the sticky lists: a cancel between the separator and the body of an indexed thinking block (kills the ConditionalExpression -> false variant at opencode-go.ts:796 and puts line 797 under coverage), and one run per streaming format that passes no abort signal at all, so every guard in the helper is exercised with an absent caller signal. Measured against the suite: each of the 17 StringLiteral -> "" rows (357, 380, 391, 407, 424, 567, 574, 626, 717, 725, 743, 797, 809, 858, 976, 1046, 1104) leaves 227/227 green, and each of the 5 OptionalChaining rows (625, 742, 796, 808, 857) leaves 227/227 green. The reason is structural, not a matter of unasserted detail: at the OptionalChaining lines the operand is the request-local signal that bridgeExternalAbortSignal/mergeAbortSignalAndTimeout always hand to the SDK, so it is never nullish there, and an inner createAbortError is replaced by the enclosing catch's own unmutated literal (for example the stream-open catch at 719 re-throwing at 725, and the completion catch at 981 re-throwing at 992), so the tests that do assert the exact contract message still see "The Opencode Go request was aborted". The one variant that is observably different is now killed: ConditionalExpression -> false at 796 fails the new thinking test (1 failed | 226 skipped) where it left the previous suite green. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0, with eslint-suppressions.json unchanged because --prune-suppressions on the two unit files reported no count change; prettier 3.9.10 --check: clean. Review round 6 (ask: kill the StringLiteral family with test-side message assertions before anything else, no new production code). The spec's two remaining name-only assertions now pin the message too (spec:3824 and spec:3867, in the two "bounds %s model resolution by the request timeout" groups), so every name assertion in the file carries the contract message. That changed no survivor, and the reason is worth recording: with the message pinned everywhere, each of the 17 StringLiteral -> "" rows still leaves 227/227 green, because the message those tests read is produced by an enclosing catch that throws its own unmutated createAbortError("Opencode Go") - the createMessage-level catch at :279 and the Chat Completions stream helper's catch at :431 - and blanking either of those two literals fails 8 and 7 tests respectively, while blanking any guard or race label fails none. The five OptionalChaining rows are equivalent for a separate reason: the streaming helpers are always handed bridgedSignal ?? new AbortController().signal at :260, so their operand is never nullish; with all five optional chains removed at once the suite is still 227/227, including the two runs that pass no caller signal at all. No production line changed in either of the last two rounds; the provider blob is unchanged at 970de27. Verification on this round: vitest 227 passed (227) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with eslint-suppressions.json unchanged; prettier 3.9.10 --check: clean. Review round 7 (authorized: the pre-yield cancel check on the Responses path - one guard, one helper, one push, no gateway propagation). `streamResponsesMessage` now hands the shared transform an iterator whose `next()` reports the stream ended when the bridged signal is already aborted, so a pull that lands after the caller cancelled can no longer deliver the event the pinned decoder had already buffered; the after-loop guard then produces the contract AbortError. The helper's cleanup forward (`return: streamIterator.return?.bind(streamIterator)`) preserves the previous delegation behaviour - an early consumer exit still closes the SDK iterator twice, as the pre-existing cleanup test asserts - and stays callable when the source iterator implements no `return` at all. This helper's signal parameter is now typed `AbortSignal` (`createMessage` supplies `bridgedSignal ?? new AbortController().signal`), which is why the after-loop guard no longer needs its optional chain. Nothing was added to the three gateway helpers, as instructed. Two tests carry it: the buffered-completion fixture (text delta and `response.completed` from one read, take the delta, cancel, require the rejection and no usage item) and a next-only source iterator, which proves the cleanup forward must not assume `return` exists. Controls: against the pre-change provider the buffered fixture fails with 'expected undefined to match object { name: AbortError }' - today the usage chunk is delivered - so this was an uncovered gap, not a restatement of covered behaviour. For the new code: the pull guard's `ConditionalExpression -> false` fails exactly the two new tests and `-> true` fails 15; the `OptionalChaining` on the cleanup forward fails the next-only test; neutering the after-loop guard now fails 3 tests including the buffered fixture, which is the variant that fixture kills. Verification on this round: vitest 229 passed (229) in declaration order and with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` from `src`: zero errors;`eslint . --ext=ts --max-warnings=0` without `--prune-suppressions`: exit 0 with `eslint-suppressions.json` unchanged and`--prune-suppressions` reporting no decrease; prettier 3.9.10 `--check`: clean. Against merge-base `75a93a9d9acc`: opencode-go.spec.ts +2543/-200=2743, opencode-go.ts +390/-91=481 = 3224 a+d. Review round 8 (CodeRabbit review 5982073495, line 3872 wall-clock row): the deadline test no longer measures elapsed time. It parks the SDK promise so it never settles, then asserts the observed abort reason (name AbortError plus the exact contract message), that the signal handed to the SDK really is an AbortSignal and had already flipped, and that a settled-flag attached to the parked promise is still false, so the rejection can only come from the provider's race; the 1s bound is gone (it was the assertion a stalled worker could fail) and the duplicated message assertion was deduplicated. The caller-cancel-under- budget test now reads the SDK-facing signal immediately before controller.abort() and immediately after it, with no await between the two reads, and the redundant post-settlement read was removed. Shared-deadline row: a new test parks the catalog fetcher, releases it, waits for the dispatch, and then asserts by reference identity that the dispatched request runs on the caller's own cancellation scope (with no timeoutMs, mergeAbortSignalAndTimeout returns the caller's signal unchanged at utils/abort-signal.ts:42-44), flips it, requires the flip on the SDK-facing signal with no await in between, and requires the completion to reject with the contract AbortError while the parked SDK promise is still unsettled. Controls: replacing signal: resolutionAbortSignal in the chat-completions dispatch with a fresh controller fails exactly that test (AssertionError: expected AbortSignal { aborted: false } to be AbortSignal { aborted: false }, 1 failed | 229 skipped), and forcing the merge's timeout arm off fails all three rows of the deadline test (3 failed). Signal identity for the timeout shapes was already pinned by assertTimeoutOption (spec:4056), which requires the caller's own object with no usable budget and a merged deadline distinct from it with a usable one. Verification on this round: vitest 230 passed (230) in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with eslint-suppressions.json unchanged (--prune-suppressions on the spec reported no count decrease, so the rewritten file was reverted); prettier 3.9.10 --check: clean. No production line changed in this round; the provider blob is unchanged at bb1acfe. Against merge-base 75a93a9: opencode-go.spec.ts +2597/-191=2788, opencode-go.ts +390/-91=481 = 3269 a+d.
…ateway
Each provider's createMessage bridges metadata.abortSignal to a
per-request AbortController (Bedrock pattern: pre-aborted guard,
{ once: true } listener, detached on completion so a task-scoped
signal does not accumulate listeners) and runs model resolution inside
the shared resolveModelWithAbort cancellation scope; aborted requests
(pre-aborted, mid-resolution, mid-stream) normalize to the provider
AbortError while non-abort failures propagate or wrap unchanged.
completePrompt forwards abortSignal/timeoutMs to the OpenAI SDK
(timeoutMs <= 0 omits the SDK timeout option); aborted completions and
APIConnectionTimeoutError normalize to the provider AbortError (series
standard).
Zoo Gateway places the entry fast-fail before ensureAuthenticated() so
a pre-aborted task surfaces the AbortError instead of an auth failure
(pinned by an unauthenticated pre-abort test).
Unit 3/3 of the Zoo-Code-Org#1295 split (content source: 62f596c); stacks on the
shared-util and opencode-go units. Three sibling OpenAI-SDK gateway
providers with an identical abort-wiring shape are kept as one unit to
avoid tripling the review surface for mechanically identical changes
(a+d soft-cap rationale per the split budget; the mutation gate is
measured on the unit delta and is green).
Part of the abort-signal series (round 1). Builds on Zoo-Code-Org#674, Zoo-Code-Org#901, Zoo-Code-Org#1008.
Addresses Zoo-Code-Org#404.
Review round (CodeRabbit threads on b1bd578, disposition recorded on each thread): each provider now races the SDK promise it awaits against the bridged signal through `settleOnAbort` — unbound's stream create and its completion, vercel-ai-gateway's completion, zoo-gateway's completion — because the OpenAI SDK sleeps out a Retry-After / retry delay without observing the signal, and the post-await `bridgedSignal?.aborted` guards that used to trail those awaits are gone, since `raceAbort` rejects synchronously at `abort()` and nothing after the await can read the flag first. Each streaming loop breaks on the caller signal at the top of an iteration, re-checks it before emitting a just-received chunk, and checks it once more before the generator returns, so a cancel the SDK swallows — the iterator ends normally without a throw — can neither emit the rest of a chunk nor report a partial turn as completed. The caller's signal is bridged rather than handed to the SDK directly and the bridge is disposed in `finally`; the detach tests name the bridge's listener by registration position, require it to differ from the model-lookup race's callback, and assert both removals by reference. Absence proofs drain the provider's own continuation instead of sleeping.
The two Opencode Go files are Zoo-Code-Org#1652's blobs, byte for byte: provider `23348a501e9f31d0c72bffa6eefb6030bb6149a3`, spec `5dbe3382d1f1d6af8d22e7637a088c546988ef18`; `git diff df29307 -- <those two paths>` is empty with `core.autocrlf=false` and the blob ids are re-verified against this commit. Once Zoo-Code-Org#1652 lands on main this unit rebases onto it and both files drop out of this diff.
Review round 2 (CodeRabbit pre-merge checks): each gateway completePrompt now pins the disabled-budget boundary at -5 — the SDK options carry no timeout key and the bridged per-request signal is still handed over (the zoo variant is one of the tests that also catches a dropped signal arm). The ported Opencode Go spec brings its own parameterized timeout-option test per wire format: NaN, Infinity and -5 omit the option, 12.5 forwards timeout: 13, MAX_TIMEOUT_MS + 1 forwards MAX_TIMEOUT_MS, and the caller signal is asserted on every row. Those rows kill the forward arms at opencode-go.ts:886/944/1027 in both directions (deleting the arm fails two rows per format, forcing it always-forward fails the three disabled-budget rows) and the toSdkTimeoutMs call sites; forcing the gateway arms to always forward fails the new -5 rows on all three providers.
Verification on this tree: vitest over the opencode-go, unbound, vercel-ai-gateway and zoo-gateway specs from `src` — 411 passed (411) in declaration order and 411 passed with `--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` leaves only the two known donor-store `integrations/misc/export-markdown.ts` rows; `eslint . --ext=ts --max-warnings=0` without `--prune-suppressions` exits 0 with `src/eslint-suppressions.json` byte-identical (a prune run over the eight touched paths reported zero count decreases); prettier 3.9.10 `--check` clean on the staged blobs extracted with `core.autocrlf=false`. Negative controls per new guard: flipping each added condition or deleting each added arm fails the specific guard test that names it — 1 failed | 195 passed for either Opencode Go chat-stream arm, 1 failed for the Responses pre-stream condition, 2 failed for the Anthropic stream condition, and the same shape for the gateway guards.
Review round 3: the mutation-diff report at 313cf0e listed 20 blocking rows (21 survived mutants plus one uncovered arm) over 338 changed executable lines. Five of them are now killed by four tests added here: unbound.ts:349 and vercel-ai-gateway.ts:280 (detachExternalAbortSignal() -> ; in the completePrompt finally) by a detach test per provider that identifies the bridge listener by the { once: true } registration and asserts its removal by reference; zoo-gateway.ts:337 (classification gate -> false) by a streaming test that feeds a name-only AbortError with a live-but-not-aborted caller signal and asserts the contract identity, that the add-credits notification never ran, and that nothing was logged; zoo-gateway.ts:346 in both directions by a streaming test where the notification itself rejects while the caller signal is live (the log must name the surfacing failure and the original 402 must still reach the caller) plus the existing cancel-while-prompt-open test, which also puts that line under coverage. Each of those four mutants was applied alone and restored: 1 failed | 414 passed, killed by the named test in every case. The remaining sixteen rows are all StringLiteral -> "" on a provider-name label inside createAbortError/settleOnAbort/rejectOnAbort; each one sits inside a catch or race whose enclosing handler re-throws with its own unmutated literal, so the provider-visible error name and message are identical through the public API and no assertion can distinguish the mutant from the code (measured: full suite green with each mutant in place). No Stryker directive was added; the equivalence is argued in the PR discussion for a maintainer to weigh.
Verification on this tree: vitest 421 passed (421) across the four provider specs in declaration order and with --sequence.shuffle (the six new opencode-go tests arrive with the re-ported blobs); tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with src/eslint-suppressions.json byte-identical; prettier 3.9.10 --check on the touched files: clean. The opencode-go blobs are re-ported from df29307 and remain byte-identical to that head (git diff --quiet against it for those two paths: exit 0), so after a maintainer merges Zoo-Code-Org#1652 these lines drop out of this diff on rebase.
Review round 4 (CodeRabbit pre-merge checks, six Major and 26 Minor rows, handled in one pass): three sibling
stream loops no longer hand a cancelled turn their last item - Unbound re-checks the caller signal in front of
the text item of a frame whose reasoning item was already delivered, and both Vercel AI Gateway and Zoo Gateway
re-check it in front of the usage item of a frame whose text was already delivered, so a cancel between the two
items of one chunk rejects instead of emitting or billing the remainder. The three "does not emit the rest of a
tool-call chunk" tests are now consumer-driven (take the first partial, cancel, require the next call to reject
without building the second one) because the getter variant aborted before either partial existed and could not
tell a per-partial check from a per-frame check. Unbound's retained usage is typed as
OpenAI.Completions.CompletionUsage | undefined, which drops its @typescript-eslint/no-explicit-any suppression
from 3 to 2 (the only suppression change in this unit). The non-array tool_calls fixture now carries a truthy
value instead of null, so the Array.isArray check is what the test pins. The Zoo Gateway SDK-timeout
classification test no longer carries a 50 ms provider deadline, and the deadline test's mock refuses to run
without the per-request signal, so a provider that stops forwarding the deadline fails loudly instead of
throwing immediately. The two add-credits streaming tests wrap their whole body in a try/finally so the console
spy is restored even when an early assertion throws. The opencode-go provider and spec are the byte-identical
blobs from Zoo-Code-Org#1652 at d4ce1ce (opencode-go.ts 970de27, opencode-go.spec.ts 8c34bbb), which carry
the Responses/Anthropic quiet-close guards, the terminal-usage guard, the captured-SDK-signal assertions and
the merged-deadline cancel rows that close this unit's opencode-go rows; on rebase over the merged Zoo-Code-Org#1652 those
lines drop out.
Not changed in this unit, with the reasoning recorded on the threads: Unbound's timeout is enforced through the
merged deadline signal rather than response-body consumption (helper-side, tracked on Zoo-Code-Org#2486), the completion
races still return a response that won the race before the cancel, and the completion paths keep using the
shared mergeAbortSignalAndTimeout signal rather than a request-local bridge.
Verification on this round: vitest 431 passed (431) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0
without --prune-suppressions: exit 0, with src/eslint-suppressions.json updated only for the unbound.ts decrease
(3 -> 2) that the prune run reported; prettier 3.9.10 --check: clean. Negative controls against the suite, each
disabling one guard: the Unbound text-item guard, the Vercel usage-item guard and the Zoo usage-item guard each
fail exactly their own new test (1 failed | 45, 56 and 103 passed respectively), the three per-partial guards
each fail exactly their rewritten tool-call test, dropping the Zoo completion's per-request signal arm fails the
seven timeout and abort-delivery tests that read it, and dropping the timeout arm fails the two option-forwarding
tests.
Review round 5 (mutation sticky at 41ba1fe: blocking 23, advisories 0): no production line was added or changed in
this round. The opencode-go provider and spec are re-ported byte-identical from Zoo-Code-Org#1652 at 40456d8 (blobs
970de27 and 4afc3ee), which carry the thinking-separator cancel test and the two no-abort-signal runs that
kill and explain the structural variants on that file. Every sibling row was measured by hand in this worktree: the label
mutants at unbound.ts:218/247/257/278/338 and vercel-ai-gateway.ts:136/168/185/267 leave their whole spec green
(46/46 and 57/57) because each inner createAbortError is replaced by the enclosing catch's own unmutated literal, while
mutating those catches' own labels (unbound.ts:224, 289, 349 and vercel-ai-gateway.ts:204, 213, 279) fails 3, 6, 5, 4, 1
and 5 tests - which is what proves the message the tests assert comes from the catch, not from the inner label. The zoo
labels (280, 308, 344) are killed outright by the abort-identity tests, and the zoo console-guard optional chain is
killed by two existing tests.
Verification on this round: vitest 434 passed (434) across the four provider specs in declaration order and with
--sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without
--prune-suppressions: exit 0 with eslint-suppressions.json carrying only the round-4 unbound.ts decrease (3 -> 2);
prettier 3.9.10 --check: clean across all eight unit files.
Review round 6: the two opencode-go files are re-ported byte-identical from Zoo-Code-Org#1652 at b51323d (blobs 970de27 and
2163ff1), which adds the two message assertions described there and no production line. Verification on this round:
vitest 434 passed (434) across the four provider specs in declaration order and with --sequence.shuffle; tsc --noEmit -p
tsconfig.json from src: zero errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with only the
round-4 unbound.ts decrease (3 -> 2) in eslint-suppressions.json; prettier 3.9.10 --check: clean across the eight unit
files. The unit's own content (excluding the 2847 a+d carried byte-identically from Zoo-Code-Org#1652, which drops out on merge plus
rebase) is 3198 a+d.
Review round 7: re-ported the two opencode-go blobs byte-identically from `371445df813b` (Zoo-Code-Org#1652 round 7), which
adds the authorized pre-yield cancel check on the Responses path and the two tests that carry it - the
buffered-completion fixture (text delta and `response.completed` from one read, take the delta, cancel, require
the rejection and no usage item) and the next-only source iterator that proves the cleanup forward must not assume
`return` exists. The three gateway helpers are untouched by that check, as instructed; series consistency of
the check is recorded as a follow-up on Zoo-Code-Org#2486 rather than folded into this unit.
Preflight reading (advisory, run incomplete, no scoring): the local Stryker preflight of the unit delta generated 402
mutants against the 400-mutant preflight limit in the previous round's run, and the added lines push that figure
higher; the run was therefore not scored, and `blocking:0` on the last completed report is an artifact of the
aborted preflight, not a clean mutation result - Zoo-Code-Org#1653's earlier completed head `41ba1fea0524` listed the same
12 `opencode-go.ts` StringLiteral rows as surviving with all three gateway specs present. No scored mutant of
this unit's own gateway code has been left without a disposition.
Decision requested (author/maintainer): either (a) split this unit further so each branch stays under the 400-mutant
preflight limit and the run can be scored, or (b) accept a reasoned narrow exclusion of the carried `opencode-go.ts`
rows from this unit's scoring on the ground that Zoo-Code-Org#1652 owns and scores those lines. Nothing here churns either unit to
force the count under 400.
Verification on this round: vitest 436 passed (436) across the four specs in declaration order and with
`--sequence.shuffle`; `tsc --noEmit -p tsconfig.json` from `src`: zero errors;`eslint . --ext=ts --max-warnings=0`
without `--prune-suppressions`: exit 0 with `eslint-suppressions.json` unchanged from this unit's own
`-1` decrease and `--prune-suppressions` reporting no further decrease; prettier 3.9.10 `--check`: clean.
Against merge-base `75a93a9d9acc`: opencode-go.spec.ts +2543/-200=2743, unbound.spec.ts +1138/-4=1142, vercel-ai-gateway.spec.ts +771/-2=773, zoo-gateway.spec.ts +820/-1=821, opencode-go.ts +390/-91=481, unbound.ts +142/-36=178, vercel-ai-gateway.ts +144/-42=186, zoo-gateway.ts +87/-9=96, eslint-suppressions.json +1/-1=2 = 6422 a+d, of which 3224 is the
byte-identical carry of Zoo-Code-Org#1652's diff, leaving 3198 this unit's own.
Review round 8 (carried from Zoo-Code-Org#1652 head 18eea83, spec blob b60a3da byte-identical): the deadline test drops its
elapsed-time bound - a stalled worker could fail it while the behaviour was correct - and now asserts the observed abort
reason (name + exact contract message), that the signal handed to the SDK is an AbortSignal that had already flipped, and
that a settled-flag attached to the parked SDK promise is still false, so the rejection can only come from the provider's
race. The caller-cancel-under-budget test reads the SDK-facing signal immediately before controller.abort() and immediately
after it, with no await between. A new test parks the catalog fetcher, releases it, waits for the dispatch and asserts by
reference identity that the dispatched request runs on the caller's own cancellation scope (no timeoutMs ->
mergeAbortSignalAndTimeout returns the caller's signal unchanged, utils/abort-signal.ts:42-44), then requires the cancel to
flip that same object with no await in between and the completion to reject while the SDK promise is still unsettled.
Controls: swapping signal: resolutionAbortSignal for a fresh controller in the chat-completions dispatch fails exactly that
test (1 failed | 229 skipped); disabling the merge's timeout arm fails all three rows of the deadline test (3 failed).
No gateway helper changed in this round; the four unit specs' own elapsed-time assertions were zero, and they remain zero.
Pre-merge rows answered without a production change: Lifecycle Resource Cleanup - completePrompt already builds one scope at
opencode-go.ts:951 via mergeAbortSignalAndTimeout(options?.abortSignal, options?.timeoutMs) and passes that merged signal to
the Anthropic, Responses and chat-completions SDK calls (:969, :1027, :1110) and to the races (:995, :1065, :1123); the raw
caller signal appears only in isRequestAborted classification. The helper registers no listener on the caller's signal -
utils/abort-signal.ts:42-44 returns it unchanged with no usable budget, :48-50 returns AbortSignal.timeout() alone, :52
returns mergeAbortSignals(external, timeout) which at :62-68 is AbortSignal.any([primary, secondary]) - so there is nothing
for the provider to detach, and the composite leaves with the request scope. The path that does attach a listener is the
streaming bridge at :256, whose dispose runs at :283, :309 and :435. Regression Evidence - the quiet-close tests the row
names already exist: spec:2376 (Anthropic streamAnthropicMessage), spec:2741 (Responses), spec:2785 (buffered completion
event delivered after the cancel), driven by the guards at opencode-go.ts:630, :644, :761 and :877.
Verification on this round: vitest 437 passed (437) across opencode-go.spec.ts, unbound.spec.ts, vercel-ai-gateway.spec.ts
and zoo-gateway.spec.ts in declaration order and with --sequence.shuffle; tsc --noEmit -p tsconfig.json from src: zero
errors; eslint . --ext=ts --max-warnings=0 without --prune-suppressions: exit 0 with eslint-suppressions.json unchanged
(--prune-suppressions over the eight unit files reported no count decrease); prettier 3.9.10 --check: clean on all eight
unit files. Against merge-base 75a93a9 the unit totals are 6467 a+d.
Summary
Fixes #615 — Core plumbing for abort signal in
completePromptpath.This PR adds an optional second parameter (
CompletePromptOptions) to all providercompletePromptmethods, enabling future abort signal and timeout support without breaking existing callers.Changes
New:
CompletePromptOptionsinterfaceDesign note: Rather than passing the full
ApiHandlerCreateMessageMetadataas issue #615 described, this PR introduces a minimal interface that only exposesabortSignalandtimeoutMs. This keeps the API surface clean while still enabling abort signal pass-through. Themetadatapattern used in the stream path (viaApiHandlerCreateMessageMetadata) is already handled separately.Updated files
src/api/index.ts— AddedCompletePromptOptions, updatedSingleCompletionHandler.completePromptsignatureoptions?: CompletePromptOptions(backward compatible, optional)src/utils/single-completion-handler.ts— Forwards options to the handlerTests (
Task.spec.ts)toBeInstanceOf(AbortSignal)→toBe(task.currentRequestAbortController!.signal)for signal identity verificationAcceptance criteria (from #615)
SingleCompletionHandler.completePromptinterface accepts optional metadata/optionssingle-completion-handler.tsforwards options to the providerTask.tsattaches abortSignal to metadata (already wired in feat(api): pass abortSignal to streaming API calls for all providers (#404) #434, this PR completes the interface layer)Related
Summary by CodeRabbit
New Features
optionsparameter, includingabortSignaland optionaltimeoutMs.completePromptacross providers and the single-completion flow to accept and forward these options.Tests
abortSignalinstance and verified retries use a fresh, initially un-aborted signal.completePromptto be called with an explicitundefinedoptions argument when omitted.completePromptwith the correct prompt/options.