Repository navigation
feat(analysis): forward the owner's result through a diverging unwrap_or_else tail (#9638) - #10802
Conversation
…_or_else tail (#9638) A hop caller whose tail is <hop call>.unwrap_or_else(<handler>) forwards the owner's Ok value when the handler is a path to the one workspace function whose whole body only panics or aborts. Closures, substituting handlers, conditional or ambiguous handlers and ok()/is_ok()/unwrap() keep the abstention. Adds the negatives first, authored corpus rows, spec text and traceability. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 16 minutes. View limit details
Comment |
…s own unshadowed item (#9638) A review found four ways the handler name could denote something other than the unique workspace fn: a caller parameter, a nested fn/const/static/let, a function in another module or behind a glob, and a custom return type with its own unwrap_or_else. Require every mention of the name in the caller to be the handler argument, the handler in the caller's own file and inline module, no glob import in the body, and a std Result/Option callee. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
…et (#9638) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
…er and its function scope (#9638) The qualifier of Type::die could be a generic parameter, a local type or an import of the same name, calling an external trait's fn. Require the qualifier to appear in the caller only as the handler path's qualifier and not as an impl-level generic, and track enclosing function bodies in the handler/caller scope comparison. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- A qualifier named like the enclosing workspace type can be accepted without proving that the resolved inherent handler belongs to that exact non-generic type.
- The
.is_ok()corpus trap demonstrates that result-collapsing tails remain uncredited, limiting false owner-result pairing outside the exact diverging handler shape.
Verification questions
- Confirm type::name handlers appear impossible to qualify when a free function of the same name exists anywhere in the workspace.
- Confirm the divergence check recognizes only the literal std::process paths and does not validate imports or rebinding of those paths.
Refuted
- The change introduces unsafe memory access, pointer aliasing, or a dangling borrowed lifetime.; refuted because: The modified production code operates on Rust strings, slices, indices, and owned vectors; it contains no raw pointer dereference, unsafe block, FFI boundary, or new borrowed resource whose lifetime is shortened.
- The unwrap-tail forwarding logic could affect resizable-buffer active-view state or stale backing-store length semantics.; refuted because: The implementation only parses masked Rust source and recognizes a narrowly shaped Result/Option unwrap_or_else tail; it performs no allocation, buffer resize, detach, transfer, or view-length operation.
- The new analyzer state may cross a worker or async handoff and create a use-after-free, GC lifetime, or detach race.; refuted because: No such runtime boundary is present in the diff. Handler metadata is owned, synchronous Rust state with no worker, JS object, GC, detach, or transfer semantics.
- Other unwrap_or_else sibling paths should be admitted by broadening this PR.; refuted because: The spec and implementation deliberately define a narrow exact-tail rule; unit/state-observation and other semantic variants require separate fail-closed rules, so broadening would exceed the stated acceptance delta.
- Recognizing a user-selected source path could introduce an unsafe type-confusion or exploit primitive.; refuted because: No unsafe Rust, FFI, pointer dereference, raw memory operation, or unsafe type cast was added. Recognition changes analyzer metadata only and is constrained to a unique workspace handler with matching placement and divergence semantics.
Parked follow-ups
- The unit-returning
fn grow(&mut self, n) { self.try_grow(n).unwrap_or_else(..) }path is explicitly parked because it needs state observation rather than result forwarding.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
…td for process exits (#9638) The enclosing-scope read took any head containing the substring impl for an impl block, so a function with impl Trait in its signature or impl in its name lost its scope. Parse heads by whole word with brace depth at the exact fn offset, read every enclosing impl header for generics, and refuse a std::process handler when any file declares or renames an item named std. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
There was a problem hiding this comment.
Confirmed findings
- The added resolver is intentionally textual rather than a full Rust name-resolution pass; unusual macro-expanded or nested-item layouts could cause missed credits or unexpected abstentions. A future dedicated resolver would provide stronger architectural isolation.
Verification questions
- Confirm textual scope/name checks may miss valid Rust shadowing forms not represented by the new fixtures, allowing a false owner-result credit.
- Confirm resolution is based on textual scope and import checks rather than full Rust name resolution; unusual alias or attribute forms may remain outside the audited route.
- Confirm the focused tests cover many abstention shapes, but no test covers a local alias that binds the unique diverging handler under another name.
- Confirm broader sibling Result/Option tail families were not exhaustively proven absent; the reviewed implementation and spec intentionally cover only an exact unwrap_or_else(path) tail.
Refuted
- The many focused unwrap_tail tests merely assert classification labels and do not themselves prove runtime discrimination.; refuted because: This concern does not undermine the corpus oracle: its authored subject and runtime mutant-kill metadata connect the exposed classification to an observable assertion. The focused analyzer tests appropriately serve as negative controls for the static rule.
- The diff could affect resizable-buffer active-view state or stale backing-store length semantics.; refuted because: The assigned diff changes static source classification and fixture metadata only; it contains no runtime buffer operations, view windows, length snapshots, resize, detach, transfer, or active-view mutation logic.
- The workspace-wide std rebinding check can reject otherwise valid process-exit handlers, but this is conservative abstention rather than a false credit.
- The change might credit a result-collapsing forwarder such as
.is_ok()and create a false owner-result pairing.; refuted because: The rule requires the complete tail to be exactly.unwrap_or_else(handler)and requires the handler path to be a known diverging workspace function;.is_ok()and other collapsing tails do not satisfy split_unwrap_or_else. - The changed code introduces unsafe memory behavior.; refuted because: Rejected because the modified logic operates on owned Rust strings and vectors and contains no unsafe block, raw-pointer operation, FFI, or lifetime-sensitive resource.
- The changed unwrap-tail analyzer crosses a JS-backed worker, async, GC, detach, or transfer boundary that could create invalid aliasing or use-after-free behavior.; refuted because: The modified production code performs synchronous Rust string parsing, indexed lookup, scope comparison, and classification. No worker, asynchronous task, JS value, GC-managed handle, detached resource, transferable object, pointer, unsafe block, or cross-thread ownership transfer is introduced or modified.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
std_name_rebound now also refuses any use item that binds the final segment std to something other than the standard crate. The Self:: handler qualifier goes through the same exactly-one-workspace-type and enclosing-impl-generics checks as a named Type:: qualifier. Adds negatives for use-bound std, Self:: on a generic or repeated type, and a local alias of the diverging handler. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Review of record, head 3a61533 Independent read-only reviews ran on successive heads from two angles: false credit/soundness, and tests/spec/corpus/policy. Each round ran throwaway probes and guard mutations in separate worktrees.
Delta ec506da..3a61533 was read directly. It only adds refusals (use-binding of Verified at this head by the implementer: Not delivered, stated in the spec and PR: the unit-returning smallvec Marking Ready and requesting Generated by Claude Code |
There was a problem hiding this comment.
Decision
- Needs verification checks before upstream.
Verification questions
- Confirm the corpus includes a positive diverging-handler case and a negative
.is_ok()trap, but the negative is result-collapsing rather than a direct scope-resolution counterexample. - Confirm the owner-result credit depends on textual scope and name checks rather than full Rust resolution, so unusual macro-expanded layouts remain a soundness boundary.
- Confirm the corpus and focused tests strongly cover the intended positive and representative negative families, but they do not exhaust macro-expanded scope/name layouts.
Refuted
- The analyzer's new textual matching might expose an unsafe native-memory or lifetime hazard.; refuted because: The feature is analyzer logic over Rust strings, slices, indices, and owned vectors; it adds no unsafe block, pointer dereference, FFI boundary, or shortened borrow.
- The change could corrupt or misread a resizable buffer's active view by forwarding an owner Result through unwrap_or_else.; refuted because: No buffer, ArrayBuffer, TypedArray, resize, detach, transfer, slice length, backing-store length, or ownership/lifetime operation is introduced. The route consumes ordinary Rust source text and owned strings, and the forwarded Result value is unchanged only on the Ok path.
- The unwrap-tail resolver could create a use-after-free or ownership-transfer defect at a worker handoff boundary.; refuted because: The resolver stores owned handler-path strings and reads analyzer summaries during synchronous classification. It neither crosses a task/thread boundary nor stores borrowed data beyond the analyzer call.
- The change could introduce exploitable memory corruption or type confusion through the new Result/Option tail handling.; refuted because: The changed production path contains no unsafe, raw-pointer, FFI, lifetime-shortening, or runtime type-confusion operation. It only resolves handler metadata and changes an analyzer classification.
Parked follow-ups
- The resolver is textual and therefore can miss or misclassify unusual macro-expanded or nested Rust layouts; this is a known residual limitation, not evidence that this change should broaden sibling handling.
- The unit-returning forwarder form remains explicitly parked because state-observation semantics would require a separate rule; broadening it here would exceed the stated #9638 slice.
- Textual resolver misses can produce false owner-result credit, but this affects static analysis correctness rather than memory safety, type confusion at runtime, disclosure, or exploitability.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
callee_returns_std_result_or_option now also requires that the callee's file has no use binding Result/Option to a non-std item (including renames) and no glob import other than super/self, so an imported type's unwrap_or_else is not read as the std method. Adds negatives with a std-import positive control. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh
|
Review-of-record addendum, head c5a5360 Devin Review reported that an imported custom Verified at this head by the implementer: Re-requesting Generated by Claude Code |
There was a problem hiding this comment.
Verification questions
- Confirm focused tests cover many handler-shadowing and tail-shape variants, but not an imported custom Result/Option in the callee file.
- Confirm the existing imported-Result false-credit concern remains applicable to the new route.
- Confirm focused unwrap-tail tests verify analyzer classifications but do not independently demonstrate runtime mutation discrimination for each credited shape.
Refuted
- The .is_ok() trap can accidentally receive the same owner-result credit as the diverging handler.; refuted because: The corpus control remains non-discriminating by design and expects limited/no_static_path, while the production tail rule accepts only the exact unwrap_or_else(path) shape.
- The changed analyzer logic introduces a worker handoff, async capture, GC boundary, detach, or transfer of memory ownership.; refuted because: The diff changes Rust analyzer source and tests only. It operates on masked text, owned strings, slices, indices, and vectors, with no worker, async, JS runtime, GC-managed object, buffer detach, or ownership transfer.
- Forwarding the owner's Ok value through unwrap_or_else could corrupt or resize an active buffer view.; refuted because: The changed route recognizes a textual helper-call tail and changes classification metadata only; it does not perform or model buffer mutation, resize, detach, transfer, or view-length operations.
- The resolver does not cover crypto, compression, or runtime-specific sibling helpers, but those meta-classes are irrelevant to this value-preserving Result/Option unwrap transformation.
- Other Result/Option forwarding or unwrapping shapes should receive equivalent owner-result credit in this PR.; refuted because: They do not have the same forwarding invariant: closures and value-substituting handlers can change the Ok value, is_ok collapses it, and unit-returning tails need state-based reachability.
- The PR could create a dangling borrow or aliasing hazard while forwarding the owner's result.; refuted because: The implementation analyzes source text and metadata only; it does not manipulate runtime ownership, references, pointers, or native buffers. The added Vec and slice accesses are ordinary bounded Rust operations.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Parked follow-ups
- The unit-returning forwarder shape is a known missed-credit family and should remain parked because it requires state observation rather than value forwarding.
- Handler resolution is intentionally textual and scope-based rather than a full Rust name-resolution pass.
|
Merged as fe57f0a (squash, expected head c5a5360). Generated by Claude Code |
Summary
<hop call>.unwrap_or_else(<handler>)now forwards the owner's result when<handler>is a path to a workspace function that only diverges, so the owner'sOkvalue passes through unchanged. This is the value-returning slice of the smallvecgrow/try_growspecimen tail in Missed credit: Rust forwarded-result and public-API reach (propagation_unknown, transitive_reach_unresolved) #9638.name(free fn) orType::name/Self::name(inherent associated fn), the one workspace function of that name, outside test or evidence source, in the caller's own file and same non-impl scope sequence (whole-word scope parsing; anything unreadable is opaque and refuses). Every mention of the handler name and of its qualifier in the caller must be the handler path itself (no parameter, generic, nested item or local binding), the qualifier must be exactly one workspace type, no glob or foreign import may rebind the name, the hop callee must return stdResult/Option, and the whole body must be one unconditionalpanic!/unreachable!/unimplemented!/todo!(not rebound) orstd::process::abort()/exit(..)withstdnot rebound by any declaration, rename orusein the workspace. Resolved once per hop at chain construction (HelperHop::diverging_handlers), then consumed bycaller_tail_forwards_call.unwrap_or/unwrap_or_default/|_| false, non-diverging or conditionally diverging handlers, ambiguous names, module-qualified/generic/external paths,.ok(),.is_ok(),.unwrap(),.expect(..), further operations on the unwrapped value, and aliases of the handler.fn grow(&mut self, n) { self.try_grow(n).unwrap_or_else(..) }). There is no result for an exact assertion to pin, so credit would need a state-observation rule (!v.spilled()) that could not be made fail-closed here. A handler declared-> !is also not read.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Spec: RIPR-SPEC-0159
Governing issue or accepted claim: #9638
Acceptance delta (one sentence): a forwarder that unwraps the owner's
Resultwith a uniquely named, unconditionally diverging workspace handler now pairs the test's boundary pin with the owner, while every substituting, closure, ambiguous, shadowed or non-diverging handler still abstains.Candidate Relationships
Candidate branch: claude/missed-credit-tail-9638
Stack parent or prerequisite PR (if any): none (follows merged #10628)
Scope
helper_transfer.rs:diverging_handlers,handler_diverges,function_only_diverges,split_unwrap_or_else, scope/qualifier/stdguards, and thecaller_tail_forwards_calltail rule; newHelperHopfield.forwarder-hop-unwrap-diverging-handler(credited) andforwarder-hop-unwrap-is-ok-tail(trap), RIPR-SPEC-0159 behavior bullets and acceptance examples 12 and 13, traceability, changelog fragment.Proof
implsubstring in scope parsing,stdbound by a pathuse); each was reproduced asexposed, fixed fail-closed with a pinned negative, and re-reviewed. The final round at ec506da found only thestduse-binding case, fixed at the current head.cargo xtask precommitexit 0 (goldens INCOMPLETE forowner_return_pin_fallible_literal, the known environment gap; hosted CI owns it).cargo clippy -p ripr -p xtask --all-targets -- -D warningsclean.helper_wrapper_reach88 passed,method_helper_reach41,crate_qualified_entry_reach12,--lib classify::1785.verdict-corpus check: 741 cases, false verdicts 0/741, contradictions 0/935. No existing row moved; no Perl or TypeScript file changed.stdrebinding each fail at least one test when removed. A few redundant guards are kept as documented defense in depth.Missed-credit accounting
missed-credit.tomlis unchanged. The unit-returning smallvec shape remains a missed credit.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh