Repository navigation
feat(explain): model attempts, scopes and causal origins in reports - #976
Conversation
Add optional invocation-use and logical-scope ownership, per-result and per-proof conditionality, bounded causal input identities and context paths. Preserve failed attempts separately from successful proof causes and distinguish uncaptured bindings from captured empty bindings. Document Rust and legacy JSON migrations and parameter-binding evidence; cover nested comprehension subjects and equal-valued helper arguments without inventing body predicates. These are report contracts, not a runtime producer. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The report can incorrectly label result existence as concrete even when assumption-dependent conflicts or errors may still cause evaluation to fail.
5 open issues
Clarify conditionality when assumptions can cause rule failures · New Add query-owned calls and scopes for arbitrary expressions · New Limit negation parity to syntactic nesting · New Link caller conditions and derivations to specific call uses · New Assign the completed negation to the enclosing scope · New
What changed in this PR
Extends Regorus’s explanation report contracts with metadata for attempts, scopes and causal origins. This change adds types, serialization rules and fixtures—not a live explanation producer.
Changes:
- Models failed alternatives, nested scopes and cached callee uses.
- Adds result/proof conditionality, computed-value origins, context paths and optional conflict keys.
- Distinguishes uncaptured bindings from captured-empty bindings and documents Rust source migration while retaining JSON schema version 2.
| File | Description |
|---|---|
src/explain/tests.rs |
Adds contract tests for ownership, origins, conditionality and capture states. |
src/explain/settings.rs |
Clarifies path capture and redaction behavior. |
src/explain/report.rs |
Defines and serializes the new explanation metadata. |
src/explain/mod.rs |
Exports new types and documents compatibility changes. |
src/explain/fixtures.rs |
Updates sample reports for new fields and optional bindings. |
Review effort: Max
Represent query-owned checks and scopes without fabricated rule attempts. Give call uses unique ids and explicit dependency paths, distinguish completed constructs from enclosing scopes, and restrict conditionality and negation context to what the evidence establishes. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The explanation model omits query witness and binding metadata, embeds caller-specific prefixes in shared proofs, and lacks explicit operand-use associations and accurate comprehension site kinds.
4 open issues
5 resolved since last review
Review effort: Max
Retain query binding and witness metadata and identify standalone comprehension sites. Associate each operand with its contributing call uses and anchor shared invocation proof paths locally, keeping external query prefixes on query evidence. Cover equal-valued siblings and cached nested uses with source-consistent fixtures. Co-authored-by: Copilot <[email protected]>
Name key and value iteration roles and retain actual arguments on caller-owned uses. Link callee binding and body operands through typed parameter projections, preserving shared proof roots and cached-use identity. Resolve comprehension kinds through matching construct sites and preserve uncertainty for uncaptured or constructed-element provenance. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved issues include an avoidable loss of QueryTarget: Eq, test expectations that double-count cached uses as derivations, and misleading loop-binding documentation.
4 open issues
3 resolved since last review
Review effort: Max
| #[derive(Debug, Clone, PartialEq, Eq, Serialize)] | ||
| /// absent. Optional `calls` and `scopes` describe evaluation outside any | ||
| /// rule invocation, including arbitrary query expressions. | ||
| #[derive(Debug, Clone, PartialEq, Serialize)] |
| /// [`witness`](ConditionExplanation::witness). `Some([])` means no loop | ||
| /// contributed; `None` means iteration bindings were not captured. |
| /// Variable bound to the iteration key, absent if unnamed or uncaptured. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub key_binding: Option<String>, | ||
| /// Variable bound to the iteration value, absent if unnamed or uncaptured. | ||
| /// These roles apply to every iteration, not just the retained sample. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub value_binding: Option<String>, |
| Count::Exact(2), | ||
| Vec::new(), | ||
| vec![proof(1), proof(2)], |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved findings identify missing fallback guard dependencies and critical test fixtures that merge distinct function invocations or miscount helper uses as separate result derivations.
7 open issues
Use distinct invocations for uncached function calls · New Preserve eligibility dependencies in fallback proofs · New Count producing paths, not cached uses, as derivations Document value-binding conventions for single- and two-variable loops Qualify the empty-bindings guarantee for nested-scope loop evidence Preserve QueryTarget Eq by deriving Eq through its fields Anchor derivation indices to the proof's containing invocation · New
Review effort: Max
| use_id: 6, | ||
| call_instance: 4, |
| /// Contributing callee-use ids, resolving to [`CallUse::use_id`] across | ||
| /// the owning invocation's calls and their descendants, never its | ||
| /// external caller/query prefixes. Includes nested uses, not failed | ||
| /// alternatives. `None` means not captured; `Some([])` means none | ||
| /// contributed. Individual checks retain their ordered use chains. |
| /// Producing body attempt, resolving in the queried invocation's | ||
| /// [`RuleExplanation::attempts`]. Absent when not captured. |
Restore query equality, distinguish producing paths from callee uses, preserve uncached function identities, and clarify loop binding capture. Co-authored-by: Copilot <[email protected]>
Anand Krishnamoorthi (anakrish)
left a comment
There was a problem hiding this comment.
LGTM. I will run one more review to catch any more high priority issues. Those can however be fixed in subsequent PRs.
e3686b2
into
microsoft:main



Summary
Extend explanation report contracts so consumers can distinguish producing attempts from failed alternatives, syntactic scopes, callee uses, and concrete versus assumption-dependent contributions.
These are report types, serialization rules, documentation and fixtures only. Runtime event capture, bounded tracing and report construction remain separate work; this change does not expose a live explanation producer.
Details
Compatibility
This intentionally changes Rust source interfaces:
Derivation.bindingsbecomesOption<Vec<IterationBinding>>;RuleOutcome::Conflictconstructions and exact patterns must account for the optionalkey. Direct constructors initialize added optional capture fields, including proof eligibility, witness roles, caller arguments and parameter origins.QueryTargetretainsEq; the captured argument types also implement it.JSON schema version 2 is retained. Omission means unknown capture state, including legacy reports that omitted empty or uncaptured bindings; only explicit
[]certifies captured empty. Empty bindings certify no result-producing iteration bindings, not no contributing nested loops. New capture fields are optional; rule-scope attempts remain required. Parameter projection paths distinguish absent/withheld/unrepresentable from explicit[]for the whole argument. Consumers should accept additional causality fields and enum variants; partial-evaluation fail-closed rules are unchanged.Related
Follows #955.
Testing