Repository navigation
fix(messaging): steer the in-band host-deny notice before every reject - #15083
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] b8ac657 Description read[DESCRIPTION-READ] 1ab4b25785c968a1f7c71f27995ad11fbaf3c421f534931a9723694232610d8f 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 |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the base-red claim ("31 failed / 13 passed") by running Not justified as shipped
What this change shipsInventory (10 items) — 9 justifiedIntent: FIX — issue #5403 slice: host denies on the messaging surfaces tell the model the host refused, not the person.
[FIRST-PRINCIPLES-REVIEWED] b8ac657 Description read[DESCRIPTION-READ] 744a9912c988512c83b9edfeda8a3f39d5b01c937bc4c0e434fcad7f329c7475 That sha256 names the PR description this verdict read. Recompute it with |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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: |
Opus 5 Review — ✅ no blocking findingsReviewed Review detailsNothing blocks; two advisory findings on the new deny-notice wording. FINDING — src/kiro_crew/channel.py:1498 — the oversize refusal reports FINDING — src/kiro_crew/channel.py:1250 — the blocked-messaging-tool deny reuses [OPUS-REVIEWED] b8ac657 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
d4ac903 to
e6d9d07
Compare
e6d9d07 to
866ccb8
Compare
#5403 slice 2) Every host deny on the three messaging surfaces -- the native Slack handler, the channel agent stream and the channel-neutral TurnDriver -- now awaits the shared deny_notice.steer_refusal_notice through a thin _steer_host_deny (which redacts the reason; Slack and the driver carry their own because their cancellation arms differ, the channel reuses llm_helpers' with the rendered tool name as title) immediately before reject_tool, so a steer-capable backend learns in the same turn that the HOST blocked the call instead of reading kiro-cli's "User denied tool execution". supports_refusal_steer False is byte-identical to before. Per site, with a verdict for every reject_tool on the three surfaces: - slack/handler.py: the PreToolUse hook's deny on the message path is DENY_CAUSE_POLICY with the hook's reason; the expired approval prompt keeps DENY_CAUSE_APPROVAL_TIMEOUT and now goes through the same helper. A Deny click in handle_interaction is a genuine user rejection and the teardown-only _reject_orphaned_tool is cleanup: both stay bare. - channel.py: the containment boundary refusing a direct-to-user messaging tool is DENY_CAUSE_SURFACE_POLICY (the model's way forward is a channel post); the PreToolUse gate's deny is DENY_CAUSE_POLICY with the gate's reason; a card the channel cannot show in full is the new DENY_CAUSE_APPROVAL_OVERSIZE, whose notice tells the model to split the request -- kept apart from approval_undeliverable, whose guidance is to state the permission needed; a card that expires unanswered is DENY_CAUSE_APPROVAL_TIMEOUT. The reader's Deny shares that reject line and sends no notice: the steer sits under the timeout flag alone. - messaging/driver.py: the deny-every-tool switch for a sender other than the operator is DENY_CAUSE_SURFACE_POLICY; the gate's deny is DENY_CAUSE_POLICY. build_tool_gate leaves the hook's reason on the gate as last_deny_reason (the ApprovalDecider.last_deny_cause shape) so the notice names the rule; a plain callable gets a notice naming the gate. The decider path is unchanged: a human's Deny stays bare. The SEL audit row precedes the steer and the reject at every newly covered site (audit-first, as the chat runner and llm_helpers do). Cancellation mid-steer schedules a strongly referenced reject_tool so a stranded permission cannot wedge the backend; that orphan reject audits only where the caller audits after the wire (audited=False on the Slack timeout arm and the driver's decider path), so an audit-first site never gains a second SEL row for one decision. Tests: a source-level guard per surface that enumerates every reject_tool( with its verdict (host / user / cleanup / mixed) and fails on a missing site, a bare host deny, a steered user rejection, or a mixed site whose steer is not under its host guard; one behavioural test per deny reason with a provider double recording steer/reject order; audit-order, capability-gate, redaction and cancellation tests. Fixes the messaging-surface slice of #5403.
866ccb8 to
b8ac657
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed on behalf of the maintainers (sweep 2026-09-30): readiness passed, required checks green on b8ac657, no blocking review threads, security posture unchanged. Approving and merging.
Problem / Motivation
Goal: On the messaging surfaces -- the native Slack handler, the channel agent stream and the channel-neutral
messaging.TurnDriver-- a host block on a tool call tells the model in the same turn that the HOST refused it, and why, instead of the bare "User denied tool execution".Bug: issue #5403 lists the
reject_tool(clusters outside the dashboard chat runner; slice 1 (#14141) coveredllm_helpers.py. The messaging surfaces named next in the issue still answer most host denies withreject_toolalone: the Slack handler's PreToolUse hook deny (slack/handler.py), the channel agent's blocked messaging tool, PreToolUse gate deny, over-long approval card and expired card (channel.py), and the TurnDriver's deny-every-tool switch and gate deny (messaging/driver.py). A person watching the Slack thread or the channel sees the reply silently give up, because the model read a refusal nobody made. Only the approval-timeout arms on Slack and in the TurnDriver already steer the shared notice from #10537.Why it matters
These are the surfaces where a human is watching: a Slack thread or a channel conversation. A model that reads a host block as the person's Deny stops, apologises to the reader for a cancellation they never made, or asks whether to retry. With the notice it learns which rule (or which surface constraint) refused the call and can post to the channel instead, pick an allowed alternative, or split an over-long request.
Not a goal
reject_tool(clusters listed in In-band deny notice: host denies on surfaces other than the chat runner still say "user denied" #5403 (cli_chat.py,task_executor.py,task_planner.py,subagent.py,eval/*,dashboard/handlers/*,agent_runner.py) -- later slices; the issue stays open.handle_interaction, the channel reader's Deny on the approval card, and a human's Deny through the TurnDriver's decider stay bare; a person said no and kiro-cli's wording is correct there._reject_orphaned_tooland the cancellation-time orphan rejects answer a wire whose own reject was skipped; they are not decisions of their own._tool_gatecopy (it stays a plain callable and gets the notice naming the gate).What changed (motivation → approach → change)
Symptom: a provider double with
supports_refusal_steer=Truedriven through each host-deny branch ofslack.handler.handle_message,channel._stream_taskandTurnDriver.runonmainrecords['reject']and no steer (the new test file is red on base: 31 failed / 13 passed).Root cause: each site answers the deny straight on the wire; the shared in-band notice helper is never called there, and on Slack and in the TurnDriver the SEL audit row was written after the reject.
Change:
_steer_host_deny(..., reason, *, cause, audited)on Slack (module-level inslack/handler.py) and the TurnDriver (a method inmessaging/driver.py) redacts the possibly agent-authored reason and forwards tokiro_crew.deny_notice.steer_refusal_notice;channel.pyreusesllm_helpers._steer_host_deny(which gains an optionaltitlekeyword for the channel'sevent.textrendering) rather than a fourth copy. It builds no text and sends nothing itself, so the "two spellings of the bounded steer" pin intest_approval_timeout_cause.pystill holds.causeis a required keyword and every site names it. The Slack approval-timeout arm and the TurnDriver's_steer_deny_causenow go through the same helper instead of inlining the cancellation handling.reject_tool(on the three surfaces has a verdict, enforced by the new source guard:handle_message: hookTOOL_DENYPOLICYtool_result.reason_request_approval: prompt expiredAPPROVAL_TIMEOUT_reject_orphaned_toolhandle_interaction: Deny clickSURFACE_POLICYPOLICY_APPROVAL_FIELD_MAX_CHARSAPPROVAL_OVERSIZEAPPROVAL_TIMEOUTunder the timeout flag onlydeny_all_tools(untrusted sender)SURFACE_POLICYtool_gatedenyPOLICYlast_deny_reason, else "blocked by the PreToolUse security gate"APPROVAL_TIMEOUTvia_steer_deny_cause(unchanged)DENY_CAUSE_APPROVAL_OVERSIZE(constants.py; wording indeny_notice._DENY_CAUSE_TEXT; not re-exported bydashboard/state.py-- nothing on the dashboard reads it): a channel approval card refused because the request is too long to show in full. Nothing about the action was judged and the fix is in the model's hands (split the request into steps that fit), so it is kept apart fromAPPROVAL_UNDELIVERABLE, whose guidance is to state the permission needed, and fromPOLICY, whose remediation would name a sanctioned alternative to an action nobody refused._APPROVAL_TIMEOUT_SECS = 3600) and records_approval_timed_outbeside the collapseddecision = "rejected", so the one reject line can steer the host's timeout and stay bare for the reader's Deny.messaging.dispatch.build_tool_gateleaves the hook's reason on the gate aslast_deny_reason(set on every call,""on allow) -- the same attribute-on-a-callable shape asApprovalDecider.last_deny_cause. The TurnDriver reads it withgetattr, so a plain callable (tests, the Discord inline copy) still works and gets a notice naming the gate.channel.pyalready audited first), matching the chat runner andllm_helpers.CancelledErrorout of the steer schedules the reject as a strongly referenced task and re-raises. Slack and the TurnDriver keep their existing shielded-await shape inside the helper, and that orphan reject audits ONLY whenaudited=False(the caller audits after the wire: the Slack approval-timeout arm, the driver's decider path); an audit-first site (audited=True) already has its SEL row, and the ledger is append-only, so a second row for one decision would be a duplicate nothing reconciles.channel.pyusesllm_helpers' arm (re-raise at once,_orphan_reject_doneretires the task and reads its outcome; never audits, every channel site is audit-first).docs/system-specs/common/injected-messages.md: the messaging surfaces' per-site causes, theapproval_oversizecause, the mixed sites, and the per-surface source guard.A backend without
supports_refusal_steerbehaves byte-identically to before.Backwards compatibility
Compatible: no verdict changes; a deny is still a deny and a user rejection is still bare. The only new observables are one extra in-band steer on steer-capable backends immediately before an existing
reject_tool, and alast_deny_reasonattribute on the gatebuild_tool_gatereturns (read withgetattr, never required).DENY_CAUSE_APPROVAL_OVERSIZEis an added constant; no existing cause is renamed or removed. The TurnDriver's cancellation-time SEL row now names the cause (reason=<cause>_cancelled_mid_steer) instead of hardcodingapproval_timeout.Tests
test/test_messaging_deny_notice.py(51 tests; 31 red on base, the 13 green ones are the user-rejection, no-steer and already-shipped assertions):await <x>.reject_tool(inslack/handler.py,channel.pyandmessaging/driver.pymust match exactly one enumerated fingerprint carrying a verdict (host/user/cleanup/mixed); the scan is cross-checked against a textual count (the non-awaited orphan spellings are pinned to one occurrence each); every host deny has the surface's steer within the window; user rejections and cleanup have none; a mixed site's steer sits directly under its host guard (if _approval_timed_out:; the decider path pins_steer_deny_cause's cause gate); every steered site with audit-first audits before the steer; every steer namescause=DENY_CAUSE_*or forwardscause=cause; each helper only forwards tosteer_refusal_noticewith a default-lesscause.handle_message,_stream_taskandTurnDriver.runwith a provider double recording steer/reject order and checking the notice names "User denied tool execution", "NOT a user action", the site's reason and the cause wording (surface-policy, oversize and timeout notices carry no "allowed alternative" guidance; policy notices carry the policy clause).['reject']only;supports_refusal_steer=Falserecords['reject']only on all three surfaces; an AWS-key-shaped secret in a hook reason does not reach the model.audit,steer,rejecton Slack, channel and driver.steer()that never returns is cancelled and the reject still reaches the wire on Slack, channel and driver, with the orphan set emptied; an audited site writes NO second SEL row, an after-wire site writes exactly one; the source guard pinsaudited=per site against the measured audit order.build_tool_gatesetslast_deny_reasonon deny and clears it on allow.Mutation-verified locally: dropping the channel gate steer fails the guard and the behavioural test; steering the reader's Deny too fails the mixed-site guard and the human-deny test.
Sibling files on the same paths, run by CI:
test_refusal_inband_notice.py(its_DENY_CAUSE_TEXTiteration covers the new cause),test_approval_timeout_cause.py,test_deny_audit_first.py,test_llm_helpers_deny_notice.py,test_messaging_driver.py,test_messaging_dispatch.py,test_messaging_import_purity.py,test_channel_blocked_tools.py,test_channel_approval_meta.py,test_slack_handler_more_coverage.py,test_transport_permission_floor.py,test_discord.py.Manual verification
N/A -- unit coverage sufficient: the behaviour is the order and content of two awaits on a provider double; the source guard pins every site on the three surfaces and the behavioural tests drive the real handlers.
Screenshots / video
N/A -- backend only, no user-visible frontend surface touched.
Related Issues
Fixes the messaging-surface slice of #5403 (slice 2; the issue stays open for the remaining clusters listed under Not a goal). Follows #14141 (slice 1) and builds on #10537 (
deny_notice.steer_refusal_notice).Pattern harvest
Rule candidate: review-prompt
Pattern: a single
reject_toolline that answers both a host decline (a timed-out prompt collapsed intodecision = "rejected") and a human's Deny hides a per-site verdict; record the provenance beside the collapsed decision and gate the notice on it, and have the source guard pin the steer under that gate.Rule candidate: review-prompt
Pattern: when a gate/decider callable returns only a verdict string and the caller needs the reason, carry it as an attribute on the callable (
last_deny_reason, likelast_deny_cause) read withgetattr, so plain callables in tests and sibling transports keep working.Not generalizable: the per-site reason strings; they name these surfaces' constraints.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)