Repository navigation
feat(agents): Codex and Gemini serve atif/1, from the CLI's rollout and its session transcript - #924
earakely-scale wants to merge 8 commits into
Conversation
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>
| following.cancel() | ||
| try: | ||
| await following |
There was a problem hiding this comment.
When the CLI exits while follow_rollout awaits asyncio.to_thread(tail.read), canceling the follower drops that batch even though the reader advances its offsets. The final read then skips those records. Gemini has the same race because SessionTail.read adds message IDs to _fed before returning them. Responses, tool results, and usage can silently disappear from the served copy.
Let the pending read finish and feed its batch before stopping, or commit reader progress only after delivery.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/agents/agents/codex/codex_bridge.py
Line: 300-302
Comment:
**Final records can disappear**
When the CLI exits while `follow_rollout` awaits `asyncio.to_thread(tail.read)`, canceling the follower drops that batch even though the reader advances its offsets. The final read then skips those records. Gemini has the same race because `SessionTail.read` adds message IDs to `_fed` before returning them. Responses, tool results, and usage can silently disappear from the served copy.
Let the pending read finish and feed its batch before stopping, or commit reader progress only after delivery.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if path is None: | ||
| self._result(record, turn) | ||
| return | ||
| thread = next((t for t, sub in self._subs.items() if sub.path == path and not sub.declared), None) |
There was a problem hiding this comment.
Reused names break later turns
When a later task spawns a new sub-agent with a previously used task_name, this lookup can select the old thread. _subs survives across tasks, while end resets every old entry's declared flag to false. The old entry therefore matches first, even if the new thread's metadata has arrived. _declare then declares the old thread again, which the builder rejects, stopping the ATIF copy.
Limit this lookup to threads first seen in the current task, or separately track retired threads.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/agents/agents/codex/codex_atif.py
Line: 184
Comment:
**Reused names break later turns**
When a later task spawns a new sub-agent with a previously used `task_name`, this lookup can select the old thread. `_subs` survives across tasks, while `end` resets every old entry's `declared` flag to false. The old entry therefore matches first, even if the new thread's metadata has arrived. `_declare` then declares the old thread again, which the builder rejects, stopping the ATIF copy.
Limit this lookup to threads first seen in the current task, or separately track retired threads.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Codex and Gemini now serve
atif/1when 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)$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 therolloutaux file (RolloutTail,rollout_aux). The exec JSON events on stdout stay the native log.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.mcp__browser__browser_navigate).summary, else the ciphertext is kept asredacted, elseomitted.spawn_agentcall 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.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.task_started, and its steps carry the attempt's number. A failed or refused model call ends its attempt'stask_completewith 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)~/.gemini/tmp/<project>/chats/session-*.json), which the CLI rewrites whole. 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.summaryreasoning.errorresult, and a cancelled call without a result iscanceled.agentenv.model_callwhose input it names (the prompt plus any tool-use prompt, as the proxy counts it).timestamp).The cards. Both offer
atif/1beside their native format, which stays the default. Their images and install lists carry the adapters.Choices to review
Testing
run_codexandrun_geminiboth feed while the CLI runs and once more after it exits.tst/data/codex_atif,tst/data/gemini_atif), through each agent's image built from this branch, withtst/manual/codex_gemini_atif/record.py:agent-env run, atif/1 prescribed, each turn followed live, each turn graded by a direct judge reading its copy:snapshot_agent_state, thendeploy_agentwith the snapshot).valid, and every live follow's pages match the final copy, the Codex sub-agent's included.🤖 Generated with Claude Code
Fix the dropped tail batches and repeated Codex sub-agent name lookup before merging.
Fix with agent prompt
Summary
Adds prescribed
atif/1copies for Codex and Gemini while keeping native formats as the default.atif/1trajectory.atif/1steps from settled messages and matching proxy calls.Intentional exclusions acknowledged by
earakely-scale: Gemini sub-agents remain usage-only steps; Codex sub-agents continued in later tasks remain unmatched because their embedded trajectory belongs to the spawning task.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR C[Codex rollout] --> CT[RolloutTail] CT --> CA[CodexAtif] G[Gemini transcript] --> GT[SessionTail] GT --> GA[GeminiAtif] P[Gemini proxy call records] --> GA CA --> B[ATIF builder] GA --> B B --> L[Live pages] B --> F[Final document]Reviews (1) · Last reviewed commit: "test(agents): a fork's copied turns hold..." · Reviewed by Greptile