Repository navigation
Commit a5f4192
feat(api): abort signal support for bedrock (completePrompt + createMessage) (#1292)
* feat(api): add abort signal support for bedrock (completePrompt + createMessage)
Wires external abort signals into the AWS Bedrock provider on both request paths.
- completePrompt: merge options.abortSignal and options.timeoutMs via
mergeAbortSignalAndTimeout (merged utils API, no cleanup) and forward the
resulting signal as client.send abortSignal; sendOptions is undefined when
no signal/timeout applies.
- createMessage: bridge metadata?.abortSignal into the existing internal
AbortController (pre-aborted guard + { once: true } listener), preserving
the existing 10-minute request timeout.
Tests: ports the reference spec additions (abort/timeout propagation to
client.send, backward compatibility, empty response handling) and adds
createMessage abort coverage (pre-aborted signal and mid-stream abort both
reject with an error whose name === "AbortError").
* fix(api): address CodeRabbit review on bedrock createMessage abort lifecycle
The external abort bridge listener was only removed when the signal actually
aborted; a completed request left the listener (and its closure over the
request controller) attached to the caller's signal. Make the controller
request-local and detach the listener in a finally block so the external
signal keeps no reference after the request ends (success or error).
Test: createMessage regression - first request completes normally, a second
request starts with a different external signal; the first signal's listener
is removed on completion and aborting it late does not cancel the second
stream.
* fix(api): clear bedrock createMessage request timeout in finally
When a caller stops consuming the generator early (break/destroy), the
generator enters the finally block without reaching the stream-completion
timeout-clearing path, leaving the 10-minute request timer active and
retaining the request controller until it expires. Clear the timeout at
the start of the finally block, before the abort-listener removal.
Test: createMessage regression - the generator is terminated early
mid-stream and the 10-minute timer handle (captured via typed spies on
setTimeout/clearTimeout) is asserted to have been cleared.
* test(api): close changed-line coverage gaps in bedrock
* test(bedrock): strengthen abort signal coverage and add CodeRabbit rules
---------
Co-authored-by: Eason Liang <[email protected]>
Co-authored-by: Elliott de Launay <[email protected]>1 parent 104700e commit a5f4192
3 files changed
Lines changed: 709 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
61 | 68 | | |
62 | 69 | | |
63 | 70 | | |
| |||
0 commit comments