Skip to content

feat(protocol): a live atif/1 read names the header it holds and how far it holds each sub-agent - #903

Merged
earakely-scale merged 5 commits into
mainfrom
edgararakelyan/fd-6926-y18-live-atif-read
Nov 24, 2026
Merged

earakely-scale merged 5 commits into
mainfrom
edgararakelyan/fd-6926-y18-live-atif-read

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Collaborator

Since #890, a prompt step whose atif/1 copy replaces native follows that copy live. This PR makes those live reads say what the reader already holds, so the agent sends only what's new:

  • The header goes only when it changed, rather than about 60 KB on every poll for Claude Code.
  • A running sub-agent's steps arrive as they close. Until now, nothing of a sub-agent was served until the root step that started it closed.

Released agents keep working as before: the follower names the new fields only to an agent whose card declares them. The PR also fixes a flaky integration test.

What changes

The protocol (a2a_agent/extensions.py, _atif_copy.py, framework.py)

  • The request. A task's cursor read (TaskEventsTrajectoryRequest) takes two optional fields:
    • header_digest: the digest of the header the reader holds, "" for none;
    • subagent_cursors: for each sub-agent, the last step_id the reader holds and its header's digest (SubagentCursor), {} at first.
  • The answer to a read that names header_digest:
    • it names the header's header_digest;
    • it leaves header out while the two match.
  • The answer to a read that names subagent_cursors:
    • it carries each of the task's sub-agents by its closed steps past its cursor, whether or not the root step that started it has closed;
    • each sub-agent's header (the trajectory without its steps) comes only when it changed, and a sub-agent with neither is left out;
    • subagent_header_digests names each sub-agent's header digest.
  • Compatibility.
    • A read that names neither field gets today's page. New answer fields appear only when a read named the fields, so an older reader never sees one.
    • The card lists both fields on the task cursor read.
    • The agent keeps no per-reader state: a digest is the sha256 of the scrubbed header as served.

The live follow (a2a_agent/trajectory_follower.py, snapshot_utils/live_trajectory.py, prompt_agent.py)

  • Which agents get the fields. live_reads_take_cursors(card) says whether an agent's card takes them, and the follower names them only then (LiveAtif.cursors).
  • What the follower holds. It keeps the latest header and each sub-agent's header, digest and last step, and names them in each read. It hands the page writer each page with the latest header and each served sub-agent's header, as before, so the stored live folder doesn't change.
  • Sub-agent-only pages. A page that carries only a sub-agent's new steps is now stored as it comes. It counts as an atif/1 page already stored, so a later refusal never mixes formats.
  • Older agents. An agent whose card doesn't take the fields is followed exactly as since feat(task-steps): always_on and the live follow keep a prescribed run's atif/1 copies, and always_on's judge grades them #890: the header on every read, deduplicated by the page writer.
  • The answer decides. An agent can bind its own get handler, so its generated card declares the fields while its answers don't carry them. An answer with no sub-agent digests is taken in today's shape, and its whole sub-agents pass as they are.

The flaky test (tst/integration/conftest.py, tst/util/published_image.py)

  • What happened. A test that runs a bundle twice expects the second run to plan what the first did. On feat(task-steps): always_on and the live follow keep a prescribed run's atif/1 copies, and always_on's judge grades them #890's slow shard, a release published the shipped Claude Code image between the two runs, so the second run pulled it rather than reusing the image the first had built.
  • Why the lookup flipped. _registry_digest keeps what it finds published for the process, but not what it doesn't, so the second run asked again.
  • The fix. An autouse fixture holds the registry still for each integration test: each image's published digest, or that it has none, as the test's first lookup of it found it.

Decided with Edgar

  • The header: the reader names the digest of the header it holds, rather than the agent numbering header versions per reader.
  • Sub-agents: a cursor per sub-agent, served whether or not the root step that started it has closed, rather than every sub-agent whole on every poll.
  • No render caching.
    • The builder already renders each served step once.
    • What's left is one parse of the document per poll: 0.9 ms on a real 19-wake always_on conversation (508 KB, 103 root steps).
    • It's left as it is.
  • Rollout in two steps.
    • This PR adds the agent side and the follower side, negotiated by the card.
    • Once this release has put the protocol on PyPI, a follow-up raises Claude Code's protocol floor, so its image serves the new fields. Until then, the shipped Claude Code image installs the released protocol and is followed as before.
  • The flaky test: fixed for the whole integration tier with one fixture, rather than this test alone or by loosening assertions.

Choices to review

  • The header is still scrubbed on every poll: the agent needs its digest to compare. Only the bytes on the link are saved.
  • Sub-agents in the byte budget. A cursor read's sub-agent steps don't count against the page's byte budget, as whole sub-agents didn't before. The first read of a long sub-agent can therefore be large; every later one carries only its new steps.
  • Task reads only. Context cursor reads (ContextEventsTrajectoryRequest) don't take the new fields: the live follow reads tasks.
  • The fixture's reach. It holds lookups made in the test's process, as every CLI test here makes them (CliRunner). A test that runs agent-env as a subprocess isn't held.

Testing

  • Unit, protocol (test_a2a_atif_serving.py), with a new scenario: a sub-agent writing steps while the call that started it waits for its result.
    • A cursor read serves the sub-agent's new step while the call waits, where today's read serves nothing of it.
    • A read naming its header's digest gets the header only when it changed. After the task ends, the final metrics come under another digest.
    • A read without the fields gets today's shape, with no digest fields.
    • Following with cursors to the end rebuilds the task's stored document exactly.
    • The card's pinned request contract gains the two fields (test_a2a_trajectory_log.py).
  • Unit, live follow (test_prompt_agent_live_atif.py):
    • Both kinds of card, through the real prompt step against an in-process SDK agent:
      • an agent whose card takes cursors gets them in every read and sends the header only when it changed;
      • an agent with an older card gets neither and sends the header on every read;
      • the pages are a prefix of the stored copy either way.
    • Card detection: only a card declaring both fields takes them.
    • A scripted agent: a running sub-agent's pages and header are stored while the root has no new step, and each read names the cursors held.
    • An agent whose card declares the fields but whose answers ignore them: its sub-agents are still stored. This test fails on the commit before the fix.
    • The suite's eight earlier live tests now run against the new card, so in cursor mode.
  • The fixture (tst/unit/test_published_image_hold.py): an image published after the test's first lookup stays unpublished to it; one published before keeps its first digest.
    • Two lookups at once, as parallel disk builds make, both get the answer stored first: a lock guards the store, though not the lookup itself.
  • Related unit folders: task_step, a2a_agent, agents and the protocol suite: 8,047 passed.
    • Six shipped agents' pinned cards (Claude Code, Codex, Gemini) were updated: they now list the two fields on the task cursor read. The endpoint accepts them for any agent and ignores them on a native read.
    • The seven failures are this Mac's known ones: four in computer_exec_test.py, and three agent tests that fail the same way on a clean main here.
  • Live chaos (kept outside the repo):
    • What it does: it's feat(task-steps): always_on and the live follow keep a prescribed run's atif/1 copies, and always_on's judge grades them #890's chaos run, with half the seeds' agents honoring the digest and cursors and the other half not, and sub-agent headers that change. A third of the cursor-card agents answer in today's shape, ignoring the fields.
    • Invariants:
      • each sub-agent's latest stored header is its last;
      • no header file repeats the one before;
      • with cursors, the agent never sends a step or an unchanged header the follower already holds.
    • Results: clean locally (340 seeds: 177 with cursors, 52 of those ignoring them). It catches three planted bugs: a header stored on every page, no native fallback, and a cursor that never moves. On the commit before the fix above, it fails at once on an ignoring agent's missing sub-agent pages. For 30 minutes on a test host, at 0db7f4f, it was clean over 10,981 seeds: 5,414 with cursors, 1,632 of those ignoring them.
  • SDK chaos (kept outside the repo).
    • What it does: a real SDK agent on the protocol tests' toy adapter, served in-process. Each seed is one conversation of 1 to 3 turns.
      • Each turn plays random toy records: root steps, tool calls answered late or never, and sub-agents that write steps while the call that started them is open, then grow after it's answered. About one turn in ten fails.
      • Each turn holds between batches of records.
      • Three readers read each task, at every hold and to the end: a cursor reader with random page limits; a plain reader, as every released follower reads; and a garbage reader, with random digests and with cursors for unknown sub-agents or past the end.
    • Invariants:
      • the cursor reader is never sent a step it holds, nor a header or sub-agent header it holds;
      • at every hold, its root steps and sub-agents equal what the agent's own live page holds of the task, so a running sub-agent's closed steps reach it before the call that started it closes;
      • the plain reader gets today's shape;
      • the garbage reader gets only 200 or 400;
      • at each task's end, both readers rebuild the task's part of the stored document exactly.
    • Results: clean locally (666 seeds in 30 s, none refused by the adapter). In 570 holds, a plain read lacked a running sub-agent's steps that the cursor read had: the case this PR fixes. It catches three planted bugs: a new digest every read, sub-agents served only beside root steps, and sub-agent cursors ignored.
    • For 30 minutes on a test host, at 0db7f4f: clean over 25,334 seeds. None was refused by the adapter, and 25,516 holds hit the case this PR fixes.
  • Real runs with Claude Code (Opus) on a test host, atif/1 prescribed, each run's live reads traced, about $0.90 in all.
    • The released image (its card doesn't take the fields), on the sub-agent task:
      • the follower named nothing;
      • every read after the document began carried the whole header (63 KB);
      • the sub-agent's steps came only with the page that closed the step that started it.
    • The branch's protocol. The run used a test-only image: the checkout's Claude Code, installing a wheel of the branch's protocol.
      • Desktop computer-use task: 17 reads, and the header was sent twice: 80 KB with the first page, 84 KB with the final metrics. The other 15 reads were 0.2 to 3.2 KB each, where each would otherwise have carried the header. There were 7 pages, all 6 screenshots were stored, and every live step equals the stored copy's.
      • Sub-agent task: the sub-agent's first page was stored while the step that started it was still open, from a read carrying its step and no root step. Its pages equal the copy's.
      • Two parallel sub-agents: each one's first page was stored before the step that started it closed. Their pages equal the copy's.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issues were found.

Summary

Adds negotiated header digests and sub-agent cursors to live atif/1 reads.

  • Compatible live readers get changed headers and new sub-agent steps as they arrive.
  • Integration tests keep each image’s first registry lookup result for the whole test.

Diagram

sequenceDiagram
  participant F as Follower
  participant A as Agent
  participant S as Live storage
  F->>A: Read with held header digest and sub-agent cursors
  A-->>F: New steps and changed headers
  F->>F: Restore held headers
  F->>S: Store new steps and changed headers
  Note over F,A: Older cards receive reads without the new fields
Loading

Reviews (9) · Last reviewed commit: "refactor(a2a): the follower holds each s..." · Reviewed by Greptile

earakely-scale and others added 2 commits November 23, 2026 17:22
…far it holds each sub-agent

A task's cursor read may name the digest of the header the reader holds and a cursor per sub-agent; the agent then
answers the header's digest, leaves the header out while it's unchanged, and serves each of the task's sub-agents by
its closed steps past its cursor (its header only when that changed), whether or not the step that started it has
closed. A read naming neither gets today's page. The card declares both fields, and the live follower names them only
to an agent whose card does, keeping its own dedupe otherwise. A page that carries only a sub-agent's new steps is
stored as it comes.

Integration tests hold the registry still for each test: a release publishing one of a bundle's images between two runs
of it made the second plan a pull where the first built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… shipped agents' pinned cards declare it

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 24, 2026 01:28
Comment thread tst/util/published_image.py Resolved
earakely-scale and others added 3 commits November 23, 2026 17:33
…both get the answer stored first

Parallel disk builds look the disk tools image up from threads: two first lookups racing could each store their own
answer, the later replacing the first, so one test could still switch between building and pulling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…swers don't carry them is followed as before

The follower took the card's word and read every answer for digests; an agent binding its own get handler answers in
today's shape, so its sub-agents reached the page writer without their ids and headers, and were never stored. An answer
with no sub-agent digests now passes its whole sub-agents as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rops what it holds on a native fallback

Each held sub-agent is a typed record rather than a dict read by string keys; a sub-agent's header is taken when the
answer names a digest other than the one held; a native fallback clears what the follower holds, so the loop asks only
whether it holds anything. The live tests share one step helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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