adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

fix(artifacts): preserve inline display names

Open he-yufeng opened this issue 6 months ago • 8 comments

## 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_metadata remains 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 -q
  • PYTHONPATH=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.py
  • python -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.py
  • git 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.

he-yufeng avatar May 30 '26 22:05 he-yufeng

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 (SUCCESS state 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_metadata structures.

Open Decision Points & Refinements (Nits)

I recommend asking the contributor to address the following minor styling nits so the codebase maintains strict style alignment:

  1. Replace deprecated type-hints: Replace Optional[X] annotations with modern Pep-604 X | None unions across the modified sections:
    • display_name: Optional[str] in the FileArtifactVersion model should be typed as str | None.
    • _write_metadata's parameter display_name: Optional[str] in file_artifact_service.py should become str | None.
    • _user_metadata's input param metadata: Optional[dict[str, Any]] in gcs_artifact_service.py should become dict[str, Any] | None.

adk-bot avatar Jun 05 '26 18:06 adk-bot

Hi @he-yufeng , Thank you for your contribution! We appreciate you taking the time to submit this pull request.

rohityan avatar Jun 05 '26 18:06 rohityan

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.py
  • PYTHONPATH=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

he-yufeng avatar Jun 06 '26 18:06 he-yufeng

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

  1. Core Objective: Preserves the original inline_data.display_name property of binary/blob artifacts when saved/loaded using FileArtifactService or GcsArtifactService.
  2. Justification & Value: Justified Fix. Resolves Issue #5833. Previously, this information was lost, causing downstream converters to default to a generic name like attachment.bin.
  3. Alignment with Principles: Pass with Nits. The code structure and parametric unit tests are highly robust. Only minor typing nits are present.
  4. 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:

  1. In file_artifact_service.py:

    • Modernize display_name: Optional[str] inside class FileArtifactVersion to str | None.
    • Modernize parameter display_name: Optional[str] in helper _write_metadata to str | None.
  2. In gcs_artifact_service.py:

    • Modernize parameter metadata: Optional[dict[str, Any]] in private helper _user_metadata (at line 44) to dict[str, Any] | None.

adk-bot avatar Jun 06 '26 18:06 adk-bot

Hi @he-yufeng , Thank you for your contribution through this pull request! Can you also implement the requested suggestions by adk-bot.

rohityan avatar Jun 09 '26 18:06 rohityan

Hi @GWeale , can you please review this.

rohityan avatar Jun 09 '26 18:06 rohityan

Pushed an updated branch for the requested typing nits and rebased cleanly onto current main.

Changes made:

  • FileArtifactVersion.display_name now uses str | None
  • _write_metadata(..., display_name=...) now uses str | None
  • _user_metadata(...) now uses dict[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.py
  • PYTHONPATH=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.py
  • python -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.py
  • git diff --check upstream/main..HEAD

he-yufeng avatar Jun 11 '26 22:06 he-yufeng

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 passed
  • python -m py_compile on the touched artifact files
  • python -m pyink --check on the touched files
  • git diff --check upstream/main..HEAD

All passed locally.

he-yufeng avatar Jun 12 '26 13:06 he-yufeng

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.py
  • 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-round03 -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.py
  • python -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.py
  • git diff --check upstream/main..HEAD

he-yufeng avatar Jun 15 '26 14:06 he-yufeng

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.

GWeale avatar Jun 18 '26 18:06 GWeale