feat(scan): findings are saved as each stage ends, and show while the scan runs (#372) #401

Merged
sharang merged 1 commits from feat/live-findings into main 2026-09-25 19:38:58 +00:00
Owner

Refs #372. Covers everything except server push, which I propose as a follow-up (see below).

Findings used to be saved only at the very end of a scan, after triage, so nothing appeared until the run was over. Now each scanner stage saves its new findings as soon as it ends, and triage later updates those same rows.

Pipeline (compliance-agent)

  • New pipeline/finding_store.rs (RunFindings):
    • save_new runs after each scanner stage: SAST (semgrep and cppcheck), patterns, secrets, lint. One $in query finds which fingerprints are already stored; the first-seen findings are saved with one insert_many (a fingerprint reported twice in one run is saved once). It raises the run's new_findings_count with $inc, so the count rises during the scan. This replaces the old find_one plus insert_one per finding.
    • write_back runs after triage (5, 5b–5d). On rows saved in this run it stores severity, confidence, triage action and rationale, remediation and control refs. It saves findings no stage saved yet (the grounded checks), and it refreshes control refs on findings stored by earlier runs, as before.
  • A person's choice is kept. Triage writes a status only onto a row that is still open. Someone who sets "Risiko akzeptiert" while the scan runs keeps it.
  • Unchanged:
    • Stage 6 (tracker issues) still gets this run's new findings, now in their final state.
    • The new-findings email (#360) fires after the run and reads the final state from the database.
  • A run that fails partway keeps what its stages already saved, in line with "never hide a finding" (#367). Its counter matches what was saved.
  • Out of scope: the PLC path still saves at the end of its stage, as before.

Dashboard

  • While a run is running, its card shows the rising new-findings count and its newest findings (up to six), refreshed every 5 s.
  • The rows are keyed by id, so only newly arrived ones fade in (the #389 animation).
  • Each row carries "wird bewertet" until triage has run.

Server push: proposed as a follow-up

#372 also asks for pushing progress to the dashboard. Stages take seconds to minutes, so the existing 5 s polling of the run and of its findings (the scan_run_id filter from #389) looks the same to a customer. A push stream would have to pass through a dashboard server function, the session auth and Orca's ingress, and each of those can buffer or cut a long-lived connection. I'd file that as its own issue rather than put it in this PR.

Nightly

Exact finding sets are unchanged: the same findings, saved earlier.

Checked

  • cargo fmt --all --check.
  • clippy --all-targets -- -D warnings for the agent and the dashboard (server, web).
  • Tests: agent 451, core 99, control-map 12, dashboard 53 / 37, manual findings 2.
  • New test tests/live_findings.rs, against a live Mongo:
    • a SAST finding is visible and counted as soon as its stage ends;
    • the same output again saves nothing;
    • triage's rationale and refs land on the same row, while the status a person set mid-run stays;
    • a grounded finding is saved with triage's status;
    • an earlier run's finding is never saved twice.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Refs #372. Covers everything except server push, which I propose as a follow-up (see below). Findings used to be saved only at the very end of a scan, after triage, so nothing appeared until the run was over. Now each scanner stage saves its new findings as soon as it ends, and triage later updates those same rows. ## Pipeline (`compliance-agent`) - **New `pipeline/finding_store.rs` (`RunFindings`):** - `save_new` runs after each scanner stage: SAST (semgrep and cppcheck), patterns, secrets, lint. One `$in` query finds which fingerprints are already stored; the first-seen findings are saved with one `insert_many` (a fingerprint reported twice in one run is saved once). It raises the run's `new_findings_count` with `$inc`, so the count rises during the scan. This replaces the old `find_one` plus `insert_one` per finding. - `write_back` runs after triage (5, 5b–5d). On rows saved in this run it stores severity, confidence, triage action and rationale, remediation and control refs. It saves findings no stage saved yet (the grounded checks), and it refreshes control refs on findings stored by earlier runs, as before. - **A person's choice is kept.** Triage writes a status only onto a row that is still `open`. Someone who sets "Risiko akzeptiert" while the scan runs keeps it. - **Unchanged:** - Stage 6 (tracker issues) still gets this run's new findings, now in their final state. - The new-findings email (#360) fires after the run and reads the final state from the database. - **A run that fails partway** keeps what its stages already saved, in line with "never hide a finding" (#367). Its counter matches what was saved. - **Out of scope:** the PLC path still saves at the end of its stage, as before. ## Dashboard - While a run is running, its card shows the rising new-findings count and its newest findings (up to six), refreshed every 5 s. - The rows are keyed by id, so only newly arrived ones fade in (the #389 animation). - Each row carries "wird bewertet" until triage has run. ## Server push: proposed as a follow-up #372 also asks for pushing progress to the dashboard. Stages take seconds to minutes, so the existing 5 s polling of the run and of its findings (the `scan_run_id` filter from #389) looks the same to a customer. A push stream would have to pass through a dashboard server function, the session auth and Orca's ingress, and each of those can buffer or cut a long-lived connection. I'd file that as its own issue rather than put it in this PR. ## Nightly Exact finding sets are unchanged: the same findings, saved earlier. ## Checked - `cargo fmt --all --check`. - `clippy --all-targets -- -D warnings` for the agent and the dashboard (`server`, `web`). - Tests: agent 451, core 99, control-map 12, dashboard 53 / 37, manual findings 2. - **New test** `tests/live_findings.rs`, against a live Mongo: - a SAST finding is visible and counted as soon as its stage ends; - the same output again saves nothing; - triage's rationale and refs land on the same row, while the status a person set mid-run stays; - a grounded finding is saved with triage's status; - an earlier run's finding is never saved twice. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-09-25 19:32:01 +00:00
feat(scan): findings are saved as each stage ends, and show while the scan runs (#372)
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 6m45s
3dad187c5d
Each scanner stage now saves its first-seen findings in one query and
one insert, and counts them on the run; triage updates the same rows at
the end, writing a status only onto a row still open so a person's
choice made during the scan is kept. The dashboard shows a running
scan's newest findings as they arrive.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 6d78d2cd1e into main 2026-09-25 19:38:58 +00:00
Sign in to join this conversation.