Repository navigation
[fix] Preserve persisted fields in the base64 media reconstruction branches - #10287
Lesereingrape wants to merge 1 commit into
Conversation
…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.
|
Real CI has not run on this PR yet - it needs one click from someone with write access. The 2 workflow runs on head The verification I do control - the 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. |
Summary
reconstruct_image_from_dict/reconstruct_video_from_dict/reconstruct_audio_from_dict/reconstruct_file_from_dictinlibs/agno/agno/utils/media.pyrestore 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 asNoneon every read-back:content)NoneImagemetadataAudioduration,metadataVideoduration,width,height,fps,eta,original_prompt,revised_prompt,metadataFilemetadatametadatais 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_audioare whatRunOutput.from_dict(run/agent.py:134-137,:907-911),TeamRunOutput.from_dict,WorkflowRunOutput.from_dict,run/base.py:282,workflow/types.pyandos/utils.py:193-198call. 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
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 threefrom_base64classmethods already take**kwargsand forward them to the constructor, so these are plain keyword arguments.File:File.from_base64takes no**kwargs, sometadatajoins that branch's existing# Preserve additional fields that from_base64 doesn't handleblock, in the same guarded-assignment style as thesize/file_type/filepath/urllines 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), andImage/Audio/Fileeach losemetadata. 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/filepathare not included because the models reject them alongsidecontent("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 inlinefrom_base64calls 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 inmodels/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 frommetadatato the full field set: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 inlinecontentso 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, withcontentbyte-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: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 (
fastapiand 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 Ion the same two files (what./scripts/format.shruns) →All checks passed!ruff format --checkon the same two files →2 files already formattedmypy 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 forregex/dns.resolverand a pre-existingRunStatusassignment — none of which this diff touches../scripts/format.sh/./scripts/validate.sh, because those sweepcookbook/and every extra on this machine and would report against the tree, not against my change.Checklist
./scripts/format.shand./scripts/validate.sh) — the ruff and mypy steps they run, scoped to the changed files, as listed aboveuv-managed venv, agno imported from this checkout viaPYTHONPATH=libs/agno; see the validation section for what was and was not runDuplicate and AI-Generated PR Check
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:reconstruct_media()dispatcher below these four functions and reorders the imports above them.httpx→httpx2migration; in this file it only renames the client insidedownload_*.enable_Xtoolkit-param rename, plus import moves in this file.mainalready has — and leaves eachfrom_base64(...)call argument-for-argument as it is.The four bodies I edited are byte-identical to upstream
mainat85b6d1d, the commit this branch was cut from. The adjacent reports are #9902 and its PRs #9926 / #9878, which are aboutMessage.from_dict; #9926's three files aremedia/media.py,models/message.pyand 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.