Skip to content

fix(hooks): give KAS spec hooks the session id as stdin session_id, like kiro-cli - #28912

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/spec-hook-stdin-session-id
Nov 3, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/spec-hook-stdin-session-id

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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 kiro backend, kiro-cli runs a spec's hooks and puts the session id on stdin as session_id and in the env as KIRO_SESSION_ID. On kas, Kiro Crew runs those hooks itself. #24952 already gave them KIRO_SESSION_ID (backported to 0.11 in #28835), but on stdin it named the id acp_session_id. A hook written for kiro-cli reads session_id from 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_id breaks there.

Not a goal

What changed (motivation → approach → change)

Symptom: a kiro-cli-style hook reads stdin session_id and gets nothing on KAS. Cause: Crew's copy of the payload names the id acp_session_id. Change: ScriptHookStore.fire now also sets session_id on the spec hooks' stdin, with the same value. acp_session_id stays, so hooks written against #24952 keep working. With no id, both keys are left out and KIRO_SESSION_ID stays unset.

KIROCREW_SPAWNED: no change needed. Crew's sandbox spawn already sets it to the constant 1 on 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.md and the hooks spec docs/system-specs/modules/memory-skills-hooks.md name session_id, keep acp_session_id as the older key, and now say a subagent's Stop hooks get the id too (they already did, via subagent_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_ID in env, session_id and acp_session_id on stdin. An ambient KIRO_SESSION_ID in the gateway env does not win, an ambient secret env var is stripped, and KIROCREW_SPAWNED=1 is 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 id None and "": no stdin key, KIRO_SESSION_ID unset, and the ambient one is not leaked.
  • The two existing session-id tests now also check 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

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners November 3, 2026 06:28
@iamwhatever
iamwhatever requested a review from buluoray November 3, 2026 06:28
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/hook_runtime/script_hooks.py

  • @iamwhatever posted a complete reasoning template for e960c01.

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

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision e960c01e8d646c33dd01887050f7e2316c6980df 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 3, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of e960c01e8d646c33dd01887050f7e2316c6980df — 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

Nothing blocks. The fix is one stdin key at the single place the payload is built, and the new tests that assert session_id would fail on base.

What this change ships

Inventory (4 items) — 3 justified

Intent: a hook written for kiro-cli gets the session id from stdin session_id on a KAS chat session too. FIX.

  1. On KAS, agent-spec hooks now get session_id on stdin, with the same value as KIRO_SESSION_ID — justified
  2. The older stdin key acp_session_id stays, carrying the same value — justified
  3. The user doc and the hooks spec now say a subagent's Stop hooks also get the id. That was already true through stop_hooks.py — justified
  4. The tests now pin KIROCREW_SPAWNED=1 and the stripping of the ambient secret on every spec-hook event — rides along

[FIRST-PRINCIPLES-REVIEWED] e960c01

Description read

[DESCRIPTION-READ] 8c8c73b0bdc14302e4337ee346cca5890ab9bd2d70d40312782f074b77a17d7e

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.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

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 acp_session_id for older hooks.

[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 .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 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] e960c01

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

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

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e960c01

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

@iamwhatever
iamwhatever force-pushed the fix/spec-hook-stdin-session-id branch from fef0d2b to e960c01 Compare November 3, 2026 06:39
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: e960c01
  • What rule changed: none. ScriptHookStore.fire adds one stdin key, session_id, on an agent spec's own hooks (extra_hooks). Its value is the session id these hooks already get as stdin acp_session_id and env KIRO_SESSION_ID. The env allowlist (_HOOK_BASE_ENV_KEYS), the deny checks and the sandbox spawn are unchanged.
  • Before -> after (what was allowed/blocked, now): before, spec hook stdin had acp_session_id only. After, it has session_id too, with the same value, which is kiro-cli's own key. Nothing is newly allowed or blocked. Stored (Hooks-page) hooks get neither key, as before.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a spec hook sees its own session id under a second key. The id is not a secret: kiro-cli gives the same value to the same hooks and to the agent's shell. No env var is added, so no gateway secret can reach a hook.
  • Evidence checked (which sandbox result proves it): test/test_crew_fired_spec_hooks.py spawns a real hook through the sandbox spawn path for AgentSpawn, UserPromptSubmit, PreToolUse, PostToolUse and Stop. The hook sees the id in env and stdin. An ambient test secret env var is stripped. An ambient KIRO_SESSION_ID does not win. With id None or "", both stdin keys are absent and KIRO_SESSION_ID is unset. prove.py: PROVEN (the per-event tests fail with the fix reverted).
  • No regression:
    • Tools still work (which tools/commands were run, result): related backend tests (770 passed on the first head); test_crew_fired_spec_hooks.py and test_hooks_composition_contract.py (136 passed on this head).
    • Backward compatible (old config / old data / old callers still work, how checked): acp_session_id is still on stdin; the existing session-id tests still assert it. fire()'s signature is unchanged, and the composition contract's shape digest still passes.
    • Existing tests (which suites passed on this head): test/test_crew_fired_spec_hooks.py, test/test_hooks_composition_contract.py, flake-pattern ratchet, flake8, isort, black.
  • How to undo: revert this commit. Hooks lose the stdin session_id key and keep acp_session_id and KIRO_SESSION_ID.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does e960c01e8d646c33dd01887050f7e2316c6980df 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: Nothing in this diff makes a rule stricter. It adds one stdin key to the extra_hooks payload (extra_event["session_id"] = acp_session_id), keeps the existing acp_session_id key, and updates docs and tests to match. It does not touch sensitive-bash, exfil, deny-rules or any validator, so there is no tightening that could refuse a legitimate operation. Ten boundary rows were submitted anyway, so the classifier gets a base-vs-head reading of the hook-authoring commands near this change.

TIGHTENING: none -- the only behavioural hunk widens what a hook receives: + extra_event["session_id"] = acp_session_id in src/kiro_crew/hook_runtime/script_hooks.py. The env allowlist is unchanged (the new test asserts "secret": None), and nothing is newly refused.

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 KIRO_SESSION_ID env var and the session_id / acp_session_id stdin keys.

  • posix: $KIRO_SESSION_ID env reads, jq and python3 -c reads of the stdin key, the pytest run, and a grep.
  • windows: the same operations in Windows spelling: %KIRO_SESSION_ID% and %USERPROFILE% with \ separators, a PowerShell read of the stdin JSON, the pytest run with a \ path, and findstr.
  • No any rows: every row names an executable or a path.
  • No platform the diff assumes is left without a candidate.

UNADJUDICATED: The docs (memory-skills-hooks.md, steering-and-hooks.md) say a subagent's Stop event also carries session_id, via subagent_manager/stop_hooks.py. That file is not in this patch, so that claim is a payload-content question and not a refusal boundary. No shell classifier verdict can cover it, and it does not affect this lane's verdict.

[SCOPE-REVIEWED] e960c01

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 3, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 3, 2026 08:05

@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.

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.

@KiroCrewCaptain
KiroCrewCaptain merged commit 03944d5 into main Nov 3, 2026
121 of 125 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/spec-hook-stdin-session-id branch November 3, 2026 08:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 3, 2026
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.

2 participants