Skip to content

[fix] Preserve persisted fields in the base64 media reconstruction branches - #10287

Open
Lesereingrape wants to merge 1 commit into
agno-agi:mainfrom
Lesereingrape:fix/media-reconstruction-drops-fields
Open

Lesereingrape wants to merge 1 commit into
agno-agi:mainfrom
Lesereingrape:fix/media-reconstruction-drops-fields

Conversation

@Lesereingrape

Copy link
Copy Markdown

Summary

reconstruct_image_from_dict / reconstruct_video_from_dict / reconstruct_audio_from_dict / reconstruct_file_from_dict in libs/agno/agno/utils/media.py restore the full field list on their media-reference branch but only part of it on their base64 branch — the branch a database row without an external reference takes. to_dict() writes all of it, so the fields the row stored came back as None on every read-back:

type persisted keys (excl. content) came back None
Image 8 metadata
Audio 8 duration, metadata
Video 11 duration, width, height, fps, eta, original_prompt, revised_prompt, metadata
File 8 metadata

metadata is the field all four models declare as "User-facing custom metadata", and this is the run-history read-back path: reconstruct_images/reconstruct_videos/reconstruct_files/reconstruct_response_audio are what RunOutput.from_dict (run/agent.py:134-137, :907-911), TeamRunOutput.from_dict, WorkflowRunOutput.from_dict, run/base.py:282, workflow/types.py and os/utils.py:193-198 call. Nothing raises — the values are simply never passed on — so the loss is silent.

Related to #10286 (filed with the measured repro).

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Improvement
  • Model update
  • Other:

What changed

13 added lines, one file, no signature or behaviour change for any caller:

  • Image/Video/Audio: pass the fields their reference branch already passes. All three from_base64 classmethods already take **kwargs and forward them to the constructor, so these are plain keyword arguments.
  • File: File.from_base64 takes no **kwargs, so metadata joins that branch's existing # Preserve additional fields that from_base64 doesn't handle block, in the same guarded-assignment style as the size/file_type/filepath/url lines next to it.

Plus a regression test.

Field-by-field scope, and what is deliberately not here

Video's base64 branch is the worst offender (8 of 11 fields), and Image/Audio/File each lose metadata. I fixed exactly the fields each function's own media-reference branch already restores, so the two branches now agree and no judgement call about "which fields matter" is buried in the diff. url/filepath are not included because the models reject them alongside content ("Only one of 'url', 'filepath', or 'content' should be provided"), so the base64 branch cannot legitimately receive them — I confirmed that by construction rather than by reading.

Not in scope, on purpose: Message.from_dict (models/message.py:161-290) rebuilds byte-backed media with its own inline from_base64 calls and has the same class of defect. That is #9902, and #9926 and #9878 are already open against it. This PR touches none of those lines and shares no file with either PR, so it neither competes with nor depends on them. If they land first, this still applies cleanly; if this lands first, they still need their own fix in models/message.py.

Bug fix verification

Against unpatched main (85b6d1d), the new test fails on the first type it probes — this is the output that made me widen from metadata to the full field set:

$ PYTHONPATH=libs/agno python -m pytest libs/agno/tests/unit/utils/test_media_reconstruction.py -q
E   AssertionError: Image.metadata: {'source': 'nightly-batch', 'page': 3} came back None
E   assert None == {'source': 'nightly-batch', 'page': 3}
1 failed, 24 passed

With the patch: 25 passed. The test drives the real persistence boundary (to_dict() → json.dumps → json.loads → reconstruct_*_from_dict), asserts the sample still carries inline content so it cannot silently drift onto the other branch, and then compares every persisted key. Before the fix it reports ['metadata'] for Image, ['duration', 'metadata'] for Audio, eight fields for Video, ['metadata'] for File; after the fix, none, with content byte-identical.

No regressions. Same command set, before and after the source change, over tests/unit/utils tests/unit/run tests/unit/models tests/unit/media:

pristine  151 failed, 1513 passed, 74 skipped, 76 errors
patched   150 failed, 1514 passed, 74 skipped, 76 errors

Exactly one test flipped, and it is the new one. The 151 failures and 76 errors are pre-existing on this box and unrelated — missing optional dependencies (fastapi and friends fail at collection) and provider tests that need live API keys. I did not triage them individually, so I am not claiming they are all environmental; only that the patched and unpatched sets are identical apart from my test.

