SkillSpector icon indicating copy to clipboard operation
SkillSpector copied to clipboard

fix(findings): deduplicate cross-analyzer findings before scoring

Open mimran-khan opened this issue 5 months ago • 2 comments

Summary

When multiple analyzers detect the same pattern in multiple files of a skill, each occurrence was treated as a completely independent finding. A skill that calls subprocess.run(cmd, shell=True) in 5 modules got 5 TM1 findings, each contributing full points to the risk score — even though it represents the same architectural decision observed in different places.

Changes

  • nodes/deduplicate.py: New module with a pure deduplicate() function implementing two-pass deduplication:
    1. Same-file dedup: identical (rule_id, file, matched_text) → keep highest confidence
    2. Cross-file dedup: identical (rule_id, matched_text) across files → keep highest confidence representative
  • nodes/report.py: Calls deduplicate() on findings before scoring and SARIF generation

Design Decisions

Decision Rationale
Dedup key uses first 100 chars of matched_text Prevents pathologically long matches from consuming memory while maintaining specificity
No cross-file dedup for empty matched_text Without matched text, there's no reliable identity signal
Dedup before scoring (in report node) Preserves raw findings for meta_analyzer LLM analysis, only deduplicates for final output
Sort output by severity then file Stable, predictable report ordering

Behavioral Impact

Scenario Before After
shell=True in 5 files, same pattern 5 × TM1 HIGH findings 1 × TM1 HIGH finding
Different subprocess calls in same file Multiple findings Multiple (different matched_text)
Same rule_id, different patterns All kept All kept (different dedup keys)
Findings without matched_text All kept All kept (no cross-file dedup)

Test Plan

  • [x] 17 unit tests covering same-file dedup, cross-file dedup, no-matched-text preservation, edge cases (empty list, sorting, whitespace normalization, truncation, mixed scenarios, real-world simulation)
  • [x] Full test suite: 693 passed, 0 failures, 0 regressions
  • [x] ruff check and ruff format clean

Fixes #137

mimran-khan avatar Jun 22 '26 17:06 mimran-khan

PS: These issues were found while running bunch of skill evals using SkillSpector and hence raising all the issues so that i can use these with correct reference to Upstream code

mimran-khan avatar Jun 22 '26 19:06 mimran-khan

Thanks for the thorough review! I've addressed the blocking concern:

Cross-file dedup now only affects scoring, not the report.

  • deduplicate() is applied only to the findings list passed to _compute_risk_score()
  • The full (non-deduped) findings list is used for SARIF, JSON, markdown, and terminal output — all affected file locations are preserved
  • Added a test (test_report_dedup_affects_score_only_not_report_output) that verifies 4 files with the same pattern all appear in the report while the score remains lower than 4x base points

Also fixed the case sensitivity issue on the severity sort (f.severity.upper()).

The matched_text[:100] prefix collision is kept as-is since it's an acceptable noise reduction tradeoff — added a note in the code comment.

mimran-khan avatar Jun 22 '26 19:06 mimran-khan