Skip to content

fix(agents): enforce PreToolUse deny on subagent/task-runner paths - #7843

Closed
aniruddhaadak80 wants to merge 2 commits into
kirodotdev:mainfrom
aniruddhaadak80:fix/subagent-hooks-deny
Closed

aniruddhaadak80 wants to merge 2 commits into
kirodotdev:mainfrom
aniruddhaadak80:fix/subagent-hooks-deny

Conversation

@aniruddhaadak80

@aniruddhaadak80 aniruddhaadak80 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

CI fixes for the gates this branch tripped:

  • Backend Lint & Type Check — the black ratchet gate requires baselined files that have become black-clean to be pruned, so this branch reformatted test/test_fire_tool_hooks.py and test/test_taskrunner_autoapprove.py and left their entries behind. Both entries are removed from .github/black-baseline.txt.
  • Lint (flake8) — F811 redefinition of unused sel in subagent_manager/run.py: the from kiro_crew.sel import sel line this branch added shadowed the sel that already arrives through the ..subagent import block. The redundant line is gone; sel still resolves from ..subagent, so behaviour is unchanged.
  • PR Hygiene — the two fixes above are squashed into this one commit so the PR stays inside the 1-2 commit budget.

Both fixes were verified locally against the pinned toolchain before pushing: black 26.3.1 --line-length 100 reports the two test files clean, and flake8 7.1.0 --select=F811 is clear on the edited module. The remaining red checks on this PR are not from this diff — Resolve desktop matrix and Publish readiness signal fail on API rate limit exceeded for installation, and the runner queue currently has ~1000 runs waiting.

@aniruddhaadak80
aniruddhaadak80 requested review from a team and patrigao September 2, 2026 10:21
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 2, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Audit note — part of this has already landed; the rest has not

Extends the PreToolUse script-hook deny gate from the dashboard chat path to the two autonomous execution paths. hooks.py gains ScriptHookResult.has_verdict/verdict (exit 0 = allow, 2 = deny), module helpers pretooluse_should_block / _hook_fail_open / _pretooluse_block_reason / _should_block_results, and a new per-hook ScriptHook.fail_open field (default False = fail closed) wired through from_dict, validate_hook_fields, ScriptHookStore.create and .update. dashboard/chat_runner.py's inner _fire() is refactored onto the shared predicate plus per-hook fail_open. subagent_manager/run.py and task_executor.py stop calling the informational fire_tool_hooks on EVENT_TOOL_CALL and instead run HookManager.on_tool_call governance (POLICY ∩ PROFILE) plus a fail-closed PreToolUse hook_store.fire gate before execution, and also add a PreToolUse hook gate on the EVENT_PERMISSION_REQUEST path, logging outcome=hook_blocked / hook_error to SEL instead of hardcoded auto_approved. 4 files, +444/-82, no tests and no docs touched.

Partly covered by 7422 (MERGED_PR, coverage PARTIAL)

