Repository navigation
fix(rvm): match OPA for undefined rules and subpackages in packages - #967
Merged
Anand Krishnamoorthi (anakrish) merged 1 commit intoNov 20, 2026
Conversation
Collaborator
|
snehabandla Rebase to latest main to fix the dependency audit errors. |
Reading a package as a value (`data.pkg`) in the RVM inserted an
`Undefined` entry for every rule in the package that was undefined, so
`count`, `object.keys`, iteration, equality and `json.marshal` saw keys
that OPA and the interpreter omit. The virtual document traversal now
skips undefined rule results and keeps subpackages as objects, so a
subpackage whose rules are all undefined reads as `{}`, as in OPA.
Subpackages that contain no rules (only functions, or nothing) were
missing from package values, and reading such a package directly was
undefined. The compiler now gives each package under a read path an
empty rule tree node and reads the path through the virtual document
lookup, so these subpackages read as `{}` as well. Package paths are
computed once per compile. Programs that do not read such a path
compile as before.
Packages without rules never conflict with base data: a non-object
base data value at or above a package path is returned as is, and
object values gain the missing subpackages as `{}`, as in OPA. A
package with only functions over non-object base data behaves the same
way; OPA rejects that policy at compile time.
Co-authored-by: Copilot <[email protected]>
snehabandla
force-pushed
the
fix/rvm-package-value-undefined-rules
branch
from
November 18, 2026 19:57
7415923 to
31da8b2
Compare
This was referenced Nov 18, 2026
Anand Krishnamoorthi (anakrish)
approved these changes
Nov 19, 2026
Anand Krishnamoorthi (anakrish)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM
| check( | ||
| &[CONSUMERS, SUB, INNER], | ||
| &[ | ||
| ("data.probe.result", EMPTY, Some(SUB_EMPTY)), |
Collaborator
There was a problem hiding this comment.
snehabandla I wonder if the yaml testing framework can be extended to run multiple such cases without having to write rust based tests.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Undefined package slots cause inconsistent data reads, while discarded allocator errors can let compilation continue with an incomplete rule tree.
2 open issues
What changed in this PR
Aligns RVM package-value reads with OPA and the interpreter: undefined rules are omitted, and subpackages without rules appear as empty objects.
Changes:
- Filters undefined rule results and materializes empty subpackages during virtual document lookup.
- Tracks package paths during compilation and adjusts base-data conflict handling for rule-less packages.
- Adds differential coverage for the interpreter and both RVM execution modes, plus a changelog entry.
| File | Description |
|---|---|
tests/rvm/rego/package_value_differential.rs |
Tests package values, derived operations, dynamic reads, and base-data merging. |
tests/rvm/rego/mod.rs |
Registers the new differential tests. |
src/rvm/vm/virtual_data.rs |
Omits undefined rules and creates empty package objects during lookup. |
src/rvm/program/rule_tree.rs |
Allows non-object base data beneath rule-less package paths. |
src/languages/rego/compiler/references.rs |
Uses virtual lookup for matching package paths, including dynamic reads. |
src/languages/rego/compiler/mod.rs |
Computes and stores package paths once per compilation. |
CHANGELOG.md |
Documents the corrected RVM package-value behavior. |
Review effort: Max
Comment on lines
+218
to
+224
| // Errors are ignored: a rule already defined on this path keeps | ||
| // its leaf (OPA rejects such policies). | ||
| if let Ok(node @ &mut Value::Undefined) = | ||
| self.program.rule_tree.make_or_get_value_mut(&package_path) | ||
| { | ||
| *node = Value::new_object(); | ||
| } |
| let Value::Object(ref mut map) = *node else { | ||
| return Ok(()); | ||
| }; | ||
| node = crate::Rc::make_mut(map).get_or_insert_with(key.clone(), Value::new_object); |
| .inner | ||
| .modules | ||
| .iter() | ||
| .filter_map(|module| get_rule_path_components(&module.package.refr).ok()) |
Anand Krishnamoorthi (anakrish)
merged commit Nov 20, 2026
cec3adb
into
microsoft:main
61 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Reading a package as a value in the RVM (
result := data.probe.sub) included anUndefinedentry for each undefined rule of the package, and left out subpackages that contain no rules. OPA and the interpreter omit undefined rules and show rule-less subpackages as{}.With input
{}, OPA and the interpreter return{"defined": 1}. Before this change, both RVM execution modes returned{"defined": 1, "undefined_body": Undefined, "undefined_value": Undefined}.package a.zOPA and the interpreter read
data.aas{"b": {}, "x": 1, "z": {}}anddata.a.b/data.a.zas{}. Before this change, the RVM returned{"x": 1}and leftdata.a.banddata.a.zundefined.Details
VirtualDataDocumentLookupbuilds a package's value by walking the rule tree and evaluating each rule (traverse_rule_tree_subobjectinsrc/rvm/vm/virtual_data.rs). It stored every rule result, includingUndefined. It now skipsUndefinedresults and creates an object for every subpackage it visits, so a subpackage whose rules are all undefined still reads as{}. Defined rules are kept, including rules whose value isfalse, default values and empty partial sets or objects.compile_data_chaininsrc/languages/rego/compiler/references.rsnow gives every package path under the read path an empty rule tree node and uses the virtual document lookup when the read path is a prefix of a package path (dynamic components such asdata.a[k]match any package name). Package paths are computed once per compile. Programs that do not read such a path compile exactly as before.RegoVM::set_dataonly reports a conflict for non-object base data when the rule tree below that path contains a rule (contains_ruleinsrc/rvm/program/rule_tree.rs), and the lookup keeps non-object base data instead of replacing it with a package object.Compatibility
Package values that used to contain
Undefinedentries no longer do. As a result,count,object.keys, iteration and equality on them change, andjson.marshalno longer emits"<undefined>"strings. Rule-less subpackages now appear as{}. The new results match OPA and the interpreter. Packages without rules never conflict with base data: a non-object base data value at or above a package path is returned as is (with{"a": {"b": "str"}}and an emptypackage a.b,data.a.bis"str"), and object values gain the missing subpackages as{}, as in OPA. A package with only functions over non-object base data behaves the same way; OPA rejects that policy at compile time (conflicting rule for data path a/b/f found). Package values whose rules are all defined and that have no rule-less subpackages are unchanged.Merge note
The
### Fixedheading added under## [Unreleased]inCHANGELOG.mdmay conflict with #964, which adds the same heading. Resolve by keeping one### Fixedheading with both entries.Testing
tests/rvm/rego/package_value_differential.rs(5 tests): evaluates each query in the interpreter and in both RVM execution modes (run-to-completion and suspendable), building the engine once per test and setting the input per case. Expected values were checked against OPA 1.2.0. It covers the package value,count,object.keys,some k, _ initeration,==,json.marshaland membership of an undefined key, with inputs where rules are undefined, partly defined, and all defined (including non-empty partial sets and objects). It also covers a parent package that contains a subpackage, an empty subpackage, a package whose rules are all undefined, subpackages with only functions or no rules (read directly and through a dynamic key,data.a[input.k]), and packages without rules over object and non-object base data. Two base-data cases ({"a": "str"}withpackage a.b, and{"a": {"b": "str"}}withpackage a.b.c) skip the interpreter, which fails on them withmake: not an objecton the base commit as well. All 5 tests fail on the unchanged source (RVM only) and pass with this change.cargo fmt --checkcargo clippy --all-targets --all-features -- -D warningscargo clippy --no-default-features -- -D warningscargo test --all-features --test mod(424 passed)cargo test --all-features --lib(1038 passed, 2 ignored)cargo xtask pre-push(OPA conformance: 2869 passed, 0 failed, 6 skipped)