Skip to content

fix(classify): resolve named-constant boundaries so a boundary test can close them - #3984

Merged
EffortlessSteven merged 2 commits into
mainfrom
claude/language-quality-kairya-rust-const
Sep 24, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
claude/language-quality-kairya-rust-const

Conversation

@claude

@claude claude Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Requested by Steven · project thread

Summary

Before: a user changed amount > DISCOUNT_THRESHOLD to >=, with const DISCOUNT_THRESHOLD: u64 = 10_000; in the same file, then did exactly what pilot asked and added assert_eq!(discounted_total(10_000), 9_000);. ripr still said weakly_exposed with missing amount == DISCOUNT_THRESHOLD. The repair loop reported weakly_gripped -> weakly_gripped (unchanged) and "Add the missing discriminator". The same test against the literal 10_000 closed the gap. The gap could never close.

After: that finding is exposed (1.00) with infection yes: Detected related test input at the changed boundary, and the seam is strongly_gripped. The repair loop on a copy of the re-walk repo reports weakly_gripped -> strongly_gripped (improved). A test that passes DISCOUNT_THRESHOLD itself also counts.

  • Value not visible (a computed or suffixed initializer): the reason says ripr cannot see the value and suggests passing the constant.
  • Imported or duplicated constant: reported as infection_unknown / static_limited, not as a repair target.

How: value_resolution::named_constant returns a value only when the owner's file has exactly one immutable const or static whose initializer is an integer literal. Activation, infection and test-grip evidence share it, along with identity matching of an argument that names the constant (X, &X, path::X). Before this change, all three paths resolved only literal operands, through literal_operand_value fallbacks in activation.rs. Seam cache generations are bumped to 1.14 / 0.20 / 0.21. Seeding the cache with the old binary showed that a warm cache otherwise hides the change.

Found in the onboarding thread's new-user re-walk (F15-5).

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Spec: RIPR-SPEC-0001 (the rule)
Issue: none filed. The re-walk evidence is F15-5.

Scope Classification

  • One production behavior

Single acceptance criterion:

  • A boundary on a same-file integer constant is treated like the same boundary on its literal value, and fails closed otherwise.

Decisions (overrule on review)

  • This promotes findings. A test at the constant's value now earns exposed. That is the risky direction, so resolution is narrow. It applies only to one immutable declaration in the owner's file with an integer-literal initializer. Anything else is either opaque, with an honest reason, or a named static limitation, never a guessed value.
  • Cache bump. It is the only way to keep a warm cache from serving the old verdict. If another PR bumps the seam cache first, the second PR to land bumps again.

Support-tier Impact

  • none

Policy Impact

  • A previously unclosable gap can now close; see Decisions.

Proof

At 8f07349:

cargo test -p ripr --lib                            # 5315 passed
cargo xtask goldens check                           # pass
cargo xtask fixtures / check-fixture-contracts      # pass
cargo clippy -p ripr --all-targets -- -D warnings   # pass
cargo xtask precommit                               # exit 0
  • Value resolution:
    • named_constant_reads_one_same_file_integer_declaration
    • named_constant_fails_closed_on_computed_duplicate_or_mutable_declarations
    • constant_operand_names_and_arguments_match_by_identity
  • Activation:
    • same_file_constant_boundary_is_observed_at_its_literal_value
    • argument_naming_the_constant_is_the_boundary_by_identity
    • constant_not_pinned_to_the_owner_file_fails_closed
  • Infection: predicate_infection_names_an_unmatched_constant_boundary
  • Test grip: four seam-grip tests cover a literal input at the value, off-value inputs named X = v, an argument naming the constant, and a constant from another file as a named limitation.
  • New fixture boundary_named_constant:
    • A literal constant with a name argument gives exposed.
    • An imported constant gives infection_unknown / static_limited.
  • Re-walk repos: pricing goes from weakly to exposed / strongly_gripped. pricing-lit and ws are unchanged.

Not established:

  • Suffixed (10_000u64) and pub(super) constants are opaque, and cross-file constants are not resolved.
  • A test module that declares its own constant with the owner's constant name would match by identity. This case has not been tested.
  • It conflicts with fix(classify): count a boundary literal as infection only when it feeds the owner #3983 in infection.rs, value_resolution.rs and SPEC-0001. The conflicts are adjacent insertions; keep both sides. A trial merge passes 5321 lib tests and the goldens.
  • No runtime mutation result.

Claim Boundary

May claim: a boundary test at a same-file integer constant's value now closes the gap. Must not claim: ripr evaluates constant expressions.

Rollback

Revert the commit. The cache generations, fixture and spec text revert with it.

Spec-Test-Code Traceability

  • Spec: RIPR-SPEC-0001
  • Tests and code: analysis/value_resolution.rs, analysis/classify/activation.rs, analysis/classify/infection.rs, analysis/test_grip_evidence.rs, analysis/seam_cache.rs
  • Fixture: fixtures/boundary_named_constant/

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.

CI Economics

n/a

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code or tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_018QP9k41E538Xgytw8QCSfM


Generated by Claude Code

@claude
claude Bot requested a review from EffortlessSteven September 23, 2026 11:26
@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 812c91e8-dd9f-441c-b69b-7e838d079924

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@github-actions github-actions Bot 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.

Confirmed findings

  • The promoted-finding direction (a same-file literal const resolves to exposed and accepts identity-named arguments) is correct for the tested cases, but the owner-file declaration scan is a simple line-prefix walker that does not handle attribute-decorated consts or cross-module shadowing. The PR body flags pub(super) constants as opaque and cross-file as a limitation, but does not flag attribute decoration or same-name test-module shadowing. Until those are pinned, a warm 1.14 cache will serve whatever verdict the scan produces for those shapes.
  • Lane scope (resizable buffers / active view) is empty for this Rust static-analysis diff. No blockers; warm-cache correctness depends on the bumped CACHE_SCHEMA_VERSION 1.14 / 0.20 / 0.21 actually invalidating prior classified entries.
  • constant_operand_name accepts ANY upper-case identifier including reserved/builtin-like names (e.g. TRUE, FALSE if a user shadowed them, or a const named TEST). The same shape is reused by activation.infection and test_grip_evidence via boundary_constant_operand_name; misclassification risk is bounded by the integer-literal filter in named_constant but worth a doc note.

