Skip to content

fix(python): star import fails closed when another binding may win the owner name (#9415) - #9580

Merged
EffortlessSteven merged 7 commits into
mainfrom
claude/py-star-import
Oct 26, 2026
Merged

EffortlessSteven merged 7 commits into
mainfrom
claude/py-star-import

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Governing issue or accepted claim: #9415 (follow-up to merged #9583)
Acceptance delta (one sentence): a star import no longer credits a public owner when the module rebinds the name, a second star import is present, or the test imports or aliases a different symbol to that name.

Before: after #9583, from M import * credits the owner even if from M import other as total, from X import total, a second star import, or a module-level reassignment means the asserted name is a different object (counterexample from the review on this PR).

After: those shapes stay weakly_exposed; the plain star import still credits.

How: import_binds_owner_name takes the test and refuses on competing bindings; star_exported additionally requires the module to bind the name exactly once. New test star_import_fails_closed_when_another_binding_may_win_the_name covers each shape.

Replaces the earlier implementation on this branch, superseded by #9583.

🤖 Generated with Claude Code

https://claude.ai/code/session_017MAPgoFThhCueiFwfZvjVz

@coderabbitai

coderabbitai Bot commented Oct 22, 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 40 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 186 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: f871a5fc-9b37-4887-859a-e2bdb23f4b7f
Commits

Reviewing files that changed from the base of the PR and between 494a296 and 4b9f393.

Files selected for processing: 3
  • crates/ripr/src/analysis/language/python/reexports.rs
  • crates/ripr/src/analysis/language/python/related_tests.rs
  • crates/ripr/src/analysis/language/python/verdict_corpus_tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request implements support for crediting Python tests that reach a changed function or class via star imports (from module import *). It introduces a star_exported field to PythonOwner and resolves star import bindings while honoring literal __all__ declarations and skipping private names. The review feedback highlights two key issues: first, a potential false positive where competing explicit imports from other modules are not correctly detected as conflicts if they do not use an alias; second, an overly restrictive check that filters out private names starting with an underscore even when they are explicitly listed in __all__.

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

Devin Review

Copy link
Copy Markdown
Member Author

Bounded independent source review of exact head ce65d4b (cloud assignment for #9415; candidate untouched): please add a same-source competing-alias control before qualification.

star_import_binds_owner excludes competing imports only when other.source_module != import.source_module. Thus this shape passes that helper even though the asserted name is another function:

# hostile/stars.py
def total(a, b):
    return a - b

def other(a, b):
    return a + b

# tests/test_stars.py
from hostile.stars import *
from hostile.stars import other as total

def test_total():
    assert total(2, 3) == 5

A fresh Python 3.12.14 in-memory execution confirms the assertion passes and the imported total is other; the changed production total(2, 3) returns -1. The star helper's source-module inequality lets that alias escape the intended competing-binding refusal. The direct credit consumer in sink_alignment.rs uses this module-identity result. The ordinary module-rebinding collector cannot enumerate the star's names, so the explicit alias is only one counted binding.

This is a source-backed counterexample request, not a fresh analyzer-output claim: this cloud image has no cargo/rustc/ripr on PATH, so exact-head analyzer reproduction and CI qualification are not established here. Suggested next step: extend the existing competing-import test to same-module other as total, require non-exposed, then repair the guard in this owned candidate if it fails. Main refreshed to b98867f still has the original named-import-only authority and false_actionable corpus row. #9583 also covers #9415; coordinate candidate selection with its owner instead of landing both.

Copy link
Copy Markdown
Member Author

Thanks, the counterexample was right. Pushed bddb067: star_import_binds_owner now refuses when any other import aliases the owner's name to a different symbol, even from the same module (plain from M import total still credits). Added star_import_fails_closed_when_the_same_module_aliases_another_name_to_the_owner_name (non-exposed), which passes. The same push also carries the earlier Rust gates fix: an owner module that binds the name more than once now fails closed. cargo xtask precommit passes locally. On #9583: this PR keeps the claim for #9415 unless its owner objects.


Generated by Claude Code

…e owner name (#9415)

#9583 credits a star import for a public owner; this refuses that credit when
the module binds the name more than once, the test star-imports a second
module, or the test imports the name from elsewhere or aliases another symbol
(including from the same module) to it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017MAPgoFThhCueiFwfZvjVz
@EffortlessSteven EffortlessSteven changed the title fix(python): credit a test that reaches the owner through a star import (#9415) fix(python): star import fails closed when another binding may win the owner name (#9415) Oct 22, 2026

Copy link
Copy Markdown
Member Author

The failing build and inspect Linux x64 wheel check is not from this PR. Main itself fails to compile at crates/ripr/src/agent/artifact.rs:719 (&subject is not in scope in validate_artifact_identity), and this branch contains none of that file. No fix has landed on main yet. Once it does I'll merge main into this branch and request merge-ready. The same job will be re-run once at that point.


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 focused proof failure resolved before upstream.

Verification questions

  • Confirm the added regression proves only the negative module-rebinding case, not the intended positive behavior of binds_once for a normal exported owner.
  • Confirm the corpus fixture tests competing test-side imports but does not independently establish that StarExports::exports and binds_once jointly credit a public all member.
  • Confirm the new regression corpus exercises owner rebinding and same-module aliasing, but not conditional/import binding forms named in binds_once documentation.

Refuted

  • A public name starting with underscore would be incorrectly credited when listed in all.; refuted because: The current implementation deliberately excludes underscore names; this may under-credit an unusual Python export shape but does not create false positive exposure.
  • The starred call must also receive assigned-result alignment for this fix to be complete.; refuted because: The stated acceptance claim is direct owner-name import exposure; existing owner_module_callees alignment is a separate route and the seeded comment does not establish it as required by this change.

Test proof

  • Focused HEAD proof failed (exit 101): cargo test --locked --package ripr --test agent_command_journey. This is a current failure, not a red/green witness.

Parked follow-ups

  • Star-import credit is limited to direct owner-name assertions and does not establish assignment-result provenance.
  • Residual: a _private name explicitly listed in a literal __all__ stays non-star-exported because the !owner.name.starts_with('_') short-circuit is preserved. This is documented as a deliberate fail-closed; a star import would in fact bind it, so this is a missed credit, not a false positive.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.
  • The PR's claimed runtime execution and precommit result are historical claims; the current sensor receipt records cargo-test as late/pending.

Copy link
Copy Markdown
Member Author

Reply to the bot review on c6029d9:

  • agent_command_journey failure (exit 101): this is the same main compile break at agent/artifact.rs:719 described above, not this PR's change. This branch does not touch that file.
  • Positive case for a normal exported owner: star_import_binds_a_public_owner_for_the_strong_oracle and star_import_honors_the_module_all_declaration (both from fix(python): a star import binds public owner names for the strong-oracle identity check (#9415) #9583) still pass with binds_once in place. They cover a plain exported owner and a literal __all__.
  • Conditional binding forms: stmt_binds already recurses into if/try/with/match. The new star_import_fails_closed_when_another_binding_may_win_the_name test lacked a conditional case, so I added one (if DEBUG: fee = ...) in the follow-up commit; it passes.
  • _private names listed in __all__: a deliberate missed credit, not a false positive, as the review notes.

Generated by Claude Code

Copy link
Copy Markdown
Member Author

Main's compile break is fixed (#9701), so I merged main into this branch (61dc0da) and added merge-ready to request the required Ripr Rust Small Result on that head. The earlier wheel failures were the break, so this is the one re-run. I'll check the result and merge if it passes.


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 verification checks before upstream.

Verification questions

  • Confirm there is no explicit positive control proving that binds_once still credits a normal public star import or a literal all member.
  • Confirm the new module-side count can reject an owner for a top-level binding collected by stmt_binds, but an augmented binding such as annotated assignment may be represented by separate AnnAssign and Assign nodes and counted twice.
  • Confirm the corpus proves negative module/test bindings but this diff does not add a focused assertion that the unchanged positive public-owner route remains exposed.
  • Confirm the focused negative tests cover rebinding, conditional rebinding, cross-module named imports, same-module aliases, and competing star imports; positive export routes are documented as already passing in the seeded thread.

Refuted

  • The assigned-result alignment gap for starred calls is a blocker for this PR.; refuted because: The PR's stated acceptance delta is direct owner-name import exposure; assigned-result alignment is an existing separate route and is outside this focused behavior change.
  • The module rebinding and competing-import fixes changed the intended plain star-import positive route.; refuted because: The guard applies only to imported == "*"; plain named imports retain the existing path, while owner.star_exported still comes from public export and binds_once checks.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.
  • The changed tests do not directly execute Python; their oracle depends on classify and fixture construction, so the final execution receipt remains important.
  • Focused executable proof is absent from the supplied evidence despite the changed Rust behavior.

Copy link
Copy Markdown
Member Author

Reply to the bot review on 61dc0da:

  • Positive control: the unchanged positive routes are pinned by star_import_binds_a_public_owner_for_the_strong_oracle (plain from src.shop import * stays Exposed) and star_import_honors_the_module_all_declaration (literal __all__ member stays Exposed). Both pass with this change.
  • Double counting: binds_once counts top-level statements, one count per statement. An AnnAssign is a single statement, so a declaration cannot count twice.
  • Execution: the focused tests ran locally and cargo xtask precommit passed. The build and inspect Linux x64 wheel check now passes on this head, so the earlier red was the main compile break.

I'm waiting on the required Ripr Rust Small Result before merging.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Handoff: this PR qualified on head 61dc0da (Ripr Rust Small Result, Linux wheel and ub-review green; all review threads answered and resolved). The squash merge was refused because main moved and now conflicts with the branch. The next step is to merge main into claude/py-star-import, resolve the conflict, then remove and re-add merge-ready for the new head and merge once Ripr Rust Small Result passes on it. The conflicting files should be among reexports.rs, related_tests.rs and verdict_corpus_tests.rs, the only files this PR changes; I haven't seen the conflict itself. I was not permitted to merge main from this session, so whoever has permission can pick this up from there.


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 verification checks before upstream.

Verification questions

  • Confirm the corpus does not prove that the changed guard preserves a plain public star import or a literal all export; seeded thread reports those unchanged positives pass, but this diff contains no positive assertion.
  • Confirm the direct star-import route reaches the changed owner-export and competing-import guards.
  • Confirm the new corpus proves the stated direct-call negative cases and retains the existing public-owner positive route.

Refuted

  • Assigned-result alignment for starred calls must be part of this fix.; refuted because: The acceptance delta and changed code target direct owner-name import exposure; assigned-result alignment is a separate route that fails closed and was explicitly parked in the seeded thread.
  • A public name beginning with underscore should be credited when explicitly listed in literal __all__.; refuted because: This is an acknowledged under-crediting behavior rather than false-positive exposure and is outside the fail-closed acceptance delta.

Evidence gaps

  • Executable verification is not yet available in the packet: the ripr sensor failed with exit code 2 and cargo-test is scheduled late.
  • Model proof intent was rejected by deterministic validation.
  • The planned ripr sensor failed, so analyzer execution and corpus behavior lack a successful receipt in the available evidence.

Copy link
Copy Markdown
Member Author

Independent exact-head proof: REPAIR_REQUIRED for whole-name star-import admission.

Canonical writer remains claude/py-star-import; no submitted branch edits or hosted dispatch. Reviewed head 7ec4ad96dbeef549db0de2f249743cce5bef7aa9, tree f450511a57ed69347cc565bafc73204d46dc7d96, PR base/merge-base d68b3420c64adbdb74ea463f0dd087e79b8f6707. Reconciled existing reviews and all five resolved inline threads, including the owner’s positive-control receipts and accepted private-name / assigned-result conservative non-goals. Those non-goals are not findings here.

A genuinely missing module-side control fails on unchanged production bytes. Using the existing verdict_corpus_tests::classify consumer (owner extraction → apply_package_reexports → classify_change_with_old), append each suffix below to the existing FEE owner fixture (def fee(amount): return amount * 3, changed from * 2), then use from src.shop import * and assert fee(2) == 6:

Owner-module suffix Observed analyzer class
globals()['fee'] = lambda amount: 6 Exposed
globals().update(fee=lambda amount: 6) Exposed
exec('fee = lambda amount: 6') Exposed
from src.other import * Exposed

These must withhold owner credit when another binding may win. StarExports::binds_once counts only stmt_binds; target_binds ignores subscript targets, expression writes are not counted, and ImportFrom explicitly excludes *. This leaves the original definition as the sole counted binding without proving it remains the exported value. The test-side import guard cannot see those owner-module writes.

Native execution on Linux x86_64, preinstalled Rust 1.95.0: cargo test --locked -p ripr --lib star_import -- --nocapture passed 4/4, including plain public owner, literal __all__, and existing competing-binding controls. Added test-only review_9580_dynamic_whole_name_controls failed, exit 101, reporting Exposed for all four rows; its sole-owner positive assertion passed first. No production edits. Experimental tree df77bdae751eb9c5d1677bdd0e546288219c68c4; patch SHA-256 4d04b99b21911d6404f9dfadbafc2622fc2f0f62cdd497d82488eaffb385b5ed; executed test binary SHA-256 857605d36dad2290cc6b4d19f7d815f89d16db883a1d7a4d46987a4a245bd7e4.

Independent Python 3.12.14 runtime control confirms each suffix replaces the exported function (for the star case, the other module exports the replacement). Mutating the original owner from * 3 to * 99 breaks the sole-owner assertion, while all four replacement cases still pass. Thus this is false positive exposure, unlike the accepted conservative missed-credit cases.

Next action for the existing implementation owner: add these negative controls to this candidate and make whole-name star admission fail closed for unresolved module namespace writes and competing module-side stars, preserving the two existing positives. No rival implementation created. This receipt establishes local analyzer/runtime behavior only; current-main composition, hosted qualification, protections and landing are unverified. The fetched main is 875d1f2a30ae4ed4ea7d68dba74f76f769e08868; no main-integration or merge claim is made.

Copy link
Copy Markdown
Member Author

Retrievable technical contribution for the existing claude/py-star-import owner: commit 3d6918ab78b304e6f95817aa5afd8e9b1c0dbe50. This creates Git objects only; the canonical branch has not been updated and no competing PR was opened.

I rechecked the owner head and discussion immediately before this handoff: the head remains 7ec4ad96dbeef549db0de2f249743cce5bef7aa9, with no intervening repair recorded. The contribution's sole parent is that head. Its tree is f8ebe4f4e2c4e517473396a39955007e8582e739, byte-identical to independently reviewed local candidate 566251b27eb6774b5c0746801a374d3544fee1b8. All 32 changed paths (31 distinct blobs), the tree and commit were read back; blob content and parent/tree identities match.

The bounded repair reuses the existing conservative namespace-write detector for source-module globals() assignment/update and exec, and counts unresolved module-side star imports only for binds_once. Package/__all__ readers retain their existing star-resolution behavior. The genuine sole-owner and literal-__all__ positives remain credited. This addresses the direct-star cases in the original finding, without widening into the accepted private-name or assigned-result non-goals.

Recorded local proof on the reviewed source:

  • 5/5 focused star-import tests and 20/20 package re-export tests passed.
  • Fresh actual CLI fixtures produced four weakly_exposed replacement findings and two exposed genuine-owner controls; both fixture comparisons passed.
  • Python owner traps show all four replacement assertions survive entry failure in the original owner, while both genuine-owner controls fail it.
  • The regular honesty-corpus gate, traceability, changelog, formatting, whitespace and isolated-index application checks passed. The regular honesty gate checks pinned outputs; it is not a fresh execution of every corpus member.
  • A separate exact-candidate reviewer accepted bounded adoption, with no remaining bounded source/oracle/fixture/output blocker.

Full proof receipt and independent review, Git blob e40e5845fdb48d61c10162e62c3dbc1f72ca5c82 contains the raw native logs, reviewer receipt, runtime controls, retained earlier outcomes and artifact digests. The proof blob was also read back byte-for-byte. Unified delta SHA-256: 3559da6e556a40a9c4332c98fc2a4dd850c18624230e4ce9800004efe0b55449.

Next action belongs to the canonical implementation owner: inspect and adopt this commit's delta into the same candidate after confirming the head still matches its parent; if the owner has advanced, reconcile only the unique residual. The existing finding remains unresolved on the canonical source until adoption. Execution and review remain bound to the recorded local commit and identical tree; the new remote commit metadata does not supply hosted qualification. Current-main composition, hosted checks, protections and landing remain unverified. Previous integration/permission holds remain unchanged; no Ready transition, CI dispatch or merge was requested or performed.

@EffortlessSteven
EffortlessSteven merged commit b6aed0a into main Oct 26, 2026
58 of 59 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/py-star-import branch October 26, 2026 03:30
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