Skip to content

fix(runtime): send bytes in events as base64 instead of a repr string - #679

Open
jariy17 wants to merge 1 commit into
mainfrom
fix/runtime-serialize-bytes
Open

jariy17 wants to merge 1 commit into
mainfrom
fix/runtime-serialize-bytes

Conversation

@jariy17

@jariy17 jariy17 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #659.

Problem

If an entrypoint yields or returns an event with bytes anywhere 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_objects has no case for bytes, so serialization falls through to json.dumps(str(obj)).

Fix

Streaming and non-streaming responses both use this serializer, so both are fixed.

Other non-JSON types such as datetime and Decimal still fall back to str(), as before.

Thanks @kimnamu for the repro and the proposed fix in #659.

Testing

  • Two new tests fail on main and pass with this change: one for convert_complex_objects, one for the SSE output.
  • Full unit suite: 3571 passed.
  • Reproduced the bug on a deployed AgentCore Runtime first: the caller received the repr string.

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
@jariy17
jariy17 requested a review from a team September 23, 2026 21:08
@github-actions github-actions Bot added the size/s PR size: S label Sep 23, 2026
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@jariy17
jariy17 deployed to auto-approve September 23, 2026 21:08 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown
Contributor

✅ No Breaking Changes Detected

No public API breaking changes found in this PR.

@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Sep 23, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Sep 23, 2026

This branch was successfully deployed

1 active deployment
auto-approve 8eaca5b1 Deployed Sep 23, 2026 by jariy17 via Test (services) #1602
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming responses silently turn unserialisable events into JSON strings of their Python repr

1 participant