#7422 (landed as ac700e0 on 2026-09-01) already put the fail-closed non-verdict rule on ONE of the three call sites — the dashboard chat gate in dashboard/chat_runner.py's inner _fire(). #7843's chat_runner hunk deletes exactly the block #7422 added (the 'Fail closed. A PreToolUse hook has a two-valued contract' comment and the elif r.exit_code not in (0, 2) branch) and re-expresses the same behaviour through hooks.pretooluse_should_block, so on the dashboard the only NEW behaviour is the per-hook fail_open opt-out. The unlanded remainder is the whole point of the PR: main's subagent_manager/run.py:1511 and task_executor.py:548 still call the informational fire_tool_hooks, whose own docstring on main says 'For EVENT_TOOL_CALL, hooks are informational only ... hook results cannot block execution', and main carries hook_blocked/hook_error rejection only in chat_runner.py (_reject_hook_blocked at :645, _reject_hook_error at :764) — nothing in subagent_manager/ or task_executor.py. This is the brief's 'main covers 3 of 5 call sites' shape, not SUPERSEDED.

  • src/kiro_crew/dashboard/chat_runner.py — PR hunk @@ -4717,48 +4722,32 @@ removes the fix(hooks): fail closed when a PreToolUse hook delivers no verdict #7422-authored fail-closed branch ('# Fail closed. A PreToolUse hook has a two-valued contract') and replaces it with if pretooluse_should_block(r, event=event, fail_open=_fail_open):. git log origin/main -S'could not deliver a verdict' -- src/kiro_crew/dashboard/chat_runner.py returns exactly ac700e0 '(fix(hooks): fail closed when a PreToolUse hook delivers no verdict #7422)'.
  • src/kiro_crew/hooks.py — main's fire_tool_hooks docstring (origin/main:src/kiro_crew/hooks.py:4390) states 'Note: For EVENT_TOOL_CALL, hooks are informational only. The tool is already running (auto-approved by kiro-cli), so hook results cannot block execution.' — the behaviour fix(agents): enforce PreToolUse deny on subagent/task-runner paths #7843 changes and which nothing on main has changed.
  • src/kiro_crew/subagent_manager/run.py — origin/main still has fire_tool_hooks, imported at :59 and await fire_tool_hooks( at :1511 with results discarded; git grep -n 'hook_blocked\|hook_error' origin/main -- src/kiro_crew matches only dashboard/chat_runner.py and dashboard/state.py, so the autonomous gate is genuinely unlanded.
  • src/kiro_crew/task_executor.py — origin/main:19 imports fire_tool_hooks and :548 awaits it under the EVENT_TOOL_CALL branch after logging outcome='auto_approved'; the PR replaces that with governance + hook gating.

Checked against main

No. None of this PR's distinctive tokens exist on main: git grep -c 'has_verdict\|pretooluse_should_block\|_hook_fail_open\|_should_block_results' origin/main -- src/kiro_crew returns nothing, and the only fail_open hit under src/kiro_crew on main is src/kiro_crew/mcp_shared.py (unrelated). What IS on main is the dashboard-only half of the contract from merged #7422 (ac700e0): chat_runner.py already blocks a non-0/2 PreToolUse exit, with tests test/test_dashboard_approval.py:554 test_auto_approve_blocked_when_pretooluse_hook_delivers_no_verdict. The autonomous paths are untouched on main (subagent_manager/run.py:1511 and task_executor.py:548 still fire hooks informationally).

Suggested action: CONTINUE_DEV — this is not finished work; the uncovered part is real.


From a repository-wide duplicate/overlap audit of every pull request open against main (2026-09-02, 330 PRs, one reviewer per PR). Each PR was read as its full merge-base diff plus its description and every comment and review, then compared against each candidate PR's own diff and against origin/main at 1a765b88ceb7. This PR is not being closed — the note is informational. If the reading is wrong, please correct the reasoning rather than just the conclusion.

@bolichen97

Copy link
Copy Markdown
Contributor

Open PR relationship audit

This is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion.

Relationship findings

  • This PR is PARTIALLY_COVERED with PR #7422. Coverage is explicitly incomplete; this finding is not a completion or closure claim. Recommended action for PR #7843: CONTINUE_DEVELOPMENT. PR #7422 landed the fail-closed rule on only the dashboard call site. The autonomous subagent and task-runner gates that are this PR's stated purpose are still absent from main, so the PR is not superseded and must not be closed as done; it needs the CI failures, the missing tests for the new gates and fail_open field, and the EVENT_TOOL_CALL enforcement gap resolved. Files: src/kiro_crew/dashboard/chat_runner.py, src/kiro_crew/subagent_manager/run.py, src/kiro_crew/task_executor.py, src/kiro_crew/hooks.py.

No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit.

@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 Sep 4, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 4, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 4, 2026
@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Rebased onto main in 810b98f (conflict was import drift in subagent_manager/run.py: kept both the upstream persistence imports and the runtime hooks import). CI re-running. Remaining from the audit: tests for the new autonomous gates + fail_open field, and the coverage gap - tracking as follow-up work.

@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 Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🔴 BLOCK

Premise-level review of cb47abab89fd213e7cda62ea079e5e85a4edb96c via the fork AI-review pipeline — 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/CONCERNS are advisory.

First-Principles-Verdict: BLOCK

The new permission-path gate re-implements permission_pre_tool_block, which base already documents for exactly these paths — and on gated turns each hook now fires twice.

Not justified as shipped

  • Item 1 — duplicate of src/kiro_crew/hooks.py:5740: permission_pre_tool_block is already "the PreToolUse hooks on a subagent or task-runner permission request", fail-closed, with the storeless case covered by strict persisted_hook_store.
    Subtraction: delete the new gate blocks, _should_block_results, fire_tool_hooks(raise_on_error=/return_results=); call the existing gate on ungated permission requests too (empty spec hooks).
    Clears when: the parallel gate is deleted and permission_pre_tool_block runs unconditionally on both paths.
  • Item 2 — duplicate of src/kiro_crew/hooks.py:5740: same second spelling on the task-runner path (task_executor.py:575 already calls the existing gate when _spec.gated).
    Clears when: same deletion as item 1.
  • Item 3 — duplicate of src/kiro_crew/hooks.py:5629: "hook store not initialized" rejects everything, where persisted_hook_store already reads saved hooks from disk, strictly, for exactly the storeless process.
    Subtraction: delete the missing-store reject branches; the existing gate's fallback covers them.
    Clears when: item 1's deletion lands.
  • Item 4 — rides along, duplicate of src/kiro_crew/hooks.py:5629: set_global_hook_store(ScriptHookStore()) in cli_server.py uses the fail-soft loader the strict persisted_hook_store was written to replace, and is unneeded once the existing gate runs.
    Subtraction: delete the cli_server.py line and its import.
    Clears when: item 1's deletion lands.
  • Item 5 — undeclared: two pins (test_invalid_json_passes_none, test_unparseable_tool_input_degrades_to_none) are rewritten to the opposite behaviour; neither the description (which mentions only black/flake8 fixes) nor the diff shows why the pinned None-degradation was wrong.
    Clears when: a linked issue or stated reason records why hooks must receive unparsed input verbatim.

What this change ships

Inventory (10 items) — 5 justified

Intent: make the operator's PreToolUse deny hooks actually reject tools on autonomous subagent/task-runner runs — a FIX (new tests fail on base), though the description text covers only CI fixups.

  1. Subagent permission requests now fail closed through script hooks — duplicate of src/kiro_crew/hooks.py:5740
  2. Task-runner permission requests likewise — duplicate of src/kiro_crew/hooks.py:5740
  3. Missing hook store now rejects every autonomous tool request — duplicate of src/kiro_crew/hooks.py:5629
  4. CLI run-task now loads and enforces Hooks-page hooks — rides along, duplicate of src/kiro_crew/hooks.py:5629
  5. Hooks receive non-JSON/scalar tool_input verbatim instead of None — undeclared (two pins rewritten, description silent)
  6. One hook execution per tool-call identity when both event forms arrive — justified
  7. Audit row now written before the reject wire response — justified
  8. Chat gate's non-verdict logic moved onto a shared predicate, behaviour-neutral — justified
  9. Two newly black-clean test files pruned from the baseline — justified
  10. Five system-spec docs updated in the same commit — justified

Blockers

Duplicate gate on the subagent/task-runner permission paths. Grepped permission_pre_tool_block: 2 production call sites, both on exactly the paths this PR gates (subagent_manager/run.py:2206, task_executor.py:575), each guarded only by if _spec.gated:. Its docstring already pins this PR's whole contract: "Run the PreToolUse hooks on a subagent or task-runner permission request… exit 2 is a delivered deny, and any other nonzero exit or a fire that raises is a gate with no verdict, which blocks. With no store registered… saved Hooks-page hooks are read from disk." The shipped second spelling is weaker (matches title only, versus the existing gate's pre_tool_match_names identity/MCP forms) and, on gated turns, runs after the existing gate so every Hooks-page hook executes twice per permission request — contradicting the diff's own doc line "prevents a second hook execution." Subtraction: delete the parallel gate (new blocks in both files, _should_block_results, the raise_on_error/return_results params, the missing-store rejects, the cli_server.py store line) and widen the existing call past _spec.gated.
Clears when: the parallel gate is deleted and permission_pre_tool_block runs on every subagent/task-runner permission request.

[FIRST-PRINCIPLES-REVIEWED] cb47aba

Description read

[DESCRIPTION-READ] 16bc172b74849d9289f4f6f9f969331962205dfdc76dd5540a69d6ba6eb76f8b

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 Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

Design-level review of cb47abab89fd213e7cda62ea079e5e85a4edb96c via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

New permission gate runs parallel to the existing permission_pre_tool_block gate instead of extending it, so gated-backend turns now execute every PreToolUse hook twice per call.

Watch

  • The new gate in subagent_manager/run.py and task_executor.py fires unconditionally on EVENT_PERMISSION_REQUEST, after the if _spec.gated: branch that already ran permission_pre_tool_block (which fires the same Hooks-page hooks, fail-closed). The identity cache is only written by the new gate's own fire_tool_hooks, never by permission_pre_tool_block, so on a gated backend (the KAS projection) each permission request runs every hook twice — side-effectful operator hooks (notifiers, counters) double, and per-call latency doubles. The spec text this PR adds ("the stable tool-call/request identity prevents a second hook execution", security.md) is therefore not true for exactly these turns.
    Clears when: both surfaces route the permission request through one gate (e.g. permission_pre_tool_block with empty spec hooks on non-gated turns, or the spec gate shares the fire cache), so a hook fires once per request.
  • Missing-store semantics now diverge for the same condition: permission_pre_tool_block falls back to persisted_hook_store() (saved hooks read from disk) when no store is registered, while the new gate hard-rejects with "hook store not initialized". Any subagent/task-runner-bearing process that misses the server/_run_task wiring rejects every tool instead of evaluating saved hooks.
    Clears when: the new gate adopts the persisted-store fallback (or a test pins that every production entry point that reaches it registers a store).
  • The description in pr-intent.txt describes only black-baseline pruning and an F811 fix; the enforcement change — the overwhelming majority of this diff — is stated nowhere but the title, with no problem/why. A reviewer reading the description approves a security-behavior change they were never shown.
    Clears when: the description states the actual problem (autonomous paths ignored script-hook denies) with the CI fixes as addenda.

[DESIGN-REVIEWED] cb47aba

Description read

[DESCRIPTION-READ] d69907643d8187d4f2ea974234359c6f32c8467193d731c68a094a291768ea56

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 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: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 15, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running 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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 17, 2026
@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

CI diagnosis on head 836de03 (run 35210278946 — no fix pushed, nothing in these failures comes from this PR): Backend Tests (3.12, 3) went 27949 passed / 1 failed; the single failure is test_pod_windows_run.py::test_public_up_prepares_home_only_after_start_reservation[False], which dies on Linux with WindowsTaskError (Task Scheduler backend is win32-only). That file carries no OS markers and was last touched upstream by #10841 — unrelated to this seam change (all hook-deny/subagent tests pass). It needs a windows_only marker (or equivalent per testing-conventions) from whoever owns that file. Coverage Gate fail is a pure cascade (backend-test=failure, failing closed) — not a coverage number. GPT 5.6 Review fail is an advisory verdict; please tell me if you want anything changed for it. PR Readiness blockers are the fork approval-gated workflows, same as before.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

CI diagnosis update on the single Backend Tests (3.12, 3) failure - this is an upstream test-isolation defect, not caused by this PR diff (which touches only chat_runner/hooks/subagent/task_executor/test_subagent). Chain: test_pod_windows_run.py::test_public_up_prepares_home_only_after_start_reservation[False] drives the public up verb; runtime.require_backend() reads runtime.IS_WINDOWS (mocked True in the model fixture); win_backend.require_backend() reads windows.IS_WINDOWS (never mocked) and raises WindowsTaskError at src/kiro_crew/pod/windows.py:178, translated to PodError at runtime.py:1031. IS_WINDOWS is defined in platform_compat and imported into both namespaces, so patching only rt.* is exactly the silent-no-op shape documented in testing-conventions (Patch the defining module, not a re-export). Repair belongs in a separate upstream PR (one-change-per-PR; unrelated to this diff): the model fixture needs monkeypatch.setattr(win, IS_WINDOWS, True), plus a stub for the later schtasks probe stages (schtasks_bin/_PROBE_OK) since Linux CI has no schtasks.exe. Happy to open that as a follow-up if useful. Coverage Gate / PR Readiness fails are cascade from this one red; GPT review is advisory.

