Skip to content

Reactivate resolved vulnerability findings instead of duplicating rows - #212

Merged
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-204-nge3ls
Jul 26, 2026
Merged

Reactivate resolved vulnerability findings instead of duplicating rows#212
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-204-nge3ls

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Summary

UpsertVulnerabilityFindingsAsync now builds its match lookup from all findings of an image version instead of the active ones only. Where several rows share a finding identity, the active row wins; among resolved rows the most recently resolved one is picked. A match against a resolved row reactivates it in place — IsActive = true, ResolvedAtUtc and ResolvedByScanRunId cleared, ScanRunId stamped with the current run and a fresh DetectedAtUtc for the new active period. The stale pass at the end of the upsert now iterates only over rows that were already active when the run started, so a row reactivated in the same run cannot be deactivated again.

Why

The lookup was restricted to active findings, so an advisory that had been resolved in an earlier run and was reported again never matched. Each re-detection inserted a brand-new row while the old one stayed behind as a resolved tombstone. That grew the findings table by a full copy of the finding set per resolve/re-detect cycle — 1236 extra rows for an image with 1236 findings — until ScanCleanupBackgroundService passed the retention cutoff, and it reported every re-detected CVE as brand new even though it was already known.

Linked issues

Closes #204

Review notes

  • The unique filtered index on (ImageVersionId, AdvisoryId, AffectedPackage) only covers active rows, so reactivation cannot collide with an existing active row for the same identity.
  • Legacy duplicates already in the database need no migration; they are resolved rows and are removed by the retention cleanup. The new preference order keeps updating the active row for such identities.
  • Three tests were added to VulnerabilityEnrichmentServiceTests: reactivation instead of insert, a reactivated row surviving the stale pass of the same run, and a legacy active/resolved pair resolving to the active row.

Follow-up work

None

The upsert built its match lookup from active findings only, so an advisory
that was resolved in an earlier run and reappeared was inserted as a new row
while the old row stayed behind as a tombstone. The lookup now covers all
findings of the image version and prefers the active row, falling back to the
most recently resolved one. A matched resolved row is reactivated in place with
a cleared resolution state and the current scan run, and the stale pass only
considers rows that were already active when the run started. Closes #204.
@sonarqubecloud

Copy link
Copy Markdown

@LarsLaskowski
LarsLaskowski merged commit 522278e into main Jul 26, 2026
4 checks passed
@LarsLaskowski
LarsLaskowski deleted the claude/issue-204-nge3ls branch July 26, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Reactivate resolved vulnerability findings instead of inserting duplicate rows

2 participants