Skip to content

feat(explain): model attempts, scopes and causal origins in reports - #976

Merged
Anand Krishnamoorthi (anakrish) merged 5 commits into
microsoft:mainfrom
snehabandla:explain/ownership-contract
Nov 24, 2026
Merged

Anand Krishnamoorthi (anakrish) merged 5 commits into
microsoft:mainfrom
snehabandla:explain/ownership-contract

Conversation

@snehabandla

@snehabandla snehabandla commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Optional invocation-local attempt, scope and call-use lists preserve ownership without joining equal values or parsing condition text. Failed pre-else checks have attempt-owned storage independent of deciding-body summaries. Optional proof eligibility checks retain the failures needed to select an else separately from successful producing-body conditions and unrelated failed alternatives.
  • Arbitrary queries have optional query-owned scopes, uses and checks, including loop witnesses, without fabricated rule/body owners. Two-variable loops name key/value witness roles; single-variable loops retain the value name on the condition. Standalone comprehension sites have a dedicated kind; the captured scope matching that site identifies the collection kind.
  • Report-wide use ids distinguish uses of one cached rule invocation from distinct uncached function invocations. Per-condition and per-operand dependency paths preserve nested caller-to-callee order, sibling dependencies and equal-valued producers. Proof paths and definition/body/attempt indices start at the containing invocation, not an external query. Copied callee checks retain physical ownership.
  • Incoming actual arguments belong to each caller-owned use. Binding and body operands refer to parameter positions and typed argument-relative projections without adding caller paths to shared callee proofs. Aggregate contributor lists do not establish constructed-element lineage; that precision remains unknown without independently captured correspondence. Projection capture and redaction follow concrete-path rules.
  • A completed negation check belongs to its enclosing scope and can identify the dynamic operand scope it completed. Scope parity describes syntactic nesting, not logical influence through intervening operations.
  • Conditionality includes producing and eligibility dependencies independently of retained proof samples; it does not guarantee evaluation success or result existence. Computed operands can carry bounded causal input paths without claiming those paths held the computed value; context is a distinct path root.
  • Derivations count successful producing paths, not separate cached uses on one path. Captured-empty producing bindings do not exclude nested-loop evidence retained on conditions. Partial-object conflicts can report a redacted or elided key.

Compatibility

This intentionally changes Rust source interfaces: Derivation.bindings becomes Option<Vec<IterationBinding>>; RuleOutcome::Conflict constructions and exact patterns must account for the optional key. Direct constructors initialize added optional capture fields, including proof eligibility, witness roles, caller arguments and parameter origins. QueryTarget retains Eq; 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

  • Explanation contract tests cover proof-local ownership, fallback eligibility and unrelated failures, producing-path counts, distinct function invocations, nested/sibling/cached use paths, query-owned checks, parameter projections, false versus undefined, capture-state distinctions and redaction.
  • Feature-enabled and feature-disabled library/integration suites.
  • Minimal explanation suite and explanation-enabled doctests.
  • All-feature/all-target and no-default library Clippy.
  • Normal pre-commit and pre-push checks.

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]>

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.

🟡 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
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

Comment thread src/explain/report.rs Resolved
Comment thread src/explain/report.rs Resolved
Comment thread src/explain/report.rs Resolved
Comment thread src/explain/report.rs Resolved
Comment thread src/explain/tests.rs Resolved
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]>

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.

Comment thread src/explain/report.rs Resolved
Comment thread src/explain/report.rs Resolved
Comment thread src/explain/report.rs Resolved
Comment thread src/explain/tests.rs Resolved
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]>

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.

Comment thread src/explain/report.rs Resolved
Comment thread src/explain/report.rs Resolved
Comment thread src/explain/report.rs Resolved
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]>

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.

🟡 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

Comment thread src/explain/report.rs Outdated
#[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)]
Comment thread src/explain/report.rs Outdated
Comment on lines +1054 to +1055
/// [`witness`](ConditionExplanation::witness). `Some([])` means no loop
/// contributed; `None` means iteration bindings were not captured.
Comment thread src/explain/report.rs
Comment on lines +1342 to +1348
/// 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>,
Comment thread src/explain/tests.rs Outdated
Comment on lines +1705 to +1707
Count::Exact(2),
Vec::new(),
vec![proof(1), proof(2)],

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.

🟡 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

Review effort: Max

Comment thread src/explain/tests.rs Outdated
Comment on lines +2179 to +2180
use_id: 6,
call_instance: 4,
Comment thread src/explain/report.rs
Comment on lines +1040 to +1044
/// 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.
Comment thread src/explain/report.rs Outdated
Comment on lines +1032 to +1033
/// 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]>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. I will run one more review to catch any more high priority issues. Those can however be fixed in subsequent PRs.

@anakrish
Anand Krishnamoorthi (anakrish) merged commit e3686b2 into microsoft:main Nov 24, 2026
61 checks passed
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.

3 participants