Skip to content

fix(hooks): give subagent and task-runner spec hooks the session id - #31495

Merged
bolichen97 merged 1 commit into
mainfrom
fix/24935-subagent-hook-session-id
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/24935-subagent-hook-session-id

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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_ID and stdin session_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's Stop hook. A subagent's AgentSpawn, UserPromptSubmit and PostToolUse spec hooks, and the PreToolUse spec hooks that gate a subagent's or a task-runner run's permission requests, still run with no KIRO_SESSION_ID and no session_id on 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 on kiro.

Not a goal

  • Hooks-page (stored) hooks: they never get the id, on any backend.
  • The informational PreToolUse fire on an ungated turn: it runs stored hooks only.
  • KIROCREW_SCRATCH or any other env key: the hook env allowlist is unchanged.
  • The dashboard chat turn, which already passes the id.

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 PostToolUse read the child's own id from its client each time they fire, exactly as its Stop hook already does. The permission gate (SpecHooks in tool_permission.py, shared by subagents and the task runner) passes the id of the client the request came over through permission_pre_tool_block to the hook store.

The hook store already gives that id to spec hooks alone, as KIRO_SESSION_ID and stdin session_id / acp_session_id, so stored hooks see no change. Before session/new the 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.

Spec hook event on kas Before After
subagent AgentSpawn, UserPromptSubmit no id changed: child's id
subagent PreToolUse (permission gate) no id changed: child's id
task-runner PreToolUse (permission gate) no id changed: run's id
subagent PostToolUse no id changed: child's id
subagent Stop, chat turn events id unchanged

Legend: 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 fires AgentSpawn, UserPromptSubmit, the PreToolUse gate, PostToolUse and Stop, and every fire carries the child's id; with no id yet, every fire carries none.
  • test_tool_permission.py: the SpecHooks floor passes the id of the request's wire client to permission_pre_tool_block; both ladders' identity test names the new keyword.
  • test_hooks_composition_contract.py: the hook owners' shape digest is re-pinned for permission_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=2 beside test_subagent_stop_hook.py and test_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_ID and stdin keys for spec hooks only is already pinned by the existing test_crew_fired_spec_hooks.py cases; 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 6, 2026 15:25
@bolichen97
bolichen97 requested a review from Zedmor November 6, 2026 15:25
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/hook_runtime/hook_dispatch.py

  • @KiroCrewCaptain: missing the ## Sensitive change review heading

How to clear this check:

  1. The PR author posts the template below as a PR comment, with
    every field filled (N/A needs a reason). Keep the
    Head commit line: it must name the current head SHA.
  2. The check turns green within a minute, with no push.
  3. A new push resets this check: post it again for the new head.

Only the author's comment counts this way. A reviewer can instead
paste the filled template into an "Approve" review on this head.
Merging still needs a reviewer's approval.

## Sensitive change review
- Head commit: 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889
- What rule changed:
- Before -> after (what was allowed/blocked, now):
- Worst case if wrong (breaks commands / leaks secret / locks user out):
- Evidence checked (which sandbox result proves it):
- No regression:
  - Tools still work (which tools/commands were run, result):
  - Backward compatible (old config / old data / old callers still work, how checked):
  - Existing tests (which suites passed on this head):
- How to undo:

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3ada8c1

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change only adds a session id, and it reuses the path the chat turn and Stop hook already take.

Notes

  • The task-runner PreToolUse gate is covered only through the shared SpecHooks unit test. No test runs a real task-runner and checks that its wire client carries the run's id.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 3ada8c1

Verdict parsed from the review's SHA-scoped output markers for commit 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • Item 1–3 — duplicate (note): the PR adds three more copies of getattr(client, "session_id", "") … isinstance(sid, str) and sid (grepped isinstance(_*sid, str) and _*sid: 6 sites in src/kiro_crew). crew_log.emit_state.session_id_of(client) already does this read. Subtraction: replace the three new inline reads with session_id_of, or with one local helper. session_id_of also falls back to the inner client's _session_id, so check that this broader read is wanted before switching.

What this change ships

Inventory (5 items) — 5 justified

Intent: delegated work and task-runner runs on kas give an agent spec's hooks their own ACP session id, the same as kiro-cli does. FIX.

  1. A subagent's AgentSpawn and UserPromptSubmit spec hooks now get the child's session id — justified
  2. A subagent's PostToolUse spec hooks now get the child's session id — justified
  3. The PreToolUse permission-gate spec hooks of subagents and the task runner now get the requesting client's session id — justified
  4. permission_pre_tool_block gains an optional acp_session_id keyword (one consumer, SpecHooks) — justified
  5. The hook spec, the subagent spec and the user guide now name the new events — justified

[FIRST-PRINCIPLES-REVIEWED] 3ada8c1

Description read

