feat(findings): a scan closes what it no longer finds and reopens what returns #443

Merged
sharang merged 1 commits from feat/auto-resolve-findings into main 2026-10-05 13:16:36 +00:00
Owner

Option (c) from the discussion of #441: a scan closes findings it no longer finds. This should merge before #441, so the first scan after #441 closes the findings of the dropped Semgrep registry rules on its own.

Why

Until now a stored finding stayed open forever:

  • Fixing the code changed nothing.
  • Code that moved (a line added above it) left a duplicate behind, because fingerprints include the line.
  • After #441, every finding from the registry rules would stay open with no tool behind it.

Change

  • Closing (RunFindings::resolve_missing): at the end of scan_tree, after write_back (a run that fails part-way closes nothing), findings of the target are set to Behoben when all of these hold:
    • their scanner completed in this run;
    • their status is still undecided (open, triaged, needs_review);
    • this run did not report their fingerprint.
    • A finding whose file now lies in vendor code is closed with its own reason instead.
  • Reopening (save_new): a Behoben finding that a completed scanner reports again goes back to Offen, whether a person or a scan had resolved it.
  • Which scanners count: only those whose completion is known: semgrep, cppcheck, gitleaks, gdpr-patterns, oauth-patterns. #442 adds mobsfscan when it is rebased.
  • Explicitly out of scope:
    • Lint: a linter can fail inside a stage that reports success.
    • LLM control checks: not repeatable.
    • Manual and imported findings: never produced by a scan.
    • PLC targets: a separate path; follow-up.
    • "No new commits": that run never reaches scan_tree.
    • Human decisions (false positive, accepted risk, ignored, wrong mapping) are never touched.
  • History:
    • StatusChange gets an optional scan: { kind, scan_run_id }, with by = "pruefwerk-scan" and kind one of no_longer_found, now_vendor_code, found_again.
    • The dashboard shows Prüfwerk-Scan plus the reason in DE and EN.
    • status_history is no longer "people only"; the doc comment says so.
  • Large repos: candidates are loaded with a projection and filtered in Rust. Updates run in chunks of 500 IDs, each guarded by the status, so a person's change made during the scan wins. There is no $nin with thousands of fingerprints.
  • Docs: docs/guide/findings.md gets a "Closed and reopened by the scan" section and an updated recommended flow.

Visible side effects (intended, named in the docs)

  • Moved code is reported at its new line as a new finding, and the old one is closed as "nicht mehr gefunden". Before, both stayed open.
  • A force-push that rewrites history closes gitleaks findings from the removed commits.

Checks

  • fmt, plus clippy with the CI flags on core, agent, MCP and both dashboard feature sets.
  • Tests: core 103, agent lib 492, dashboard finding_detail 4 (new: the scan actor's name in DE and EN).
  • New Mongo integration test tests/resolve_findings.rs, run against a local Mongo:
    • a run without a completed scanner closes nothing;
    • fixed and vendored findings close, each with its reason;
    • a false positive, a lint finding and another target's finding stay as they were;
    • a returning finding is not reopened by a run whose scanner did not complete, and is reopened by one whose scanner did.
    • The existing live_findings test still passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Option (c) from the discussion of #441: a scan closes findings it no longer finds. **This should merge before #441**, so the first scan after #441 closes the findings of the dropped Semgrep registry rules on its own. ## Why Until now a stored finding stayed open forever: - Fixing the code changed nothing. - Code that moved (a line added above it) left a duplicate behind, because fingerprints include the line. - After #441, every finding from the registry rules would stay open with no tool behind it. ## Change - **Closing (`RunFindings::resolve_missing`):** at the end of `scan_tree`, after `write_back` (a run that fails part-way closes nothing), findings of the target are set to **Behoben** when all of these hold: - their scanner **completed in this run**; - their status is still **undecided** (open, triaged, needs_review); - this run did **not report** their fingerprint. - A finding whose file now lies in vendor code is closed with its own reason instead. - **Reopening (`save_new`):** a **Behoben** finding that a completed scanner reports again goes back to **Offen**, whether a person or a scan had resolved it. - **Which scanners count:** only those whose completion is known: `semgrep`, `cppcheck`, `gitleaks`, `gdpr-patterns`, `oauth-patterns`. #442 adds `mobsfscan` when it is rebased. - **Explicitly out of scope:** - **Lint:** a linter can fail inside a stage that reports success. - **LLM control checks:** not repeatable. - **Manual and imported findings:** never produced by a scan. - **PLC targets:** a separate path; follow-up. - **"No new commits":** that run never reaches `scan_tree`. - **Human decisions** (false positive, accepted risk, ignored, wrong mapping) are never touched. - **History:** - `StatusChange` gets an optional `scan: { kind, scan_run_id }`, with `by = "pruefwerk-scan"` and `kind` one of `no_longer_found`, `now_vendor_code`, `found_again`. - The dashboard shows *Prüfwerk-Scan* plus the reason in DE and EN. - `status_history` is no longer "people only"; the doc comment says so. - **Large repos:** candidates are loaded with a projection and filtered in Rust. Updates run in chunks of 500 IDs, each guarded by the status, so a person's change made during the scan wins. There is no `$nin` with thousands of fingerprints. - **Docs:** `docs/guide/findings.md` gets a "Closed and reopened by the scan" section and an updated recommended flow. ## Visible side effects (intended, named in the docs) - **Moved code** is reported at its new line as a new finding, and the old one is closed as "nicht mehr gefunden". Before, both stayed open. - **A force-push that rewrites history** closes gitleaks findings from the removed commits. ## Checks - fmt, plus clippy with the CI flags on core, agent, MCP and both dashboard feature sets. - **Tests:** core 103, agent lib 492, dashboard `finding_detail` 4 (new: the scan actor's name in DE and EN). - **New Mongo integration test `tests/resolve_findings.rs`**, run against a local Mongo: - a run without a completed scanner closes nothing; - fixed and vendored findings close, each with its reason; - a false positive, a lint finding and another target's finding stay as they were; - a returning finding is not reopened by a run whose scanner did not complete, and is reopened by one whose scanner did. - The existing `live_findings` test still passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-05 13:07:56 +00:00
feat(findings): a scan closes what it no longer finds and reopens what returns
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m21s
d4834d2a98
Until now a finding stayed open forever once stored: fixing the code
changed nothing, and moved code left a duplicate behind.

At the end of a code scan (after write_back, so a failed run closes
nothing), RunFindings::resolve_missing sets Resolved on the target's
findings that a scanner which completed in this run stored earlier but did
not report again, if nobody decided about them yet (open, triaged,
needs_review). A finding whose file now lies in vendor code is closed with
that reason instead. save_new reopens a Resolved finding that a completed
scanner reports again.

Only scanners whose completion is known count: semgrep, cppcheck, gitleaks
and the GDPR/OAuth patterns. Lint (a linter can fail inside a stage that
succeeds) and the LLM checks (not repeatable) close nothing; manual and
imported findings are never a scan's; PLC targets are not covered yet.

Every such change is in the status history as a StatusChange with
`by = "pruefwerk-scan"` and a `scan` entry (kind, run id); the dashboard
shows "Prüfwerk-Scan" and the reason in German or English.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang force-pushed feat/auto-resolve-findings from 2734e361cc to d4834d2a98 2026-10-05 13:07:56 +00:00 Compare
sharang merged commit 82736a1eec into main 2026-10-05 13:16:36 +00:00
Sign in to join this conversation.