Skip to content

Conversation

@kevin-orellana
Copy link
Contributor

Summary

  • download_file() and download_files() crashed with UnicodeDecodeError when the API returned binary content (PNG, JPEG, PDF) as base64-encoded blobs
  • Root cause: .decode("utf-8") was called unconditionally on decoded blob bytes
  • Fix uses try/except to decode UTF-8 where possible (preserving str return for backwards compatibility) and falls back to raw bytes for true binary content
  • Return type annotations updated to Union[str, bytes]

Test plan

  • 54 unit tests pass (uv run pytest tests/bedrock_agentcore/tools/test_code_interpreter_client.py -v)
  • test_download_file_binary — PNG header bytes returned as bytes
  • test_download_files_binary — mixed text/binary multi-file download
  • test_download_file_blob_utf8_returns_str — UTF-8-valid blob returned as str
  • test_download_files_blob_utf8_returns_str — same for multi-file variant
  • Integration: reproduce_bug.py confirms bug no longer reproduces
  • Integration: validate_readfiles_binary.py passes 10/10

@kevin-orellana kevin-orellana requested a review from a team February 8, 2026 19:06
…eDecodeError

download_file() and download_files() crashed with UnicodeDecodeError
when the API returned binary content (PNG, JPEG, PDF) as base64-encoded
blobs, because .decode("utf-8") was called unconditionally on decoded
blob bytes.

Fix uses try/except to decode UTF-8 where possible (preserving str
return for backwards compatibility) and falls back to raw bytes for
true binary content. Return type annotations updated to
Union[str, bytes].

Add tests covering both the binary-returns-bytes and
utf8-blob-returns-str paths for download_file and download_files.
@siwachabhi siwachabhi merged commit e8b63be into main Feb 9, 2026
20 checks passed
@jariy17 jariy17 deleted the fix/download-file-binary-content branch February 10, 2026 00:10
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.

4 participants