Skip to content

Fix: ignore Codex hook events from subagent threads - #193

Open
aayank13 wants to merge 1 commit into
mainfrom
fix/codex-subagent-hooks
Open

aayank13 wants to merge 1 commit into
mainfrom
fix/codex-subagent-hooks

Conversation

@aayank13

Copy link
Copy Markdown
Owner

Fixes #157

Inside a Codex subagent, every hook payload carries agent_id, and session_id is the subagent's own thread id. The adapter already dropped subagent prompts but let everything else through. So when a subagent ran cargo test and it failed with an error a procedure was learned from, the PostToolUse hook served that procedure to the subagent and recorded the injection under the child thread id. Subagent rollouts are never learned on their own (the parser refuses them and leaves them to the parent session), and the parent's trace has a different id, so nothing ever settled that injection: its outcome was never scored and the row stayed in the store for good. The subagent's Stop, PreCompact and SessionEnd hooks had a similar problem, since each one started a background ingest of the child rollout that could only fail.

Now the Codex adapter ignores any hook event that has agent_id set, before it even looks at the event name. The parent session already captures what the subagent did when its rollout is learned, so there is nothing a subagent hook could add, and dropping them all is simpler than picking events one by one. The parent's own hooks are unchanged.

Copilot CLI has the same symptom (#158), but it marks subagent events differently, and telling them apart there needs its own check, so it is left for a separate change.

To reproduce, I built the binary, used a scratch TRODDEN_HOME, learned a procedure by ingesting a Codex rollout where cargo test failed with E0425, the file was edited and the test then passed, and fed trodden hook codex two PostToolUse payloads with the same failing output: one from the root thread and one with agent_id and a child session_id. Before the fix both got the procedure back, and the injections table had a row for the child thread id next to the root one. After the fix the subagent payload gets no reply and only the root session's injection is recorded.

The new test sends each hook event Codex fires, checks it maps to a moment from the root thread, then adds the subagent fields and checks it is ignored. It fails before the fix for PostToolUse and passes after.

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.

Codex: failure recalls inside a subagent are recorded under a session no trace will have

1 participant