Skip to content

fix(eval-subagent): steer the in-band host-deny notice before every reject - #16357

Merged
iamwhatever merged 1 commit into
mainfrom
rebase/15463-deny-notice-eval-subagent
Oct 3, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
rebase/15463-deny-notice-eval-subagent

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Supersedes #15463 by @CrysisDeu (branch fix/deny-notice-eval-subagent-5403). That PR had readiness: passed but conflicted with main; this is the identical change rebased onto current main (conflicts in injected-messages.md, subagent.py, run.py resolved; CrysisDeu kept as commit author so Rebase-and-merge lands their commit). Full credit to @CrysisDeu.

Problem / Motivation

Goal: On the eval harness and the subagent surface, a tool call the HOST refuses must reach the model as a host-deny notice, never as "user denied".

A rejected session/request_permission reaches the model as kiro-cli's fixed "User denied tool execution" -- the ACP permission response carries only outcome/optionId, so the host has no channel to say more. The dashboard chat runner (#5332/#5401), llm_helpers (#14141), the messaging surfaces (#15083) and the task runner (#15372, pending) steer the real reason into the running turn BEFORE the reject. Three surfaces still did not:

  • eval/runner.py -- 3 reject_tool( sites (permission gate refusal, the harness's own filesystem path check, a tool it does not know to be read-only): audit, then a bare reject.
  • eval/judge.py -- 1 site (the judge refuses every tool): bare reject.
  • subagent.py -- the _reject_and_log funnel called from 9 sites in subagent_manager/run.py: reject FIRST, then the metric and the SEL row, never a notice.

Measured on origin/main @ aec81410e: grep -c "_steer_host_deny\|steer_refusal_notice" is 0 in all four files; grep -c "reject_tool(" is 3 / 1 / 1 / 0 (run.py denies only through the funnel).

Why it matters

An eval scenario or a subagent that hits a policy block reads "the user denied this", apologises for a cancellation nobody made, and abandons or routes around a call that was never judged -- the model's recovery is aimed at the wrong actor. On the unattended subagent surface there is no person to notice the misattribution and correct it, so the whole fan-out inherits it.

Not a goal

  • The remaining surfaces of In-band deny notice: host denies on surfaces other than the chat runner still say "user denied" #5403 (dashboard/handlers/optimizer.py, dashboard/handlers/taskrunner.py, apps/builtins/auto_improvement/spine/agent_runner.py) -- later slices.
  • Distinguishing an approver's timeout from an approver's "no" on the subagent surface: the factory / gateway callbacks return a bare False for both, and the cause of that False is not plumbed here. Both stay cause=None (kiro-cli's wording is the truth for the "no"; the timeout arm is a separate change on the callback contract).
  • A new notice text or a new cause: every site uses the existing DENY_CAUSE_POLICY / DENY_CAUSE_SURFACE_POLICY wording from deny_notice.py.
  • Steering on a run bail (turn_limit, child_escalation_limit): the run ends at that reject, so there is no continuing turn for a notice to correct.

What changed (motivation → approach → change)

Motivation: the sites above hand the model kiro-cli's generic string with nothing to correct it.

Approach: the one established by the merged slices -- call llm_helpers._steer_host_deny(provider, event, reason, cause=...) immediately BEFORE each host-deny reject_tool, after the SEL row. While the permission request is unanswered the turn is provably in flight, which is what gets the notice queued rather than dropped. Every site gets a per-site verdict; nothing is spot-fixed.

Change, per site:

eval/runner.py (inline, audit → steer → reject)

  • permission gate refusal (refusal_for returned a reason) -- DENY_CAUSE_POLICY, with the gate's own reason (redacted by the helper).
  • filesystem tool on a sensitive path / no readable path -- DENY_CAUSE_POLICY; the sensitive-path reason uses the fixed "sensitive credential path" wording so deny_guidance lands it in the same secret-file class as the hook gate's refusal.
  • tool not on the read-only allowlist -- DENY_CAUSE_SURFACE_POLICY; the reason says the harness runs tools read-only. No remediation, because nothing about the call was judged.

eval/judge.py (inline)

  • every tool call -- DENY_CAUSE_SURFACE_POLICY ("the eval judge runs no tools"). Steered inside the existing if event.request_id: guard: with no id nothing is answered on the wire, so there is no in-flight refusal to correct.

subagent.py -- SubagentManager._reject_and_log gains a REQUIRED keyword-only cause: str | None and reason: str = "". Order becomes metric + SEL row → steer (when cause is not None) → reject_tool, matching every other deny surface (the row was written AFTER the wire call before; a backend that stops reading stdin could cancel the coroutine with the decision acted on and unaudited). Two reason constants live here because run.py's _impl functions resolve globals through bind_component_globals.

subagent_manager/run.py -- the nine call sites, each with its verdict:

site verdict cause
spec PreToolUse gate blocked (spec_hook) host POLICY, reason = the gate's block text
stored hooks TOOL_DENY (hook_deny) host POLICY, reason = tool_result.reason
headless deny-by-default (no_policy_deny_default) host SURFACE_POLICY, _HEADLESS_DENY_REASON (names every tier that could still authorize: parent_policy=auto, hooks.auto_approve_tools, the read-only classification)
low-fidelity child request, no approver (child_origin_no_command_context) host SURFACE_POLICY, _LOW_FIDELITY_DENY_REASON
child approver said no (child_interactive_rejected) user None
per-subagent factory said no (factory_rejected) user None
gateway fallback said no user None
turn_limit bail teardown None
child_escalation_limit bail teardown None

docs/system-specs/common/injected-messages.md -- a paragraph recording the three surfaces and their per-site verdicts next to the messaging one.

Backwards compatibility

  • SubagentManager._reject_and_log is a private static method; its new cause= keyword is required, so an in-tree caller that forgets it fails at call time rather than inheriting a wrong verdict. The two existing test call sites (test_subagent_coverage.py, test_hang_resilience_metrics.py) are updated with cause=None.
  • Behaviour on a backend without supports_refusal_steer is unchanged: the helper probes the capability and returns without sending; the reject always runs. A steer failure is swallowed at debug; the reject always runs.
  • SEL rows keep their exact shape (outcome, error, metadata, request_id); the child-denial metric keeps its closed-enum reason. Only their ORDER relative to the wire call moves (now before it).
  • No config, wire format or public API change.

Tests

test/test_eval_subagent_deny_notice.py (new, 46 tests) -- red on origin/main @ aec81410e (33 failed / 13 passed; the 13 are the no-steer and cause-None paths that were already bare), green on this head. Two halves:

  • Behavioural, one per deny reason, driving the real EvalRunner._run_turn, LLMJudge.judge_turn and SubagentManager._reject_and_log with a provider double that records steer/approve/reject ORDER: gate refusal, sensitive path, unreadable path, unsafe tool, judge refusal, judge request without an id (neither steers nor rejects), policy / headless / low-fidelity funnel causes, cause=None sends nothing, no-steer backend only rejects, a raising steer still rejects, the SEL row (and the child metric) land before the steer, agent-authored text is redacted before it reaches the model.
  • Source-level guards that enumerate every reject_tool( in the two eval modules and every _reject_and_log( call in run.py, give each a per-site verdict, and fail when a host deny is not steered, a user rejection or a bail IS steered, a steer is not under cause=DENY_CAUSE_*, the SEL row comes after the steer, run.py grows a wire reject of its own, or the funnel's cause gains a default.

Mutation-verified on a scratch checkout: removing the runner's unsafe-tool steer -> 5 fail; changing the headless site to cause=None -> 1 fail; reject-before-steer in the funnel -> 6 fail; reject-before-steer in the judge -> 4 fail.

Sibling files run locally: test_subagent_coverage.py, test_hang_resilience_metrics.py, test_eval_harness.py -- 342 passed. Static gates (black via the baseline script, isort, flake8, mypy) clean on every changed file. Full suites run in CI.

Manual verification

Not applicable: no user-visible surface changes. The notice text itself is the existing deny_notice.build_refusal_steer_notice output, already verified on the chat runner, llm_helpers and the messaging surfaces.

Screenshots / video

Not applicable (backend-only; no UI change).

Related Issues

Fixes the eval/subagent slice of #5403. Follows #14141 (slice 1), #15083 (slice 2) and #15372 (slice 3, task runner). Related: #5332, #5401 (the chat runner's notice).

Pattern harvest

Rule candidate: review-prompt -- a reject_tool( on any surface must be immediately preceded by _steer_host_deny / steer_refusal_notice under an explicit host cause, or by an explicit not-a-host-deny verdict (cause=None / a comment naming the user rejection or the teardown); a reject funnel must take its cause as a REQUIRED keyword so a new call site cannot inherit a wrong verdict by default.
Not generalizable: the bind_component_globals indirection that forces the reason constants into subagent.py rather than next to their call sites in run.py is specific to the subagent manager's component split.

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

@iamwhatever
iamwhatever requested a review from a team as a code owner October 3, 2026 02:00
@iamwhatever
iamwhatever requested a review from bolichen97 October 3, 2026 02:00
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 2601024f7585d2cfffa2a2ffefeb94ff96ea2793 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check one change the visible description doesn't mention: _reject_and_log now catches SEL audit-write failures and only logs them. A failed audit used to raise.

[DESIGN-REVIEWED] 2601024

Description read

[DESCRIPTION-READ] 22f57fc18a8005459975b1ba8dd404b7149466381b49cb4f3f126e9d2e3f02d6

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2601024

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 2601024f7585d2cfffa2a2ffefeb94ff96ea2793: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 2601024f7585d2cfffa2a2ffefeb94ff96ea2793 — 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: CONCERNS

The fix is complete on its own; reordering the subagent audit ahead of the wire reject relies on symmetry and makes SEL audit failures best-effort without saying so.

Not justified as shipped

  • Item 4 — rides along, inherited: the stated reason is "matching every other deny surface" (task_executor._reject_and_log). That is the symmetry argument. The other reason, "cancel the coroutine with the decision acted on and unaudited", does not apply to the steer: a cancellation during the steer happens before reject_tool, so nothing has been acted on yet.
    Subtraction: keep the base order (reject first, then SEL) and put only _steer_host_deny ahead of reject_tool.
    Clears when: a reproduction or issue shows an unaudited, acted-on reject under the base order, or the reorder is removed.
  • Item 5 — undeclared: the new try: sel().log_tool_invocation(...) except Exception: logger.exception(...) only exists because of item 4's reorder. Before this change a SEL failure propagated after the reject; now it is logged and swallowed. The visible description never mentions this.
    Subtraction: delete the try/except along with item 4's reorder.
    Clears when: item 4 is reverted, or a linked defect shows the unswallowed raise stranding a request.

What this change ships

Inventory (6 items) — 4 justified

Intent: on eval and subagent runs, the model should be told when the host refused a tool call, not that a user denied it. This is a FIX.

  1. Eval runner refusals (gate, path check, unsafe tool) now send a host-deny notice before the reject — justified
  2. The eval judge's refusal of every tool now sends a surface-policy notice — justified
  3. Subagent host denies (spec gate, hook deny, headless default, low-fidelity child) now send a notice; approver "no" answers and limit bails send none — justified
  4. The subagent SEL row and child metric are now written before the wire reject — rides along, symmetry only
  5. A failed subagent SEL audit write is now logged and swallowed instead of raised — undeclared
  6. Spec paragraph listing the per-site verdicts in injected-messages.md — justified

[FIRST-PRINCIPLES-REVIEWED] 2601024

Description read

[DESCRIPTION-READ] 1ae406c2b90b099769c3dd7b668b180d2a2c8bf37d39e33a7861fe1ca6e85cda

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.

@iamwhatever
iamwhatever force-pushed the rebase/15463-deny-notice-eval-subagent branch from 4e6b3c1 to 77a36d3 Compare October 3, 2026 02:12
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 2601024

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 2601024f7585d2cfffa2a2ffefeb94ff96ea2793: <one-sentence reason>

@github-actions github-actions Bot added 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: checking Automated validation is still running labels Oct 3, 2026
…eject

Outside the chat runner a rejected permission reaches the model as kiro-cli's
fixed "User denied tool execution", so on the eval harness and the subagent
surface a host verdict read as a person cancelling. Every host deny on
eval/runner.py, eval/judge.py and the subagent funnel now steers the shared
deny notice (llm_helpers._steer_host_deny) while the permission request is
still unanswered, then rejects; the subagent funnel takes a REQUIRED cause=
so each of its nine call sites in subagent_manager/run.py carries a per-site
verdict (policy / surface_policy / None for approver rejections and limit
bails). Audit rows stay first at every site.

The subagent funnel's SEL audit is best-effort: a failure to write it (an
unloadable SEL trust root is permanent per process) no longer skips the steer
and the reject, which would leave the permission request unanswered and hang
the turn. Answering the model is the critical path.

Fixes the eval/subagent slice of #5403.

Co-authored-by: iamwhatever <12429733+iamwhatever@users.noreply.github.com>
@iamwhatever
iamwhatever force-pushed the rebase/15463-deny-notice-eval-subagent branch from 77a36d3 to 2601024 Compare October 3, 2026 04:12
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision 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 Oct 3, 2026

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

Summary

Head 2601024f7585d2cfffa2a2ffefeb94ff96ea2793. This adds the in-band host-deny notice (llm_helpers._steer_host_deny) before each host reject_tool on three surfaces: the eval runner (3 sites), the eval judge (1 site), and the subagent reject funnel SubagentManager._reject_and_log (9 call sites in subagent_manager/run.py, now with a required cause=). No path in the diff can turn a deny into an allow. The diff adds no approve_tool call, and every touched branch still ends in reject_tool. A failure on the new steer path still answers the request with a reject:

  • Steer Exception is swallowed inside steer_refusal_notice (deny_notice.py). The reject then runs.
  • Steer CancelledError schedules an orphan reject_tool before it re-raises (llm_helpers.py:1544-1548).
  • An SEL write failure in the funnel is caught, and the code still steers and rejects (subagent.py:4093-4112).
  • emit_counter never raises (metrics/events.py:22-29).

Every new error path fails closed.

Verified

  • Read docs/system-specs/modules/security.md first. Nothing in it constrains this path beyond the existing rule that deny decisions are audited and stay denies. Both still hold.
  • Read every changed site at the head SHA:
    • eval/runner.py:510-617: gate refusal, then path check (sensitive / no path), then unsafe tool.
    • eval/judge.py:104-113: the steer sits inside the existing if event.request_id: guard.
    • subagent.py:4033-4112: the funnel order is metric → SEL (best-effort) → steer if cause is not None → reject.
    • run.py: each of the 9 verdicts matches the PR's table. Spec gate and hook deny → POLICY. Headless and low-fidelity → SURFACE_POLICY. The three approver "no" answers and the two limit bails → None.
  • The orphan reject in _steer_host_deny uses event.request_id, and the funnel rejects request_id. Every caller passes event.request_id for both, so the orphan answers the same request.
  • test/test_eval_subagent_deny_notice.py: 47 passed. test_subagent_coverage.py + test_hang_resilience_metrics.py: 275 passed.
  • Mutations. Each one was restored from a backup, and git status --short was clean afterwards:
    • Funnel steer removed → 7 fail, including test_funnel_policy_cause_steers_the_reason_before_rejecting and TestSubagentDeniesThroughOneSteeringFunnel::test_the_funnel_audits_then_steers_then_rejects.
    • Funnel SEL try/except neutered so the raise propagates → test_funnel_failing_audit_still_steers_and_rejects fails.
    • Runner unsafe-tool steer removed → 5 fail (test_unsafe_tool_steers_the_surface_cause_before_rejecting, …).
    • Runner gate steer removed → 4 fail (test_permission_gate_refusal_steers_the_gates_reason_before_rejecting, test_eval_gate_reason_is_redacted_before_it_reaches_the_model, …).
    • Judge steer removed → 4 fail (test_judge_refusal_steers_the_surface_cause_before_rejecting, …).
    • Headless site, and separately the low-fidelity site, set to cause=None → test_every_host_deny_names_a_deny_cause_and_a_reason fails in each case.
    • Factory rejection given cause=DENY_CAUSE_POLICY → test_user_rejections_and_bails_are_not_steered fails.
  • Owning spec: docs/system-specs/common/injected-messages.md gained the per-surface paragraph, in the same place as the earlier slices.
  • CI at the head SHA: 82 success, 12 skipped, 0 failure. Auto-merge is off. No human review yet (REVIEW_REQUIRED).
  • Tests were not run locally beyond the three targeted files above. The full suite was left to CI.

Bot claims disposition

  • GPT 6.1 / Opus 5.5 line review: no findings. Consistent with what I read.
  • Design Review (PASS): says the change the description doesn't mention is that _reject_and_log now swallows SEL write failures. Real, and it does not block. The swallow is on a path whose decision is already a deny, so audit loss cannot weaken enforcement. With the audit now first, the swallow is also what stops a raising SEL from leaving the permission request unanswered and hanging the turn. It is logged at exception level. The only defect is that the PR body doesn't declare it (see follow-ups).
  • First Principles (CONCERNS), items 4/5 (reordering is "symmetry only"; the swallow is undeclared): partly real, and it does not block. The bot is right about one narrow point: a cancellation during the steer happens before anything is acted on, so the steer itself doesn't need audit-first. Even so, the reorder is defensible beyond symmetry, because reject_tool is also an await on the same pipe. Under the old order, a cancellation after the reject's write left the decision acted on and unaudited. It also matches every other merged deny funnel (task_executor._reject_and_log, chat runner). Item 5 follows necessarily from item 4: without the swallow, an SEL raise would skip the reject. Both fail closed, so neither is a logic defect. The PR body should declare the behaviour change.

Follow-ups (non-blocking)

  1. PR body / squash message: state that a subagent SEL audit-write failure is now logged and swallowed rather than raised. Name the trade-off: the deny is still sent, the audit row is lost but logged, and the request is no longer stranded. This keeps the undeclared change out of main's permanent history.
  2. PR body says "46 tests"; the file has 47 at this head.
  3. Backwards-compatibility bullet "Only their ORDER relative to the wire call moves" is no longer complete, because the SEL raise semantics changed too (see 1).

@iamwhatever
iamwhatever enabled auto-merge (squash) October 3, 2026 06:02
@iamwhatever
iamwhatever merged commit b85e4c8 into main Oct 3, 2026
97 checks passed
@iamwhatever
iamwhatever deleted the rebase/15463-deny-notice-eval-subagent branch October 3, 2026 06:02
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 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.

3 participants