Skip to content

feat(a2a-agent): an atif/1 copy's media files wait on the agent's disk until the worker pulls them - #834

Merged
earakely-scale merged 5 commits into
mainfrom
edgararakelyan/fd-6077-y3-media
Nov 20, 2026
Merged

earakely-scale merged 5 commits into
mainfrom
edgararakelyan/fd-6077-y3-media

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Y3 for FD-6077: an atif/1 copy's media files wait on the agent's disk until the worker pulls them at each turn's end. This is the SDK half only (Y3-8). The run's folder, the pull helper and the atif/1 fetch that calls it land with Y4 (FD-6078), so each piece lands with its caller. Closes FD-6077.

What changes

  • The media spool (a2a_agent/_media_spool.py). An agent that serves atif/1 writes each media file its copies name (media/<sha256>.<ext>) to its disk, one file per sha256, instead of keeping the bytes in memory for the context's life.
    • A file is held by the contexts whose copies reference it.
    • It goes when a push confirms it, or when its context is evicted or restored over.
    • Whatever is left goes when the server stops.
    • The spool has no cap for now (Y3-7).
    • A file it can't write, on a full disk say, is left out with a warning: a push reports it missing, and the copy goes on.
  • Image sizes from the header (atif/_image_size.py). A PNG, JPEG, GIF or WebP image's width and height are read from its header when the adapter gives none (Y3-6).
    • It is plain Python, so the agent extra still has no Pillow.
    • A header it can't read leaves the size out, and the image is still stored.
  • A media call on the trajectory extension (POST /ext/trajectory/media). It is listed on the card only of an agent that serves atif/1; old agents and native-only agents never get it.
    • It takes {context_id, objects: {path: write grant}} and uploads each file that context holds under its exact-object grant, 8 at a time, checking each upload against the file's name. The spool does the uploading (MediaSpool.push), so its hold numbers stay inside it, and the framework's handler only calls it.
    • The answer has objects (what it uploaded), missing (paths the context holds no file for) and failed (uploads that failed, with why). Neither of the last two stops the rest.
    • Only media/<64 hex>.<ext> paths are accepted.
    • It is served by the SDK alone (OperationDefinition.sdk_only). An agent that serves its own trajectory reads keeps it, and binding it is refused.
    • Each spooled file is hashed before its upload. One that no longer matches its name is reported failed and never reaches the store.
  • The reader-side check. atif.media_file takes a part path only as media/<sha256>.<ext> in the document's own folder, never another path or a URL. atif.check_media refuses bytes that don't match their name. The validator now shares the same pattern.
  • A fix to feat(a2a-agent): atif/1 reads leave out the secrets the SDK knows #827's scrub. A grant URL with no query had its token-like path segments taken as its credential, and a media call's grant URL can name the file it writes (.../media/<sha256>.png). The scrub then redacted every copy's media paths. A media file's name is never taken for a token now. Chaos found this as soon as it pushed media.
  • Shared helpers: atif.reader.MEDIA_NAME is the one media file-name pattern (MEDIA_PATH and the scrub use it), and transfers.sha256_file is the one file hash (the spool and the browser's downloads use it; website_browser still exports HASH_CHUNK_BYTES).
  • Docs: the README's Serving ATIF section and PROFILE.md's media section.

Choices to review

  • The spool is a temp folder per server process, made on the first file and removed when the server stops. It isn't under the user's state folder: a restarted server can't serve the old copies, so their media would only be litter. It follows TMPDIR, so where /tmp is a memory filesystem the files sit in memory.
  • Nothing pulls yet. Until Y4's pull is in the worker, an agent that serves atif/1 keeps every media file for its container's life. FD-6078 and FD-6079 now say Y4 ships before, or with, the first agent image that serves atif/1.
  • A pushed file is gone from the agent. A repeat request after a lost answer, or a second overlapping push, answers missing or failed for a file already stored. FD-6078 now requires its pull helper to check the store first.
  • A file shared by two contexts stays until neither holds it. A push for one context releases only that context's hold. Each hold has its own number, so an upload that outlives a restore or eviction releases only the hold it began with, never the one a later copy took on the same path.
  • The spooled file is checked against its name twice: hashed before the upload, and the upload's checksum after. A corrupted spool file fails before anything is written.
  • The route's format check now runs only on trajectory get. It used to run on every trajectory call, and the media call carries no format.

Testing

  • tests/test_a2a_atif_media.py (28 tests):

    • an inbound image is spooled by sha256, with its size and name in the profile, and a push uploads it, leaves the spool and answers its sha256;
    • the same bytes added twice are spooled and pushed once;
    • a path the context doesn't hold, and an upload that fails, don't stop the rest, and another context can't push what it doesn't hold;
    • only media paths are accepted;
    • an agent that overrides TRAJECTORY_V1.get still starts and serves media, and binding media is refused;
    • releasing an old hold after a drop and a new copy leaves the new hold;
    • a spooled file changed on disk is reported failed, and the store gets nothing;
    • an upload whose checksum doesn't match is reported failed, and its file stays held;
    • a file the spool can't write is reported missing, and the copy goes on serving atif/1 and spooling later files;
    • only an agent that serves atif/1 lists media;
    • a media call's grants leave the copy's media paths as they are (the scrub fix);
    • a video and a HEIC image are spooled and pushed like any file, with their plain notes;
    • eviction and restore drop a context's files, but not those another context still holds;
    • the spool goes with the server;
    • the native trajectory is unchanged;
    • header sizes for PNG, JPEG, GIF and three WebP forms, two bad headers, two truncated WebP headers, and a type ATIF has no part for;
    • dimensions an adapter passes win;
    • the reader-side path and bytes checks.

    Removing the spool, the header sizes, the release, the drop on eviction, the sdk_only refusal or its exemption from the override rule, the hold numbers, the pre-upload hash, the WebP length guard or the spool's write guard fails them.

  • Integration: a new test in test_prompt_agent_live_trajectory_local.py.

    • It deploys the echo agent and sends it a PNG, then reads the atif/1 copy's media path.
    • It mints an exact-object grant from the local store's grant server, and pushes it through the media call.
    • It checks that the object is in the store with the same bytes, the answer's sha256, and the width and height in the profile.
  • Serving chaos (the Y2b harness): after every task's final read it pushes the copy's new media and checks:

    • every file is uploaded with bytes matching its name, with nothing missing or failed;
    • asking again finds nothing held.

    60 s locally at c7b8dc8: 4,095 seeds, and at 9243aaf: 4,929 seeds, no failures. 20 min on an x86 test host at c7b8dc8: 83,560 seeds, 313,159 tasks, 4.09M reads, 31,214 restarts and 31,152 restores, no failures.

  • On the test host at c7b8dc8, the live-trajectory integration tests pass (5/5, the media push among them). 2343d57 only names a constant. At 2500a2d (the spool's write guard), the same integration tests pass (5/5), and 5 min of chaos ran 21,229 seeds, 79,963 tasks and 1.05M reads with no failures.

  • All 2,035 protocol tests pass, and ruff check . passes. Four tst/unit/task_step/computer_exec_test.py tests fail on macOS only, because BSD base64 has other flags. They don't involve this change, and CI runs them on Linux.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The changes since the previous review appear safe to merge.

Summary

Adds disk-backed media storage and an SDK upload endpoint for agents serving atif/1. The latest changes move uploads into MediaSpool and share file hashing and media-name checks.

  • ATIF agents keep media on disk until a caller uploads it.
  • ATIF copies fill in missing image dimensions from supported headers.
  • ATIF readers accept only media paths tied to their file contents.
  • Grant URLs keep media filenames visible in ATIF copies.

No new actionable issues found. The earlier findings remain fixed.

Reviews (9) · Last reviewed commit: "refactor(a2a_agent): the spool pushes it..." · Reviewed by Greptile

…k until the worker pulls them

An agent that serves atif/1 spools each media file its copies name to its disk, one file
per sha256, instead of holding the bytes in memory, with a PNG, JPEG, GIF or WebP image's
width and height read from its header when the adapter gives none. The trajectory
extension gains a media call, listed on such an agent's card: given a context and an
exact-object write grant per media/<sha256>.<ext> path, it uploads each file the context
holds, 8 at a time, checking each upload against its name, and answers what it uploaded,
the paths it holds no file for and the uploads that failed. An uploaded file leaves the
disk, as do a context's files when it is evicted or restored over, and the rest when the
server stops. atif.media_file and check_media take a part path only as
media/<sha256>.<ext> and only with the bytes that name, and the scrub never takes a media
file's name in a grant's URL for its token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 20, 2026 01:21
…k what they send

- The media call is served by the SDK alone (`OperationDefinition.sdk_only`): an agent that serves its
  own trajectory reads keeps it, and binding it is refused.
- Each spool hold has its own number, so an upload that outlives its context's copy releases only the
  hold it began with.
- A spooled file is hashed before its upload; one that no longer matches its name is reported failed
  and never reaches the store.
- A WebP header too short for its size fields gives no size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale and others added 3 commits November 19, 2026 17:55
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he copy goes on

A write that failed, on a full disk say, raised in the copy's guard and stopped the context's
atif/1 copy for good, naming the adapter. The spool now logs it and keeps no file, so a push
reports that path missing, as the validator's media rule does, and later files still spool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dia name and file hash are written once

- MediaSpool.push uploads a context's files and builds the answer, so hold numbers stay inside the
  spool; the framework's media handler only calls it.
- atif.reader.MEDIA_NAME is the one media file-name pattern; MEDIA_PATH and the scrub use it.
- transfers.sha256_file is the one file hash, used by the spool and the browser's downloads;
  website_browser keeps exporting HASH_CHUNK_BYTES.
- Two comments that repeated a docstring are gone; the media tests read the spool through a helper
  and its folder property, and a test covers the upload's own checksum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit adb3408 into main Nov 20, 2026
36 of 37 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/fd-6077-y3-media branch November 20, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant