Skip to content

fix(bedrock): cancelling an embed call stops the rest of the batch - #126

Merged
cabljac merged 3 commits into
mainfrom
fix/bedrock-embedder-cancelled-batch
Dec 1, 2026
Merged

cabljac merged 3 commits into
mainfrom
fix/bedrock-embedder-cancelled-batch

Conversation

@hilariie

@hilariie hilariie commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Cancelling a Bedrock embed call now stops the documents that haven't been sent yet. Before, the batch kept running after the caller was gone: every queued document still went to InvokeModel and was billed, and the results were thrown away.

task = asyncio.create_task(ai.embed_many(embedder='amazon-bedrock/amazon.titan-embed-text-v2:0', content=docs))
...
task.cancel()
# before: all 50 documents still sent to Bedrock
# after: only the up to 10 already in flight are sent

Changes

  • Cancelling an embed call cancels every per-document call, queued or in flight. Requests already sent to Bedrock can't be recalled, but nothing new is sent.

Breaking changes

None.

Fixes #221. Port of genkit-ai/genkit#6439.

@cabljac cabljac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits

hilariie and others added 3 commits December 1, 2026 11:02
Upstream-PR: genkit-ai/genkit#6439
Co-authored-by: rootkiller6788 <221446036+rootkiller6788@users.noreply.github.com>
…t batch cancel

Catch asyncio.CancelledError instead of BaseException around asyncio.wait and around the drain gather.

- GeneratorExit no longer runs task.cancel() on a closed loop, which printed an extra "Event loop is closed" traceback.
- KeyboardInterrupt and SystemExit raised during the drain are no longer replaced by the original CancelledError.

The docstring now states that cancelling the caller cancels the whole batch, in-flight calls included.
…unded

Also raise a CancelledError that came out of a call instead of returning it as a vector, and test in-flight cancel and caller timeouts.
@hilariie
hilariie force-pushed the fix/bedrock-embedder-cancelled-batch branch from c1e0999 to 1a6b0d2 Compare December 1, 2026 10:08
@cabljac
cabljac merged commit 1096ffe into main Dec 1, 2026
22 checks passed
@cabljac
cabljac deleted the fix/bedrock-embedder-cancelled-batch branch December 1, 2026 10:40
@huangjeff5 huangjeff5 mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(py/plugins/amazon-bedrock): embedder tasks keep running after the caller is cancelled

2 participants