Repository navigation
perf(crew): match a Bot's tool approvals by index, not all-pairs - #37691
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: this is a backend-only change. It indexes the same Notes
[DESIGN-REVIEWED] 96d50a1 Description read[DESCRIPTION-READ] 516c34d496606e5e6aeb49f3c1ad2497599ae3523bf91a2b4a3d140fab6a6059 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 (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: the index removes the measured cubic matching cost at the code that causes it, returns the same answers as before, and has a real consumer. What this change shipsInventory (3 items) — 3 justifiedIntent: let someone who added hundreds of tool approvals to a Bot open, preview and save its Abilities and Approvals panes without a timeout. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 96d50a1 Description read[DESCRIPTION-READ] b6489d18adc10f024032efca7574af19ce148cd162de6a3a3dd71949b6744d4e That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
Code change approver recommendation: ApproveWhy: the decider estimates an 8% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. ReachIndex gives the same answer as any(entry_reaches(e, ref)). Glob-free entries reduce to equality before or after case folding, so set lookups give the same result. The bare-entry verb lookup gives the same result because casefold works per character and never adds or removes '/'. Entries with a literal server part can only match refs on that server, raw or folded, so bucketing them by folded server name is safe. Server globs and bare globs still go through entry_reaches. The caller keeps main's progressive, list-ordered expansion: set.update(generator) on main also added each ref as it was produced. The index is built per call and nothing persists, and entry_grants (the strict trust check) is untouched. One new test checks the index against the all-pairs answer; a scale test counts entry_reaches calls through get, preview and save. CI is green. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved. On this head the review checked that ReachIndex gives the same answer as any(entry_reaches(...)) for each bucket (exact set, per-server bucket, fallback scan). An independent seeded fuzz over case folding, glob classes, @ and @/x found 0 mismatches. The caller keeps main's list-order expansion, entry_grants is untouched, and the PR's tests plus the sibling worker_summary and listed-skills suites passed locally (132 passed). Removing the bare-verb lookup reds the equivalence tests, as the body says.
Done well: the index never re-implements the matching rule, and the scale test bounds a deterministic call count instead of wall time.
Optional:
- Deleting
index.add(ref)inmate_capabilities.pyreds no test. A small case where a spec ref is reached only through an earlier one (@notes/a?then@notes/a*then@notes/abc) would pin it. - In the scale test,
countedcould callpytest.failas soon as the count passesMAX_MATCHES. A regression would then fail by name instead of through the 120 s timeout. - The scale test takes about 12.5 s. A smaller server count would still show the gap at a fraction of the runtime.
Problem / Motivation
Goal: A Bot with hundreds of tool approvals opens, previews and saves its Abilities and Approvals panes instead of timing out.
A Bot with many tool approvals (many
@server/toolentries inallowedTools) shows "Couldn't load this Bot's approvals." and "Couldn't load this Bot's capabilities." The capabilities GET gives up after 20 s and answers503 capabilities_unavailable. Measured onmainwith a tool-only Bot and no skills: 408 approvals take 34 s, 520 take 66 s, 1020 take 509 s. #37626 speeds up the skill side of the same read and leaves this tool side as it is.Why it matters
The people who added the most tools to a Bot are the ones who cannot see, switch off or remove them. Preview and save run the same read again, so a remove costs two slow reads, and the save holds the agents config lock for the whole read.
Not a goal
_GET_TIMEOUT_SECSor changing the view's shape, theremovefield or the frontend.What changed (motivation → approach → change)
Symptom → cause.
worker_summaryinsrc/kiro_crew/mate_capabilities.pychecks, for every added row, whether its Remove would make the row go away. Each check rebuilds the worker's effective tools and approvals, then tests every listed ref against every entry withentry_reaches. That is rows × refs × entries: about 10^9 calls for 1000 approvals.Change. A new
ReachIndexinsrc/kiro_crew/agent_sdk/mcp_refs.pyanswersany(entry_reaches(entry, ref) for entry in entries)with the same result, without trying every entry. An entry with no glob characters can only match its own case-folded spelling, so it is a set lookup. An entry whose server name has no glob can only match refs on that server, so it is tried only for those. Server globs, bare globs and anything else still go throughentry_reachesitself. The per-row check now uses the index and keeps its list order, so a ref it adds still reaches later refs, as before. Preview and save still build their view with one read each; that read is now fast, so they are left as they are.mainBackwards compatibility
Compatible: every row, state and Remove target is the same; only how many matches run changes.
Removes nothing: no field, row, key or function is removed or tightened.
Tests
test_reach_index_answers_what_trying_every_entry_answersandtest_reach_index_agrees_on_every_subset_and_after_addspinReachIndex.reachestoany(entry_reaches(...))over exact refs,@server,@server/,@server/*, tool globs,[...]classes, server globs (@*,@kirocrew-*),*, bare names and globs, case andß/SSfolding,@,@/xand the empty string, on 300 seeded random subsets built partly byadd. Dropping the bare-verb lookup fails them.test_get_preview_and_put_do_not_match_every_approval_against_every_other: a Bot file with 1000 approvals over 10 servers.get,previewandputeach list every added row as removable, the preview reports the removal, the save writes it, andentry_reachesruns fewer than 20 × 1000 times per call. It counts work instead of timing it; on the parent it does not finish before the 120 s pytest timeout.worker_summary, listed-skills and redaction tests pass unchanged.-n0, plus a run at-n 4 --dist loadwith the worker-summary file, all green.Proof: not provable -- other: the new scale test runs past the 120 s pytest timeout on the parent instead of failing an assertion
Manual verification
A tool-only Bot of 4 × 50 approvals was summarised by
worker_summaryon the parent and on this change: the full JSON output was byte-identical. The branch also merges cleanly with #37626, and the combined tree passes the worker-summary, listed-skills, redaction, scale andentry_reachestests (143) and reads the 1020-approval Bot in 2.6 s.Related Issues
Part of #37625
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)