Validation

  • ruff check libs/agno/agno/utils/media.py libs/agno/tests/unit/utils/test_media_reconstruction.py → All checks passed!
  • ruff check --select I on the same two files (what ./scripts/format.sh runs) → All checks passed!
  • ruff format --check on the same two files → 2 files already formatted
  • mypy libs/agno/agno/utils/media.py --config-file libs/agno/pyproject.toml → no error is reported in that file. It does report 4 errors in files it pulls in transitively (knowledge/page/_commands.py, _source.py, filesystem.py, team/_run.py) — missing third-party stubs for regex/dns.resolver and a pre-existing RunStatus assignment — none of which this diff touches.
  • I ran the two-file scoping above rather than whole-tree ./scripts/format.sh / ./scripts/validate.sh, because those sweep cookbook/ and every extra on this machine and would report against the tree, not against my change.

Checklist

  • Code complies with style guidelines
  • Ran format/validation scripts (./scripts/format.sh and ./scripts/validate.sh) — the ruff and mypy steps they run, scoped to the changed files, as listed above
  • Self-review completed
  • Documentation updated (comments, docstrings) — docstring added to the new test; no docstrings needed changing in the source
  • Examples and guides: Relevant cookbook examples have been included or updated (if applicable) — not applicable, no public API or usage change
  • Tested in clean environment — uv-managed venv, agno imported from this checkout via PYTHONPATH=libs/agno; see the validation section for what was and was not run
  • Tests added/updated (if applicable)

Duplicate and AI-Generated PR Check

  • I have searched existing open pull requests and confirmed that no other PR already addresses this issue
  • If a similar PR exists, I have explained below why this PR is a better approach
  • Check if this PR was entirely AI-generated (by Copilot, Claude Code, Cursor, etc.)

Duplicate check, and how this differs from what is already open. I enumerated all 763 open PRs and filtered by changed-file. Four touch libs/agno/agno/utils/media.py, and none of them passes the missing keyword arguments on a base64 branch, which is the defect:

The four bodies I edited are byte-identical to upstream main at 85b6d1d, the commit this branch was cut from. The adjacent reports are #9902 and its PRs #9926 / #9878, which are about Message.from_dict; #9926's three files are media/media.py, models/message.py and a new test, so it shares no file with this change. This is the other half of the same defect, in the file nobody has opened yet — measured, not asserted: I picked up from #9902's table that the pattern is not local to one function, then checked which half was still unclaimed.

The one thing I would want a reviewer to push back on if I am wrong: whether Video's eight extra fields should ride along here or be split out. They share one root cause and one test, and the reference branch in the same function is the authority for which fields belong, so I kept them together at 13 lines rather than opening two PRs that both need the same test file.

Additional Notes

Security: no. This is a read-back fidelity fix; it changes nothing about storage, paths, or what gets serialized.

Disclosure, since the box above is ticked: the investigation, the diff and this text were produced by an AI coding agent working under the account owner's standing instruction to find and fix defects of this kind and open PRs for them. No human read the diff before it was opened. Everything in the validation section is that agent's own terminal output from a local checkout at 85b6d1d, and each command is reproducible on a fresh clone of this branch. The commit carries no AI co-author trailer.

…anches

Each reconstruct_*_from_dict restores the full field list on its
media-reference branch but only part of it on the base64 branch, which is
the branch a database row without an external reference takes. metadata was
lost for all four media types, duration also for Audio, and eight of Video's
eleven persisted fields.

Pin the contract with a round-trip test that reconstructs every non-content
key to_dict() emits.
@Lesereingrape

Copy link
Copy Markdown
Author

Real CI has not run on this PR yet - it needs one click from someone with write access.

The 2 workflow runs on head e6834e1f (PR Lint, Validation) are both completed / action_required, i.e. queued and waiting for a maintainer to press Approve and run. The only check that has executed is Triage PR (success), which is why the merge box reads blocked: a missing approval, not a failing check.

The verification I do control - the ruff and mypy runs and the test results they produced - is recorded in the description above; I am not adding new claims here.

Six sibling PRs from this account are in the same state (#10281, #10297, #10301, #10320, #10323, #10325); I have asked on 3 of them, so clearing the whole set is 20 clicks in total. Say the word and I will narrow it down.

Disclosure: this account is being operated by an AI coding assistant on the owner's instruction, and the PR bodies say so as well.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant