Conversation
convert_complex_objects had no case for bytes, so an event holding bytes fell through to json.dumps(str(obj)) and the client got the dict's repr as a JSON string. Encode bytes and bytearray as base64, and convert the output of model_dump() and asdict() too, so bytes inside Pydantic models and dataclasses are covered. Fixes #659
Contributor
✅ No Breaking Changes DetectedNo public API breaking changes found in this PR. |
Contributor
|
Claude Security Review: no high-confidence findings. (run) |
This branch was successfully deployed
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.
Fixes #659.
Problem
If an entrypoint yields or returns an event with
bytesanywhere in it, the client gets a JSON string holding the Python repr, like"{'data': b'abc'}", instead of a JSON object. Nothing is logged, and clients that call.get()on the event crash.convert_complex_objectshas no case forbytes, so serialization falls through tojson.dumps(str(obj)).Fix
bytesandbytearrayas base64 strings. This matches what Strands'AgentResult.to_dict()now does (fix(agent): make AgentResult.to_dict JSON-serializable with bytes strands-agents/harness-sdk#4313).model_dump()andasdict()output back throughconvert_complex_objects. Without this, bytes inside a Pydantic model or dataclass, such as a StrandsAgentResult, still hit the fallback.Streaming and non-streaming responses both use this serializer, so both are fixed.
Other non-JSON types such as
datetimeandDecimalstill fall back tostr(), as before.Thanks @kimnamu for the repro and the proposed fix in #659.
Testing
mainand pass with this change: one forconvert_complex_objects, one for the SSE output.