Skip to content

Rename nontrivial_residual_policies to residual_policies; residual_policies to policies - #2418

Merged
john-h-kastner-aws merged 11 commits into
mainfrom
tpe-api-tweaks
Jun 25, 2026
Merged

Rename nontrivial_residual_policies to residual_policies; residual_policies to policies #2418
john-h-kastner-aws merged 11 commits into
mainfrom
tpe-api-tweaks

Conversation

@john-h-kastner-aws

@john-h-kastner-aws john-h-kastner-aws commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Description of changes

  • Deprecate nontrivial_residual_policies
  • Change residual_policies to return only non-trivial residual policies
  • Add policies matching original behavior of residual_policies, plus policy_set to get these policy collected into a PolicySet
  • Add get_policy to lookup a partially evaluated policy by id, which may be useful when using one of the policy id iterators

Not attached to these exact names if there are any strong opinions, but I do think the current combination of nontrivial_residual_policies and residual_policies is bad.

Also contain an unrelated change to document some slightly subtle invariant on query_resource and query_principal.

Issue #, if available

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).
  • A backwards-compatible change requiring a minor version bump to cedar-policy (e.g., addition of a new API).
  • A bug fix or other functionality change requiring a patch to cedar-policy.
  • A change "invisible" to users (e.g., documentation, changes to "internal" crates like cedar-policy-core, cedar-validator, etc.)
  • A change (breaking or otherwise) that only impacts unreleased or experimental code.

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).
  • Does not update the CHANGELOG because my change does not significantly impact released code.

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-spec, and how you have tested that your updates are correct.)
  • Requires updates, but I do not plan to make them in the near future. (Make sure that your changes are hidden behind a feature flag to mark them as experimental.)
  • I'm not sure how my change impacts cedar-spec. (Post your PR anyways, and we'll discuss in the comments.)

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar language specification.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-docs. PRs should be targeted at a staging-X.Y branch, not main.)
  • I'm not sure how my change impacts the documentation. (Post your PR anyways, and we'll discuss in the comments.)

@john-h-kastner-aws
john-h-kastner-aws requested review from luxas and victornicolet and removed request for luxas June 19, 2026 22:04
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
@john-h-kastner-aws

john-h-kastner-aws commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

DRT build failure is expected due to API change.

semver-checks failure is warning that adding #[deprected] should be on a minor because it introduces new compile warnings. Since this is an experimental API, we're fine with making the change on a patch.

It's also worth calling out that the behavior change in residual_policies could be breaking for some callers. If they depend on getting all policies from this function, then they need to update to policies or risk being broken. This is also acceptable for an experimental API and is documented in the changelog

@github-actions

Copy link
Copy Markdown

Coverage Report

Head Commit: ba46ba3aa5db5aadd91a115ebf05750e15f3040a

Base Commit: 1171b5f5111eeff86616f4a9aa1d45702941cc69

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 93.55%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/command/tpe.rs 🟢 1/1 100.00%
cedar-policy-core/src/tpe/response.rs 🟢 5/5 100.00%
cedar-policy/src/api/tpe.rs 🟢 52/56 92.86% 616-617, 620, 622

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.94%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% 92.55%
cedar-policy 🟢 4557/5679 80.24% 80.41%
cedar-policy-cli 🟡 1257/1649 76.23% 76.23%
cedar-policy-core 🟢 24724/28046 88.16% 88.14%
cedar-policy-formatter 🟢 914/1088 84.01% 84.01%
cedar-policy-symcc 🟢 6827/7308 93.42% 93.42%
cedar-wasm 🔴 0/28 0.00% 0.00%

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 refines the experimental TPE (“type-aware partial evaluation”) residual-policy APIs to reduce naming confusion: TpeResponse::residual_policies() now yields only non-trivial residuals, the old nontrivial_residual_policies() is deprecated, and a new TpeResponse::policies() exposes the original “all residuals” behavior. It also renames several cedar-policy-core tpe::response::Response accessors to better reflect semantics (true_*, policies), updates CLI output accordingly, and documents an invariant for query request wrappers.

Changes:

  • Adjust TPE residual policy iterators: non-trivial residuals via residual_policies(), all residuals via new policies(), deprecate nontrivial_residual_policies().
  • Rename cedar-policy-core TPE Response iterators/accessors (satisfied_*true_*, residual_policiespolicies) and update tests/callers.
  • Update CLI TPE command output and add CHANGELOG entry for the API behavior change.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
cedar-policy/src/api/tpe.rs Updates public TPE response API (residual_policies semantics, adds policies, deprecates alias) and adjusts permission-query implementation.
cedar-policy/CHANGELOG.md Documents the updated TPE residual policy API behavior and new iterator name.
cedar-policy-core/src/tpe/response.rs Renames core TPE response accessors and changes get_residual return type; adds new policies() iterator.
cedar-policy-core/src/tpe.rs Updates tests to match the new core TPE response accessor names and types.
cedar-policy-cli/src/command/tpe.rs Updates CLI output to print all residuals using ans.policies().

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