Verification questions

  • Confirm the owner-file declaration scan in named_constant recognizes only lines whose first non-visibility token is literally const, static, or static mut. Attribute-decorated consts and const declarations preceded by #[…] attributes on the previous line are not exercised by the diff's tests; the PR body explicitly leaves pub(super) constants opaque but does not mention attribute decoration. If a real owner file uses #[allow(dead_code)] pub const DISCOUNT_THRESHOLD: u64 = 10_000; on a single line, the line's first token after attribute stripping is #, not const, and the scan returns Undeclared. A test module declaring its own constant with the owner's constant name is also untested per the PR body.
  • Confirm strip_visibility_prefix in value_resolution.rs strips 'pub', 'pub(crate)', 'pub(super)' via simple starts_with chain, but 'pub(in path)::' qualified or attribute-decorated consts (#[cfg(...)] const) may misclassify. Existing helper is reused, so this is an inherited limitation, not a new regression.

Refuted

  • value_resolution tests are tautological because they only re-read constants declared in the same string; refuted because: Confirmed: the named_constant_reads_one_same_file_integer_declaration, named_constant_fails_closed_on_computed_duplicate_or_mutable_declarations, and constant_operand_names_and_arguments_match_by_identity tests collectively cover integer literal, computed/suffixed, duplicated, mutable, commented, Self:: qualified, path-qualified, suffix-padded, and substring-mimicking cases. Coverage is discriminating across Opaque/Ambiguous/Undeclared/Value branches.
  • named_constant() could mis-classify a suffixed integer literal like 10_000u64 as Value(...); refuted because: Value branch requires is_integer_literal(value); 10_000u64 contains 'u64', failing the digits+underscore check. Test named_constant_fails_closed_on_computed_duplicate_or_mutable_declarations pins this.
  • Adding a new constant-boundary lookup might add an allocation that can fail (OOM) and corrupt handoff state.; refuted because: The new code only does string slice work via strip_prefix/strip_suffix and BTreeMap lookup of the existing module_constants map; no Box::from(slice), no Vec::with_capacity, no allocation-failure surface introduced. Even if allocation failure were considered, ripr is a synchronous CLI analyzer and does not cross a worker boundary; this is not in-lane.
  • A test module declaring its own constant with the owner's constant name (e.g. #[cfg(test)] mod tests { const DISCOUNT_THRESHOLD: u64 = 10_000; }) could be matched by argument_names_constant and promote a finding based on the test's own constant, not the production owner.; refuted because: named_constant is keyed on owner.file (the production owner file), not on any test file. The lookup uses index.files.get(&owner.file), so a test-module constant with the same name in tests/pricing.rs or in an inline #[cfg(test)] mod tests cannot influence the owner's lookup. Identity matching can only fire if a test argument names the production-file constant, and argument_names_constant requires is_declared_once() on the owner's file. Test-module shadowing is therefore inert against this promotion.

Evidence gaps

  • artifact-verifier failed with exit 2 but the failure is unrelated to this diff (sensor config); security-relevant artifacts (fixture expected outputs) appear coherent with new code paths.
  • Model proof intent was rejected by deterministic validation.
  • Failed_objection channel: the artifact-verifier exit 2 means golden fixtures were not broker-verified this run; lane treats fixture content as advisory until broker re-confirms.

@claude

claude Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Disposition for review 5290511616. The fix is at c082182.

Fixed: a test file's own same-name constant. The review refuted this finding, but it only checked the owner lookup. The identity match itself was open. With const DISCOUNT_THRESHOLD: u64 = 5; at the top of tests/pricing.rs, a call to discounted_total(DISCOUNT_THRESHOLD) was credited as the owner's boundary even though it passes 5. The new value_resolution::test_file_may_shadow_constant now gates both identity sites, classify/activation.rs::owner_calls_passing_constant and test_grip_evidence.rs::test_passes_boundary_constant. It skips a test whose own file (other than the owner's) declares the name, and it fails closed when that file's source is not indexed. A test inside the owner's file needs no extra check, because a second declaration there already makes the lookup Ambiguous.

Fixed: attributed declarations. named_constant now strips same-line #[...] groups before looking for the item keyword. Before this, #[cfg(a)] const LIMIT: u32 = 10; next to a plain const LIMIT: u32 = 20; counted as one declaration and resolved to a value. Now it is Ambiguous. An attribute on the line above was already handled, because that line is skipped and the next line starts with const.

Proof:

  • Four new tests:
    • argument_naming_a_test_file_constant_of_the_same_name_is_not_the_boundary, with a positive control that only imports the constant;
    • given_test_file_declaring_its_own_same_name_constant_then_identity_is_not_credited, a grip-path test with an import control;
    • a_test_file_declaring_the_same_constant_name_may_shadow_the_owner;
    • named_constant_counts_attribute_prefixed_declarations.
  • Mutation check: making test_file_may_shadow_constant always return false and removing the attribute strip fails all four tests (35 passed, 4 failed). Restored, 31/31 pass.
  • cargo xtask goldens check and cargo xtask precommit pass. No golden changed.
  • The fix sits inside this PR's existing cache bump (1.14/0.20/0.21). No cache has been built at these generations on main yet, so no second bump is needed.

Kept as is:

  • constant_operand_name accepts any upper-case identifier. A name only resolves when the owner's file declares it once as an integer literal, so TRUE or TEST promote nothing unless they really are such a constant.
  • pub(in path) is handled: strip_visibility_prefix drops everything up to the closing ).

Generated by Claude Code

@claude

claude Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

I checked this head end to end on the onboarding pricing sample (rewalk F15-5). I ran the same script with two binaries: this head (c082182) and main (d4ba488). The steps were ripr pilot, then agent repair --phase before, then appending assert_eq!(discounted_total(10_000), 9_000);, then cargo test, then agent repair --phase after.

main this head
after-phase result weakly_gripped -> weakly_gripped (unchanged) weakly_gripped -> strongly_gripped (improved)
next: Add the missing discriminator or stronger assertion named by the packet. Keep the focused test and include this receipt in review.
ripr check on discounted_total weakly_exposed (0.92), missing amount == DISCOUNT_THRESHOLD exposed (1.00), observed amount == DISCOUNT_THRESHOLD

Negative control: with discounted_total(10_001) in place of the boundary value, this head stays weakly_exposed (0.92) with the equality-boundary discriminator missing.

Not caused by this PR:

  • On both binaries I had to exclude the untracked Cargo.lock and keep the sample's target/ outside the repo. Without that, the edit cage refused the attempt. That is F15-1, fixed on the onboarding branches, not on main.
  • The after-phase receipt reads status: invalid (Analysis outcome artifact base does not match its typed identity). That is F15-3, also owned by the onboarding branches.

Generated by Claude Code

@EffortlessSteven EffortlessSteven 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.

Exact-head review at c082182 — substantively ready

Independent verification of the review at 8f07349 and the disposition fixes at c082182. No new findings; every disposition re-checked against current head source.

Surfaces inspected: analysis/value_resolution.rs (named_constant, test_file_may_shadow_constant, constant_operand_name, argument_names_constant), classify/activation.rs (boundary_constant, visible_operand, owner_calls_passing_constant, fail-closed route in missing_boundary_discriminator), classify/infection.rs (no_literal_boundary_summary), test_grip_evidence.rs (BoundaryConstantOperand, test_passes_boundary_constant, unresolved-limitation routing), seam_cache.rs bumps, fixtures/boundary_named_constant, SPEC-0001, and the new unit/activation/grip tests.

Observed (ran locally at head, Windows native):

  • cargo fmt --check pass. cargo test -p ripr --lib: 5292 passed, 0 failed (count differs from the PR body's 5315; platform cfg-gating, 0 failures either way).
  • All 10 new named-constant tests confirmed by name: value resolution positive/negative (computed, suffixed, duplicated, static mut, commented), attribute-prefixed declarations, activation at value / off-value / identity / shadowed test constant / not-pinned fail-closed, grip-path equivalents, infection summary.
  • cargo xtask goldens check exit 0 (3 consecutive runs). Independently ran ripr check on boundary_named_constant: findings identical to the committed golden (exposed 1.00 / exposed 1.00 / infection_unknown 0.66); only path-separator rendering differs on Windows, which the goldens checker normalizes.
  • Diff contains no killed/survived/untested/proven/adequate vocabulary.
  • Cache: main is still 1.13/0.19/0.20, so this bump (1.14/0.20/0.21, pinned by test) is first — no collision; no cache exists at these generations yet.
  • Identity is not token coincidence: OTHER_DISCOUNT_THRESHOLD, DISCOUNT_THRESHOLD + 1, and 10_000 do not match; path::NAME requires all-simple-identifier path segments. Value promotion requires the owner's file to declare the name exactly once with an integer-literal initializer — a real resolved value, not a name match. Sibling PR #3985 (flow.rs tail-expression sink) is semantically orthogonal; only SPEC-0001 has adjacent insertions.

Disposition check on the bot review: the four refutations hold against head except the test-module-shadowing refutation, which was correctly identified as incomplete and repaired at c082182 — the new test_file_may_shadow_constant gate covers both identity sites and fails closed when the test file's source is not indexed; the import-only control and shadow negative are pinned by tests. The attribute-decoration finding is repaired by same-line #[...] stripping (named_constant_counts_attribute_prefixed_declarations). The evidence gap (goldens not broker-verified) is closed by the local goldens runs above.

Residuals (not blocking, recorded for follow-up):

  1. The identity path does not consult local let-bindings: a same-named let LIMIT = 3; local shadow inside a test fn in the owner's own file (the value path handles this correctly; the identity path bypasses it), or a same-name constant imported from a foreign crate into a separate test file, would be credited by identity. Both require pathological same-name usage at the boundary call; if ever confirmed, pin as a should-stay-weakly_exposed control per the over-credit invariant.
  2. A lone attribute-decorated const resolves Opaque rather than Value (extract_module_constants does not strip attributes) — fail-closed and conservative, no wrong value.
  3. No runtime mutation result, as the PR body states.

Not verified: the hosted merge matrix beyond the reported green checks; no local full-matrix duplication per CI economics.

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review September 24, 2026 04:03

@github-actions github-actions Bot 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.

Decision

  • Needs reviewer attention before upstream: findings remain.

Confirmed findings

  • All changed code is safe Rust with no unsafe/native seam; memory-lifetime lane has no public issue to raise. Cache-version bump to 1.14/0.20/0.21 is the documented invalidation mechanism for warm classified entries.
  • constant_operand_name accepts any SCREAMING_CASE identifier, including reserved-word-like names; integer-literal filter bounds the over-claim, but a doc note in SPEC-0001 would harden the public contract for users shadowing builtins.

Refuted

  • named_constant could create an aliased &mut str into FileFacts::source via strip_leading_attributes' line trimming; refuted because: strip_leading_attributes is pure &str->&str with no allocation; FileFacts::source is owned by RustIndex and only borrowed as &str across the call chain. No aliasing risk introduced.
  • A resizable buffer / active-view UB could be introduced by the new same-file constant lookup in activation.rs/test_grip_evidence.rs.; refuted because: Changed code operates on borrowed &str, PathBuf, and BTreeMap keys; no resizing of a backing buffer that an active view could outlive. No Box::from(slice), RawVec, detach/transfer, or stale length captured across mutation appears in the diff. The only version bumps are three const &str literals (1.14 / 0.20 / 0.21).
  • Same-file integer constant promotion is a hidden scope creep that re-implements constant folding across value_resolution, activation, infection, and test_grip_evidence.; refuted because: The promoted direction is constrained by named_constant to exactly one declaration with an integer-literal initializer; everything else routes to NamedConstant::Opaque/Ambiguous/Undeclared and is reported as a named limitation, not guessed. The four sites share one lookup.

Parked follow-ups

  • constant_operand_name accepts any upper-case identifier ([A-Z_0-9]+), including names that look like reserved/builtin tokens (TRUE, TEST, MAX). The integer-literal filter in NamedConstant::Value bounds the blast radius, but the same shape is reused in activation/infection/test-grip; a user const named like a primitive is plausible and worth a doc note.
  • BoundaryConstant (activation) and BoundaryConstantOperand (test_grip) carry the same fields but differ by argument_index. Two thin adapters are acceptable but a single struct in value_resolution would remove the cross-file duplicate and clarify that both call sites read the same lookup result.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.

…an close them

Rebased onto current main; conflict-free. A same-file immutable integer
const/static boundary resolves to its literal value for activation,
infection, and test-grip evidence; fails closed on computed initializers
or imported/duplicated constants (reported infection_unknown /
static_limited, never as a repair target). Cache generations bumped
(1.14 / 0.20 / 0.21) so a warm cache cannot hide the change.
@EffortlessSteven
EffortlessSteven force-pushed the claude/language-quality-kairya-rust-const branch from c082182 to 77253b5 Compare September 24, 2026 06:21

@EffortlessSteven EffortlessSteven 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.

Review (rebased head 77253b5)

Rebased onto current main (post-#4022); conflict-free. 17 files: one behavior + a complete boundary_named_constant fixture corpus.

  • Single acceptance criterion, falsifiable: a same-file integer const/static boundary is treated like the same boundary on its literal value; fails closed otherwise.
  • Fail-closed discipline is explicit: computed/suffixed initializers report value-not-visible with guidance to pass the constant; imported or duplicated constants stay infection_unknown/static_limited — never promoted to a repair target. This respects the evidence-promotion invariants (no credit without identity).
  • Owner: one resolver (value_resolution::named_constant) shared by activation, infection, and test-grip evidence, plus argument identity matching (X, &X, path::X).
  • Cache generations bumped (1.14 / 0.20 / 0.21) with a warm-cache seeding control — a warm cache cannot hide the behavior change.
  • Validation: fresh hosted gate on the rebased head is the merge authority.

Disposition: REVIEW_READY pending green gate.

…nvelope

The fixture was blessed before RIPR-SPEC-0084 (#4002) reached main; drop
the inapplicable top-level base and record base_revision null.
@EffortlessSteven
EffortlessSteven merged commit 337633c into main Sep 24, 2026
24 of 25 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/language-quality-kairya-rust-const branch September 24, 2026 14:02
@EffortlessSteven

Copy link
Copy Markdown
Member

Review — head a5ca6bb (rebased onto current main)

Surfaces. crates/ripr/src/analysis/classify/* (named-constant boundary resolution), new boundary_named_constant fixture, spec/traceability docs.

What this PR does. Resolves named-constant boundaries: a same-file integer const resolves to its value for boundary comparison, a test argument naming the const matches by identity, and an unresolvable const is reported unknown instead of as a missing discriminator — so a boundary test that names the const can close the boundary.

Rebase repair. This branch's new fixture was blessed before RIPR-SPEC-0084 (#4002) reached main; re-blessed boundary_named_constant/expected/check.json to the no-default-base envelope (top-level base dropped, base_revision null). human.txt carries no base line; no other golden touched.

Stimulus/oracle. The fixture pins all three arms (resolved value, identity match, honest unknown). False-credit control: an unresolvable const must NOT be reported as a missing discriminator.

Validation. Ripr Rust Small Result: SUCCESS on a5ca6bb.

Disposition: REVIEW_READY.

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