Repository navigation
Register Codex SessionEnd, SubagentStart and SubagentStop hooks - #294
Merged
Siddhant-K-code merged 1 commit intoOct 24, 2026
Merged
Conversation
`agent-strace setup --cli codex` now registers SessionEnd, SubagentStart and SubagentStop alongside the existing five hooks. Codex traces get a session_end event, and subagent lifecycle is recorded as subagent_start/subagent_stop in the parent trace with agent_id and agent_type. Codex subagents share the parent session_id, so no child session is linked or created. SessionEnd uses a 3s timeout (Codex's cap; its default is 1s). Update the capture matrix, the Codex 0.163.0-alpha.11 fixture, tests and docs. Existing users must re-run setup and re-trust the hooks in /hooks; codex exec skips untrusted hooks. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Siddhant-K-code
deleted the
siddhant-k-code-codex-session-end-subagent-hooks
branch
October 24, 2026 17:17
This was referenced Oct 24, 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.
Summary
agent-strace setup --cli codexused to register five Codex hooks (SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop). This PR adds SessionEnd, SubagentStart and SubagentStop.agent-strace hook session-end, with"timeout": 3. Codex defaults SessionEnd hooks to 1s and caps them at 3s. Codex traces now get asession_endevent, clear their active-session marker and finalize inhealth.subagent-start/subagent-stop. These reuse the feat(copilot): link subagent sessions to their parent via subagentStart/subagentStop #286 handler, so they are recorded assubagent_start/subagent_stopin the parent trace withagent_idandagent_type.session_idand are not separate sessions. Codex is not in_SUBAGENT_SESSION_PROVIDERS, so_link_subagent_sessionnever runs: no child session is invented, the parent is not rewritten and nothing is refused.agent_idis added to the recorded keys only for providers outside that set, so Copilot behavior is unchanged.codex execsilently skips untrusted hooks).Observed payloads (codex-cli 0.163.0-alpha.11, field names only)
"other"in every run), session_id, transcript_path. No turn_id or modelPre/PostToolUse calls made by a subagent also carry
agent_idandagent_type.agent_typewasdefault.agent_idis a UUID distinct from the session id.Order in both live runs:
The #280 capture had SubagentStart after the wait_agent PreToolUse, so that position is racy. Both orders are now fixture scenarios. The spawn_agent result does not include the
agent_id, so a subagent cannot be tied to the tool call that spawned it.Verification
CODEX_HOME, a temp trace dir and no bypass/yolo flags:setup --cli codex./hooksshowed all 8 hooks as modified (untrusted). After re-trusting,setup --verifyreported 8/8.codex exec -s read-onlysubagent run recorded:healthreported a finalized session.codex exec resume --lastappendedsession_start(resume)followed bysession_endto the same trace.replay,replay --tree,--expand-subagents,tree,stats --include-subagentsandexplainall exited 0.TestCodexSessionEndAndSubagentHooksintests/test_codex_hooks.py:tests/test_capture_matrix_fixtures.py.tests/test_setup_verify.py:--verifytests/test_health.pyCodex cases. The provider-without-session-end path keeps its coverage through a patched matrix.TMPDIR=/private/tmp PYTHONPATH=src python3 -m unittest discover -s tests: 2385 tests OK (2 skipped).Upgrade note for existing users
Re-run
agent-strace setup --cli codex, then re-trust the hooks in Codex's/hooks. Until you re-trust them,codex execsilently skips the modified hooks. Traces recorded by older installs never cleared their active-session marker, sohealthnow reports them assession_activeinstead of treating a missing end as a Codex limitation. This is documented indocs/commands.mdanddocs/capture-matrix.md.Docs and matrix
capture_matrix.json, codex entry:session_endis nowcapturedother, subagents are not separate sessionslast_verifiedupdateddocs/capture-matrix.md: updated the coverage table, the Codex section and the machine-readable row.docs/setup.md: hooks JSON, field notes and an upgrading paragraph.docs/integrations.md: updated the Codex row.docs/commands.md:subagent-start/subagent-stoprows to the hook tableDeferred
last_assistant_messageandagent_transcript_pathare not recorded.agent_idyet.agent_id. replay.py is in Refuse sessions with non-object event data instead of printing a traceback #293's scope.codex exec..pending-callsfile is left after session endagent-strace listignoresAGENT_TRACE_DIRRelated
No version bump, tag or release.