fix(583): gate every model-less dispatch, not just implementer-looking ones
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 14s
PR Gates / Docs update reminder (pull_request) Successful in 16s
PR Gates / decisions lifecycle (pull_request) Successful in 17s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m37s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 55s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 6m23s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 16m22s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 14s
PR Gates / Docs update reminder (pull_request) Successful in 16s
PR Gates / decisions lifecycle (pull_request) Successful in 17s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m37s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 55s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 6m23s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 16m22s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Independent review of d221a065 found the prompt-text heuristic both over- and
under-fired. Confirmed repros: a read-only recon brief merely mentioning
"worktree" nagged, while "author the change and open a PR", "land this on the
branch" and "make the changes and commit them" all passed silently — the gate
missed exactly the case it existed to catch.
Root cause behind all three findings: the hook contradicted its own rule. The
HARD CONSTRAINT says "every dispatched agent"; the hook gated only dispatches
whose prose looked like an implementer. Prompt text is not a reliable signal for
authority.
Inverted: ask whenever `model` is absent, exempting only `fork` (the tool ignores
a fork's model override, so a prompt could not be acted on). This dissolves all
three findings rather than patching the regex — no phrasing dependence, no
false-positive concept, and no "cannot commit" claim to be wrong about. The
reviewer was right that Explore/Plan/claude-code-guide all carry Bash, so the old
exemption rationale was false.
The noise objection is answered by the escape hatch, not by scoping: naming a
tier costs one parameter and the hook never fires. Self-eliminating for anyone
following the rule.
Decision record updated to record the rejected narrow design and why.
Re-verified: 11 payloads incl. all three findings, the invariants (model named ->
never fires; fork exempt; non-Agent passes), and robustness (malformed JSON,
empty payload, missing tool_input, embedded backticks/quotes/newlines) — never
crashes, never emits malformed JSON. decisions-validate: OK.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# PreToolUse / Agent — ask when a COMMITTING agent is dispatched without an explicit `model`.
|
||||
# PreToolUse / Agent — ask when an agent is dispatched without an explicit `model`.
|
||||
#
|
||||
# The kickoff prompt (docs/handoffs/chicorytv-issue-queue.md) says to route by capability: cheap/fast
|
||||
# for bounded recon, mid tier for a mechanical slice against a documented contract, orchestrator tier
|
||||
@@ -12,12 +12,26 @@
|
||||
# no forcing function was the one that got defaulted. A check that runs beats a rule you must remember
|
||||
# (the same reasoning as pretooluse-bom-guard.sh).
|
||||
#
|
||||
# Deliberately NARROW, because a hook that fires on every fan-out trains one-shot dismissal:
|
||||
# - read-only / recon agent types -> pass through (cheap by nature, routing barely matters)
|
||||
# - subagent_type "fork" -> pass through (a fork ALWAYS inherits the parent model; the
|
||||
# `model` field is ignored by the tool, so asking is nonsense)
|
||||
# - an explicit `model` -> pass through (the choice was made — that is the whole point)
|
||||
# - a committing/implementer agent with NO model -> ask (surface the choice to a human)
|
||||
# SCOPE — gate EVERY dispatch that names no model, not just implementer-looking ones. The first cut
|
||||
# tried to be clever: it fired only when the prompt text matched implementer signals (`git commit`,
|
||||
# `worktree`, `fixes #`…). Review of that version (#583) confirmed the heuristic both over- and
|
||||
# under-fired — a read-only recon brief mentioning "worktree" nagged, while "author the change and
|
||||
# open a PR", "land this on the branch" and "make the changes and commit them" all sailed through
|
||||
# silently, i.e. it missed the exact case it existed to catch. Prompt prose is not a reliable signal
|
||||
# for authority, and a gate with an unreliable catch rate is worse than an honest one.
|
||||
#
|
||||
# Two further reasons the broad form is correct here:
|
||||
# - The HARD CONSTRAINT itself says "every dispatched agent". A narrower hook contradicted the rule
|
||||
# it was built to enforce.
|
||||
# - Routing matters MOST for the cheap cases. The old exemption list ("read-only, so routing barely
|
||||
# matters") had it backwards: bounded recon is precisely what should be explicitly routed DOWN to
|
||||
# a fast tier, and that review also showed the premise was false — Explore, Plan and
|
||||
# claude-code-guide all carry Bash, so none of them provably "cannot commit".
|
||||
#
|
||||
# The prompt costs nothing to avoid: name a tier and this never fires. That is the habit being built.
|
||||
#
|
||||
# Exempt: `fork` only — a fork ALWAYS inherits the parent model and the tool IGNORES a `model`
|
||||
# override, so asking would demand something unachievable.
|
||||
#
|
||||
# "ask", never "deny": routing is a judgment call with no derivable right answer, unlike the
|
||||
# merge-consent gate (H6/H10) which derives a verifiable state. This gate exists to make an invisible
|
||||
@@ -31,42 +45,32 @@ input=$(cat)
|
||||
tool=$(printf '%s' "$input" | jq -r '.tool_name // ""' 2>/dev/null || true)
|
||||
[ "$tool" = "Agent" ] || exit 0
|
||||
|
||||
# An explicit choice was made — nothing to surface.
|
||||
# An explicit choice was made — nothing to surface. This is the path to prefer.
|
||||
model=$(printf '%s' "$input" | jq -r '.tool_input.model // ""' 2>/dev/null || true)
|
||||
[ -z "$model" ] || exit 0
|
||||
|
||||
subagent=$(printf '%s' "$input" | jq -r '.tool_input.subagent_type // ""' 2>/dev/null || true)
|
||||
|
||||
# Types that cannot commit, plus fork (whose model override is ignored by the tool).
|
||||
case "$subagent" in
|
||||
fork|Explore|Plan|claude-code-guide|statusline-setup) exit 0 ;;
|
||||
feature-dev:code-explorer|feature-dev:code-reviewer|feature-dev:code-architect) exit 0 ;;
|
||||
esac
|
||||
|
||||
# Does this brief actually put an agent on the keyboard? Recon dispatched to general-purpose is
|
||||
# cheap and frequent; an implementer is the case worth one prompt.
|
||||
prompt=$(printf '%s' "$input" | jq -r '.tool_input.prompt // ""' 2>/dev/null || true)
|
||||
[ -n "$prompt" ] || exit 0
|
||||
printf '%s' "$prompt" \
|
||||
| grep -qiE 'git commit|git push|committing agent|worktree|fixes #|implement( the| this|ing)?\b' \
|
||||
|| exit 0
|
||||
# A fork's model is fixed to the parent's by the tool; a prompt here could not be acted on.
|
||||
[ "$subagent" = "fork" ] && exit 0
|
||||
|
||||
label="${subagent:-general-purpose}"
|
||||
reason="Dispatching a committing agent (subagent_type: ${label}) with no explicit \`model\`.
|
||||
reason="Dispatching an agent (subagent_type: ${label}) with no explicit \`model\`.
|
||||
|
||||
It will silently inherit this session's model — which may be right, but it is a default, not a choice.
|
||||
Name the tier (and say so in the dispatch message), per the kickoff routing rule
|
||||
\`process.per-agent-model-routing\`:
|
||||
|
||||
- bounded recon / inventory / log triage -> cheapest fast tier (haiku), effort low
|
||||
- bounded recon / inventory / log triage -> cheapest fast tier (haiku)
|
||||
- mechanical slice against a documented contract -> mid tier (sonnet)
|
||||
- judgment-heavy: design, compiler/parser, security,
|
||||
migrations, review arbitration -> orchestrator tier (opus)
|
||||
migrations, review arbitration -> orchestrator tier (opus)
|
||||
|
||||
Independent review should also prefer a DIFFERENT model family than the implementer — a cold
|
||||
same-family review is worth less than a cross-family one.
|
||||
|
||||
Approve as-is only if inheriting the orchestrator tier is the deliberate call."
|
||||
Pass \`model\` on the Agent call and this never fires. Approve as-is only if inheriting the
|
||||
orchestrator tier is the deliberate call."
|
||||
|
||||
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"ask",permissionDecisionReason:$r}}'
|
||||
exit 0
|
||||
|
||||
@@ -558,18 +558,30 @@ Three aggravating factors, all worth checking when writing any future rule here:
|
||||
|
||||
Hence the two-part fix: a keyed HARD CONSTRAINT that requires the tier to be **stated out loud in the
|
||||
dispatch** (a self-correcting mechanism — it turns an invisible omission into visible output), plus
|
||||
`.claude/hooks/pretooluse-agent-model.sh`, which `ask`s when a **committing** agent is dispatched with
|
||||
no explicit `model`.
|
||||
`.claude/hooks/pretooluse-agent-model.sh`, which `ask`s whenever an agent is dispatched with no
|
||||
explicit `model`. It exempts only `fork`, whose `model` override the tool ignores by design, so a
|
||||
prompt there could not be acted on. It is `ask`, never `deny`: routing is a judgment call with no
|
||||
derivable right answer, unlike the H6/H10 merge gate (`release.merge-consent-autogrant`), which
|
||||
derives a verifiable state and can therefore grant or refuse outright.
|
||||
|
||||
The hook is deliberately **narrow**, and the scoping is the load-bearing design choice: it passes
|
||||
through read-only/recon agent types, `fork` (whose `model` override is ignored by the tool by design,
|
||||
so prompting would be nonsense), and any dispatch that already names a tier. A gate that fires on
|
||||
every fan-out trains one-shot dismissal and becomes noise — which would leave it worse than no gate.
|
||||
It is `ask`, never `deny`: routing is a judgment call with no derivable right answer, unlike the
|
||||
H6/H10 merge gate (`release.merge-consent-autogrant`) which derives a verifiable state and can
|
||||
therefore grant or refuse outright.
|
||||
**The first cut was narrower, and review killed it** — worth recording, because the reasoning was
|
||||
seductive. It fired only when the prompt *text* matched implementer signals (`git commit`, `worktree`,
|
||||
`fixes #`), on the theory that a gate firing on every fan-out trains one-shot dismissal. Independent
|
||||
review confirmed the heuristic both over- and under-fired: a read-only recon brief merely *mentioning*
|
||||
"worktree" nagged, while "author the change and open a PR", "land this on the branch" and "make the
|
||||
changes and commit them" all passed silently — it missed precisely the case it existed to catch.
|
||||
**Prompt prose is not a reliable signal for authority**, and a gate with an unreliable catch rate is
|
||||
worse than none, because it gets trusted.
|
||||
|
||||
**Known limitation:** review agents (`feature-dev:code-reviewer`) pass through, since they cannot
|
||||
commit — so the "prefer a different model family for independent review" half of the rule remains
|
||||
doc-only, unenforced. That half is the higher-value routing decision of the two; if cross-family
|
||||
review drift shows up again, gate it next.
|
||||
Two further reasons the broad form is right, both of which the narrow version had backwards:
|
||||
|
||||
- **It now matches the rule it enforces.** The HARD CONSTRAINT says "every dispatched agent"; a hook
|
||||
gating only implementer-looking dispatches contradicted its own rule.
|
||||
- **Routing matters MOST for the cheap cases.** The old exemption list justified itself as
|
||||
"read-only, so routing barely matters" — but bounded recon is exactly what should be explicitly
|
||||
routed *down* to a fast tier. The premise was also false: `Explore`, `Plan` and `claude-code-guide`
|
||||
all carry Bash, so none of them provably "cannot commit".
|
||||
|
||||
The noise objection is answered by the escape hatch rather than by scoping: **naming a tier costs one
|
||||
parameter and the hook never fires again**. The prompt is self-eliminating for anyone following the
|
||||
rule, which is the habit being built.
|
||||
|
||||
Reference in New Issue
Block a user