Repository navigation
fix(hooks): give KAS spec hooks the session id as stdin session_id, like kiro-cli - #28912
Conversation
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix is one stdin key at the single place the payload is built, and the new tests that assert What this change shipsInventory (4 items) — 3 justifiedIntent: a hook written for kiro-cli gets the session id from stdin
[FIRST-PRINCIPLES-REVIEWED] e960c01 Description read[DESCRIPTION-READ] 8c8c73b0bdc14302e4337ee346cca5890ab9bd2d70d40312782f074b77a17d7e That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change adds one stdin key, on the spec-hook payload only, matching kiro-cli's name. It overwrites no existing key and keeps [DESIGN-REVIEWED] e960c01 Description read[DESCRIPTION-READ] 7d0ef27cf9d544ccea702961fb25fc43641bd1cde7414b29d2ee0fba14d4f426 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: |
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: |
fef0d2b to
e960c01
Compare
Sensitive change review
|
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: Nothing in this diff makes a rule stricter. It adds one stdin key to the extra_hooks payload ( TIGHTENING: none -- the only behavioural hunk widens what a hook receives: ADJUDICATED: 10 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: The diff makes no new assumption about a path, separator, interpreter or executable. The only names it involves are the existing
UNADJUDICATED: The docs ( [SCOPE-REVIEWED] e960c01 |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (4 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: spec hooks also get the ACP session id under kiro-cli's stdin key session_id; acp_session_id is kept, with tests on every hook event. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/memory-skills-hooks.md.
Problem / Motivation
Goal: On a KAS chat session, an agent spec's own hooks read the session id under the same stdin key kiro-cli uses,
session_id.On the
kirobackend, kiro-cli runs a spec's hooks and puts the session id on stdin assession_idand in the env asKIRO_SESSION_ID. Onkas, Kiro Crew runs those hooks itself. #24952 already gave themKIRO_SESSION_ID(backported to 0.11 in #28835), but on stdin it named the idacp_session_id. A hook written for kiro-cli readssession_idfrom stdin, finds nothing, and logs the event with no session.Why it matters
A user reports that on KAS almost every spec hook event reaches their telemetry with no session id, while the same agent on kiro-cli logs one on every hook. KAS is the default backend, so any hook that joins on stdin
session_idbreaks there.Not a goal
_HOOK_BASE_ENV_KEYS).What changed (motivation → approach → change)
Symptom: a kiro-cli-style hook reads stdin
session_idand gets nothing on KAS. Cause: Crew's copy of the payload names the idacp_session_id. Change:ScriptHookStore.firenow also setssession_idon the spec hooks' stdin, with the same value.acp_session_idstays, so hooks written against #24952 keep working. With no id, both keys are left out andKIRO_SESSION_IDstays unset.KIROCREW_SPAWNED: no change needed. Crew's sandbox spawn already sets it to the constant1on every hook it runs (sandbox_spawn.py), as kiro-cli's hooks inherit it. Adding it to the allowlist would only forward the gateway's own copy, which a normal gateway does not have. The new test pins that the hook sees it.The session id is not a secret: kiro-cli hands the same value to the same hooks and to the agent's shell.
Docs:
src/kiro_crew/docs/steering-and-hooks.mdand the hooks specdocs/system-specs/modules/memory-skills-hooks.mdnamesession_id, keepacp_session_idas the older key, and now say a subagent's Stop hooks get the id too (they already did, viasubagent_manager/stop_hooks.py).Backwards compatibility
Compatible: the spec hooks' stdin gains one key; every existing key, env var and keyword stays.
Removes nothing: the change only adds a stdin key on one hook kind.
Tests
test/test_crew_fired_spec_hooks.py, spawning a real hook that dumps its env and stdin:test_every_spec_hook_event_gets_the_session_id_as_kiro_cli_names_it, for AgentSpawn, UserPromptSubmit, PreToolUse, PostToolUse and Stop:KIRO_SESSION_IDin env,session_idandacp_session_idon stdin. An ambientKIRO_SESSION_IDin the gateway env does not win, an ambient secret env var is stripped, andKIROCREW_SPAWNED=1is present even with none in the gateway env.test_no_session_id_means_no_key_and_no_env_on_every_event, the same five events with idNoneand"": no stdin key,KIRO_SESSION_IDunset, and the ambient one is not leaked.session_id, and that a stored hook gets neither key.Determinism: the session tests ran 3 times serially and once under
-n4, all green. Related backend tests: 770 passed.Proof: PROVEN test/test_crew_fired_spec_hooks.py::test_every_spec_hook_event_gets_the_session_id_as_kiro_cli_names_it[AgentSpawn], test/test_crew_fired_spec_hooks.py::test_every_spec_hook_event_gets_the_session_id_as_kiro_cli_names_it[UserPromptSubmit], test/test_crew_fired_spec_hooks.py::test_every_spec_hook_event_gets_the_session_id_as_kiro_cli_names_it[PreToolUse], test/test_crew_fired_spec_hooks.py::test_every_spec_hook_event_gets_the_session_id_as_kiro_cli_names_it[PostToolUse], test/test_crew_fired_spec_hooks.py::test_every_spec_hook_event_gets_the_session_id_as_kiro_cli_names_it[Stop] (head e960c01)
Manual verification
N/A — the tests spawn a real hook subprocess and read its env and stdin, which is the whole path this changes.
Related Issues
Part of #24935
Sibling sweep
Swept: git grep -n "acp_session_id" -- src/
Sibling: src/kiro_crew/hook_runtime/script_hooks.py -- changed here
Sibling: src/kiro_crew/dashboard/chat_turn/turn_spec_hooks.py -- not affected -- it passes the id to fire(), which builds the payload
Sibling: src/kiro_crew/subagent_manager/stop_hooks.py -- not affected -- a subagent's Stop already passes the id to fire(), so it gains session_id from this change too
Sibling: src/kiro_crew/agent_sdk/spec_hooks.py -- tracked in #24935
Pattern harvest
Not generalizable: a one-off key name in a payload that mirrors kiro-cli's; the per-event test now pins kiro-cli's names.
Checklist