@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 Sep 19, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…kirodotdev#9605)

`bind_component_globals` rebuilds every `*_impl` on the manager component
types with `FunctionType(code, vars(subagent))`. The function keeps its own
code but runs on `subagent.py`'s globals. So an import at the top of the
module that defines it does nothing for it. The name has to exist in
`subagent.py`.

Nothing checked that. A missing name raises `NameError` only when its line
runs. Several of these implementations load a global inside a `try:` whose
`except Exception` denies, so the miss looks like a gate that refuses
everything instead of an error. kirodotdev#7843 hit this twice in five days.

This adds a test that walks the bytecode of every rebound `*_impl`,
collects each global it loads (nested bodies included), and asserts the
name resolves in `subagent.py` or in builtins. Bytecode, not `co_names`:
`co_names` also holds attribute names, which would report dozens of names
that are not globals.

Current `main` is clean, so this is a regression test, not a code change.
The docstring on `bind_component_globals` now states the consequence a
reader has to know before adding an import to one of those modules.

Fixes kirodotdev#9534

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of 836de035b4 — needs changes (review-only, nothing pushed)

Read-only review against origin/main @ b83100d136, with tests and mutations run in a throwaway worktree at this head. The shape and file set are right; seven things block it as it stands.

1. The task-runner half is inert on the path it targets. set_global_hook_store is called only from dashboard/server.py and dashboard/handlers/hooks.py. cli_server.py builds TaskRunner with a HookManager but never constructs a ScriptHookStore, so get_global_hook_store() returns None there and the new if _store is not None: gate skips silently. The dashboard treats a missing store on PreToolUse as BLOCK ("BLOCKED:system:hook store not initialized"), so this is also a parity gap, not only a coverage one.

2. The gated events carry no tool input. AcpEvent.shell_command's docstring in acp/types.py states that on permission_request events the params are resolved into tool_input and raw_tool_params is NOT set. Both new gates pass tool_input=event.raw_tool_params. An argument-sensitive deny hook therefore fires with empty input on exactly the event class the PR gates, and allows what the operator wrote the rule to stop.

3. Audit-after-wire breaks an invariant the repo pins with its own test file. test/test_deny_audit_first.py pins "the SEL audit write must precede any wire I/O for that decision", enforced by a source scan bounded to chat_runner. The two new denial branches audit after client.reject_tool (task_executor) and after SubagentManager._reject_and_log (subagent), outside that scan's reach.

4. Duplicate audit rows on the subagent path. _reject_and_log already writes outcome="denied", error="hook_blocked"; the new branch then writes a second row with outcome="hook_blocked". One decision, two rows — and only the second carries subagent_id.

5. The new imports in run.py are dead. _run_inner_impl executes on kiro_crew.subagent's globals (its own comment says so), so the module-level from kiro_crew.hooks import … and from kiro_crew.sel import sel in run.py are inert; commit 2's _COMPONENT_GLOBAL_BINDINGS entries are the live mechanism. Verified by deleting both lines — the new test still passes.

6. Tests cover one arm of three, and not the risk arm. Measured mutations at this head: _should_block_results returning (False, "") fails TestSubagentPreToolUseHookGate (good). _should_block_results returning (True, "…") — deny every tool on every gating event — leaves 1104 tests green. So there is no allow control, no timeout case, no task-runner test, and the new exit-0-with-stderr warning in chat_runner is unpinned. The unpinned arm is the one that breaks operators: a hook that exits nonzero by accident.

7. Stale — the PR's own regression pin no longer passes on main. mergeable: CONFLICTING. A local rebase onto b83100d136 produces one 2-line conflict in run.py's TYPE_CHECKING import list, trivially resolved; after that TestSubagentPreToolUseHookGate fails with ValueError: memory_unavailable: no captured execution context (run.py:948) because main added a precondition the test's SubagentInfo double does not satisfy. The production hunks themselves rebase clean.

