Skip to content

feat(agents): Codex and Gemini serve atif/1, from the CLI's rollout and its session transcript - #924

Open
earakely-scale wants to merge 15 commits into
mainfrom
edgararakelyan/fd-6082-y8-codex-gemini-atif
Open

earakely-scale wants to merge 15 commits into
mainfrom
edgararakelyan/fd-6082-y8-codex-gemini-atif

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Collaborator

Codex and Gemini now serve atif/1 when a run prescribes it, as Claude Code has since #854. Their native trajectories stay the default. Before this, a prescribed run fell back to native for these two agents, so their judges and live followers read the CLI's stdout events, which carry no times, no per-call usage, no thoughts and (for Gemini) no tool results.

What changes

Codex (agents/codex/codex_atif.py, codex_bridge.py)

  • Where the copy comes from. The bridge tails the CLI's rollout ($CODEX_HOME/sessions/.../rollout-*.jsonl) while the CLI runs, and each sub-agent's rollout as it appears, at any depth. It feeds the records the adapter reads as the rollout aux file (RolloutTail, rollout_aux). When the CLI exits, the follower finishes any read in progress and feeds it, then reads once more. The exec JSON events on stdout stay the native log.
  • A step per model response. A step holds the response's reasoning, message and calls, timed by its first item. It takes the response's own usage from its token_usage_record. A response that wrote nothing gets a step for its usage alone, so the steps add up to the turn's usage.
  • Calls and results.
    • Calls keep the rollout's call ids.
    • An MCP tool keeps its namespace, as the model sees it (mcp__browser__browser_navigate).
    • A patch keeps its text.
    • An image a tool returns is a media file.
    • A web search the provider ran has no output item, so the adapter answers it with the status the rollout gives. Otherwise its step would wait on a result until the turn ended, and live followers would stall there.
  • Reasoning. A summary is summary, else the ciphertext is kept as redacted, else omitted.
  • Sub-agents. Each sub-agent is an embedded trajectory under the spawn_agent call that started it. The bridge marks each sub-agent's records with the thread that spawned it. The spawn's result and the sub-agent's records are held until both have arrived, in either order. A sub-agent an earlier task saw never takes a later spawn that reuses its path.
  • Forks. A sub-agent forked with its parent's history (fork_turns: "all") begins its rollout with a copy of the parent's meta and turns, the parent's own replies among them, under their ids. The tail leaves out the records of every turn the parent's rollout holds, so the sub-agent's trajectory holds only what it did. A turn the parent's rollout didn't hold when the fork was found has the parent's rollout read again before it's taken for the sub-agent's own.
  • Attempts and failures. A resumed attempt starts with another task_started, and its steps carry the attempt's number. A failed or refused model call ends its attempt's task_complete with an error, which becomes a step with no model call holding that error.

Gemini (agents/gemini/gemini_atif.py, gemini_bridge.py, a2a_server.py)

  • Where the copy comes from. The bridge tails the session transcript (~/.gemini/tmp/<project>/chats/session-*.json, rewritten whole, or .jsonl, a line per message, as a session restored from a snapshot may be). It feeds each model message once a later message follows it, since the CLI adds a message's calls and results after writing it, and the last message at the turn's end (SessionTail, session_aux). A resumed session's earlier messages aren't fed again.
  • A step per model response.
    • Its thoughts are summary reasoning.
    • It holds its text, its calls and their results. A file a result carries, beside its response (an MCP tool's image) or in its own parts (a file read_file gives the model), is a media file. An error response is an error result, and a cancelled call without a result is canceled.
    • Its usage is that of the proxy's agentenv.model_call whose input it names (the prompt plus any tool-use prompt, as the proxy counts it), of the calls that had ended when its message was written. The CLI writes a message a few milliseconds after its call ends, and the next call ends after that.
  • Calls with no message.
    • A call the proxy forwarded that wrote no message (the CLI's routing and next-speaker checks) is a step with its usage alone.
    • A refused call is a step with no model call holding the error, which the CLI's own report replaces when the turn ended there.
  • A response the proxy didn't count takes the transcript's count. It is joined only to an uncounted call that no answered call comes ahead of, so no call is counted twice.
  • The proxy's records now say when each call ended (timestamp).

The cards. Both offer atif/1 beside their native format, which stays the default. Their images and install lists carry the adapters.

Claude Code's protocol floor (agents/claude-code/requirements.txt, claude_code_atif.py)

Choices to review

  • Codex's copy comes from the rollout alone, not stdout. The exec JSON events have no times and only the turn's total usage. The rollout has each item's time and each response's usage. The cost is one more file the bridge follows.
  • Gemini's live copy runs one response behind. A message is fed once the next one exists, because the CLI keeps changing the last one (its calls, then their results). Feeding every version would mean merging versions in the adapter.
  • Gemini sub-agents aren't embedded. The CLI writes them to transcripts of their own. Their calls still reach the copy, as steps with their usage alone, so the totals hold.
  • A Codex sub-agent the CLI continues in a later turn isn't placed in that turn's copy. ATIF embeds a sub-agent under the call that spawned it, in that call's task. Its records stay in the native log and are counted as unmatched.
  • Codex's and Gemini's protocol floors stay as they are (0.1.640 and 0.1.643). Both adapters import only what those versions have. The recorded fixtures replay through each floor's own protocol with no finding, as Claude Code's do through 0.1.660.

Testing

  • Unit, the adapters
    • Each mapping above has a case, run through the protocol's adapter kit (the live rule after every record, the document valid).
    • Seeded conversations, 150 per agent, about 3 s each:
      • Codex: random responses, sub-agents, attempts.
      • Gemini: random proxy records and messages fed late.
    • Each copy's usage is checked against what was fed, with every call answered and every sub-agent embedded.
  • Unit, the tails
    • Codex's rollout tail: a resumed thread read from where it ended; a line still being written; sub-agents at any depth, one seen before its parent; a replaced file; a fork's copies left out.
    • Gemini's session tail: messages fed once settled; a resumed session; a transcript caught half-written; a restored .jsonl session, a message written again in one, and a transcript moved from .json to .jsonl just before the final read.
    • run_codex and run_gemini both feed while the CLI runs and once more after it exits, and a read still in flight when following stops is fed before the final one.
  • Recorded runs (tst/data/codex_atif, tst/data/gemini_atif), through each agent's image built from this branch, with tst/manual/codex_gemini_atif/record.py:
    • Codex: coding over two turns, a browser screenshot, high reasoning effort, a refused call, a resumed attempt, a sub-agent, and a second turn's forked sub-agent, whose rollout copied the first turn and the parent's reply (none of it reaches the copy).
    • Gemini: coding over two turns, a browser screenshot, a refused call, failed calls the CLI retried.
    • Each replays to its document under the live rule.
    • Its steps sum to each turn's reported usage, every response has its time and model, and every call has its result.
  • Chaos (kept outside the repo)
    • Adapters: harsher random conversations. For Codex, interleaved sub-agents, depth two, forks, continued sub-agents, broken images and non-JSON arguments. For Gemini, lag of 0 to 3 messages, side calls, refused and uncounted calls, equal inputs. Invariants: no kit finding, the copy's prompt tokens equal to what was fed, every call once with its result, every sub-agent that showed embedded once. Clean over 68,227 seeds per adapter locally and 67,289 in 30 minutes on a test host. It catches seven planted bugs: Codex usage dropped, sub-agent records not held, held results lost, attempts ignored; Gemini joined by order, tool-use tokens ignored, side calls lost at the end. It found both ways Gemini's copy could count a call twice, fixed above.
    • Tails: a writer thread tearing lines, replacing files, starting forks and rewriting the transcript non-atomically, against a polling reader, fresh and resumed. Invariant: each record fed exactly once, in its file's order, a fork's copies never, and each Gemini message as its final version. Clean over 6,717 seeds per agent locally and 15,281 in 30 minutes on a test host. It catches three planted bugs: fork copies kept, torn lines fed, and the last message fed before it settled. It led to the fork check reading the parent's rollout again for a turn it hadn't seen yet.
  • Rebased on feat(agents): Codex follows the env's clock, its CLI on real time and the model told the env's date #926 (Codex on the env's clock, its model calls through a per-run relay), tested again on a test host:
    • Codex recorded again through its clocked image, all seven scenarios. Every copy passes the validator with no finding, the steps still sum to each turn's reported usage under the relay, and each replay equals the copy the agent served. The new fork's sub-agent holds none of its parent's copied records.
    • Bundle runs:
      • Codex on an armed clock (sync_env_clock with agent_clock, frozen in 2031): the model ran date and an MCP tool through the egress proxy, and the judge passes it from the copy. The copy's times stay the rollout's real time, as the server's do.
      • Codex's two turns with a forked sub-agent, and Gemini's two turns: both judges pass.
      • Codex's snapshot and restore: the restored agent resumes, replying "three" and the first turn's "one-42". This time the restored turn's judge failed it, since that turn's copy holds that turn alone and the judge couldn't see where "one-42" came from. The same judge passed the same reply before the rebase.
      • Every turn's copy is recorded valid, and every live follow's pages match the final copy.
    • Straight against each image: a restart between turns and two contexts at once behave as before.
    • Chaos on the rebased code: clean over 22,844 adapter seeds and 2,154 tail seeds per agent, every plant caught; and 739 tail seeds with .jsonl transcripts half the time, some moved from .json mid-turn or as the turn's last write (which the previous version failed within 180 seeds).
  • e2e on a test host before the rebase, about $2 in all, recordings included
    • Bundle runs with agent-env run, atif/1 prescribed, each turn followed live, each turn graded by a direct judge reading its copy:
      • Codex, two turns, the second spawning a sub-agent forked with the conversation: both judges pass. The judge's reasons name the fork, the sub-agent's own command and its result.
      • Gemini, two turns: both judges pass.
      • Snapshot and restore. Each agent's turn was snapshotted and restored into a fresh agent under a new context (snapshot_agent_state, then deploy_agent with the snapshot).
        • The restored turn resumes from the restored rollout or transcript, and its judge passes for both agents: the reply recalls the first turn's output.
        • Its copy holds its own turn alone.
        • One Gemini judge failed the first turn because the model replied "Output: one-42" when asked for the output alone. The copy matches the agent's reply.
      • Every copy and live follow. Every turn's copy is recorded valid, and every live follow's pages match the final copy, the Codex sub-agent's included.
    • Straight against each image:
      • A restart between turns gives the second turn a valid copy of its own turn alone.
      • Two contexts at once each hold only their own calls, and each Codex context only its own sub-agent.
    • Claude Code's floor. Recorded through its image built from this branch (coding over two turns, and a /compact between turns, with tst/manual/claude_code_atif/record.py):
      • The image installed protocol 0.1.660.
      • All five turns' copies are profile 1.2 and pass the validator with no finding.
      • The compaction carries its token counts: 28,634 before and 2,815 after.
    • Recordings. All 14 recorded turns' served copies pass the validator with no finding. Each replay through the adapter equals the served copy, except for the task data the SDK adds at the end.

🤖 Generated with Claude Code

Confidence Score: 5/5 · The PR appears safe to merge; no new blocking issues remain.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new blocking issues remain.

Summary

Codex and Gemini now offer atif/1 beside their native formats, using the CLI’s saved records for richer steps.

  • Codex serves an ATIF copy when a run asks for one.
  • Gemini serves an ATIF copy when a run asks for one.
  • Claude Code records compaction token counts with the updated protocol.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  C[Codex rollout] --> CT[RolloutTail]
  CT --> CA[CodexAtif]
  G[Gemini transcript] --> GT[SessionTail]
  GT --> GA[GeminiAtif]
  P[Proxy call records] --> GA
  CA --> A[Live ATIF copy]
  GA --> A
Loading

Reviews (14) · Last reviewed commit: "fix(agents): Gemini's copy keeps a file ..." · Reviewed by Greptile

@earakely-scale
earakely-scale marked this pull request as ready for review November 25, 2026 18:25
@earakely-scale
earakely-scale requested a review from a team as a code owner November 25, 2026 18:25
earakely-scale and others added 13 commits November 25, 2026 21:45
The bridge tails the thread's rollout, and each sub-agent's, and feeds its
records as the rollout aux file; the adapter writes a step per model
response with its items' times and the response's own usage, embeds each
sub-agent under its spawn_agent call, marks a resumed attempt, and turns
a failed call into an error step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts proxy's calls

The bridge tails the session transcript and feeds each model message once
it is settled; the adapter writes a step per response with its thoughts,
calls, results and images, takes each step's usage from the proxy call
whose input it names, and writes the calls that wrote no message, and the
refused ones, as steps of their own. Each proxy record now has a time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… images

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and answers hosted web searches

A sub-agent forked with its parent's history begins its rollout with a copy
of the parent's meta and turns, whose call ids the copy already holds: the
tail leaves out the records of every turn the parent's rollout holds. A web
search the provider runs has no output item, so its step waited on a result
until the turn ended: the adapter answers it with its status. Adds the
recorded fixtures and tests for both agents, and seeded conversations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cks a fork's parent for a new turn

A Gemini response the proxy didn't count is joined only to an uncounted call
no answered call comes ahead of, and leaves the calls not yet written alone,
since they may be later messages'. A forked Codex sub-agent's record of a
turn its parent's rollout didn't hold when the fork was found reads the
parent's rollout again before taking the turn for the sub-agent's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…th a forked sub-agent

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h the tail leaves out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lier task's sub-agent never takes a later spawn

Stopping the rollout and transcript followers cancelled them, so a read
still running in its thread moved past records whose batch was then
dropped: the followers now finish that read and feed it before the final
one. A sub-agent an earlier task saw kept matching a later spawn that
reused its path, declaring it twice: only this task's sub-agents match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h atif/1 profile 1.2

Its adapter writes a compaction's token counts, which profile 1.2 holds, and
now takes is_token_count and COMPACTION_TRIGGERS from the protocol rather
than defining its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mage

Its model calls now go through the turn's relay; the copies' steps still sum
to each turn's reported usage, and each replay equals what the agent served.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n restored from one is

A snapshot keeps its transcript's format, and the tail read only .json, so a
restored .jsonl session's copy had its proxy calls' usage and nothing else.
It now reads either: a .jsonl line per message, one written again replacing
its earlier copy, a line not yet whole left out; and a transcript the CLI
moves from .json to .jsonl is found again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ll in the read that finds it gone

A move from .json to .jsonl after the last poll cleared the path and
returned, and the turn's final read, its only one left, then fed nothing of
what the turn wrote since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale force-pushed the edgararakelyan/fd-6082-y8-codex-gemini-atif branch from ca3fafd to 4109f34 Compare November 26, 2026 05:46
earakely-scale and others added 2 commits November 25, 2026 22:14
…nded when its message was written

The transcript runs a response behind, so the next call can be waiting when
a message arrives; with the same input as the message's own call the proxy
couldn't count, it took the message, and its counts with it. A call that
ended after the CLI wrote the message is a later one's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
read_file gives a model that takes media in a tool's response the file in
the function response's parts, which the copy left out, keeping only its
placeholder text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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