[DESCRIPTION-READ] 6f034d6f424a3779766570e4ec042c9f8f47966cd8425ff7f1c8af54fc001768

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 15:43
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 3ada8c1c38d7a7eada33b4456ca2d9b3a3163889 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 6 classified, 0 newly refused, 6 still allowed.
  • ubuntu-latest (platform posix): 6 classified, 0 newly refused, 6 still allowed.
  • windows-latest (platform windows): 4 classified, 0 newly refused, 4 still allowed.

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 (acp_session_id, and KIRO_SESSION_ID in the hook's env) to the payload of agent-spec hooks on subagent and task-runner events. It doesn't touch the shell deny composite or any refusal predicate. The 10 candidates probe the shell tier near the new field; the gap that no candidate can measure is the SpecHooks.refuse call path, named under UNADJUDICATED below.

TIGHTENING: none. No deny tier, validator or gate predicate got stricter. The closest hunk is in tool_permission.SpecHooks.refuse: sid = getattr(getattr(ask.wire, "client", None), "session_id", "") … acp_session_id=sid if self._spec.hooks and isinstance(sid, str) and sid else None. It passes a new keyword into permission_pre_tool_block and on to the spec hooks. It refuses no new threat.

ADJUDICATED: 10 candidates. The harness handed me no verdicts, so no newly-refused row is confirmed.

PLATFORM COVERAGE:

  • posix (6 rows): $KIRO_SESSION_ID and printenv reads, a stdin payload replay into a ./hooks/ script, a jq read of session_id/acp_session_id, a per-session log path under $HOME, and a pytest run with / separators.
  • windows (4 rows): %KIRO_SESSION_ID%, PowerShell $env:KIRO_SESSION_ID, a type … | .\hooks\guard.cmd replay, and pytest with \ separators.
  • any: no rows, because every candidate names a path, an env-var spelling or an executable.

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:

  • Guard: tool_permission.SpecHooks.refuse, the PreToolUse floor on subagent and task-runner permission requests.
  • Call path: permission request → SpecHooks.refuse(ask) → new getattr(getattr(ask.wire, "client", None), "session_id", "") → hook_dispatch.permission_pre_tool_block(..., acp_session_id=...) → fire(..., extra_hooks=spec.hooks, acp_session_id=...).
  • What it does: this lookup runs before the fire. The fire's own except Exception wrapper, which makes "a gate with no verdict" block, doesn't cover it. It runs even when there are no spec hooks, because the self._spec.hooks check comes after it. So if a wire client's session_id raised anything other than AttributeError, the request would fail in a way the shell classifier can't see.
  • Inputs I would have submitted, in prose: a request whose ask.wire is None; a wire whose client has no session_id; a client whose session_id is "" or not a string; and the same requests on a turn with no spec hooks. That last one shows whether a Hooks-page-only gate behaves exactly as before.
  • Why it doesn't block: the updated tests in test/test_tool_permission.py cover the first two (the "acp_session_id": None "wire has no client" case). I have no call path showing a real client whose session_id raises.

[SCOPE-REVIEWED] 3ada8c1

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/24935-subagent-hook-session-id branch from 9989cfd to 3865239 Compare November 7, 2026 02:48
@bolichen97

Copy link
Copy Markdown
Contributor Author

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]

@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/24935-subagent-hook-session-id branch from 3865239 to f699ae9 Compare November 7, 2026 05:38
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/hook_runtime/hook_dispatch.py, test/test_crew_fired_spec_hooks.py, test/test_hooks_composition_contract.py, docs/system-specs/modules/memory-skills-hooks.md, docs/system-specs/modules/subagent.md and src/kiro_crew/docs/steering-and-hooks.md since this head's CI ran (c5c4de1 -> 6f9aaf6); CI re-running.

The two test files conflicted with #31670, which added session_model to the hook functions. Both sides of the spec-hooks test file are kept. The hook owners' shape digest is re-pinned for both new keywords. The PR's own change is otherwise byte-identical. The related backend tests pass on the new base, and prove.py reports PROVEN.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 7, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/24935-subagent-hook-session-id branch from 54f0fca to 649cbcc Compare November 7, 2026 13:04
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_hooks_composition_contract.py and src/kiro_crew/ since this head's CI ran, and main now carries the line-budget fix #32252 (0795ebc -> 1ab5673); CI re-running.

The hook owners' shape-digest test conflicted again: main re-pinned _BASE_SHAPE_DIGEST for the safe_read_file_bytes_nolink / validate_file_path keyword. I kept main's comment and re-pinned the digest to the value with both changes (main's keyword plus this PR's trailing acp_session_id=None on permission_pre_tool_block). No other line of the diff changed. [operator: bolichen97]

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 7, 2026
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.
@bolichen97
bolichen97 force-pushed the fix/24935-subagent-hook-session-id branch from 649cbcc to 3ada8c1 Compare November 8, 2026 03:45
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 8, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased: the PR had a merge conflict with main in test/test_hooks_composition_contract.py (649cbcc -> 3ada8c1, onto main 217b335); CI re-running.

Main re-pinned _BASE_SHAPE_DIGEST again, so the digest is re-pinned to main's moved-name shapes plus this PR's one new keyword, acp_session_id=None on permission_pre_tool_block, with a comment saying so. No other code changed.

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

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 8, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bolichen97
bolichen97 merged commit f222dbc into main Nov 8, 2026
102 of 104 checks passed
@bolichen97
bolichen97 deleted the fix/24935-subagent-hook-session-id branch November 8, 2026 04:44
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
buluoray added a commit that referenced this pull request Nov 8, 2026
…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)
buluoray added a commit that referenced this pull request Nov 8, 2026
…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)
buluoray added a commit that referenced this pull request Nov 8, 2026
…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)
buluoray added a commit that referenced this pull request Nov 8, 2026
…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)
buluoray added a commit that referenced this pull request Nov 8, 2026
…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)
buluoray added a commit that referenced this pull request Nov 8, 2026
…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)
buluoray added a commit that referenced this pull request Nov 8, 2026
…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)
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.

KAS: pass the ACP session id to agent-spec hooks (stdin field or KIRO_SESSION_ID)

2 participants