Skip to content

fix(analysis): credit direct field constant boundaries - #1511

Merged
EffortlessSteven merged 3 commits into
mainfrom
analysis/field-constant-observation
Jul 10, 2026
Merged

EffortlessSteven merged 3 commits into
mainfrom
analysis/field-constant-observation

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Summary

  • credit direct, source-ordered field = CONST, CONST - 1, and CONST + 1 evidence for safe equality-boundary observations
  • fail closed for opaque, conditional, unrelated, ambiguously owned, or invalidated assignments with the named field_assignment_value_unresolved limitation
  • preserve assignment ordering: an earlier mutation does not invalidate a later exact assignment, while a later mutation cannot reveal a stale struct-literal fallback

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm
  • repair or follow-up for a same-repo swarm PR
  • swarm-only CI, runner, routing, source-of-truth, or agent-operating surface
  • other swarm-scoped work

Source-of-truth Links

Proposal: none
Spec: RIPR-SPEC-0001, RIPR-SPEC-0021
ADR: none
Plan item: analysis/field-constant-observation
Active goal: rust-one-shot-evidence-to-repair
Issue: #1423

Scope

  • one Rust analysis behavior: safe direct field-assignment value resolution and its fail-closed limitation route

Scope Classification

  • One production behavior
  • One public contract
  • One architectural seam
  • Docs/spec/test-only evidence package
  • Other

Production delta:

  • same-test direct field assignments with exact same-file named constants and bounded offsets may satisfy the matching equality boundary when source order, ownership, and value flow are unambiguous

Evidence/support delta:

  • positive, adversarial, control-flow, alias-invalidation, ordering, limitation-normalization, and traceability coverage

Single acceptance criterion:

Non-goals:

  • no general dataflow engine, interprocedural constant propagation, alias analysis, new dependency, gate-authority change, or support-tier promotion

Support-tier Impact

  • none
  • updates docs/status/SUPPORT_TIERS.md
  • changes a README, release, docs, CLI, JSON, editor, CI, or package claim

Claim/proof notes:

  • this closes one registered Rust accuracy gap; it does not claim general field-assignment or runtime mutation adequacy

Policy Impact

  • none
  • doc artifacts
  • CI lane
  • package boundary
  • lint / Clippy
  • no-panic
  • file policy
  • generated artifact
  • dependency
  • process/network

Ledger or exception notes:

  • no new source exception or governed artifact ID

Proof

cargo fmt --check
cargo check -p ripr --all-targets
cargo test -p ripr value_resolution --lib -- --test-threads=1
cargo test -p ripr mutable_borrow --lib -- --test-threads=1
cargo test -p ripr test_grip_evidence --lib -- --test-threads=1
git diff --check

Result, failures, or skipped proof:

  • PASS on corrected head: formatting, ripr all-target check, 31 value-resolution tests, 3 mutable-borrow ordering tests, all 216 test-grip-evidence tests, and diff whitespace.
  • NOT COMPLETED on corrected head: cargo xtask goldens check produced no diagnostic before the 20-minute local timeout and left no orphaned process. A fresh protected current-head result is required before merge.
  • The prior head passed Ripr Rust Small Result; that result is not used as proof for the corrective commit.

Claim Boundary

  • May claim: RIPR can credit the registered direct field/named-constant boundary shapes when syntactically safe and source ordered, and names an unresolved limitation otherwise.
  • Must not claim: general assignment dataflow, alias completeness, coverage adequacy, runtime mutation adequacy, or support-tier promotion.

Rollback

  • revert this PR to restore the earlier conservative unresolved behavior; no persisted data or migration is involved

Spec-Test-Code Traceability

  • Spec: RIPR-SPEC-0001, RIPR-SPEC-0021
  • Tests: analysis::value_resolution::tests, analysis::test_grip_evidence::tests, output::evidence_record normalization tests
  • Code: analysis/value_resolution.rs, analysis/test_grip_evidence.rs, output/evidence_record.rs
  • Golden outputs: none intentionally changed
  • Metrics: no metric definition change
  • ADR/learning: capability matrix and output-schema limitation vocabulary updated

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

CI Economics

  • LEM impact: no workflow change
  • Workflows touched: none
  • Branch protection impact: none
  • Failure mode caught: impossible field-boundary recommendation or stale/ambiguous assignment over-credit
  • Cheaper signal considered: focused same-module tests are the primary local proof
  • Required lanes affected: existing Rust Small only
  • Advisory lanes affected: existing coverage/review only
  • On-demand/release lanes affected: none
  • Labels that alter behavior: none
  • Artifact families affected: none
  • Rollback path: revert the PR

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.
  • New non-Rust programming files are allowlisted with owner, surface, and reason.
  • New generated, dependency, process-spawn, or network surfaces are allowlisted with owner and reason.
  • Errors are reported with actionable context.
  • Public JSON/schema changes are documented.

Gates

  • cargo fmt --check
  • cargo check --workspace --all-targets
  • cargo test --workspace
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo doc --workspace --no-deps
  • cargo package -p ripr --list
  • cargo publish -p ripr --dry-run
  • cargo xtask check-static-language
  • cargo xtask check-doc-artifacts
  • cargo xtask check-support-tiers
  • cargo xtask check-no-panic-family
  • cargo xtask check-allow-attributes
  • cargo xtask check-local-context
  • cargo xtask check-file-policy
  • cargo xtask check-executable-files
  • cargo xtask check-workflows
  • cargo xtask check-spec-format
  • cargo xtask check-spec-numbering
  • cargo xtask check-fixture-contracts
  • cargo xtask check-generated
  • cargo xtask check-badge-diff-policy
  • cargo xtask check-generated-clean
  • cargo xtask check-dependencies
  • cargo xtask check-process-policy
  • cargo xtask check-network-policy

Extension changes: none.

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Rust equality-boundary analysis now credits eligible direct field assignments from same-file constants and bounded offsets, rejects unsafe or ambiguous cases, and reports field_assignment_value_unresolved with dedicated routing, tests, specifications, and documentation.

Changes

Field Assignment Evidence

Layer / File(s) Summary
Field assignment value resolution
crates/ripr/src/analysis/value_resolution.rs, crates/ripr/src/analysis/value_resolution/tests.rs
Direct field writes are scanned, supported constant expressions are resolved, invalidation is tracked, and conservative resolution tests are added.
Evidence activation and validation
crates/ripr/src/analysis/test_grip_evidence.rs, crates/ripr/src/analysis/test_grip_evidence/tests.rs, .ripr/traceability.toml
Evidence activation recognizes unresolved assignments, supports borrowed projections, and tests valid, mismatched, opaque, nested, and invalidated assignments.
Static limitation routing
crates/ripr/src/output/evidence_record.rs
Unresolved field-assignment reasons receive a dedicated category and repair route with normalization coverage.
Contracts and specification coverage
CHANGELOG.md, docs/CAPABILITY_MATRIX.md, docs/OUTPUT_SCHEMA.md, docs/specs/*, .ripr/traceability.toml
Documentation and traceability describe supported assignments, fail-closed behavior, limitation routing, and mapped tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TestModule
  participant ValueEnv
  participant EvidenceAnalysis
  participant EvidenceRecord
  TestModule->>ValueEnv: provide direct field assignment
  ValueEnv->>EvidenceAnalysis: return observed value or unresolved status
  EvidenceAnalysis->>EvidenceRecord: emit evidence limitation category
  EvidenceRecord->>EvidenceRecord: map category to repair route
Loading

Suggested labels: codex

Poem

I’m a rabbit with constants tucked tight,
Assigning field values in source order just right.
Opaque paths get a cautious decree,
Mutable borrows stale what used to be.
Hop, hop—evidence blooms bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: crediting direct field constant boundaries.
Description check ✅ Passed The description follows the template and fills the required sections with concrete scope, links, proof, and rollback details.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch analysis/field-constant-observation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.89441% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ripr/src/analysis/value_resolution.rs 97.00% 8 Missing ⚠️
crates/ripr/src/analysis/test_grip_evidence.rs 95.12% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot added the codex label Jul 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
crates/ripr/src/analysis/test_grip_evidence.rs (1)

407-517: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting the shared call/argument iteration between observed_value_facts_for_test and field_assignment_value_unresolved_for_test.

Both functions build the same ValueEnv, iterate indexed.test.calls filtered by call.name == owner_name, resolve call_arguments, and apply the same operand-projection logic. This duplication will grow as more field-assignment-style checks are added; a shared helper that yields (call, projected_arg) pairs for a given owner_name/selection would reduce the surface to keep in sync.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/ripr/src/analysis/test_grip_evidence.rs` around lines 407 - 517,
Extract the duplicated call/argument traversal from
observed_value_facts_for_test and field_assignment_value_unresolved_for_test
into a shared helper that builds projected (call, argument) pairs for the
selected owner_name and ObservedArgumentSelection, including filtering calls,
resolving call_arguments, and applying projections. Update both functions to use
this helper while preserving their existing value-resolution and
unresolved-check behavior.
crates/ripr/src/analysis/value_resolution.rs (1)

262-282: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Stale struct-literal fallback when a field assignment is invalidated (not just unresolved).

field_assignment_at returns None both when no candidate assignment exists and when a candidate exists but is invalidated (Line 341-343). In resolve_identifier_or_literal_at, that None is indistinguishable from "never assigned", so execution falls through to the struct_field_bindings lookup (Lines 283-298) and can resurface the original struct-literal value even though a later direct assignment was invalidated by a mutable borrow.

Concretely, for:

let mut file = File { body_model_version: 0, .. };
file.body_model_version = SUPPORTED_VERSION; // credited, then invalidated below
mutate(&mut file);
lower(&file);

field_assignment_at returns None (invalidated) at the call site, so resolve_identifier_or_literal_at falls back to the struct literal and resolves file.body_model_version to "0" — a stale value — instead of failing closed. This makes observed non-empty, which in turn makes activate_evidence's field_assignment_value_unresolved flag false (Lines 254-259 in test_grip_evidence.rs), producing "Observed 1 concrete activation value(s)…" instead of the intended "Field assignment value is unresolved…" summary. This appears to directly contradict the new test given_mutable_borrow_after_field_assignment_then_stale_value_is_not_credited in test_grip_evidence/tests.rs (Lines 10194-10239), which asserts neither outcome should occur.

The fix must short-circuit whenever any candidate assignment is found for the object/field before the call — regardless of invalidation state — rather than only when a value was resolved.

🐛 Proposed fix: never fall through once a candidate assignment exists
         if let Some((object, field)) = field_projection(expr)
-            && let Some(assignment) = self.field_assignment_at(object, field, call_position)
+            && let Some((local_binding, assignment)) =
+                self.field_assignment_candidate_at(object, field, call_position)
         {
-            return assignment
-                .values
-                .iter()
-                .cloned()
-                .map(|value| (value, ValueContext::FunctionArgument))
-                .collect();
+            return if self.field_assignment_is_invalidated(object, local_binding, call_position) {
+                Vec::new()
+            } else {
+                assignment
+                    .values
+                    .iter()
+                    .cloned()
+                    .map(|value| (value, ValueContext::FunctionArgument))
+                    .collect()
+            };
         }

field_assignment_at then becomes unused at this call site; either remove it or repurpose it consistently with field_assignment_value_unresolved_at_call.

Also applies to: 333-345

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/ripr/src/analysis/value_resolution.rs` around lines 262 - 282, Prevent
stale struct-literal fallback when a field assignment was invalidated. Update
resolve_identifier_or_literal_at to detect whether any prior assignment
candidate exists for the object/field, and return without resolving a value
whenever such a candidate exists but cannot produce a valid assignment; do not
fall through to struct_field_bindings. Reuse or replace field_assignment_at
consistently with field_assignment_value_unresolved_at_call, removing the
now-unused helper if appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/ripr/src/analysis/value_resolution.rs`:
- Around line 210-231: Update field_assignment_is_invalidated call sites in
field_assignment_at and field_assignment_value_unresolved_at_call to begin the
invalidation window at the selected assignment’s source position rather than
local_binding. Use the assignment position already available on the assignment
record, preserving the existing call_position end bound and invalidation checks.

---

Outside diff comments:
In `@crates/ripr/src/analysis/test_grip_evidence.rs`:
- Around line 407-517: Extract the duplicated call/argument traversal from
observed_value_facts_for_test and field_assignment_value_unresolved_for_test
into a shared helper that builds projected (call, argument) pairs for the
selected owner_name and ObservedArgumentSelection, including filtering calls,
resolving call_arguments, and applying projections. Update both functions to use
this helper while preserving their existing value-resolution and
unresolved-check behavior.

In `@crates/ripr/src/analysis/value_resolution.rs`:
- Around line 262-282: Prevent stale struct-literal fallback when a field
assignment was invalidated. Update resolve_identifier_or_literal_at to detect
whether any prior assignment candidate exists for the object/field, and return
without resolving a value whenever such a candidate exists but cannot produce a
valid assignment; do not fall through to struct_field_bindings. Reuse or replace
field_assignment_at consistently with field_assignment_value_unresolved_at_call,
removing the now-unused helper if appropriate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 11094f07-be69-43cd-9f56-1c0b9657c4db

📥 Commits

Reviewing files that changed from the base of the PR and between 757d793 and edf9805.

📒 Files selected for processing (11)
  • .ripr/traceability.toml
  • CHANGELOG.md
  • crates/ripr/src/analysis/test_grip_evidence.rs
  • crates/ripr/src/analysis/test_grip_evidence/tests.rs
  • crates/ripr/src/analysis/value_resolution.rs
  • crates/ripr/src/analysis/value_resolution/tests.rs
  • crates/ripr/src/output/evidence_record.rs
  • docs/CAPABILITY_MATRIX.md
  • docs/OUTPUT_SCHEMA.md
  • docs/specs/RIPR-SPEC-0001-static-exposure-loop.md
  • docs/specs/RIPR-SPEC-0021-evidence-record.md

@EffortlessSteven

Copy link
Copy Markdown
Member Author

Addressed the current review findings in f424977. Invalidation is now anchored to the selected assignment position, so a pre-assignment mutable borrow does not deny a later exact value. Once a candidate field assignment exists, an invalidated or unresolved assignment returns no value and cannot fall through to stale struct-literal evidence. Added both internal-state regressions plus a real source-shape ordering regression. Focused proof: value_resolution 31/31, mutable_borrow 3/3, test_grip_evidence 216/216, cargo fmt --check, cargo check -p ripr --all-targets, and git diff --check. The suggested duplicated-traversal extraction is valid maintainability follow-up but is intentionally outside this correctness correction.

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.

1 participant