Repository navigation
fix(hooks): give subagent and task-runner spec hooks the session id - #31495
Conversation
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change only adds a session id, and it reuses the path the chat turn and Notes
[DESIGN-REVIEWED] 3ada8c1 Description read[DESCRIPTION-READ] 2249415e4f3f993bb19d1efcdd887a36a956502beb4e1e1fcd776d0b76c00ddc That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS This fixes a reported defect (#24935), and each item passes the session id along a path that already existed. The only issue is a copied idiom, noted below. Notes
What this change shipsInventory (5 items) — 5 justifiedIntent: delegated work and task-runner runs on
[FIRST-PRINCIPLES-REVIEWED] 3ada8c1 Description read[DESCRIPTION-READ] 6f034d6f424a3779766570e4ec042c9f8f47966cd8425ff7f1c8af54fc001768 That sha256 names the PR description this verdict read. Recompute it with |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: This change doesn't make any rule stricter. It only adds the ACP session id ( TIGHTENING: none. No deny tier, validator or gate predicate got stricter. The closest hunk is in ADJUDICATED: 10 candidates. The harness handed me no verdicts, so no newly-refused row is confirmed. PLATFORM COVERAGE:
The diff makes no path, separator or interpreter assumption of its own. The only platform-shaped surface it adds is the env-var name a hook reads, and both spellings are probed. UNADJUDICATED:
[SCOPE-REVIEWED] 3ada8c1 |
9989cfd to
3865239
Compare
|
Rebased: main moved in docs/system-specs/modules/memory-skills-hooks.md, docs/system-specs/modules/subagent.md, src/kiro_crew/docs/steering-and-hooks.md, src/kiro_crew/subagent_manager/run_turn.py, src/kiro_crew/subagent_manager/turn_session.py, src/kiro_crew/tool_permission.py since this head went green (b3c17ad -> c5c4de1); CI re-running. [operator: bolichen97] |
3865239 to
f699ae9
Compare
|
Rebased: main moved in The two test files conflicted with #31670, which added [operator: bolichen97] |
54f0fca to
649cbcc
Compare
|
Rebased: main moved in The hook owners' shape-digest test conflicted again: main re-pinned |
On kas, an agent spec's own hooks that Kiro Crew runs for a dashboard chat turn, and a subagent's Stop hook, get the session's ACP id as KIRO_SESSION_ID and stdin session_id. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse gate hooks of subagents and the task runner, got none, so a hook that joins its events to state the agent wrote under its own session id stopped working for delegated work. Pass the run's own id at those fire sites too: the subagent reads it from its client when the hooks fire, and the permission gate reads the client its request came over. Stored Hooks-page hooks still get none.
649cbcc to
3ada8c1
Compare
|
[operator: bolichen97] Rebased: the PR had a merge conflict with main in Main re-pinned Checks run on 3ada8c1: the 196 related backend test files pass (6808 passed), flake8, isort, black and mypy pass, and local GPT and Opus reviews found nothing. The earlier lane reds on 649cbcc were the CI app's GitHub rate limit. AI-assisted, posted on behalf of bolichen97 |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved at the author's request: PR Readiness passed on 3ada8c1, and all five review lanes report no blocking finding and no missing evidence on this head. No open change request, and no linked issue is T3 or T4.
…31495) On kas, an agent spec's own hooks that Kiro Crew runs for a dashboard chat turn, and a subagent's Stop hook, get the session's ACP id as KIRO_SESSION_ID and stdin session_id. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse gate hooks of subagents and the task runner, got none, so a hook that joins its events to state the agent wrote under its own session id stopped working for delegated work. Pass the run's own id at those fire sites too: the subagent reads it from its client when the hooks fire, and the permission gate reads the client its request came over. Stored Hooks-page hooks still get none. (cherry picked from commit f222dbc) Original author: @bolichen97 (picked by hand: kept the release versions of test_crew_fired_spec_hooks.py and test_hooks_composition_contract.py, added this change's new subagent session-id test, and set the base shape digest for the one changed permission_pre_tool_block signature)
…31495) On kas, an agent spec's own hooks that Kiro Crew runs for a dashboard chat turn, and a subagent's Stop hook, get the session's ACP id as KIRO_SESSION_ID and stdin session_id. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse gate hooks of subagents and the task runner, got none, so a hook that joins its events to state the agent wrote under its own session id stopped working for delegated work. Pass the run's own id at those fire sites too: the subagent reads it from its client when the hooks fire, and the permission gate reads the client its request came over. Stored Hooks-page hooks still get none. (cherry picked from commit f222dbc) Original author: @bolichen97 (picked by hand: kept the release versions of test_crew_fired_spec_hooks.py and test_hooks_composition_contract.py, added this change's new subagent session-id test, and set the base shape digest for the one changed permission_pre_tool_block signature)
…31495) On kas, an agent spec's own hooks that Kiro Crew runs for a dashboard chat turn, and a subagent's Stop hook, get the session's ACP id as KIRO_SESSION_ID and stdin session_id. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse gate hooks of subagents and the task runner, got none, so a hook that joins its events to state the agent wrote under its own session id stopped working for delegated work. Pass the run's own id at those fire sites too: the subagent reads it from its client when the hooks fire, and the permission gate reads the client its request came over. Stored Hooks-page hooks still get none. (cherry picked from commit f222dbc) Original author: @bolichen97 (picked by hand: kept the release versions of test_crew_fired_spec_hooks.py and test_hooks_composition_contract.py, added this change's new subagent session-id test, and set the base shape digest for the one changed permission_pre_tool_block signature)
…31495) On kas, an agent spec's own hooks that Kiro Crew runs for a dashboard chat turn, and a subagent's Stop hook, get the session's ACP id as KIRO_SESSION_ID and stdin session_id. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse gate hooks of subagents and the task runner, got none, so a hook that joins its events to state the agent wrote under its own session id stopped working for delegated work. Pass the run's own id at those fire sites too: the subagent reads it from its client when the hooks fire, and the permission gate reads the client its request came over. Stored Hooks-page hooks still get none. (cherry picked from commit f222dbc) Original author: @bolichen97 (picked by hand: kept the release versions of test_crew_fired_spec_hooks.py and test_hooks_composition_contract.py, added this change's new subagent session-id test, and set the base shape digest for the one changed permission_pre_tool_block signature)
…31495) On kas, an agent spec's own hooks that Kiro Crew runs for a dashboard chat turn, and a subagent's Stop hook, get the session's ACP id as KIRO_SESSION_ID and stdin session_id. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse gate hooks of subagents and the task runner, got none, so a hook that joins its events to state the agent wrote under its own session id stopped working for delegated work. Pass the run's own id at those fire sites too: the subagent reads it from its client when the hooks fire, and the permission gate reads the client its request came over. Stored Hooks-page hooks still get none. (cherry picked from commit f222dbc) Original author: @bolichen97 (picked by hand: kept the release versions of test_crew_fired_spec_hooks.py and test_hooks_composition_contract.py, added this change's new subagent session-id test, and set the base shape digest for the one changed permission_pre_tool_block signature)
…31495) On kas, an agent spec's own hooks that Kiro Crew runs for a dashboard chat turn, and a subagent's Stop hook, get the session's ACP id as KIRO_SESSION_ID and stdin session_id. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse gate hooks of subagents and the task runner, got none, so a hook that joins its events to state the agent wrote under its own session id stopped working for delegated work. Pass the run's own id at those fire sites too: the subagent reads it from its client when the hooks fire, and the permission gate reads the client its request came over. Stored Hooks-page hooks still get none. (cherry picked from commit f222dbc) Original author: @bolichen97 (picked by hand: kept the release versions of test_crew_fired_spec_hooks.py and test_hooks_composition_contract.py, added this change's new subagent session-id test, and set the base shape digest for the one changed permission_pre_tool_block signature)
…31495) On kas, an agent spec's own hooks that Kiro Crew runs for a dashboard chat turn, and a subagent's Stop hook, get the session's ACP id as KIRO_SESSION_ID and stdin session_id. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse gate hooks of subagents and the task runner, got none, so a hook that joins its events to state the agent wrote under its own session id stopped working for delegated work. Pass the run's own id at those fire sites too: the subagent reads it from its client when the hooks fire, and the permission gate reads the client its request came over. Stored Hooks-page hooks still get none. (cherry picked from commit f222dbc) Original author: @bolichen97 (picked by hand: kept the release versions of test_crew_fired_spec_hooks.py and test_hooks_composition_contract.py, added this change's new subagent session-id test, and set the base shape digest for the one changed permission_pre_tool_block signature)
Problem / Motivation
Goal: An agent spec's own hooks that Kiro Crew runs for a KAS subagent or a task-runner run get that run's ACP session id, as
KIRO_SESSION_IDand stdinsession_id, the way kiro-cli gives it.On
kas, a dashboard chat turn's spec hooks already get the session id (#24952, #28912), and so does a subagent'sStophook. A subagent'sAgentSpawn,UserPromptSubmitandPostToolUsespec hooks, and thePreToolUsespec hooks that gate a subagent's or a task-runner run's permission requests, still run with noKIRO_SESSION_IDand nosession_idon stdin.Why it matters
A hook that joins its events to state the agent wrote under its own session id (for example, a reminder that renews the locks a session holds) silently stops working for delegated work and task-runner runs on
kas, while the same hook works onkiro.Not a goal
PreToolUsefire on an ungated turn: it runs stored hooks only.KIROCREW_SCRATCHor any other env key: the hook env allowlist is unchanged.What changed (motivation → approach → change)
A spec hook on a subagent or task-runner turn now gets the session id of the run it fired for. The subagent's prompt hooks and
PostToolUseread the child's own id from its client each time they fire, exactly as itsStophook already does. The permission gate (SpecHooksintool_permission.py, shared by subagents and the task runner) passes the id of the client the request came over throughpermission_pre_tool_blockto the hook store.The hook store already gives that id to spec hooks alone, as
KIRO_SESSION_IDand stdinsession_id/acp_session_id, so stored hooks see no change. Beforesession/newthe id is left out, as on the chat turn. The hook specs and the user hook guide (steering-and-hooks.md) name the new events.kasAgentSpawn,UserPromptSubmitPreToolUse(permission gate)PreToolUse(permission gate)PostToolUseStop, chat turn eventsLegend: changed, unchanged.
Backwards compatibility
Compatible: every new parameter is an optional keyword defaulting to
None, and a hook only gains an env var and two stdin keys it can ignore.Removes nothing: the change only adds the session id to hook payloads that had none.
Tests
test_crew_fired_spec_hooks.py::test_a_subagent_run_hands_its_spec_hooks_its_own_session_id: a real subagent run on a KAS client double firesAgentSpawn,UserPromptSubmit, thePreToolUsegate,PostToolUseandStop, and every fire carries the child's id; with no id yet, every fire carries none.test_tool_permission.py: theSpecHooksfloor passes the id of the request's wire client topermission_pre_tool_block; both ladders' identity test names the new keyword.test_hooks_composition_contract.py: the hook owners' shape digest is re-pinned forpermission_pre_tool_block's new keyword.Proof: PROVEN test/test_crew_fired_spec_hooks.py::test_a_subagent_run_hands_its_spec_hooks_its_own_session_id[sess_child-sess_child], test/test_crew_fired_spec_hooks.py::test_a_subagent_run_hands_its_spec_hooks_its_own_session_id[-None], test/test_hooks_composition_contract.py::test_the_moved_names_keep_their_base_shapes, test/test_tool_permission.py::test_spec_hooks_consult_the_gate_on_gated_and_ungated_turns, test/test_tool_permission.py::test_each_ladder_gives_its_spec_hooks_the_callers_identity[subagent] (head 54f0fca)
Determinism: the changed tests passed 20 runs at
-n0, 10 runs at-n 4 --dist loadgroup --max-worker-restart=2besidetest_subagent_stop_hook.pyandtest_subagent_prompt_hooks.py, and the three changed files in a shuffled order (seed 30353, 284 passed).Manual verification
N/A — unit coverage sufficient: how the hook store turns the id into
KIRO_SESSION_IDand stdin keys for spec hooks only is already pinned by the existingtest_crew_fired_spec_hooks.pycases; this change forwards the id to it.Screenshots / video
N/A — no frontend change.
Related Issues
Closes #24935
Sibling sweep
Swept: git grep -n "extra_hooks=" -- src/kiro_crew/
Sibling: src/kiro_crew/subagent_manager/prompt_hooks.py -- changed here
Sibling: src/kiro_crew/subagent_manager/run_turn.py -- changed here
Sibling: src/kiro_crew/hook_runtime/hook_dispatch.py -- changed here
Sibling: src/kiro_crew/subagent_manager/stop_hooks.py -- not affected -- already passes the child's id on Stop
Sibling: src/kiro_crew/dashboard/chat_turn/turn_spec_hooks.py -- not affected -- already passes the chat session's id
Pattern harvest
Rule candidate: semgrep
Pattern: a ScriptHookStore.fire call that passes extra_hooks= but no acp_session_id=
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.