Repository navigation
Carry binary file content across the Gemini file upload activities - #180
Merged
brianstrauch merged 1 commit intoOct 26, 2026
Merged
brianstrauch merged 1 commit into
brianstrauch merged 1 commit into
Conversation
TemporalAsyncFiles.upload and TemporalAsyncFileSearchStores.upload_to_file_search_store put the bytes of an in-memory stream into the activity input model as a bytes field. The Pydantic payload converter writes bytes as UTF-8 text, so a PDF, image or audio file raised "invalid utf-8 sequence" while the workflow encoded the activity input. That is a workflow task failure: the workflow retried it until it timed out and no activity was ever scheduled. Only bytes that happened to be valid UTF-8 worked. The content now travels as base64 text in a new file_base64 field of both request models, and the activities decode it before handing a BytesIO to the SDK. file_bytes stays on the models and is still read, so an upload activity that an earlier version scheduled and an upgraded worker attempts keeps working; it is no longer set. Downloads already returned a raw binary payload, and generate_content carries image bytes as the base64 text the SDK writes into the request, so neither needed a change. Tests upload a 1x1 PNG, a non-UTF-8 byte string, every byte value and ASCII through a workflow and through the real activities against a local server that speaks the resumable upload protocol, and assert that the server received the same bytes. A history recorded on 7eea646 with the old input shape replays, and an activity input in the old shape still runs.
brianstrauch
enabled auto-merge (squash)
October 26, 2026 18:10
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.
What was changed
_GeminiUploadFileRequestand_GeminiUploadToFileSearchStoreRequestget afile_base64: str | Nonefield.TemporalAsyncFiles.uploadandTemporalAsyncFileSearchStores.upload_to_file_search_storefill it with the base64 text of the stream's content instead of settingfile_bytes._upload_sourcehelper in_gemini_activity.pypicks whatgemini_files_uploadandgemini_file_search_stores_uploadhand to the SDK:file_base64decoded to aBytesIO, elsefile_bytesas aBytesIO, elsefile_path.file_bytesstays on both models and is still read, so an upload activity that an earlier version scheduled and an upgraded worker attempts keeps working. It is no longer set.register_files.Why?
file_bytes: bytesgoes through the plugin'sPydanticPayloadConverter, which writes bytes as UTF-8 text, so a PDF, image or audio file raisedinvalid utf-8 sequencewhile the workflow encoded the activity input. That is a workflow task failure: no activity was scheduled and the workflow task was retried until the workflow timed out. Only content that was valid UTF-8 uploaded. Base64 text round-trips any bytes, and unlike a marker-tagged form it is a typed field, so no ordinary value can be mistaken for it.Replay: only the activity input changes. The upload and download results are encoded and decoded as before, and Python replay does not compare activity inputs, so histories recorded before this change replay as before. I recorded one on 7eea646 with ASCII content (the only kind that version could upload) and replay it as a test. Keeping
file_bytescovers an activity that was scheduled under the old shape and runs after the upgrade.Checklist
Closes [Bug] google_genai: files.upload and upload_to_file_search_store cannot upload binary content (PDF, image, audio) from an in-memory stream #179
How was this tested:
New
tests/test_files_bytes.pyruns realgenai.Clients against a local HTTP server that speaks the resumable upload and download protocol and keeps the bodies it receives. A workflow uploads a 1x1 PNG, a non-UTF-8 byte string, all 256 byte values (repeated) and ASCII throughfiles.uploadandupload_to_file_search_store, downloads a binary file, and the test asserts the server received exactly the uploaded bytes and the download came back as the same bytes. The same payloads go through the real activities directly (ActivityEnvironment), plus an empty stream, and an input in the old shape (file_bytes, nofile_base64) is run both directly and through a worker. One test reads the recorded activity input from the workflow history and checks it is base64 text; another replaystests/histories/legacy_ascii_files.json, recorded on 7eea646. Intests/test_gemini.pythe existing upload tests checkfile_base64, and there is a new in-memory File Search store test. Onmain(install rebuilt withmake syncand checked against the source) 16 tests fail, 14 of them new: the three workflow-level tests with non-UTF-8 content fail with the workflow task failure above, the rest fail becausefile_base64does not exist there. With the changemake lintis clean andmake testpasses (129, 19 of them new). Not run against the real Gemini API. Uploads over 1.5 MB or so still hit the payload size limit.Any docs updates needed?
No. The
uploaddocstrings already say anio.IOBaseis sent across the activity boundary; the README table needs no change.