Repository navigation
feat: add abort signal core plumbing - #674
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:
📝 WalkthroughWalkthroughAdds an optional ChangesAbortSignal propagation to API metadata and task execution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
f036c90 to
60a0dcf
Compare
edelauna
left a comment
There was a problem hiding this comment.
Thanks for doing this. Would like to see an additional test case, and also could you update Condensing/context-management API calls, three ApiHandlerCreateMessageMetadata construction sites in Task.ts — at lines 1555, 3763, and 3979 — do not set abortSignal. These are used for long-running condensing and context-management API calls that are also cancellable, but the "core plumbing" claim is incomplete if these paths are excluded.
Suggested fix: Pass the active currentRequestAbortController?.signal to these metadata objects, or document explicitly that condensing calls are intentionally out of scope with a comment at each site.
| // Create an AbortController to allow cancelling the request mid-stream | ||
| this.currentRequestAbortController = new AbortController() | ||
| const abortSignal = this.currentRequestAbortController.signal | ||
| metadata.abortSignal = abortSignal |
There was a problem hiding this comment.
The Promise.race between firstChunkPromise and abortPromise (lines 4187–4198) is the core behaviour this adds — if the signal fires before the first chunk, attemptApiRequest should throw "Request cancelled by user". Is that path covered by a test? The new tests verify the signal is passed correctly, but I don't see one that actually calls abort() during iterator.next() and asserts the error.
| // Create an AbortController to allow cancelling the request mid-stream | ||
| this.currentRequestAbortController = new AbortController() | ||
| const abortSignal = this.currentRequestAbortController.signal | ||
| metadata.abortSignal = abortSignal |
There was a problem hiding this comment.
Minor: abortSignal is grafted onto metadata after the object literal closes (line 4144), while every other field is set inline. Worth pulling the AbortController creation up above the literal and including abortSignal there?
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/core/task/__tests__/Task.spec.ts`:
- Around line 1957-2002: The test for AbortController signal propagation in the
handleContextWindowExceededError method bypasses the production request
lifecycle by pre-seeding the currentRequestAbortController and directly invoking
handleContextWindowExceededError(). Instead, refactor this test to drive the
assertion through the attemptApiRequest() method by setting up conditions that
force a context-window failure, which will validate that the AbortSignal is
properly propagated through the real error/retry path where controller timing is
critical to the production behavior.
In `@src/core/task/Task.ts`:
- Around line 3771-3775: The abort signal propagation issue occurs because
this.currentRequestAbortController is created too late in the
attemptApiRequest() method (at line 4177) relative to when it's accessed at
lines 3771 and 3992 for context-management calls. Move the creation of
this.currentRequestAbortController to the beginning of the attemptApiRequest()
method, before any code that references it for the abortSignal metadata field.
This ensures the abort controller is available throughout the entire request
attempt lifecycle, including during context-window handler execution, allowing
stop/cancel operations to reliably terminate HTTP requests.
🪄 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: aabfd282-d122-4ea7-aa26-8db27f118753
📒 Files selected for processing (2)
src/core/task/Task.tssrc/core/task/__tests__/Task.spec.ts
3b56639 to
9d02617
Compare
9d02617 to
11cc3ad
Compare
11cc3ad to
b26ec5d
Compare
edelauna
left a comment
There was a problem hiding this comment.
thank you for breaking this up
- 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.
…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>
- 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
Core plumbing to pass
AbortSignalthrough the API layer so HTTP requests can be cancelled mid-stream when the user clicks stop. Prevents wasted API tokens/compute on the provider side.Changes
abortSignal?: AbortSignaltoApiHandlerCreateMessageMetadatainterfaceAbortController.signalinto createMessage metadataRelated
Closes #434
Summary by CodeRabbit