Comment thread cedar-policy/src/api/tpe.rs Outdated
Comment thread cedar-policy/src/api/tpe.rs Outdated
Comment thread cedar-policy-core/src/tpe/response.rs
Comment thread cedar-policy-core/src/tpe/response.rs
Comment thread cedar-policy-core/src/tpe/response.rs Outdated
john-h-kastner-aws and others added 4 commits June 22, 2026 15:56
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
@github-actions

Copy link
Copy Markdown

Coverage Report

Head Commit: ca284d5acb57146f7b3228475d54b3713ee8ba03

Base Commit: 1171b5f5111eeff86616f4a9aa1d45702941cc69

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 95.24%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/command/tpe.rs 🟢 1/1 100.00%
cedar-policy-core/src/tpe/response.rs 🟢 12/12 100.00%
cedar-policy/src/api.rs 🟢 4/4 100.00%
cedar-policy/src/api/tpe.rs 🟢 61/65 93.85% 623-624, 627, 629
cedar-policy/src/proto/api.rs 🟢 1/1 100.00%
cedar-policy/src/proto/traits.rs 🟢 1/1 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.94%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% 92.55%
cedar-policy 🟢 4568/5690 80.28% 80.41%
cedar-policy-cli 🟡 1257/1649 76.23% 76.23%
cedar-policy-core 🟢 24724/28049 88.15% 88.14%
cedar-policy-formatter 🟢 914/1088 84.01% 84.01%
cedar-policy-symcc 🟢 6834/7315 93.42% 93.42%
cedar-wasm 🔴 0/28 0.00% 0.00%

@github-actions

Copy link
Copy Markdown

Coverage Report

Head Commit: c276ce07bc7ab7e5b68e6e922939d2a18257d508

Base Commit: 1171b5f5111eeff86616f4a9aa1d45702941cc69

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 95.24%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/command/tpe.rs 🟢 1/1 100.00%
cedar-policy-core/src/tpe/response.rs 🟢 12/12 100.00%
cedar-policy/src/api.rs 🟢 4/4 100.00%
cedar-policy/src/api/tpe.rs 🟢 61/65 93.85% 623-624, 627, 629
cedar-policy/src/proto/api.rs 🟢 1/1 100.00%
cedar-policy/src/proto/traits.rs 🟢 1/1 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.94%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% 92.55%
cedar-policy 🟢 4568/5690 80.28% 80.41%
cedar-policy-cli 🟡 1257/1649 76.23% 76.23%
cedar-policy-core 🟢 24724/28049 88.15% 88.14%
cedar-policy-formatter 🟢 914/1088 84.01% 84.01%
cedar-policy-symcc 🟢 6834/7315 93.42% 93.42%
cedar-wasm 🔴 0/28 0.00% 0.00%

@luxas luxas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the followup, looks nice 👍

Comment thread cedar-policy-core/src/tpe/response.rs Outdated
Comment thread cedar-policy-core/src/tpe/response.rs Outdated
Comment thread cedar-policy/src/api/tpe.rs
Comment thread cedar-policy/src/api/tpe.rs Outdated
/// Call [`Policy::to_pst()`] on each result to get a [`crate::pst::Policy`]
/// for structured inspection. Residual expressions may contain
/// [`crate::pst::Expr::ResidualError`] nodes indicating subexpressions that
/// would error at runtime; use [`crate::pst::Expr::has_error()`] to check.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would certainly or could possibly error? I guess that those that did concretely error already should not be shown here, but those that certainly will error should be here, as we don't know yet which exact error it will be, and thus it is non-trivial.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmmm, the whole has_error function is questionably useful. It says only that there is some subexpression which, if evaluated, will evaluate to an error. But, the subexpression might never be evaluated, or some other expression might error regardless of what has_error returns.

I think it's only useful when you want to represent a residual as cedar policy text since error residuals aren't directly representable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated comment here and on has_error to be clearer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, it feels like this is one of the things that will get easier to reason about once I add the possible_bool_outcomes after my vacation 👍

Comment thread cedar-policy/src/api/tpe.rs Outdated
Comment thread cedar-policy/src/api/tpe.rs Outdated
Comment thread cedar-policy/src/api/tpe.rs
Comment thread cedar-policy-core/src/tpe.rs Outdated
john-h-kastner-aws and others added 3 commits June 23, 2026 13:38
Co-authored-by: Lucas Käldström <luxas@users.noreply.github.com>
Signed-off-by: John Kastner <jkastner@amazon.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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Comment thread cedar-policy/src/api.rs
Comment thread cedar-policy/src/api/tpe.rs
Comment thread cedar-policy/src/api/tpe.rs
Comment thread cedar-policy/src/api/tpe.rs
Comment thread cedar-policy/CHANGELOG.md Outdated
Comment thread cedar-policy-core/src/tpe/response.rs
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
@github-actions

Copy link
Copy Markdown

Coverage Report

Head Commit: ae747d851a370efe3578e29d64df89b467066944

Base Commit: 1171b5f5111eeff86616f4a9aa1d45702941cc69

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 95.18%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/command/tpe.rs 🟢 1/1 100.00%
cedar-policy-core/src/tpe/response.rs 🟢 12/12 100.00%
cedar-policy/src/api.rs 🟢 4/4 100.00%
cedar-policy/src/api/tpe.rs 🟢 60/64 93.75% 632-633, 638, 640
cedar-policy/src/proto/api.rs 🟢 1/1 100.00%
cedar-policy/src/proto/traits.rs 🟢 1/1 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.94%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% 92.55%
cedar-policy 🟢 4568/5690 80.28% 80.41%
cedar-policy-cli 🟡 1257/1649 76.23% 76.23%
cedar-policy-core 🟢 24734/28059 88.15% 88.14%
cedar-policy-formatter 🟢 914/1088 84.01% 84.01%
cedar-policy-symcc 🟢 6834/7315 93.42% 93.42%
cedar-wasm 🔴 0/28 0.00% 0.00%

@github-actions

Copy link
Copy Markdown

Coverage Report

Head Commit: 4e4965389a1cc6d470fadc08154a1ead097ca920

Base Commit: 1171b5f5111eeff86616f4a9aa1d45702941cc69

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 95.18%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/command/tpe.rs 🟢 1/1 100.00%
cedar-policy-core/src/tpe/response.rs 🟢 12/12 100.00%
cedar-policy/src/api.rs 🟢 4/4 100.00%
cedar-policy/src/api/tpe.rs 🟢 60/64 93.75% 632-633, 638, 640
cedar-policy/src/proto/api.rs 🟢 1/1 100.00%
cedar-policy/src/proto/traits.rs 🟢 1/1 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.94%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% 92.55%
cedar-policy 🟢 4568/5690 80.28% 80.41%
cedar-policy-cli 🟡 1257/1649 76.23% 76.23%
cedar-policy-core 🟢 24734/28059 88.15% 88.14%
cedar-policy-formatter 🟢 914/1088 84.01% 84.01%
cedar-policy-symcc 🟢 6834/7315 93.42% 93.42%
cedar-wasm 🔴 0/28 0.00% 0.00%

@github-actions

Copy link
Copy Markdown

Coverage Report

Head Commit: 11ff87e88a9474ba903a19b33add47493bea6525

Base Commit: 1171b5f5111eeff86616f4a9aa1d45702941cc69

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 95.18%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-cli/src/command/tpe.rs 🟢 1/1 100.00%
cedar-policy-core/src/tpe/response.rs 🟢 12/12 100.00%
cedar-policy/src/api.rs 🟢 4/4 100.00%
cedar-policy/src/api/tpe.rs 🟢 60/64 93.75% 632-633, 638, 640
cedar-policy/src/proto/api.rs 🟢 1/1 100.00%
cedar-policy/src/proto/traits.rs 🟢 1/1 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.94%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% 92.55%
cedar-policy 🟢 4568/5690 80.28% 80.41%
cedar-policy-cli 🟡 1257/1649 76.23% 76.23%
cedar-policy-core 🟢 24734/28059 88.15% 88.14%
cedar-policy-formatter 🟢 914/1088 84.01% 84.01%
cedar-policy-symcc 🟢 6834/7315 93.42% 93.42%
cedar-wasm 🔴 0/28 0.00% 0.00%

@luxas luxas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, LGTM 👍

}

#[track_caller]
pub(super) fn assert_resource_get_attr(residual: &Residual, expected_attr: &str) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I felt it was quite nice to use assert_snapshot and interpret_typed_str_to_str in #2323. I'm thinking to convert most TPE tests to that style down the road.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, insta is really nice. I'd be happy to review PRs adopting it where applicable.

Comment thread cedar-policy-core/src/tpe.rs Outdated
});
});
// (User::"aaron" in (resource["readers"])) || (User::"aaron" in (resource["editors"]))
assert_matches!(residuals.get_residual(policy2.id()).unwrap().get_residual().as_ref(), Residual::Partial { kind: ResidualKind::Or{ left, right }, .. } => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah this was for sure a pain to read, thanks for making it better!

@john-h-kastner-aws
john-h-kastner-aws merged commit aa28dee into main Jun 25, 2026
31 of 34 checks passed
@john-h-kastner-aws
john-h-kastner-aws deleted the tpe-api-tweaks branch June 30, 2026 18:43
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.

4 participants