Repository navigation
Conversation
|
Raw measurements behind the Manual verification table. The command is the reproducer from #13980, verbatim. Each line is one checkout: main The two Denial differential on the base-ref golden-paths corpus ( |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the walk is a pure function of its text, the memo lasts one decision, and verdict equality is pinned against an unshared walk. Notes
[DESIGN-REVIEWED] 848209d Description read[DESCRIPTION-READ] 1d3e354cfa62ec4e83666bb0159f1b09e9fb27a9723e6ad8e4531d9dd64d3644 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 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Opus 5.5, fork) — 🔴 BLOCKPremise-level review of First-Principles-Verdict: BLOCK The walk memo adds a second per-call What this change shipsInventory (6 items) — 4 justifiedIntent: stop one long shell command from blocking the gateway's event loop past the watchdog by tokenizing it once per deny decision. This is a FIX (perf; #13980).
BlockersSecond per-decision cache scope around [FIRST-PRINCIPLES-REVIEWED] 848209d Description read[DESCRIPTION-READ] 096a6085782566a480e041902a859886976d8ae6b74c1b89c1e5d8453886e864 That sha256 names the PR description this verdict read. Recompute it with |
Security Scope Review (fork) — ✅ PASSWhich legitimate operations does adjudicated, zero confirmed regressions Scope-Verdict: PASS Reason: This change does not make any rule stricter. It adds a per-decision memo around TIGHTENING: No deny boundary got stricter. The only mechanism change is caching the walk the floors already share -- " ADJUDICATED: 16 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix rows: two heredoc-fed [SCOPE-REVIEWED] 848209dSecurity scope review -- adjudicated candidates
No candidate flipped from allowed to refused. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. Notes:
[OPUS-REVIEWED] f2e798d |
|
On the Design Review's cost note: under CI's Hypothesis profile (20 examples), the composed-command differential runs in 0.10 s locally and the corpus differential in 0.02 s. |
dcdc367 to
ccce02d
Compare
|
🤖 Kiro Crew [operator: dwu96#8c08bee0]: Security scan flagged this PR for manual review. Findings:
A maintainer will review before any automated action is taken. Context for the reviewer: both hits are in an added block of |
|
PR triage (2026-10-05): REBASE + merge-discussion (OVERLAPPING, no blocker) Checked against
Recommendation: rebase onto main, re-pin the line budget, then proceed. |
f2bcdd1 to
e91be95
Compare
Every structural floor of is_denied asks _shell_payload_walk to tokenize the same command text, so one decision on a long heredoc-fed script repeated the same super-linear walk once per floor, and that repetition was nearly all of the decision's cost on the event loop. Run is_denied inside a call-scoped memo keyed by the exact text walked. The walk is a pure function of its text, so the floors of one decision share one result without any floor seeing a different view; the memo is dropped when the call returns, so the gate keeps no state between tool calls. Each caller still receives fresh lists, and a walk that raises is not remembered. Re-pin the security package line budget to the new measured total. Refs kirodotdev#13980
e91be95 to
848209d
Compare
First Principles review found two per-call ContextVar scopes stacked on is_denied. Drop _one_payload_walk_per_decision and the walk's own ContextVar; _shell_payload_walk now keeps its frames in the cache sharing_views already opens, under (tag, text) tuple keys that cannot collide with the redirect-view str keys. The test helper restores the scope by value (Semgrep contextvar-token-reset). Refs kirodotdev#13980
12d47c9 to
f2e798d
Compare
|
[operator: bolichen97] Continuing this in #32115; thanks for the start. |
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.
Builds on #14993 by @yiyabo.
Part of #13980
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.
Builds on #14993 by @yiyabo.
Part of #13980
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.
Builds on #14993 by @yiyabo.
Part of #13980
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.
Builds on #14993 by @yiyabo.
Part of #13980
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.
Builds on #14993 by @yiyabo.
Part of #13980
One is_denied call asked for the same shell payload walk once per
floor, about ten times on a heredoc-fed script, and each walk read
every $( span twice to find its close. The walk now keeps its frames in
the per-call cache sharing_views already opens, so each distinct text
is walked once per decision, and the paren walk skips its second
${...}-aware pass when the span holds no "{", where both passes take
the same steps. Verdicts are unchanged; on the issue's reproducer an
8 KB heredoc goes from about 15 s to 1.7 s.
Builds on #14993 by @yiyabo.
Part of #13980
Backport note: the security package is 34,921 lines on release (main's
base was 35,071), so the pick's 20 lines need the budget raised by 5,
from 34,936 to the measured 34,941, instead of main's 20; the code
merged unchanged.
(cherry picked from commit 9093ac6)
Problem / Motivation
Goal: One deny decision tokenizes each shell command once instead of once per floor, so a long command blocks the gateway's event loop for a fraction of the time.
Every shell tool call goes through
is_deniedon the event loop before it runs. Several structural floors each ask_shell_payload_walkto tokenize the same command, and on a long command that tokenizing is almost all of the decision's cost. #13980 reports an 8 KB command stalling the loop for seconds and a 32 KB one outlasting the 25 s hang watchdog, which kills the gateway.Why it matters
The deny check is synchronous and sits in front of every shell call, so while it runs no other session, channel or dashboard request is served. An agent that writes a long heredoc script freezes the whole gateway, and past the watchdog budget the gateway dies mid-work. With one walk per decision the 30,946-character case below drops from ~51 s to ~6.3 s: under the watchdog, though still a multi-second stall (see Not a goal).
Not a goal
_self_tokensover_iter_shell_chars); rewriting the bash-fidelity scanner needs its own differential review.What changed (motivation → approach → change)
One deny decision tokenizes each command text once and shares the result with every floor that asks for it, so a long command pays for one walk instead of one per floor.
security/shell_normalizer.py_payload_walk_memo()ContextVarand keyed by the exact text walked. It is dropped on exit, and a nested block reuses the outer one.security/shell_normalizer.py_shell_payload_walk()_shell_payload_walk_uncached.security/__init__.py_one_payload_walk_per_decisionis_deniedinside one memo block.The walk is a pure function of its text, and the floors of one decision ask for it on the same text. So the decision can share one result without any floor seeing a different view. The self-subcommand floors walk the command with line continuations joined, which is a different text and gets its own entry.
The memo lives exactly as long as one
is_deniedcall. The gate keeps no state between tool calls, so there is nothing to invalidate. A decorator leaves the body ofis_deniedand every floor's signature untouched.security.mdrecords the mechanism and the remaining single-walk cost. The package line budget intest_security_gate_liveness.pyis re-pinned to the new measured total, with its reason.Backwards compatibility
Compatible: verdicts are identical, because the walk is a pure function of its text and the memo is keyed by that exact text for one call; no signature, rule, config or output changes.
Tests
test/test_denied_commands_security.py::TestOneDecisionSharesEachPayloadWalk:test_one_decision_walks_each_text_once: on a long heredoc, every text the floors request is walked exactly once, with a precondition that several floors requested it.test_each_distinct_text_keeps_its_own_walk: a continuation-joined view is walked separately, and each text gets its own frames.test_a_later_decision_walks_again: nothing carries between two decisions.test_a_shared_walk_hands_out_fresh_lists,test_a_walk_that_raises_is_not_remembered,test_a_nested_block_reuses_the_enclosing_memo: the memo's isolation and lifetime.test_verdicts_match_an_unshared_walk_on_the_floor_corpusandtest_verdicts_match_an_unshared_walk_on_composed_commands(Hypothesis): shared and unshared decisions return the same verdict, over one command per structural floor and over generated compositions of them.The pin counts walks instead of timing a budget, because a wall-clock complexity guard measures the scheduler and flips under load (testing-conventions).
test/test_security_gate_liveness.py:_PACKAGE_LINE_BUDGETre-pinned to the measured package total.Manual verification
The reproducer from #13980, unchanged, on macOS arm64 with Python 3.12. Each cell is the median of 5 timed
is_deniedcalls after a warm-up, with an empty data home:3b0f4ad04Walks are counted with
cProfileon an untimed call; profiling the longest command is too slow to be worth it, and the count depends on the floors, not the length. All six verdicts areNoneon both sides.Related Issues
Refs #13980 (the walk-once slice: one walk is still super-linear in command length, so the issue stays open).
Pattern harvest
Rule candidate: review-prompt
Pattern: several predicates of one decision each recompute the same pure parse of the same input; share it for that decision only, never across calls.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)