Skip to content

feat(policy): expose scan failure reason in ScanFacts and ScannerResult - #2501

Merged
ramizpolic merged 3 commits into
agntcy:mainfrom
ravithemore:gh-2481-policy-scan-failure-reason
Nov 18, 2026
Merged

ramizpolic merged 3 commits into
agntcy:mainfrom
ravithemore:gh-2481-policy-scan-failure-reason

Conversation

@ravithemore

Copy link
Copy Markdown
Contributor

Closes #2481.

Previously, meta.scan.status reported SCAN_STATUS_FAILED when all stored scanner rows failed, but did not expose the underlying failure reason to policies. Consequently, policies could not distinguish local scanner infrastructure outages (e.g. scanner-timeout, scanner-crashed) from defects attributable to the record or external endpoint (e.g. source-unreachable, endpoint-url-invalid).

Key Changes

  1. Protobuf (proto/agntcy/dir/policy/v1/policy_input.proto):

    • Added ScanFailureReason enum mirroring all 12 scanner.FailureReason values.
    • Added ScanFailureReason failure_reason = 6; to ScannerResult.
    • Added ScanFailureReason failure_reason = 8; to ScanFacts (populated when all failed scanners agree, UNSPECIFIED otherwise).
    • Generated Go code via task gen.
  2. Policy Fact Projection (server/policy/meta.go):

    • Projected failure_reason onto individual ScannerResult entries and aggregate ScanFacts.
  3. GORM Policy Invalidation (server/database/gorm/policy_invalidation.go):

    • Extended scanFactsChanged to check before.FailureReason != after.FailureReason so transitioning failure reasons invalidates cached policy verdicts.
  4. Documentation & Tests:

    • Updated docs/content/dir/dir-content-policy-enforcement.md.
    • Added unit tests in server/policy/meta_test.go and server/database/gorm/policy_invalidation_test.go.

Verification

  • go test -v ./policy (PASS)
  • go test -v -run "TestUpsertScanReport|TestFactGettersAreAccountedFor" ./database/gorm (PASS)
  • go vet ./policy ./database/gorm (PASS)

@ravithemore
ravithemore requested a review from a team as a code owner November 12, 2026 10:39
@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Nov 12, 2026
@ravithemore ravithemore changed the title policy: expose scan failure reason in ScanFacts and ScannerResult feat(policy): expose scan failure reason in ScanFacts and ScannerResult Nov 12, 2026
Comment thread server/policy/meta_test.go Resolved
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ravithemore

Copy link
Copy Markdown
Contributor Author

Added table-driven unit tests in server/policy/meta_test.go covering all ScanFailureReason enum mappings and edge cases to ensure 100% test coverage for the new projection logic.

meta.scan.status reports SCAN_STATUS_FAILED when all scanners fail,
but previously did not expose the failure reason to policies. A policy
could not distinguish local scanner infrastructure outages from defects
attributable to the record or external endpoint.

Add ScanFailureReason enum mirroring scanner.FailureReason, add
failure_reason fields to ScannerResult and ScanFacts, project the
values in server/policy, and extend scanFactsChanged in GORM policy
invalidation to compare failure_reason.

Closes agntcy#2481

Signed-off-by: Ravi Themore <[email protected]>
@lgecse
lgecse force-pushed the gh-2481-policy-scan-failure-reason branch from 13b0ac8 to cfd3f17 Compare November 17, 2026 06:24
@lgecse
lgecse requested a review from ramizpolic November 17, 2026 20:35
@ramizpolic
ramizpolic added this pull request to the merge queue Nov 18, 2026
Merged via the queue into agntcy:main with commit c215276 Nov 18, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: A policy cannot see why a scan failed, so it cannot avoid penalising a record for our own outage

2 participants