Skip to content

fix(rust): refuse owner pin expected values a macro or static rebinds (#7847) - #8597

Merged
EffortlessSteven merged 8 commits into
mainfrom
claude/issue-7847
Oct 19, 2026
Merged

EffortlessSteven merged 8 commits into
mainfrom
claude/issue-7847

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Requested by Steven · project thread

Closes #7847.

expected_binding_calls_owner (owner_pin.rs) now fails closed for an expected word that (a) a non-bounded statement macro names (bound_by_macro, as s!(expected);), or (b) the test body writes outside a let (written_by_test: assignment, &mut name, or a mutating call such as .store(..), .set(..), .push(..), *_mut, fetch_*, set_*). A let declaration, and a static the test only reads, still pin.

Proof: new an_expected_value_a_macro_or_a_static_rebinds_from_the_owner_is_not_a_pin in owner_pin/tests.rs (macro, AtomicU32::store, static mut assignment refused; independent let and read-only static still admitted).

Validation gap: the shared box OOMs on lib-test compiles. Locally only cargo fmt --check and cargo check -p ripr --lib --tests -j1 ran (clean); the new test, cargo xtask precommit and goldens are not run locally and rely on hosted CI. The macro check is lexical and may over-refuse (fail-closed) where an expected word also appears in another macro's arguments; hosted goldens will show any such movement.

Source-of-truth Links

Governing issue or accepted claim: #7847
Acceptance delta (one sentence): Owner-pin refuses an expected value that a statement macro or a non-let write in the test rebinds, instead of pinning it.


Generated by Claude Code

@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!

@EffortlessSteven EffortlessSteven self-assigned this Oct 17, 2026
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 87 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 8cf03e59-c5bd-4530-900e-c39ebb8aa102
📥 Commits

Reviewing files that changed from the base of the PR and between 33cdc4e and 5aa226a.

📒 Files selected for processing: 3
  • changelog.d/7847-macro-static-expected-rebind.md
  • crates/ripr/src/analysis/classify/owner_pin.rs
  • crates/ripr/src/analysis/classify/owner_pin/tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

  • crates/ripr/src/analysis/classify/owner_pin.rs:9667 — Add a control test asserting written_by_test returns false on plain let name = rhs; where name immediately follows let, and a EXPECTED = rhs; (no method, plain identifier) case to lock the lexical pre-trim exemption; today only positive cases are exercised in the new test.
  • Lexical scanner is fail-closed by design (PR body and code comment agree). Strongest plausible false-positive vector -- a &mut name on the RHS of a macro that bound_by_macro already refuses -- collapses to a single refusal, so no double-counting nor false admission is introduced. Resolved check.

Verification questions

  • Confirm written_by_test covers assignment, &mut borrow, compound assign, and 22 mutating methods plus mut/fetch/set_* suffixes; conservative lexical scan.
  • Confirm unit_tests test harness in owner_pin/tests.rs only feeds the prelude+body pair into the scan; the new macro test relies on macro_rules! expansion at parse time, which unit_tests does not perform. If macro expansion is what makes 'let expected = weight(4)' visible, sibling 'let-only' controls in the same test confirm that bound_by_macro is the active branch, not written_by_test. Worth a unit probe.
  • Confirm oracle covers macro-rebind and Atomic/static-mut writes plus positive let + read-only static, exercising refuse/admit parity through path_admitted.

Refuted

  • The raw allocator (Box<[u8]>::from style) may silently return None or an empty box on OOM in the new lexical scan paths, hiding failures.; refuted because: Both new functions (written_by_test, bound_by_test-style macro probe) work entirely on borrowed &str of the masked body -- no heap allocation, no Box::from conversion in the patched region. Allocation-failure mode does not apply to this diff.
  • The new written_by_test mutator-name list or method-prefix matching (*_mut, fetch_*, set_*) could misclassify a buffer/view's active length and skew the owner pin.; refuted because: Function is purely string-level: it inspects identifiers around an expected word via whole_word_offsets and a const MUTATORS slice, with no buffer, view, length field, or resize operation. There is no active-view state to be stale. Active-view UB preconditions are absent.
  • PR diff is a lexical owner-pin classifier addition (bound_by_macro + written_by_test); no active-view or resizable-buffer surface touched, so lane UB scope is inapplicable.
  • written_by_test could grow lifetime/aliasing UB by introducing a borrowed &mut name or method dispatch through a static; refuted because: The function is a pure lexical scan over masked_body slices with no Rust ownership semantics; &mut name detection is a substring check on before, not an actual borrow. Memory-lifetime is not engaged by the classifier path itself.

Evidence gaps

  • Validation gap: author states shared box OOMs on lib-test compile; only 'cargo fmt --check' and 'cargo check -p ripr --lib --tests -j1' ran locally; new test, cargo xtask precommit, and goldens rely on hosted CI. Lane cannot witness red/green locally.
  • Author's own admission: validation gap -- shared box OOMs on lib-test compiles, only cargo fmt --check and cargo check -p ripr --lib --tests -j1 ran locally; new test, cargo xtask precommit, and goldens rely on hosted CI, which is the only place lexical over-refusal would surface.
  • Model proof intent was rejected by deterministic validation.

@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!

…ed type (#7847)

written_by_test treated `let e: Config = ..` as an assignment to `Config`,
withholding credit from a typed independent expected binding. A name preceded
by a single `:` is a type or field label, not a write target.

The lib regression used bare `weight(4)` without importing the owner, so its
positive cases were vacuous and its controls could never admit; use
`crate::weight` and add a typed-let control. The positive cases fail on the
pre-fix production code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0193fZVBGjXWpxEYFUzBGCYt
@EffortlessSteven
EffortlessSteven marked this pull request as draft October 18, 2026 04:18
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 18, 2026 04:18
@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!

…rs; scope let-annotation skip (#7847)

written_by_test now follows a place chain (.field, .0, [i], calls) to an
assignment or a mutating call, widens the mutator set, and skips a ':' only
inside a let pattern annotation so a struct-literal field value stays scanned.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0193fZVBGjXWpxEYFUzBGCYt

@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

  • crates/ripr/src/analysis/classify/owner_pin.rs:10240 — Collapse the duplicated mutator table in is_mutating_method: the exact-name MUTATORS array and the trailing prefix/suffix arrays overlap on fill/drain/retain/extend/insert/remove/or_insert/get_or_insert/dedup/swap_remove/pop/clone_from/store/set. One source of truth (e.g. MUTATORS only, with _mut, _assign, fetch_, set_ as the only pattern matches) removes a maintenance trap and keeps behaviour identical.

Verification questions

  • Confirm is_mutating_method duplicates method lists: an exact-name MUTATORS array and a separate prefix/suffix check both fire. fill, drain, retain, extend, insert, remove, or_insert, get_or_insert, dedup, swap_remove, pop appear in MUTATORS while fill, drain, retain, extend, insert, remove, or_insert, get_or_insert, dedup, swap_ are also prefix matches. Suffix groups _mut, _assign plus prefixes copy_, clone_from, fetch_*, set_* overlap with MUTATORS names (clone_from, store, set). Functionally equivalent but a maintenance hazard.
  • Confirm coverage is positive-only for the trim exemption: written_by_test returning false on a plain let name = rhs; with no annotation, and on a plain identifier assignment EXPECTED = rhs; (no method, no field), is asserted only by inference from the 3 admitted controls — there is no explicit assert!(!written_by_test(..)) test or negative path_admitted.len()==0 for the independent-let case.
  • Confirm mutator prefix list duplicates MUTATORS entries (push/pop/sort/fill/drain/retain/extend/insert/copy_/clone_from/remove/or_insert/get_or_insert/dedup/swap_) and *_assign suffix matches benign names like fn_contains_assign. Fail-closed design treats every hit as mutation; reduncant list is harmless but suggests the two checks were meant to be the single source of truth.
  • Confirm prior review correctly asked whether written_by_test covers every mutating shape; suite exercises store/swap/fill/field/.0/index, but does not exercise &mut expected, +=/-=/*= compound assigns, let mut expected = ..; expected.sort(); on a bare call, or *_assign/fetch_*/set_* method families named in the scanner.

Refuted

  • expected_binding_calls_owner introduces a worker/async/GC handoff that can tear the masked test body and make the rebind scan observe stale bytes; refuted because: All new helpers (written_by_test, place_is_written, skip_balanced, in_let_annotation, bound_by_macro) operate on borrowed &str with no shared/threaded handle, no JS bridge, no async yield, no detaching transfer, and no allocator crossing; closure capture is by & borrow and the masked string is fully owned and stack-resident in the same call frame.
  • Adding the bound_by_macro/written_by_test check before receiver_let_bindings introduces a double-counting or false-admission failure path because the macro/static case may also be picked up by the existing let scan or by binds_outside_let.; refuted because: bound_by_macro and written_by_test return true (refuse) on their own branch, so the downstream branches are unreachable for that word. The new gate is strictly an additional refusal path: no path admits where the prior scan refused, and any path the prior scan admitted but the new scan refuses is the intended #7847 fix. PR body and code comment agree on fail-closed semantics.
  • Could the new lexical written_by_test scan introduce an info-disclosure or UAF via incorrect parsing of test bodies (e.g., mis-scanning a string literal that contains 'EXPECTED.store') leading to a false admission used as an exploit primitive?; refuted because: whole_word_offsets runs over the masked body produced by the existing masker used throughout expected_binding_calls_owner; string/comment masking is unchanged. Even a malformed parse fails closed (returns true), so a mis-parse never weakens the pin gate. No OOB/UAF/type-confusion surface: this is pure static analysis on test source text; no runtime memory access is gated by the result.
  • Owner pin may mis-pin an expected value bound by an ArrayBuffer/TypedArray view's set/fill/etc., so x.buffer resize during the test detaches the view and the length snapshot becomes stale.; refuted because: ripr owner-pin classifies Rust test bodies statically from a string; it never observes a live buffer, view, or backing store. No JS interop, no typed array in the call graph. The PR's written_by_test is a lexical scan of &str, not a runtime buffer view.
  • place_is_written treats an unbalanced bracket scan as a refusal (returns true on None), which is the documented fail-closed contract. This means an unparseable chain like expected[ or expected.foo( is refused — equivalent to an over-refusal, never a false admit. PR body confirms fail-closed is intended.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.

Parked follow-ups

  • Mutator list is the lexical source of truth for what written_by_test treats as writing. Family rules (push/sort/fill/drain/retain/mut/assign/fetch/set) overlap the literal list (store, set, insert, fill, sort, drain, retain, push, swap_remove, etc.). A name in both buckets is checked twice, not harmfully; a name like get_or_insert_mut matches both _mut suffix and get_or_insert prefix and is a single match in any. No path is missed, only duplicated work; parked.

More mutators (with, next*, nth, write_*, splice, replace_range,
make_ascii_*); turbofish and ? in a place chain fail closed; an all-caps
name borrowed into a non-reader Path::callee(&NAME, ..) call is a write.
Adds refusal and operator/let-boundary admit controls.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0193fZVBGjXWpxEYFUzBGCYt
@EffortlessSteven
EffortlessSteven marked this pull request as draft October 18, 2026 08:15
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 18, 2026 08:15

@devin-ai-integration devin-ai-integration 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.

Devin Review found 4 potential issues.

Devin Review

Any non-reader call taking &name is a write; destructuring-assignment
patterns containing the name are writes; write!/writeln! control added;
duplicate exact mutator entries covered by prefix families dropped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0193fZVBGjXWpxEYFUzBGCYt
@EffortlessSteven
EffortlessSteven marked this pull request as draft October 18, 2026 08:35
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 18, 2026 08:35
Explicit first-argument check for write!/writeln! (trusted macros skip
bound_by_macro); an unreadable turbofish callee refuses; add
compare_exchange*, try_lock, try_write, as_mut_ptr; narrow next* to
next/next_back/next_chunk.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0193fZVBGjXWpxEYFUzBGCYt
@EffortlessSteven
EffortlessSteven marked this pull request as draft October 18, 2026 08:53
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 18, 2026 09:10
A callee ending in ) ] or } refuses; resize_with, compare_and_swap,
next_if*, peek* join the mutator set.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0193fZVBGjXWpxEYFUzBGCYt
@EffortlessSteven
EffortlessSteven marked this pull request as draft October 18, 2026 09:42

@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

  • is_mutating_method carries two overlapping sources of truth (MUTATORS array and prefix/suffix arrays). Not a #7847 blocker; tracked for a future collapse.
  • Hardening opportunity: is_mutating_method has overlapping exact-name and prefix tables (store,set,with,fill,drain,retain,extend,insert,remove,or_insert,get_or_insert,dedup,pop). A single source of truth keyed by name family would remove the dup without changing behavior; not a correctness defect for #7847.
  • written_by_test catches EXPECTED.store(..), &EXPECTED to qualified call, write!(..), but a static write via a non-call helper closure (EXPECTED.with(\|c\| c.set(..))) and a for_each(\|e\| e.store(&EXPECTED, v))-style call that does NOT name EXPECTED textually inside the lambda are not caught. The lexical scan cannot see through closures. Recommend documenting this residual as a known over-admit vector, and add a negative test exercising the closure form so the gap is explicit. (crates/ripr/src/analysis/classify/owner_pin.rs:10165).
  • Devin helper-static comment (#1): write(&EXPECTED, ..) to an unqualified helper. After fix in PR (borrowed_into_path_call), write(&EXPECTED, ..) IS refused because head ends in '(' and callee is non-macro, non-whitelisted, non-turbofish-ending.
  • PR body states validation gap: hosted CI is the only runner for cargo xtask precommit and goldens. Locally only fmt + check ran. Local evidence is incomplete; no actionable PR-side fix but a flag for the merge gate.
  • Lane scope (JS-backed worker/async/GC/detach/transfer) is not touched by this pure-Rust lexical-analysis PR; no public findings to post on ub-worker-handoff.

Verification questions

  • Confirm sibling helper expected_return_bindings_owner was not updated by this PR; if a test uses an 'expected_owner'-style name with s!(x) rebind or EXPECTED.store(w), the return-binding path can still credit a pin despite the new gate in expected_binding_calls_owner.
  • Confirm new test an_expected_value_a_macro_or_a_static_rebinds_from_the_owner_is_not_a_pin exercises 21 refusals plus 7 control admissions; written_by_test_reads_operators_and_let_boundaries locks 13 read shapes and 27 write shapes including destructured assignment and write!/writeln.

Refuted

  • borrowed_into_path_call under-refuses a JS-side worker.postMessage(&expected, [expected]) transfer that mutates owner value across the bridge; refuted because: ripr has no JS bridge; the PR diff adds no wasm-bindgen/postMessage/Transferable surface. Refuted as not-applicable to this lane.

Evidence gaps

  • Validation gap: shared box OOMs on lib-test compiles so cargo test was not run locally; hosted CI gate is the proof.
  • Negative-case bodies reference Ordering, AtomicU32, Cell, Wrapper, E::bump, S::widen, expect, bump, widen, and the unwrapped methods. They are passed only to path_admitted (lexical scan over prelude+body text); the harness unit_tests does not compile them, so cargo test only proves lexical classification, not that real compiler versions accept the test as written.
  • Model proof intent was rejected by deterministic validation.

EffortlessSteven commented Oct 18, 2026 •

Copy link
Copy Markdown
Member Author

67654 prerequisite reconciliation; c4 frozen: StoredAny firstrefuses; budget.rs own use crate::* independently blocks primitive-return identity, before expectedMAX. Decisive residual is scoped PrimitiveScalarIdentity through actualimports/reexports/expansions; Names/noassertsites/c4assertionlocality flag cannot supply it. Your existing parity/helperargument/expectedword claim is unchanged and is not reassigned. Canonicalroot#5500 retains integration; no separate exactprimitivewriter found in targetedallstateinspection. No bounded actualconsumer-changing patch justified under no-broad-serde; no rivalimplementation.

Reproducible12control packet, sound acceptance/resume contract, independent assessment; sourcec4 unchanged, evidence51324e92c482f4f27d7eac7eec4a5af9c547433d. Native24compile0/12original0/9zero101/3zero0; customimportedu64alwaysTrueEq staysweak despite Names(empty). IsolatedMAXweak/numericExposed pair provesseparate expectedstage.107sourcebytesets matchretainedexactconsumerreplay0; all52objects+topfields unchanged,targetweak/currentweak18. No duplicatedproductvalidation or PR/hostedCI/Ready/merge/release. Canonical handoff.


Final separate assertion prerequisite: ordinary pushed source c4a8f7828e15426c4d872718f66bd4bac3ab0daf on codex/5500-local-glob-assertion-identity; frozen656 untouched. Narrow direct local-module glob assertion identity only under explicit complete-index/composed source visibility; custom/shadowed/opaque/unresolved refusals preserved. General classified cache full1.85/compact0.91/sharded0.91, filefacts1.43 unchanged. No change to your disclosure/parity, helperargument or expectedrebinding mechanism/ownership.

Final local15gate strictClippy/checkfast0,precommit0,502fixtures1272comparisons0drift,dogfood0,honesty0;35currentfocused+36currentindependentCLI pass;265unchanged24a tests retained (300total selected). Independent source review complete/no current finding; hostedqualification intentionallyincomplete. Exact consumer native0/all52fullfindingobjects+topfields byte-identical656, target67654weak/currentweak18; no18→17 claim. CandidateAny/expectedglob refusal unchanged.

Evidence 4cafbc5255252bc1a7d8e9c3c3f0c34713a2552e; review, inventory, canonical #5500. Shared8772cb6f7667/8592 2b3013d/8597 5aa226a heads rechecked unchanged. All lanecommands terminal, transportrecovered without duplicatevalidation, prior24a/656/16ff custody retained. No PR/hostedCI/Ready/merge/release.


#5500 continuation coordination — macro soundness repair

Canonical ownership/result, ordinary pushed source 656d6d7effb51a888c4b627e2a0cd44c3bbd37ef on codex/5500-whole-tail-observation. The separate whole-tail MatchExpr-header receipt remains outside individual-arm authority; shared constructor extraction leaves ordinary MatchArm exclusion intact. No edits to your macro-site parity/helper-argument/expected-rebinding mechanisms and no ownership takeover.

Independent external custom-u64 P1 and fresh expected-MAX/local-proc/ancestor-derive counterexamples now refuse through conservative existing namespace/provenance checks plus wildcard/absent workspace macro-context refusal. Qualified assertion identity is not owner primitive identity. The original/selected-zero native controls both compile/pass, and the corrected honesty cases reject actual false-promoting old outputs. Ordinary primitive positives remain supported; no serde expansion, gap/unknown threshold or public schema change.

Final successor32 focused tests and23 independent frozen-artifact CLI controls pass. Check-fast native0 on stable74-file selector (15gates, explicit CLI-help skip), strict workspace/all-target Clippy native0; precommit native0 with selected ripr+xtask strict all-target Clippy and502fixtures/1272comparisons,0drift/violations. Advisory dogfood and final honesty native0. All owned successor commands terminal; no hosted qualification inferred.. Exact consumer PR1503 replay remains complete52/52, all52 objects and top-level fields unchanged;0introduced/removed/changed,18currentweak, target67654dc6 weak.18→17 remains NOT_ESTABLISHED. Direct numeric assertion macro identity and saturation expected-glob independence remain separate prerequisites; no claim that an adjacent PR automatically fixes either.

Current owners rechecked8772 cb6f766,8592 0588422,8597 5aa226a. The8592 successor only changes helper-side eligibility and a From precaution; its existing no-conflict confirmation is preserved.

Fresh independent exact-head source/artifact/oracle/consumer review reports no current actionable findings and all requested bounded local proof complete. Formal REVIEW_INCOMPLETE applies only to unrequested hosted/full-merge qualification; no local blocker or Ready/merge/release authority.

Immutable repair summary and manifest:416 text artifacts /7,425,729 bytes, manifest SHA256 1adf173988e8fa031ff844ae9e977e1db30a1feb0d209e8f3dcd460025f443ca; evidence tree f59a2251480cebc298217bfe31df079beec9e128. Remote commit/tree/manifest blob verified. Fresh final review and all52-row inventory.. Original16ff completed validation and old690975cf evidence custody preserved; oldf4be source clearance does not clear the independent P1. Parent coordinates any next separately sound prerequisite and repeats exact consumer replay. No PR or hostedCI/Ready/merge/release requested by this lane. All witnesses retained, no cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rust: an owner pin credits an expected value that a statement macro or a static rebinds from the owner

2 participants