Skip to content

feat(analysis): forward the owner's result through a diverging unwrap_or_else tail (#9638) - #10802

Merged
EffortlessSteven merged 9 commits into
mainfrom
claude/missed-credit-tail-9638
Oct 27, 2026
Merged

EffortlessSteven merged 9 commits into
mainfrom
claude/missed-credit-tail-9638

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • A hop caller whose tail is exactly <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's Ok value passes through unchanged. This is the value-returning slice of the smallvec grow/try_grow specimen tail in Missed credit: Rust forwarded-result and public-API reach (propagation_unknown, transitive_reach_unresolved) #9638.
  • Narrowest sound case: the handler is name (free fn) or Type::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 std Result/Option, and the whole body must be one unconditional panic!/unreachable!/unimplemented!/todo! (not rebound) or std::process::abort()/exit(..) with std not rebound by any declaration, rename or use in the workspace. Resolved once per hop at chain construction (HelperHop::diverging_handlers), then consumed by caller_tail_forwards_call.
  • Everything else keeps the abstention: any closure, 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.
  • Not delivered: the unit-returning specimen (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

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

Source-of-truth Links

Spec: RIPR-SPEC-0159
Governing issue or accepted claim: #9638
Acceptance delta (one sentence): a forwarder that unwraps the owner's Result with 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/std guards, and the caller_tail_forwards_call tail rule; new HelperHop field.
  • Authored corpus rows forwarder-hop-unwrap-diverging-handler (credited) and forwarder-hop-unwrap-is-ok-tail (trap), RIPR-SPEC-0159 behavior bullets and acceptance examples 12 and 13, traceability, changelog fragment.

Proof

  • Negatives first throughout. Four independent read-only review rounds on successive heads each found a real false credit (handler-name shadowing, qualifier shadowed by a generic parameter, impl substring in scope parsing, std bound by a path use); each was reproduced as exposed, fixed fail-closed with a pinned negative, and re-reviewed. The final round at ec506da found only the std use-binding case, fixed at the current head.
  • cargo xtask precommit exit 0 (goldens INCOMPLETE for owner_return_pin_fallible_literal, the known environment gap; hosted CI owns it). cargo clippy -p ripr -p xtask --all-targets -- -D warnings clean.
  • Focused: helper_wrapper_reach 88 passed, method_helper_reach 41, crate_qualified_entry_reach 12, --lib classify:: 1785.
  • Rust verdict-corpus check: 741 cases, false verdicts 0/741, contradictions 0/935. No existing row moved; no Perl or TypeScript file changed.
  • Mutation checks: handler-in-known-set, name uniqueness, caller rebinding, placement, evidence role, import/rename shadow, body divergence, macro rebinding, std/Result-Option callee check, scope-sequence equality, name-only-as-handler, qualifier check and std rebinding each fail at least one test when removed. A few redundant guards are kept as documented defense in depth.

Missed-credit accounting

missed-credit.toml is unchanged. The unit-returning smallvec shape remains a missed credit.


Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_018HD9fbAVQpnXMUzif6Y2oh

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

@coderabbitai

coderabbitai Bot commented Oct 26, 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 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 163 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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: f21e92db-9032-4c3a-be4b-dc658ea5dee3
Commits

Reviewing files that changed from the base of the PR and between 477569c and c5a5360.

Files ignored due to path filters: 1
  • fixtures/rust-verdict-corpus/spec-examples.lock is excluded by !**/*.lock
Files selected for processing: 20
  • .ripr/traceability.toml
  • changelog.d/9638-diverging-unwrap-tail.md
  • crates/ripr/src/analysis/classify/activation.rs
  • crates/ripr/src/analysis/classify/boundary_pairing.rs
  • crates/ripr/src/analysis/classify/helper_transfer.rs
  • crates/ripr/src/analysis/classify/helper_transfer/returned_ledger.rs
  • crates/ripr/src/analysis/classify/owner_pin.rs
  • crates/ripr/src/analysis/classify/related_tests.rs
  • crates/ripr/src/analysis/classify/related_tests/fmt_dispatch.rs
  • crates/ripr/tests/helper_wrapper_reach.rs
  • docs/specs/RIPR-SPEC-0159-bounded-helper-transfer.md
  • fixtures/rust-verdict-corpus/cases/forwarder-hop-unwrap-diverging-handler.diff
  • fixtures/rust-verdict-corpus/cases/forwarder-hop-unwrap-diverging-handler.json
  • fixtures/rust-verdict-corpus/cases/forwarder-hop-unwrap-is-ok-tail.diff
  • fixtures/rust-verdict-corpus/cases/forwarder-hop-unwrap-is-ok-tail.json
  • fixtures/rust-verdict-corpus/expected/rows/forwarder-hop-unwrap-diverging-handler.json
  • fixtures/rust-verdict-corpus/expected/rows/forwarder-hop-unwrap-is-ok-tail.json
  • fixtures/rust-verdict-corpus/subjects/authored-forwarder-hop.json
  • fixtures/rust-verdict-corpus/subjects/authored-forwarder-hop/src/lib.rs.txt
  • fixtures/rust-verdict-corpus/subjects/authored-forwarder-hop/tests/main.rs.txt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

…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
…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

@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

  • 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

@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 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
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 27, 2026 04:10
@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!

Copy link
Copy Markdown
Member Author

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.

Head reviewed Finding Resolution
b8aeb27 Handler name shadowed by a parameter, nested item, other module, glob, or a custom unwrap_or_else type Fixed in f417127 with pinned negatives
f7fe1a9 Qualifier of Type::die shadowed by a generic parameter (reproduced exposed) Fixed in 1bd37bc
1bd37bc contains("impl") substring dropped function scope, reproduced exposed Replaced with whole-word scope parsing in ec506da
ec506da std bound by a path use (use ext::std;) left std::process::abort() credited; Self:: skipped the type checks Fixed in 3a61533, with alias and Self negatives

Delta ec506da..3a61533 was read directly. It only adds refusals (use-binding of std, Self through the same qualifier checks). At ec506da the reviewer attacked the scope parser with about 45 noise controls and attacks and found no false credit from it.

Verified at this head by the implementer: cargo xtask precommit exit 0 (known goldens INCOMPLETE environment gap), clippy clean, helper_wrapper_reach 88 passed, Rust verdict corpus 0/741 false. The final delta's tests were not independently re-run by a reviewer, so hosted CI is the remaining check. Automated reviews were noise or hypotheses already covered (textual resolution is intentional; unit-returning shape is parked in the spec).

Not delivered, stated in the spec and PR: the unit-returning smallvec grow shape.

Marking Ready and requesting merge-ready on this exact head.


Generated by Claude Code

@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 1 potential issue.

Devin Review

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

Copy link
Copy Markdown
Member Author

Review-of-record addendum, head c5a5360

Devin Review reported that an imported custom Result/Option (use dependency::Result;) could be taken for std, so a custom unwrap_or_else that transforms the Ok value would still credit the forwarder. A first review had noted the same gap as a nit. The source confirmed it, so I treated it as a real false-credit path. c5a5360 now refuses when the callee's file has any use binding Result or Option (including renames) other than the exact std/core paths, or any glob import other than super::*/self::*. The negative test covers eight spellings, with std/core result::Result and a no-import control staying exposed. The check was neutralised and the test failed, so it bites. The scan covers the whole callee file, which over-refuses on purpose.

Verified at this head by the implementer: cargo fmt --check, clippy -p ripr -p xtask --all-targets -D warnings and cargo xtask precommit all exit 0. helper_wrapper_reach 89, method_helper_reach 41, crate_qualified_entry_reach 12, --lib classify:: 1785 passed. verdict-corpus check-all: Rust 0/741 false, 0/935 contradictions, traps credited 0/43. The Perl 1/88 and TypeScript 1/361 false verdicts sit outside this Rust-only change; I confirmed the PR touches no Perl or TypeScript files. This delta was not independently re-run by a separate reviewer. The earlier review rounds and hosted CI are the remaining independent checks.

Re-requesting merge-ready on this exact head. The prior run was on 3a61533.


Generated by Claude Code

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

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.

@EffortlessSteven
EffortlessSteven merged commit fe57f0a into main Oct 27, 2026
59 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/missed-credit-tail-9638 branch October 27, 2026 05:35

Copy link
Copy Markdown
Member Author

Merged as fe57f0a (squash, expected head c5a5360). Ripr Rust Small Result was green on that exact head (run 40451573344), the PR was mergeable clean, and the only review thread (Devin, imported Result) was replied to and resolved. Review of record and addendum above.


Generated by Claude Code

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.

2 participants