fix(artifacts): preserve inline display names
## Summary
FileArtifactService and GcsArtifactService currently preserve the bytes and MIME type of inline_data artifacts, but drop inline_data.display_name on load. That leaves downstream converters without the user-facing filename even when the caller provided one.
This stores the display name alongside the artifact payload and restores it when loading binary artifacts:
- file-backed artifacts persist it in the per-version metadata JSON
- GCS-backed artifacts store it in an internal blob metadata key
- user-supplied
custom_metadataremains unchanged when artifact version metadata is listed or fetched
Fixes #5833.
Tested
PYTHONPATH=src python -m pytest tests/unittests/artifacts/test_artifact_service.py::test_save_load_preserves_inline_data_display_name -qPYTHONPATH=src python -m py_compile src/google/adk/artifacts/file_artifact_service.py src/google/adk/artifacts/gcs_artifact_service.py tests/unittests/artifacts/test_artifact_service.pypython -m pyink --check src/google/adk/artifacts/file_artifact_service.py src/google/adk/artifacts/gcs_artifact_service.py tests/unittests/artifacts/test_artifact_service.pygit diff --check
I also ran the full artifact-service test file locally with PYTHONPATH=src. It passed all GCS/in-memory/display-name cases, with two existing Windows-only failures in tests that parse file:///C:/... URIs back with Path(unquote(parsed.path)), producing /C:/...; those are unrelated to this change.
pre-commit run --files ... passed the format/import hooks, but the two repository-local bash hooks could not run on this Windows checkout because /bin/bash is unavailable.
I have analyzed Pull Request #5914, which addresses a key bug in the ADK repository where the inline_data.display_name property of binary artifacts was discarded on save/load cycles in disk and cloud storage services.
I have compiled the comprehensive analysis into a premium PR Analysis Report artifact. Please inspect the report directly here:
📖 analysis_report.md
Key Summary of the Analysis
- Status & Target: This PR addresses Issue #5833, resolving a bug where both FileArtifactService and GcsArtifactService lost the original file display names on save/load pathways (unlike InMemoryArtifactService).
- Compliance Gate Passed: The contributor CLA check completed successfully on GitHub (
SUCCESSstate in action telemetry). - Recommendation: Approve with Nits. The code is exceptionally clean, covers all edge cases gracefully, introduces robust unit tests, and avoids exposing framework-internal storage keys in
custom_metadatastructures.
Open Decision Points & Refinements (Nits)
I recommend asking the contributor to address the following minor styling nits so the codebase maintains strict style alignment:
- Replace deprecated type-hints: Replace
Optional[X]annotations with modern Pep-604X | Noneunions across the modified sections:display_name: Optional[str]in the FileArtifactVersion model should be typed asstr | None._write_metadata's parameterdisplay_name: Optional[str]in file_artifact_service.py should becomestr | None._user_metadata's input parammetadata: Optional[dict[str, Any]]in gcs_artifact_service.py should becomedict[str, Any] | None.
Hi @he-yufeng , Thank you for your contribution! We appreciate you taking the time to submit this pull request.
Rebased this branch onto current main and force-pushed the cleaned head. The PR diff is still limited to the artifact display-name roundtrip change.
Validated locally:
python -m py_compile src/google/adk/artifacts/file_artifact_service.py src/google/adk/artifacts/gcs_artifact_service.py tests/unittests/artifacts/test_artifact_service.pyPYTHONPATH=src C:\dev\GITHUB-clean\adk-python\.venv\Scripts\python.exe -m pytest -q tests/unittests/artifacts/test_artifact_service.py -k "display_name or inline" --basetemp .tmp\pytest-5914 -p no:cacheprovider(3 passed)git diff --check upstream/main..HEAD
I have completed the analysis for PR #5914, which addresses a key bug where the original display name of binary inline artifacts was lost during save/load pathways on disk and cloud backends.
Below is a summary of the analysis. You can also view the full detailed analysis in the premium report artifact: 📖 analysis_report.md
🔍 ADK Pull Request Analysis: PR #5914
Title: fix(artifacts): preserve inline display names
Author: @he-yufeng
Status: OPEN
Impact: 94 additions, 7 deletions across 3 files
Executive Summary
- Core Objective: Preserves the original
inline_data.display_nameproperty of binary/blob artifacts when saved/loaded using FileArtifactService or GcsArtifactService. - Justification & Value: Justified Fix. Resolves Issue #5833. Previously, this information was lost, causing downstream converters to default to a generic name like
attachment.bin. - Alignment with Principles: Pass with Nits. The code structure and parametric unit tests are highly robust. Only minor typing nits are present.
- Recommendation: Approve with Nits.
Minor Refinement Points (Typing Nits)
To match ADK's modern typing conventions, we should request that the contributor modernize newly added or updated parameter/field annotations:
-
In file_artifact_service.py:
- Modernize
display_name: Optional[str]inside class FileArtifactVersion tostr | None. - Modernize parameter
display_name: Optional[str]in helper _write_metadata tostr | None.
- Modernize
-
In gcs_artifact_service.py:
- Modernize parameter
metadata: Optional[dict[str, Any]]in private helper_user_metadata(at line 44) todict[str, Any] | None.
- Modernize parameter
Hi @he-yufeng , Thank you for your contribution through this pull request! Can you also implement the requested suggestions by adk-bot.
Hi @GWeale , can you please review this.
Pushed an updated branch for the requested typing nits and rebased cleanly onto current main.
Changes made:
FileArtifactVersion.display_namenow usesstr | None_write_metadata(..., display_name=...)now usesstr | None_user_metadata(...)now usesdict[str, Any] | None
Validation:
python -m py_compile src\google\adk\artifacts\file_artifact_service.py src\google\adk\artifacts\gcs_artifact_service.py tests\unittests\artifacts\test_artifact_service.pyPYTHONPATH=src python -m pytest -q tests\unittests\artifacts\test_artifact_service.py -k "display_name or inline" --basetemp .tmp\pytest-5914 -p no:cacheprovider(3 passed)python -m pre_commit run isort --files src\google\adk\artifacts\file_artifact_service.py src\google\adk\artifacts\gcs_artifact_service.py tests\unittests\artifacts\test_artifact_service.pypython -m pre_commit run pyink --files src\google\adk\artifacts\file_artifact_service.py src\google\adk\artifacts\gcs_artifact_service.py tests\unittests\artifacts\test_artifact_service.pygit diff --check upstream/main..HEAD
Rebased this on current main and re-ran the focused local checks:
PYTHONPATH=src python -m pytest tests/unittests/artifacts/test_artifact_service.py::test_save_load_preserves_inline_data_display_name -q --basetemp .tmp/pytest-5914 -p no:cacheprovider-> 3 passedpython -m py_compileon the touched artifact filespython -m pyink --checkon the touched filesgit diff --check upstream/main..HEAD
All passed locally.
Rebased this onto current main and re-ran the focused artifact checks.
Current head: 0aa97110
Validation:
python -m py_compile src\google\adk\artifacts\file_artifact_service.py src\google\adk\artifacts\gcs_artifact_service.py tests\unittests\artifacts\test_artifact_service.pyPYTHONPATH=src python -m pytest tests\unittests\artifacts\test_artifact_service.py::test_save_load_preserves_inline_data_display_name -q --basetemp .tmp\pytest-5914-round03 -p no:cacheprovider-> 3 passedpython -m pre_commit run isort --files src\google\adk\artifacts\file_artifact_service.py src\google\adk\artifacts\gcs_artifact_service.py tests\unittests\artifacts\test_artifact_service.pypython -m pyink --check src\google\adk\artifacts\file_artifact_service.py src\google\adk\artifacts\gcs_artifact_service.py tests\unittests\artifacts\test_artifact_service.pygit diff --check upstream/main..HEAD
Thanks for the PR. Preserving inline_data.display_name across save/load for both the file and GCS backends already landed in main via the fix for #5833 (see src/google/adk/artifacts/file_artifact_service.py and gcs_artifact_service.py, with a round-trip test in test_artifact_service.py), so we are closing this as already resolved.