Skip to content

feat(server): supersede only the verdicts the changed metadata affects - #2432

Merged
tkircsi merged 1 commit into
mainfrom
feat/verdict-invalidation-scope
Oct 29, 2026
Merged

tkircsi merged 1 commit into
mainfrom
feat/verdict-invalidation-scope

Conversation

@tkircsi

@tkircsi tkircsi commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Description

Part of #2343. The first PR made a metadata write supersede a record's verdicts; this one narrows that to the policies whose answer the write can have changed.

A policy's fact dependencies are read off its own source when it compiles — the CEL AST for meta.<group> selects, the Rego module for input.meta.<group> references — and registered with the policy version by the reconciler, in the same call that records the version. Each of the six metadata writers then names the group it changed, and the supersede keeps only the verdicts of versions recorded as reading that group.

This matters for availability, not CPU. A superseded verdict withholds the record until the policy task next runs, and that task is only woken by the indexer on a five-minute default interval. Before this, a rescan that changed nothing a policy reads could hide a record for that long.

Two cases decide correctness, and both are load-bearing in the dependsOnFactGroup predicate. A version with no dependency rows is superseded by anything, because nothing here can say it is unaffected — that is any policy evaluated before an upgrade across this change. A version that reads nothing is recorded explicitly, carrying a none sentinel, which is the only way "reads nothing" is distinguishable from "nothing recorded": both are otherwise an empty query result.

Dependencies are keyed by version, so a verdict from an edited policy is judged by what the version behind it read, not by what the current one reads.

Changes

  • server/policy/factgroups.go: reads the metadata groups a CEL or Rego policy depends on, falling back to all groups when a reference cannot be resolved.
  • server/policy: Evaluator reports FactGroups(), collected at compile time and carried through the registry.
  • RegisterPolicyVersion takes the groups and writes them with the version in one transaction, into a new policy_fact_dependencies table.
  • SupersedePolicyEvaluations takes the fact group that changed and scopes the update to the policies reading it.
  • Each writer names its group: scan reports scan; signature verifications and the signed flag signature; identity claims identity.
  • Docs: the metadata-changes section now says which policies each write reaches.

Testing

Unit tests cover dependency extraction for both engines, the conservative fallbacks, registration, and the scoping — including that each writer reaches its own group, that a policy reading nothing or another group keeps its verdict, that an unrecorded policy is always superseded, and that dependencies follow the version the verdict came from.

Mutation-checked: removing either arm of the predicate, or making a writer name the wrong group, fails tests.

@tkircsi
tkircsi requested a review from a team as a code owner October 29, 2026 08:43
@tkircsi tkircsi self-assigned this Oct 29, 2026
@tkircsi tkircsi added kind/feature Categorizes issue or PR as related to a new feature. area/dir/server labels Oct 29, 2026
@github-actions github-actions Bot added the size/L Denotes a PR that changes 1000-1999 lines label Oct 29, 2026
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.16239% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/policy/registry.go 81.0% 4 Missing ⚠️
server/database/gorm/policy_version.go 90.0% 2 Missing ⚠️
server/policy/factgroups.go 98.1% 1 Missing ⚠️
server/types/database.go 0.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tkircsi
tkircsi added this pull request to the merge queue Oct 29, 2026
@tkircsi
tkircsi removed this pull request from the merge queue due to a manual request Oct 29, 2026
@tkircsi
tkircsi dismissed csirmazbendeguz’s stale review October 29, 2026 13:24

The merge-base changed after approval.

@tkircsi
tkircsi force-pushed the feat/verdict-invalidation-scope branch from 160d6eb to e6fe877 Compare October 29, 2026 13:24
@tkircsi
tkircsi added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 4f85b29 Oct 29, 2026
37 checks passed
@tkircsi
tkircsi deleted the feat/verdict-invalidation-scope branch October 29, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dir/server kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 1000-1999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants