Repository navigation
fix(classify): resolve named-constant boundaries so a boundary test can close them - #3984
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
Confirmed findings
- The promoted-finding direction (a same-file literal const resolves to
exposedand 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 flagspub(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_constantrecognizes only lines whose first non-visibility token is literallyconst,static, orstatic 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 leavespub(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#, notconst, and the scan returnsUndeclared. 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 byargument_names_constantand promote a finding based on the test's own constant, not the production owner.; refuted because:named_constantis keyed onowner.file(the production owner file), not on any test file. The lookup usesindex.files.get(&owner.file), so a test-module constant with the same name intests/pricing.rsor in an inline#[cfg(test)] mod testscannot influence the owner's lookup. Identity matching can only fire if a test argument names the production-file constant, andargument_names_constantrequiresis_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.
|
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 Fixed: attributed declarations. Proof:
Kept as is:
Generated by Claude Code |
|
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
Negative control: with Not caused by this PR:
Generated by Claude Code |
EffortlessSteven
left a comment
There was a problem hiding this comment.
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 --checkpass.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 checkexit 0 (3 consecutive runs). Independently ranripr checkonboundary_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/adequatevocabulary. - 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, and10_000do not match;path::NAMErequires 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.rstail-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):
- 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_exposedcontrol per the over-credit invariant. - A lone attribute-decorated const resolves
Opaquerather thanValue(extract_module_constantsdoes not strip attributes) — fail-closed and conservative, no wrong value. - 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.
There was a problem hiding this comment.
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, andBTreeMapkeys; 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 threeconst &strliterals (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_nameaccepts any upper-case identifier ([A-Z_0-9]+), including names that look like reserved/builtin tokens (TRUE,TEST,MAX). The integer-literal filter inNamedConstant::Valuebounds 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.
c082182 to
77253b5
Compare
EffortlessSteven
left a comment
There was a problem hiding this comment.
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/staticboundary 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.
Review — head a5ca6bb (rebased onto current main)Surfaces. 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 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. |
Requested by Steven · project thread
Summary
Before: a user changed
amount > DISCOUNT_THRESHOLDto>=, withconst DISCOUNT_THRESHOLD: u64 = 10_000;in the same file, then did exactly what pilot asked and addedassert_eq!(discounted_total(10_000), 9_000);. ripr still saidweakly_exposedwithmissing amount == DISCOUNT_THRESHOLD. The repair loop reportedweakly_gripped -> weakly_gripped (unchanged)and "Add the missing discriminator". The same test against the literal10_000closed the gap. The gap could never close.After: that finding is
exposed (1.00)withinfection yes: Detected related test input at the changed boundary, and the seam isstrongly_gripped. The repair loop on a copy of the re-walk repo reportsweakly_gripped -> strongly_gripped (improved). A test that passesDISCOUNT_THRESHOLDitself also counts.infection_unknown/static_limited, not as a repair target.How:
value_resolution::named_constantreturns a value only when the owner's file has exactly one immutableconstorstaticwhose 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, throughliteral_operand_valuefallbacks inactivation.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
ripr-swarmSource-of-truth Links
Spec: RIPR-SPEC-0001 (the rule)
Issue: none filed. The re-walk evidence is F15-5.
Scope Classification
Single acceptance criterion:
Decisions (overrule on review)
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.Support-tier Impact
Policy Impact
Proof
At 8f07349:
named_constant_reads_one_same_file_integer_declarationnamed_constant_fails_closed_on_computed_duplicate_or_mutable_declarationsconstant_operand_names_and_arguments_match_by_identitysame_file_constant_boundary_is_observed_at_its_literal_valueargument_naming_the_constant_is_the_boundary_by_identityconstant_not_pinned_to_the_owner_file_fails_closedpredicate_infection_names_an_unmatched_constant_boundaryX = v, an argument naming the constant, and a constant from another file as a named limitation.boundary_named_constant:exposed.infection_unknown/static_limited.pricinggoes from weakly to exposed / strongly_gripped.pricing-litandwsare unchanged.Not established:
10_000u64) andpub(super)constants are opaque, and cross-file constants are not resolved.infection.rs,value_resolution.rsand SPEC-0001. The conflicts are adjacent insertions; keep both sides. A trial merge passes 5321 lib tests and the goldens.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
analysis/value_resolution.rs,analysis/classify/activation.rs,analysis/classify/infection.rs,analysis/test_grip_evidence.rs,analysis/seam_cache.rsfixtures/boundary_named_constant/Static Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code or tests.🤖 Generated with Claude Code
https://claude.ai/code/session_018QP9k41E538Xgytw8QCSfM
Generated by Claude Code