Checked and fine

Baseline at this head: test_subagent.py, test_fire_tool_hooks.py, test_hooks.py → 322 passed. The only red CI test is test_pod_windows_run.py::test_public_up_prepares_home_only_after_start_reservation[False], unrelated to hooks; Coverage Gate is red only because backend-test was red. Leaving the auto-approved EVENT_TOOL_CALL branch informational is correct and matches the dashboard — the tool is already running there — so the comment-only change on that branch is the right call.

Two corrections to the ticket's premise (Mesh-3030)

The main-session path already enforces deny: chat_runner._fire blocks on exit 2 and fail-closed on any non-verdict, and _reject_hook_blocked / _reject_hook_error reject and audit. That landed in #7422. A grep for the class name ScriptHookResult misses that consumer because it reads r.blocked / r.exit_code duck-typed.

So the remaining gap is narrower than "subagent hooks never deny": it is the missing script-hook consultation on the permission-request branch of subagent_manager/run.py and task_executor.py. That part is genuinely absent from main and this PR is not superseded.

What would clear this

A rebase, three tests (exit 0 allows, timeout denies, task-runner gate denies), tool_input derived the way the dashboard derives it, the audit moved before the wire write on both new branches, the duplicate SEL row dropped, and a decision on store-absent behaviour — block like the dashboard, or a comment establishing it is unreachable.

@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Addressed the review in cfcc61b4f and rebased onto current main (c54439c45).

  • Done in cfcc61b4f: initialize the task-runner ScriptHookStore.
  • Done in cfcc61b4f: pass structured and scalar tool_input without erasing non-JSON values.
  • Done in cfcc61b4f: fail closed on missing/error hooks, coalesce tool-call and permission events by stable identity, and audit before rejecting.
  • Done in cfcc61b4f: add missing-store, hook-error, combined-event, scalar-input, and ordering regressions; align the owning specs.

Validation: 612 passed, 14 skipped; Black, isort, flake8, and git diff --check pass.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 24, 2026
@aniruddhaadak80

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (9b098d79) and resolved the chat_runner.py conflict by preserving the new main behavior plus the PR fail-closed gate in b07276fc9.

Validation: 1,762 passed, 14 skipped; touched-file Black, isort, flake8, py_compile, subprocess encoding, comment-history, and diff checks pass. Mypy reports only three pre-existing project_scan.py:306-312 errors.

Rebased onto upstream main 972675c as a single commit.

Two files drifted against main and are resolved by intent rather than by
discarding either side:

- subagent_manager/run.py — main added the sel and 	eardown_capture
  imports into the existing import block; both are kept alongside this
  branch's hook-gating changes.
- docs/system-specs/modules/security.md — main added the paragraph on the
  two ACP transports repeating the identity-free security floor in
  �pprove_tool; this branch added the paragraph on task-runner and
  subagent permission requests passing through the global ScriptHookStore
  PreToolUse gate. Both paragraphs are kept; the spec now documents the two
  layers together rather than one replacing the other.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Rebased onto upstream main 972675c as a single commit.

Two files drifted against main and are resolved by intent rather than by
discarding either side:

- subagent_manager/run.py — main added the sel and 	eardown_capture
  imports into the existing import block; both are kept alongside this
  branch's hook-gating changes.
- docs/system-specs/modules/security.md — main added the paragraph on the
  two ACP transports repeating the identity-free security floor in
  ^Gpprove_tool; this branch added the paragraph on task-runner and
  subagent permission requests passing through the global ScriptHookStore
  PreToolUse gate. Both paragraphs are kept; the spec now documents the two
  layers together rather than one replacing the other.

Squashes two CI-gate fixes so this PR stays within the 1-2 commit budget:
the black ratchet baseline prunes two entries this branch made black-clean, and the
duplicate sel import in subagent_manager/run.py is removed (flake8 F811).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor

Open-PR triage (2026-10-05): PARTIALLY_COVERED. Needs a REBASE and has one fail-open blocker

I checked head cb47abab against origin/main af1eb612, using the full merge-base diff (base d8fa6a52). The branch is 597 commits behind main. git merge-tree reports conflicts in hooks.py, subagent.py, subagent_manager/run.py, task_executor.py and test/test_auto_approve.py. Main has also moved fire_tool_hooks, persisted_hook_store and permission_pre_tool_block into hook_runtime/hook_dispatch.py (#16865).

What main already covers

The PR is therefore not superseded, and I'm not closing it.

Blocker: fails open, a regression against main (raised by the Opus bot and still present at this head)

  • cli_server.py:2708 calls set_global_hook_store(ScriptHookStore()). That store loads fail-soft: on JSONDecodeError or OSError it ends up with zero hooks.
  • Main's persisted_hook_store() returns the registered store whenever one exists. So with this change in place, an unreadable hooks.json under kirocrew run looks like "no PreToolUse hooks" instead of raising.
  • The effect: permission_pre_tool_block allows the call, and kas_agents.pre_tool_hook_matchers returns (). Saved deny hooks stop gating, where main fails closed today.
  • Fix: register persisted_hook_store() instead, or drop the line.

Other issues still open at this head

  • On a gated turn the new permission gate (task_executor.py:~626-711, run.py:~2280-2330) fires again after permission_pre_tool_block, so every hook runs twice. It also matches only event.title, not pre_tool_match_names. Both were raised by the GPT and Design bots. Skip the gate when _spec.gated, or reuse the gated result.
  • Behaviour change for autonomous paths: a PreToolUse hook that exits with anything other than 0 or 2, or that raises, now rejects the tool call. On main such a hook is informational there. This tightening is intended, but the PR body should say so and the affected specs should say so.
  • Review items from @iamwhatever, refactor: rename project KiroClaw to KiroCrew #2 through feat: webapp artifact kind + Artifact Deploy console (folded into Artifacts) #6, need a reply that says which ones the reshaped head resolves.

Overlap: no other open PR implements this gate. #12643 (open PR) edits the same EVENT_PERMISSION_REQUEST branches for push-verdict activation. That's a different goal, so whichever PR lands second resolves the merge mechanically.

Recommendation: rebase onto the hook_runtime split, fix the cli_server fail-open, and gate only the non-gated turns. Then continue development to close #7547.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P0] kirocrew run registers a fail-soft hook store, turning the strict saved-hooks gate fail-open

Class: Security guard turned fail-open (saved PreToolUse hooks).

Mechanism: _run_task now registers a plain ScriptHookStore(), whose load is fail-soft. Because a store is registered, permission_pre_tool_block no longer falls back to the strict persisted_hook_store() read, so an unreadable or malformed hooks.json loads no deny hooks and the call is allowed. On main the same case blocks.

User impact: Under kirocrew run, an operator's deny hooks silently stop applying when hooks.json cannot be read.

Location: src/kiro_crew/cli_server.py:2708 @ cb47abab89fd213e7cda62ea079e5e85a4edb96c

Minimum fix: Drop set_global_hook_store(ScriptHookStore()) from _run_task so the runner keeps the strict read, or register the store built by persisted_hook_store() and fail the run closed if it raises.

How to verify: With a temp KIROCREW_HOME holding a malformed hooks.json, run _run_task's store setup, then assert permission_pre_tool_block(get_global_hook_store(), ...) returns a block reason. It returns None on this head.

Exploit details are left out on purpose. They are available to maintainers through the repo's private security reporting.

Independently re-verified on head cb47abab89 with a focused local reproduction.


# Opt-out state is sourced from the keystone denied_commands.json, not
# config.json's hooks section (the agent cannot write the keystone file).
set_global_hook_store(ScriptHookStore())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P0] kirocrew run registers a fail-soft hook store, turning the strict saved-hooks gate fail-open — see the review summary for mechanism, fix and test.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks for this fix, @aniruddhaadak80! Main now enforces the agent spec's PreToolUse hooks on both the subagent path (src/kiro_crew/subagent_manager/run.py) and the task-runner path (src/kiro_crew/task_executor.py), consolidated in #17220 (commit 8e06ee3). So we're closing this as superseded. If you see a path that still skips the deny, please reopen or file an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants