Skip to content

fix(workflow): decode base64 bytes after JSON session resume - #7853

Closed
ninglinLiu wants to merge 11 commits into
google:mainfrom
ninglinLiu:fix/7852-workflow-bytes-resume
Closed

ninglinLiu wants to merge 11 commits into
google:mainfrom
ninglinLiu:fix/7852-workflow-bytes-resume

Conversation

@ninglinLiu

Copy link
Copy Markdown
Contributor

Fixes

Fixes #7852

Summary

When a Workflow resumes from DatabaseSessionService / SqliteSessionService, node outputs are restored from JSON-serialized Events. Event.output is typed Any, so pydantic's ser_json_bytes/val_json_bytes do not round-trip bytes: they become base64 strings such as "AAE=". FunctionNode then coerced those strings with TypeAdapter(bytes), which utf-8-encodes the string and yields b"AAE=" instead of b"\x00\x01".

Changes

  • When a parameter annotation is bytes/bytearray and the value is still a str, prefer base64.b64decode(..., validate=True) before TypeAdapter
  • Fall back to the existing TypeAdapter path when the string is not valid base64
  • Unit tests for the Event JSON round-trip + coerce path

Test plan

  • pytest tests/unittests/workflow/test_function_node_bytes_json_resume.py

Event.output is typed Any, so Database/Sqlite JSON round-trips turn
bytes into base64 strings. TypeAdapter(bytes) then utf-8-encodes the
string. Prefer base64 decode when the parameter annotation is bytes.

Fixes google#7852
copybara-service Bot pushed a commit that referenced this pull request Oct 30, 2026
Merge #7853

When a Workflow resumes from a JSON session store (DatabaseSessionService,
SqliteSessionService), a finished node's `bytes` output comes back as its
base64 text. The replayed output is now base64-decoded when the node
declares a `bytes` output: a FunctionNode whose return annotation is
`bytes`, `bytes | None` or a generator of either, or a node whose
`output_schema` is `bytes` or `bytes | None`.
Text that is not valid base64 replays unchanged. Live runs are unchanged.

A producer with no return annotation still replays as base64 text, since
the stored event does not record that the value was bytes.

Part of #7852

PiperOrigin-RevId: 1010881203
@adk-bot

adk-bot commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Thank you @ninglinLiu for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit 81c3fe6.

Closing this PR as the changes are now in the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A Workflow resumed from DatabaseSessionService passes bytes on as base64 text

3 participants