Repository navigation
Description
Symptom
OpenRouter does not honour the caller's metadata.abortSignal and the configured request timeout the way the merged providers do. Cancelling a request mid-flight does not stop the model lookup, the SDK call, or the stream, and a completion that lands after the cancel is still delivered to the caller.
Evidence on main
- The provider does not race its SDK promise through
rejectOnAbort(src/api/providers/utils/abort-signal.ts:226), so a cancellation during SDK retry backoff or a request that never settles waits for the transport. - The caller signal is handed to the SDK instead of a per-request bridge. The pinned
openaiSDK doessignal.addEventListener('abort', () => controller.abort())inclient.mjsand never removes the listener, so a long-lived caller signal accumulates one listener and one request controller per request. - Nothing re-checks the signal after the stream ends, so an iterator that closes without throwing - which the SDK does when it converts an aborted read into a normal end - reports success.
src/api/providers/openrouter.tshas noisRequestAbortedcall anywhere, so an abort the SDK reports on its own is wrapped as a completion failure instead of normalised.
Expected
The provider follows the shared contract exactly as requesty.ts (#1537) and zoo-gateway.ts (#2430) do: bridge the caller signal and dispose it on every exit path, race the SDK promise and the model lookup through rejectOnAbort / resolveModelWithAbort, guard the emit loop and the post-loop end, and normalise an SDK-side abort with isRequestAborted so a cancellation surfaces as AbortError with the message The <provider> request was aborted.
Scope
Provider file plus its spec. No change to utils/abort-signal.ts or utils/request-timeout.ts; the timeout-versus-body-consumption question is tracked separately in #2486.
Acceptance criteria
Derived from the Expected and Evidence sections above; they exist so a PR can cite them rather than paraphrase
them. Each names the observable, not the implementation.
- AC-1 The caller's
metadata.abortSignalis bridged per request and the bridge is disposed on every exit
path (completion, failure, abort, late result), so the caller signal accumulates no listener across requests. - AC-2 The SDK promise and the model lookup are raced through
rejectOnAbort/resolveModelWithAbort, so a
cancellation settles the await instead of waiting for the transport. - AC-3 The emit loop and the post-loop end are guarded, so an iterator that closes without throwing after an
abort does not report success. - AC-4 An abort reported by the SDK is normalised with
isRequestAbortedand surfaces as anAbortError
whose message isThe openrouter request was aborted. - AC-5 A completion that resolves after the caller aborted is not delivered to the caller.
- AC-6 (scope) Changes stay inside the provider file and its spec.
utils/abort-signal.tsand
utils/request-timeout.tsare untouched; the timeout-versus-body-consumption question stays in refactor(api): move hand-written abort bridges to the shared helper #2486.
Activity