fix(ai-amazon-bedrock): emit streaming "finish" after metadata arrives#6272
Open
tsushanth wants to merge 1 commit into
Open
fix(ai-amazon-bedrock): emit streaming "finish" after metadata arrives#6272tsushanth wants to merge 1 commit into
tsushanth wants to merge 1 commit into
Conversation
Closes Effect-TS#6237. The Bedrock Converse stream sends `metadata` (with the populated `usage` block) AFTER `messageStop`, but the SDK was emitting `"finish"` synchronously on `messageStop`, capturing the still-empty `{ inputTokens: undefined, outputTokens: undefined, totalTokens: undefined }` defaults. The caller's terminal stream event always saw `usage.inputTokens === undefined` / `usage.outputTokens === undefined`. Buffer the finish reason on `messageStop`, then emit `"finish"` from the `metadata` case once `usage`, `cacheWriteInputTokens`, and `trace` are populated. Output payload shape (reason / usage / metadata.bedrock) is unchanged; only the timing moves. I didn't add a streaming test — `converseStream` is `null as any` in the existing test harness in `AmazonBedrockLanguageModel.test.ts`, so there's no pattern to mock `ConverseResponseStreamEvent` against yet. Happy to follow up with a focused stream test once the maintainers point at the preferred mocking shape.
🦋 Changeset detectedLatest commit: d6cac31 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6237.
Summary
The Bedrock Converse stream sends
metadata(with the populatedusageblock) aftermessageStop. The SDK was emitting the"finish"part synchronously onmessageStop, capturing the still-empty{ inputTokens: undefined, outputTokens: undefined, totalTokens: undefined }defaults — so the caller's terminal stream event always sawusage.inputTokens === undefinedandusage.outputTokens === undefined, matching the reporter's symptom exactly.Fix
Buffer the finish reason on
messageStop, then emit"finish"from themetadatacase onceusage,cacheWriteInputTokens, andtraceare populated. The output payload shape (reason/usage/metadata.bedrock) is unchanged — only the timing moves.Notes
I didn't add a streaming test —
converseStreamisnull as anyin the existing test harness inAmazonBedrockLanguageModel.test.ts, so there's no pattern yet for mockingConverseResponseStreamEvent. Happy to follow up with a focused stream test once the maintainers point at the preferred mocking shape.