Repository navigation
fix(sessions): preserve artifact custom_metadata when rewinding - #8510
Open
llalitkumarrr wants to merge 1 commit into
Open
llalitkumarrr wants to merge 1 commit into
llalitkumarrr wants to merge 1 commit into
Conversation
…sion When a rewind restores an artifact to the version it had at the rewind point, compute_artifact_delta_for_rewind loaded that version's data with load_artifact and saved it as a new version, but never carried over the version's custom_metadata. The restored version therefore always had empty metadata, even though the original version still held it. load_artifact returns only the payload, so the rewind now also reads the version's ArtifactVersion with get_artifact_version and passes its custom_metadata to save_artifact. Tombstones written for artifacts that did not exist at the rewind point keep empty metadata, and if the version metadata cannot be found the data is still restored as before. Closes google#8483
1 task done
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.
When a rewind restores an artifact to the version it had at the rewind point, compute_artifact_delta_for_rewind loaded that version's data with load_artifact and saved it as a new version, but never carried over the version's custom_metadata. The restored version therefore always had empty metadata, even though the original version still held it.
load_artifact returns only the payload, so the rewind now also reads the version's ArtifactVersion with get_artifact_version and passes its custom_metadata to save_artifact. Tombstones written for artifacts that did not exist at the rewind point keep empty metadata, and if the version metadata cannot be found the data is still restored as before.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
Runner.rewind_async()restores an artifact to the version it had at the rewind point by loading that version withload_artifactand saving it as a new version.load_artifactreturns only the payload andcompute_artifact_delta_for_rewindnever passedcustom_metadatatosave_artifactso the restored version always hadcustom_metadata== {} even though the original version still held it.Solution:
In
compute_artifact_delta_for_rewindafterload_artifactsucceeds for the rewind point version also callget_artifact_version(..., version=vt)and pass itscustom_metadatatosave_artifact. The change is confined tosrc/google/adk/sessions/_rewind_utils.py.Testing Plan
Unit Tests:
New tests:
tests/unittests/sessions/test_rewind_utils.pytest_compute_artifact_delta_restores_custom_metadata(parametrized):{"unit": "km"}→{"unit": "mi"}→ rewind restores{"unit": "km"}and no metadata →{"unit": "mi"}→ rewind restores{}.test_compute_artifact_delta_tombstone_has_no_custom_metadata: an artifact created after the rewind point is tombstoned with{}.test_compute_artifact_delta_restores_data_when_version_metadata_missing: whenget_artifact_versionreturnsNone, data is still restored andcustom_metadata=Noneis passed.AsyncMockbased test now setsget_artifact_version.return_value = Noneso no mock object leaks into save_artifact.tests/unittests/runners/test_runner_rewind.pytest_rewind_async_preserves_artifact_custom_metadata: end-to-end through the publicRunner.rewind_async, mirroring the scenario in [Bug] compute_artifact_delta_for_rewind restores file data without custom_metadata #8483.Manual End-to-End (E2E) Tests:
The script below reproduces the issue without an LLM or API key. It saves
route.csvtwice with differentcustom_metadata, appends the matching session events, rewinds the second invocation throughRunner.rewind_asyncand compares the new current version with version 0.