Skip to content

fix(rego): schedule comprehensions in rule outputs - #825

Open
Maksym (maksym-mishchenko) wants to merge 3 commits into
microsoft:mainfrom
maksym-mishchenko:maksym-mishchenko-rego-inline-comprehension
Open

Maksym (maksym-mishchenko) wants to merge 3 commits into
microsoft:mainfrom
maksym-mishchenko:maksym-mishchenko-rego-inline-comprehension

Conversation

@maksym-mishchenko

Copy link
Copy Markdown
Contributor

Problem

An inline comprehension in a guarded rule output loads and compiles, but interpreter evaluation fails with statements not scheduled in query {query:?} when the guard succeeds. Moving the comprehension into a separate rule works; RVM already handles the inline form.

The reported empty-input failure did not reproduce: empty or missing collections correctly leave the guarded rule undefined, not false.

Fix

I schedule comprehensions in output expressions with the body's local variables visible, including nested outputs, function results, and bodyless partial-set keys. Branch analysis follows the output actually evaluated, preserving else and independent partial-rule body semantics.

Regression tests cover interpreter/RVM parity and fresh-engine eval_rule/eval_query, including empty and missing inputs and duplicate/false array elements.

Verification

  • 24 comprehension cases, 29 Rego YAML test functions, and the public Engine suite passed.
  • cargo xtask ci-debug passed.
  • Repository pre-commit and pre-push checks passed: build, workspace/binding formatting and Clippy, doc tests, no_std build, and OPA conformance (2,875 passed, 0 failed).

Maksym Mishchenko and others added 3 commits September 25, 2026 10:35
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟢 Approval recommended

The scheduler logic aligns with interpreter branch semantics and is comprehensively covered by focused regression tests.

Review effort: Balanced
Findings: None

What changed in this PR

Schedules inline comprehensions in Rego rule outputs so interpreter evaluation matches RVM behavior.

Changes:

  • Schedules comprehensions using body-local scope.
  • Handles nested, function, partial-rule, and else outputs.
  • Adds interpreter/RVM parity and fresh-engine regression tests.
File Description
src/​scheduler.rs Adds output-expression scheduling and nested-scope propagation.
tests/​engine/​mod.rs Tests fresh-engine evaluation and variable safety.
tests/​rvm/​rego/​cases/​comprehensions.yaml Covers comprehension output variants and parity.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants