Repository navigation
Attribute Codex subagent tool calls and record what subagents return - #300
Merged
Siddhant-K-code merged 1 commit intoOct 26, 2026
Merged
Conversation
Codex fires a subagent's hooks under the parent session_id, so its tool calls were indistinguishable from the parent's. Record agent_id and agent_type on tool_call, tool_result and error events for providers that keep subagents in-session, and record SubagentStop's last_assistant_message (as text) and agent_transcript_path, with redaction. stop_hook_active does not suppress subagent_stop. Copilot events are unchanged. Pending-call pairing still matches by tool_use_id first; without one it prefers a pending call from the same agent. replay, replay --tree/--expand-subagents, tree, stats and explain show the attribution only when agent_id is present, so unattributed traces render as before. Disclosure counts a subagent's returned text as a response. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Siddhant-K-code
deleted the
siddhant-k-code-attribute-codex-subagent-tool-events
branch
October 26, 2026 18:00
Siddhant-K-code
added a commit
that referenced
this pull request
Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #294. Codex fires a subagent's hooks under the parent
session_id. Because of that, a subagent's tool calls could not be told apart from the parent's, and the trace did not record what the subagent returned.Recording (
hooks.py)_SUBAGENT_SESSION_PROVIDERS),tool_call,tool_resultanderrorevents getagent_idandagent_typewhen the payload has anagent_id. Copilot events are unchanged.subagent_stoprecordslast_assistant_messageastextand also recordsagent_transcript_path, the same wayhandle_stopdoes, and redaction applies.stop_hook_activedoes not suppress the event.tool_use_idfirst. When there is notool_use_id, it prefers a pending call from the same agent, then the oldest one.Rendering
Attribution only appears when
agent_idis present, so unattributed traces render exactly as before. I checked this byte-for-byte against main, with and without color.replay[subagent <type> <short id>]tag on tool_call/tool_result/error;agent=<id>on subagent_start/stop;returned: "…"line on subagent_stopreplay --expand-subagents(event tree)agent=<short id>on start/stop;returned:linereplay --tree,tree(summary)└─ subagent <type> <short id> N tools ✗ N errorsline under the session;tree --jsongainssubagentsonly when presentstatsSubagent Tool Calls:section, only when a subagent made tool callsexplainSubagent: <type> <short id> N toolsline per phaseThe short ID is the last 8 characters, because Codex agent IDs are UUIDv7 and share a timestamp prefix with the session ID.
Synthetic before/after for
replay:tree:Final-answer audit
A
subagent_stopnow carriestext, so I checked every consumer that readstextor a final message to make sure none of them takes this as the session's answer:assistant_responseorllm_response.A test checks that the checkpoint, OTLP, GenAI and timeline final answer stays the same when a
subagent_stopwith text comes after the session's answer.Docs
capture_matrix.jsonanddocs/capture-matrix.mdare updated. The remaining Codex gap: no event links a subagent to thespawn_agentcall that started it.docs/integrations.mdanddocs/commands.mdare also updated.Tests
New or extended tests cover:
agent_idagent_typewithoutagent_idis ignoredstop_hook_active, and both store-level and hook-level redactiontool_use_id, and oldest-call fallbackFull suite: 2482 tests OK (2 skipped). I also ran a live check with codex-cli 0.163.0-alpha.11: one subagent ran one shell command in a read-only sandbox, and its tool events carried
agent_id/agent_typeand rendered as attributed.subagent_stophadtextandagent_transcript_path.