Skip to content

fix(python): reach a nested function through its enclosing call only when the enclosing body calls it - #12181

Merged
EffortlessSteven merged 2 commits into
mainfrom
fix/python-nested-owner-parent-call-reach
Nov 1, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
fix/python-nested-owner-parent-call-reach

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

  • Nested Python function owners now record nested_called_by_parent: whether the enclosing function's own body, outside the nested def, calls it by name.
  • The parent-call (body_calls_owner), parent-name (related_test_relation) and parent-import (import_binds_owner_name) reach branches added in fix(python): require receiver identity for attribute-sink credit and qualify nested owners #11182 are gated on that flag. A test that only calls an enclosing function that merely defines the nested helper no longer relates to, or credits, the helper's changed body.
  • Fail-closed: a call inside the nested body itself, or returning the nested def without calling it, does not count.

Swarm / Source Boundary

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

Source-of-truth Links

Spec: docs/specs/RIPR-SPEC-0028-python-adapter.md
Governing issue or accepted claim: #12141
Acceptance delta (one sentence): A test of an enclosing Python function that never calls its nested def no longer reaches or credits the nested def's changed body, while a called nested def stays credited.

Scope

Proof

  • New unit tests: nested_owner_records_whether_the_enclosing_body_calls_it (called, defined-only, recursion-only, returned-callable, top-level) and body_calls_owner_refuses_nested_function_the_enclosing_body_never_calls. The existing body_calls_owner_reaches_nested_function_through_enclosing_call still pins the called case.
  • The py-hostile-nested-function verdict-corpus row must stay credited; that is read from the hosted verdict-corpus check-all output on the exact head.
  • No local Rust build was available. rustfmt passes on every touched file; hosted CI is the only compile and test evidence. All 12 PythonOwner { .. } literals (3 in owners_tests.rs, 8 in python_tests.rs, 1 in static_limits.rs) were grepped and updated.

Claim Boundary

May claim: uncalled nested defs get no parent-call reach. Must not claim: observed-result separation for a parent that does call the nested def.

Rollback

Revert the squash commit. No schema or public-contract change.

Engineering Check

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

Generated by Claude Code

…when the enclosing body calls it (#12141)

Records nested_called_by_parent on nested function owners and gates the
parent-call, parent-name and parent-import reach branches on it, with
unit tests for called, defined-only, recursion-only and returned-callable
nested defs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG
@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 Nov 1, 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 15 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 149 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: 403d25fc-2b12-47da-a480-7f7655407d83
Commits

Reviewing files that changed from the base of the PR and between e9c5b8e and 2977d4d.

Files selected for processing: 10
  • .ripr/traceability.toml
  • changelog.d/12141-python-nested-owner-parent-call-reach.md
  • crates/ripr/src/analysis/language/python.rs
  • crates/ripr/src/analysis/language/python/fact_store.rs
  • crates/ripr/src/analysis/language/python/owners_tests.rs
  • crates/ripr/src/analysis/language/python/owners_tests/tests.rs
  • crates/ripr/src/analysis/language/python/python_tests.rs
  • crates/ripr/src/analysis/language/python/related_tests.rs
  • crates/ripr/src/analysis/language/python/static_limits.rs
  • docs/specs/RIPR-SPEC-0238-python-oracle-and-reach-rules.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Copy link
Copy Markdown
Member Author

Non-goal tracked separately: observed-result separation for a parent that does call the nested def is #12182.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review November 1, 2026 14:52
@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!

@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 suite does not prove that only an actual parent-body call enables parent-name, parent-call, and parent-import reach; alias calls and shadowed names are untested.
  • Confirm the nested-parent search uses only qualified name and file, not scope, so same-named functions in different lexical scopes may be confused.
  • Confirm the parent-call detector excludes every line in the nested definition, including a one-line function definition whose call may be semantically part of the parent body.

Evidence gaps

  • Compile and test completion remain unverified in the available packet, and ripr failed with exit code 2.
  • Model proof intent was rejected by deterministic validation.
  • Compile and test proof is unavailable: cargo-test was scheduled but has no receipt, while ripr failed with exit code 2.

@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 5 potential issues.

Devin Review

…ted-def calls (#12141)

Compute nested_called_by_parent from the enclosing body's own statements
(nested defs and classes excluded), accept spaced calls, fail closed on a
rebound name, bump the python-file-facts schema to 14 for the new owner
field, and add spec rule 31 with traceability.

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

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEW_READY — head 2977d4d

Full review of #12181 (#12141) at this head. I did not use the earlier 5e650e6 review.

Production path, not test-only. owners_tests.rs is an unconditional module (mod owners_tests; with no cfg(test)), and collect_owners_from_statements is the production owner collector. body_calls_nested_def sets nested_called_by_parent at both the FunctionDef and AsyncFunctionDef sites. Its input is the enclosing body's own statements, with nested defs and classes excluded.

Gates. The flag gates all three reach branches in related_tests.rs: the name-anchor parent mention, body_calls_owner and import_binds_owner_name. A direct test call of the nested name is unchanged.

Literals. There are 12 PythonOwner { .. } literals (3 in owners_tests.rs, 1 in static_limits.rs, 8 in python_tests.rs), and each sets nested_called_by_parent: false. The three production constructors set false, and only the nested path overwrites it, so nothing over-credits by default. A default of false removes parent-call reach.

Behaviour, run with the head binary (ripr check, fast) on the hostile fixture variants.

  • py-hostile-nested-function as authored (return inner(n)): exposed, still credited.
  • Defines only, return n: no_static_path.
  • Spaced call inner (n): exposed.
  • Rebound inner = len then inner(n): no_static_path.
  • Called only through a helper def (other() calls inner, return other()): no_static_path. This is the documented fail-closed case, and a missed credit is the safe direction.
  • The unit test also pins recursion-only, returned-callable and unused-sibling. Alias calls (f = inner; f(n)) have no by-name call, so they are false.

Schema bump 13 to 14. PythonOwner derives Serialize/Deserialize and the new field has no serde default. A 13 entry would fail to deserialize, but the schema version is part of the fact-store key, so 13 entries read as misses and are not parsed. That makes the bump necessary. The precedent is the 12 to 13 bump in #11854, which touched only fact_store.rs and not CACHE_SCHEMA_VERSION or the seam-cache constants, so no further cache bump follows from this change. No golden or test pins "13". I found no other open PR bumping PYTHON_FILE_FACT_SCHEMA_VERSION, but a later one would have to take 15 at merge, as with the other hand-bumped constants.

Spec and traceability. Rule 31 in RIPR-SPEC-0238 matches the code (spaced calls, nested defs and classes excluded, rebind fail-closed, the assertion-observation split pointed to #12182). Both new tests are mapped in .ripr/traceability.toml.

Non-blocking. Defs nested inside an if, with or for block within the enclosing body are not excluded from the executed text, because only top-level defs and classes are filtered. A call from an unused def inside such a block would count. This is rare, and it is no worse than before, when all nested owners were reached. Also, a second def inner in the same body is not treated as a rebind.

Limits of my run. Whole-workspace lib tests are killed by this sandbox's memory limit, so the two new unit tests were not run here and compile only in the routed shards. The behaviour above was checked through the built binary.


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.

Decision

  • Needs reviewer attention before upstream: findings remain.

Confirmed findings

  • The call detector can credit a nested definition when a different local binding shadows or replaces it.

Verification questions

  • Confirm a parent-body call nested under a non-executed control-flow branch is still counted as parent reach, although the spec says only statements that run with outer call inner.
  • Confirm a call inside an enclosing-body control-flow block is not established as executed by the enclosing function, but the detector counts it as a parent call.
  • Confirm the detector can count a qualified call such as module.inner() as a call to the nested function named inner.
  • Confirm the helper boundary intentionally excludes nested defs and classes, but its rebinding detection is a lexical subset rather than a complete Python binding analysis.
  • Confirm the detector misses a valid call when whitespace separates the nested name and opening parenthesis.

Evidence gaps

  • Executable proof is unavailable in the supplied packet because cargo-test has no receipt and ripr failed with exit code 2.
  • Model proof intent was rejected by deterministic validation.
  • Successful Rust compile/test evidence is unavailable at this packet.
  • Compile and test completion are not established in the available evidence packet.

Copy link
Copy Markdown
Member Author

Review of record — head 2977d4d61ecde666ea072aea32c54dbf0fb61939

Angles: (1) independent full review at this head by the coordinator's reviewer, REVIEW_READY (review 5728734504), including behavior through the built binary on hostile variants: py-hostile-nested-function still exposed; defines-only, rebound and helper-only calls no_static_path; spaced call exposed; (2) hosted evidence on this exact head; (3) review-thread triage.

No blocking findings. Merging with expectedHeadSha.


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.

1 participant