Repository navigation
fix(python): reach a nested function through its enclosing call only when the enclosing body calls it - #12181
Conversation
…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
|
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 15 seconds. View limit details
|
|
Non-goal tracked separately: observed-result separation for a parent that does call the nested def is #12182. Generated by Claude Code |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
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.
…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
left a comment
There was a problem hiding this comment.
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-functionas authored (return inner(n)):exposed, still credited.- Defines only,
return n:no_static_path. - Spaced call
inner (n):exposed. - Rebound
inner = lentheninner(n):no_static_path. - Called only through a helper def (
other()callsinner,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
There was a problem hiding this comment.
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.
|
Review of record — head 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:
No blocking findings. Merging with Generated by Claude Code |
Summary
nested_called_by_parent: whether the enclosing function's own body, outside the nested def, calls it by name.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.Swarm / Source Boundary
ripr-swarmSource-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
nested_owner_records_whether_the_enclosing_body_calls_it(called, defined-only, recursion-only, returned-callable, top-level) andbody_calls_owner_refuses_nested_function_the_enclosing_body_never_calls. The existingbody_calls_owner_reaches_nested_function_through_enclosing_callstill pins the called case.py-hostile-nested-functionverdict-corpus row must stay credited; that is read from the hostedverdict-corpus check-alloutput on the exact head.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
panic,unwrap,expect,todo, orunimplementedin production code.Generated by Claude Code