Streaming responses silently turn unserialisable events into JSON strings of their Python repr
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
Research direction
Start in runtime/app.py at _safe_serialize_to_json_string and trace its use in _stream_with_error_handling, then inspect convert_complex_objects in runtime/utils.py. Reproduce an entrypoint generator yielding a dictionary containing bytes and read the SSE data line; done means binary-containing events are not emitted as Python repr strings and instead follow one of the stated JSON-safe or explicit-error behaviors.
Written by the indexing model from the issue text.
Description
Describe the bug
When an entrypoint generator yields an object that json.dumps cannot serialise, BedrockAgentCoreApp._safe_serialize_to_json_string (runtime/app.py line 898 in 1.22.0) tries convert_complex_objects and then falls back to json.dumps(str(obj)). convert_complex_objects (runtime/utils.py) handles Pydantic models, dataclasses, dicts, lists, tuples and sets but not bytes, so any event that contains binary data anywhere in its tree reaches the third fallback. The SSE data: line then carries a JSON string holding the Python repr of the dictionary, for example "{'result': {'type': 'agent_result', 'message': {... b'rsn_...'}}}", rather than a JSON object or an error.
The client cannot tell this apart from a legitimate string event, and it cannot recover the original payload from the repr. In our case a supervisor agent consuming a sub-agent's stream did event.get("error") on what was now a str and failed with AttributeError: 'str' object has no attribute 'get', turning every affected turn into a user-facing failure. Nothing was logged on the producing side, because the fallback succeeds.
To Reproduce
- Write a streaming entrypoint whose generator yields a dictionary containing a
bytesvalue somewhere inside it. A real-world source is theAgentResult.to_dict()from Strands when the model returns areasoningContent.redactedContentblock, which OpenAI GPT-5.6 Luna on Bedrock does after tool calls. Any otherbytesvalue in a yielded event, such as image or documentsource.bytesfrom a tool result, takes the same path. - Invoke the runtime and read the SSE stream.
- Observe that the event arrives as
data: "{'result': ...}"(a JSON string) instead ofdata: {"result": ...}.
Expected behavior
One of:
- binary values are converted to something JSON can carry (for example base64), or
- the event is replaced by an explicit error event, as
_stream_with_error_handlingalready does for exceptions, and a warning is logged.
Either way the consumer should never receive a Python repr as the payload.
Additional context
- Versions: bedrock-agentcore 1.22.0 (latest on PyPI), Python 3.13, Strands 1.54.0, runtime container on Bedrock AgentCore.
- The final fallback that logs a warning only fires if
json.dumps(str(obj))itself fails, which it never does for a dictionary. - Related: #198 (closed) reported bytes-in-message failing in the memory converter; this is the same class of input on the response-streaming path.
- Companion report about
AgentResult.to_dict()not being JSON-serialisable: strands-agents/harness-sdk#4167.
- Dominant language
- Python
- Stars
- 764
- Forks
- 149
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws/bedrock-agentcore-sdk-python
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
aws/bedrock-agentcore-sdk-python#496 · 1 comment ·
-
Pydantic deprecation warning: Support for class-based `config` is deprecated, use ConfigDict instead Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
aws/bedrock-agentcore-sdk-python#320 · 2 comments · 3 reactions ·
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
All issues in aws/bedrock-agentcore-sdk-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100