You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(discover): estimate_hook_coverage double-scans for unattestable constructs #3650
Found by `/code-review high` while iterating on #3206 (not fixed there — pre-existing, and a real fix touches a shared function's contract used by other callers).
In `src/discover/mod.rs`, the estimate fallback path scans the same command with `lexer::contains_unattestable_construct` twice per call:
`permissions::check_command_with_rules` (called from `estimate_hook_coverage`) already calls it internally, to force an `Ask` verdict on unattestable constructs.
`estimate_hook_coverage_with_verdict` calls it again explicitly, because a `check_command_with_rules`-returned `Ask` verdict is ambiguous — it doesn't distinguish "unattestable construct" from "an ask_rules pattern matched" — and the real hook (`hooks::hook_cmd::decide_from_verdict`) unconditionally defers on unattestable constructs regardless of verdict, so `estimate_hook_coverage_with_verdict` needs to know that fact directly, not just that the verdict was `Ask`.
This runs in `rtk discover`'s per-command scan loop — over a large history (tens of thousands of commands) this is avoidable duplicate work in the exact path #3206 was optimizing.
Possible fix: have `check_command_with_rules` (or a new variant) return whether it hit the unattestable-construct branch alongside the verdict, so callers don't need a second scan. This touches `src/hooks/permissions.rs`'s public(crate) contract and its other callers (`hooks::hook_cmd`), so it's a slightly bigger change than a one-file fix — worth scoping as its own PR rather than folding into #3206.
estimate_hook_coverage redundantly scans commands twice for unattestable constructs in the discover per-command loop; fix requires widening check_command_with_rules's contract and should be its own PR.
📁 Relevant files
src/discover/mod.rs
src/hooks/permissions.rs
src/hooks/hook_cmd.rs
Triaged automatically by wshm · This is an automated analysis, not a human review.
I’d like to work on this. I’ll make the permission check return the unattestable-construct fact alongside its verdict, thread that result through the existing hook/discover callers, and add regression coverage showing the discover estimate does not rescan the command. I’ll keep the change scoped to this contract/performance issue.
Update after checking the latest develop: the estimate_hook_coverage path this issue targets only exists on the still-open #3206 branch, so a fix today would have to be a stacked PR and would not be independently mergeable into develop. I’m stepping back for now rather than creating that dependency; this should be picked up once #3206 lands (or if maintainers explicitly want a stacked change).
Implemented in #4637, independently based on current develop now that #3206 has landed.
Discover reuses a command-bound permission result, so an ordinary estimate attests once instead of twice. Existing verdict-only APIs and permission precedence remain unchanged. An early wrapper Ask retains an unknown attestation and still scans once when needed; it is not treated as safe.
The PR includes the original failing call-count regression, fixed/short-circuit/contract tests, and a negative control that rejects an intentionally unsafe cache value. Full workspace tests passed (4,965; all 8 ignored tests also passed separately), as did 4,505 no-default-feature tests.
Twenty native CLI scenarios preserve discover report values, rewrite stdout and exit codes. The linked screenshot and 14.36-second recording run actual local binaries on isolated synthetic transcripts, not product UI or hosted CI. Timing observations are not a claim of a 50% overall speedup.
Maintainer security review and the account holder's CLA signature remain outstanding.
Activity
pszymkowiak commentedon Aug 23, 2026
🔍 Automated Triage
buglowSummary
estimate_hook_coverage redundantly scans commands twice for unattestable constructs in the discover per-command loop; fix requires widening check_command_with_rules's contract and should be its own PR.
📁 Relevant files
src/discover/mod.rssrc/hooks/permissions.rssrc/hooks/hook_cmd.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
k4its1t commentedon Aug 24, 2026
I’d like to work on this. I’ll make the permission check return the unattestable-construct fact alongside its verdict, thread that result through the existing hook/discover callers, and add regression coverage showing the discover estimate does not rescan the command. I’ll keep the change scoped to this contract/performance issue.
k4its1t commentedon Aug 24, 2026
Update after checking the latest
develop: theestimate_hook_coveragepath this issue targets only exists on the still-open #3206 branch, so a fix today would have to be a stacked PR and would not be independently mergeable intodevelop. I’m stepping back for now rather than creating that dependency; this should be picked up once #3206 lands (or if maintainers explicitly want a stacked change).ZXLyyds100 commentedon Oct 17, 2026
Implemented in #4637, independently based on current
developnow that #3206 has landed.Discover reuses a command-bound permission result, so an ordinary estimate attests once instead of twice. Existing verdict-only APIs and permission precedence remain unchanged. An early wrapper Ask retains an unknown attestation and still scans once when needed; it is not treated as safe.
The PR includes the original failing call-count regression, fixed/short-circuit/contract tests, and a negative control that rejects an intentionally unsafe cache value. Full workspace tests passed (4,965; all 8 ignored tests also passed separately), as did 4,505 no-default-feature tests.
Twenty native CLI scenarios preserve discover report values, rewrite stdout and exit codes. The linked screenshot and 14.36-second recording run actual local binaries on isolated synthetic transcripts, not product UI or hosted CI. Timing observations are not a claim of a 50% overall speedup.
Maintainer security review and the account holder's CLA signature remain outstanding.