Skip to content

perf(discover): reuse permission attestation in coverage estimates - #4637

Open
ZXLyyds100 wants to merge 1 commit into
rtk-ai:developfrom
ZXLyyds100:fix/discover-reuse-permission-attestation
Open

ZXLyyds100 wants to merge 1 commit into
rtk-ai:developfrom
ZXLyyds100:fix/discover-reuse-permission-attestation

Conversation

@ZXLyyds100

Copy link
Copy Markdown
Contributor

Summary

  • Fixes perf(discover): estimate_hook_coverage double-scans for unattestable constructs #3650: reuse the permission check's attestation when estimating historical hook coverage, instead of scanning an ordinary command twice.
  • Keep the verdict-only APIs and deny/defer/ask/allow behavior unchanged. The detailed result borrows the original permission command; an early wrapper verdict leaves attestation unknown and evaluates it lazily once if discover needs it.
  • Add call-count/short-circuit/contract regressions and document the reuse boundary. No production lexer behavior, dependencies, config, output format or live hook protocol changes.

Test plan

  • TDD: the original logic fails the new regression with 2 calls instead of 1; fixed assertion passes. Counter is per-thread and cfg(test) only.
  • Focused suites: 683 discover tests and 103 permission tests passed.
  • cargo fmt --all --check, proxy formatting, cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
  • cargo test --workspace --locked: 4,965 passed, 0 failed, 8 ignored; all 8 ignored tests also passed separately.
  • cargo test --no-default-features --locked: 4,505 passed, 0 failed, 8 ignored.
  • Hostile GIT_DIR/German locale: 11 coverage tests passed. Nested TMPDIR: both result-contract tests passed.
  • Negative control: intentionally treating an unscanned wrapper Ask as safe incorrectly counts a redirected wrapper's sibling as covered; the regression fails. That mutation was reverted before final validation.
  • Manual testing: original/fixed native binaries preserve all discover report values, rewrite stdout and exit codes in 20 isolated scenarios, including explicit safe/unsafe wrapper siblings.
  • Replayed the same 20,000-request synthetic transcript through both real binaries; report digests match.

Before / after

Path Before After
Ordinary estimated command Two attestation calls One, reused
Missing hook / deny / defer Short-circuit Still short-circuits
Early wrapper Ask Separate attestation needed Still evaluated once; unknown is not safe
Permission decisions and report values Existing behavior Preserved in the tested scenarios

This removes duplicate predicate work, not 50% of total discover runtime. The included debug-build timing samples are noisy local observations, not a production speedup claim.

Actual native CLI comparison, 14.36-second recording, and replay

The image is a local evidence harness, not product UI. It runs actual RTK binaries over isolated synthetic stored transcripts; transcript commands are never executed. No hosted CI or real agent session is claimed.

Native discover reports remain identical while test-counter evidence goes from two scans to one

Recording · Twenty-scenario results · Original failing test · Fixed passing test · Negative control · Validation and replay instructions

Media and the optional harness remain on a fork-only evidence branch, outside this four-file code PR. Native verification was on macOS; other platforms remain subject to repository CI.

Review scope

Read merged #3206 and its approved review as precedent. The prior issue volunteer explicitly stepped back while that dependency was unmerged; it has since landed. This PR is independently based on current develop, not a stack on the unrelated open lexer/gain work.

Implemented with coding-agent assistance and two self-review passes. Permission/hook code remains subject to maintainer security review; local test results do not claim human or hosted-CI approval.

Targets develop, per the contribution guide.

@CLAassistant

CLAassistant commented Oct 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Refactors estimate_hook_coverage in the discover module to reuse the permission check's detailed attestation result instead of re-scanning the command a second time via lexer::contains_unattestable_construct. Adds thread-local call-count instrumentation (test-only) plus new regression tests verifying the single-scan behavior, short-circuit paths, and early-wrapper-Ask attestation, while preserving existing deny/defer/ask/allow decision semantics.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #3650


Analyzed automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(discover): estimate_hook_coverage double-scans for unattestable constructs

2 participants