Skip to content

fix(bedrock): wrap streamed text deltas in TextContent before updateContentBlock()#601

Merged
ilvalerione merged 1 commit into
neuron-core:3.xfrom
campbellking:fix/bedrock-stream-text-content
Jul 15, 2026
Merged

fix(bedrock): wrap streamed text deltas in TextContent before updateContentBlock()#601
ilvalerione merged 1 commit into
neuron-core:3.xfrom
campbellking:fix/bedrock-stream-text-content

Conversation

@campbellking

Copy link
Copy Markdown
Contributor

Problem

src/Providers/AWS/HandleStream.php passes the raw delta string to StreamState::updateContentBlock(int $index, ContentBlockInterface $block):

if (isset($event['contentBlockDelta']['delta']['text'])) {
    $textChunk = $event['contentBlockDelta']['delta']['text'];
    $this->streamState->updateContentBlock($event['contentBlockDelta']['contentBlockIndex'], $textChunk);
    yield new TextChunk($this->streamState->messageId(), $textChunk);
}

Since declare(strict_types=1) was added to this file, this is a runtime TypeError on every Bedrock ConverseStream response that contains a text block — i.e. any streamed text completion via the Bedrock provider:

TypeError: StreamState::updateContentBlock(): Argument #2 ($block) must be of type ContentBlockInterface, string given

The adjacent reasoningContent branch already handles this correctly (wraps the delta in ReasoningContent before calling updateContentBlock); the text branch never got the same treatment.

Fix

Mirror the reasoning-branch pattern for text deltas by wrapping the chunk in TextContent.

Reproduction

Any stream() call through BedrockRuntime against a Converse-compatible model that returns text.

Context

We have carried this as a downstream composer patch since v3.3.10, where the same line produced a malformed content-block shape that dropped tool_use blocks; strict_types has since upgraded it from silent corruption to a hard crash. Happy to adjust style (e.g. import TextContent instead of the FQCN) if preferred.

…ontentBlock()

HandleStream passes the raw delta string to StreamState::updateContentBlock(),
whose second parameter is typed ContentBlockInterface. With strict_types this
is a TypeError on every Bedrock ConverseStream response containing a text
block. Mirror the adjacent reasoningContent branch, which already wraps its
delta in a content block before updating stream state.
@ilvalerione ilvalerione merged commit faf0b2d into neuron-core:3.x Jul 15, 2026
11 of 12 checks passed
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.

2 participants