Skip to content

Fix OS versions not populated in vulnerability details - #42759

Merged
mostlikelee merged 3 commits into
mainfrom
fix-os-versions-vuln-details
Apr 1, 2026
Merged

Fix OS versions not populated in vulnerability details#42759
mostlikelee merged 3 commits into
mainfrom
fix-os-versions-vuln-details

Conversation

@mostlikelee

@mostlikelee mostlikelee commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds UpdateOSVersions to the vulnerability cron so aggregated_stats is refreshed immediately after vulnerability scanning completes
  • Fixes issue where os_versions array is empty when viewing OS-only vulnerabilities (e.g., macOS CVEs)

Resolves #40581

Root Cause

OSVersionsByCVE() intersects operating_system_vulnerabilities (populated by vuln cron) with aggregated_stats (populated by UpdateOSVersions in cleanups cron). The cleanups cron runs hourly, creating up to 1 hour lag where os_versions data is stale/empty.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where OS versions were not populated in vulnerability details for OS-only vulnerabilities, such as macOS CVEs.

Fixes issue where `os_versions` array is empty in vulnerability details
for OS-only vulnerabilities (e.g., macOS CVEs). This happened because
`OSVersionsByCVE()` intersects `operating_system_vulnerabilities` with
`aggregated_stats`, but the latter was only updated by the hourly
cleanups cron, creating up to 1 hour lag after vulnerability scanning.

By adding `UpdateOSVersions` to the vulnerability cron, the aggregated
stats are refreshed immediately after vulnerability scanning completes.
The operation remains in the cleanups cron as well for cases where
vulnerability scanning is disabled.
@mostlikelee

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This change addresses an issue where OS versions were not populated in vulnerability details for OS-only vulnerabilities like macOS CVEs. The fix adds a new vulnerability-processing step to the vulnerability processing pipeline that calls UpdateOSVersions on the datastore. The change includes both documentation updates in the changelog and a modification to the vulnerability processing workflow in the command layer to execute this update step during the main processing loop.

Possibly related PRs

  • 31214 linux vulns optimization #31722: Adds a different NamedVulnFunc to the same getVulnFuncs function for kernel software mapping updates, following the same pattern of extending the vulnerability processing pipeline.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main bug fix in the changeset: populating OS versions in vulnerability details.
Description check ✅ Passed The description clearly explains the fix, root cause, and references the related issue #40581; however, it does not follow the provided template structure or mention testing details.
Linked Issues check ✅ Passed The changes address the core issue #40581 by adding UpdateOSVersions to the vulnerability cron, eliminating the lag that caused empty os_versions in CVE details.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue: a changelog entry and a code change to add UpdateOSVersions to the vulnerability processing pipeline.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-os-versions-vuln-details

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/fleet/vuln_process.go (1)

198-205: Good placement for update_os_versions; add explicit runtime observability.

This ordering is correct for reducing stale os_versions in CVE details right after vuln processing. Since UpdateOSVersions is a full aggregation, please add/confirm a dedicated metric (duration + failures) for vuln.update_os_versions so DB pressure/regressions are visible early.

Based on learnings: In cmd/fleet/cron.go, cleanup sequencing after vulnerability writes is deliberate to avoid lock contention with software_cve and operating_system_vulnerabilities.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/fleet/vuln_process.go` around lines 198 - 205, Wrap the call to
ds.UpdateOSVersions (inside the vuln.update_os_versions tracer span in
vuln_process.go) with explicit runtime observability: record a duration metric
(e.g., vuln.update_os_versions.duration_seconds as a histogram/summary) starting
just after tracer.Start and observe it when the call returns, and increment a
failure counter (e.g., vuln.update_os_versions.failures_total) if
UpdateOSVersions returns an error; ensure you use the project’s existing metrics
helper/registry and include the error branch to increment the failure metric
before returning the error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/fleet/vuln_process.go`:
- Around line 198-205: Wrap the call to ds.UpdateOSVersions (inside the
vuln.update_os_versions tracer span in vuln_process.go) with explicit runtime
observability: record a duration metric (e.g.,
vuln.update_os_versions.duration_seconds as a histogram/summary) starting just
after tracer.Start and observe it when the call returns, and increment a failure
counter (e.g., vuln.update_os_versions.failures_total) if UpdateOSVersions
returns an error; ensure you use the project’s existing metrics helper/registry
and include the error branch to increment the failure metric before returning
the error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 455f01c0-b22d-4624-8ecf-f76b34ce4fb8

📥 Commits

Reviewing files that changed from the base of the PR and between 617cf71 and 7dc7e38.

📒 Files selected for processing (2)
  • changes/40581-os-versions-vuln-details
  • cmd/fleet/vuln_process.go

@codecov

codecov Bot commented Mar 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.79%. Comparing base (8d63bf2) to head (26274d0).
⚠️ Report is 79 commits behind head on main.

Files with missing lines Patch % Lines
cmd/fleet/vuln_process.go 16.66% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #42759      +/-   ##
==========================================
+ Coverage   66.72%   66.79%   +0.07%     
==========================================
  Files        2536     2536              
  Lines      203587   203855     +268     
  Branches     9077     9077              
==========================================
+ Hits       135834   136160     +326     
+ Misses      55461    55349     -112     
- Partials    12292    12346      +54     
Flag Coverage Δ
backend 68.61% <16.66%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mostlikelee
mostlikelee marked this pull request as ready for review March 31, 2026 20:25
@mostlikelee
mostlikelee requested a review from a team as a code owner March 31, 2026 20:25
Copilot AI review requested due to automatic review settings March 31, 2026 20:25

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a lag where OS-only vulnerability details could show an empty os_versions array by ensuring OS version aggregated stats are refreshed as part of the vulnerabilities schedule.

Changes:

  • Adds an update_os_versions job to the vulnerability processing schedule (getVulnFuncs) to refresh aggregated_stats.
  • Adds a release-note entry describing the fix for OS-only vulnerability details.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
cmd/fleet/vuln_process.go Adds UpdateOSVersions as a scheduled vulnerability-processing step (used by both cron scheduling and the vuln_processing command).
changes/40581-os-versions-vuln-details Release note documenting the OS versions population fix for OS-only vulnerabilities.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/fleet/vuln_process.go Outdated
cronVulnerabilities calls ds.OSVersions() to get the list of OS versions
to scan. This reads from aggregated_stats, so UpdateOSVersions must run
first to ensure fresh data is available for the vulnerability scanner.
@mostlikelee
mostlikelee merged commit baa4634 into main Apr 1, 2026
48 checks passed
@mostlikelee
mostlikelee deleted the fix-os-versions-vuln-details branch April 1, 2026 23:09
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.

Inconsistent view of vulnerabilities

3 participants