Repository navigation
fix(python): demote self.attr truthiness swaps in compound conditions - #11931
Conversation
Extend the #9186 truthiness-swap allow-list so a single differing and/or operand can engage, including self.<attr> when class __init__ assigns that attribute once from a constructor literal. Unreadable constructions, extra writes, and two swapped operands stay fail-open. Governing issue: #11890 Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
|
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 58 minutes. View limit details
|
EffortlessSteven
left a comment
There was a problem hiding this comment.
Exact-head source review of 78bd1480893f87cc1af95584c07240c00c0e4356 (author COMMENT; not an approval).
Reviewed surface: crates/ripr/src/analysis/language/python/truthiness_swap.rs only. Semantic owner is the #9186 truthiness-swap allow-list. Production still fail-closes unless joiners match, exactly one operand parses as a swapped single-operand test, and either the name is an unrebound owner parameter or self.<attr> with a unique __init__ self.x = param write and inline Class(...).method() constructor literals. A second class write, Addr("h", 0), two swapped operands, and receivers built elsewhere stay not-demoted.
Oracle: the Addr None/8080 case failed as Exposed on 7118be7310 and now demotes with discriminator self.port == 0. Existing #9186 classify controls still pass. No fenced paths, goldens, or corpus files were edited.
Gemini quota and CodeRabbit rate-limit comments are missing provider evidence, not a clean review.
Disposition: REVIEW_INCOMPLETE — source/oracle review is current for this SHA; hosted required checks are not yet terminal. Hosted green is not itself merge clearance.
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- Constructor binding does not validate keyword arguments against the init signature before using them.
bind_init_paramaccepts arbitrary keyword names and binds positional arguments only fromparams, soAddr(port=8080, host="h")can be misbound:hostis not associated with thehostparameter when it appears as a keyword, while positional indexing still advances only for positional segments. Validate keyword names againstinit_paramsand ensure every required parameter is bound exactly once before reading the target. (crates/ripr/src/analysis/language/python/truthiness_swap.rs:610).
Verification questions
- Confirm negative controls cover falsy constructor input, later attribute writes, and two differing operands, but do not independently prove the unreadable-construction fail-open claim.
- Confirm constructor parameter parsing rejects annotated parameters, so a valid
def __init__(self, port: int = None)mapping fails open instead of demoting. - Confirm the failed ripr run may hide a source-route or analyzer regression; its exit code alone does not identify whether the failure is caused by this diff.
Parked follow-ups
- The self-attribute extension is placed in the existing truthiness-swap evidence module, but it duplicates Python source parsing that is already split across no_behavior and boundary helpers, increasing maintenance risk.
Evidence gaps
- The new focused cargo-test receipt was absent in the shared packet, and ripr failed with exit code 2.
- Current-head executable proof remains unconfirmed in this packet.
- Model proof intent was rejected by deterministic validation.
- The current evidence packet does not establish terminal current-SHA proof: ripr failed with exit code 2 and the scheduled cargo-test receipt is absent.
Validate constructor keywords against __init__ and require every required parameter exactly once, so an extra kwarg or missing host cannot demote a self.attr truthiness swap. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
EffortlessSteven
left a comment
There was a problem hiding this comment.
Exact-head source review of 14862384a6808ce1d5b14b0847ecde539daabac7 (author COMMENT; not an approval).
Reviewed surface: crates/ripr/src/analysis/language/python/truthiness_swap.rs only. Semantic owner is the #9186 truthiness-swap allow-list. ub-review’s confirmed finding was valid: bind_init_param could demote on Addr("h", extra=1) and Addr(port=8080) because unknown keywords were accepted and missing required parameters were ignored. The repair fail-closes unless every keyword is an __init__ parameter, every required parameter is bound exactly once, and there is no positional-after-keyword. Keyword-order Addr(port=8080, host="h") still demotes.
Oracle: those two constructions classified WeaklyExposed on 78bd148089 and now stay not-demoted. Addr None/8080 still demotes with discriminator self.port == 0. Existing #9186 classify controls still pass. No fenced paths, goldens, or corpus files were edited.
Verification questions: unreadable-construction fail-open is now covered by unknown-keyword and missing-required tests. Annotated __init__ parameters remain fail-open via the existing identifier-only header parser (closed allow-list, not a promotion). The ub-review packet’s missing cargo-test receipt and ripr exit 2 are instrument/packet gaps, not a source-route defect on this SHA; local cargo test -p ripr --lib -- truthiness_swap passed.
Parked follow-up (duplicate parsing vs no_behavior/boundary) stays out of scope: those files are fenced.
Disposition: REVIEW_INCOMPLETE — source/oracle review is current for this SHA; hosted required checks are not yet terminal. Hosted green is not itself merge clearance.
|
Addressing the ub-review finding on constructor binding ( Valid defect, repaired on Verification questions:
Parked follow-up about sharing parse helpers with |
EffortlessSteven
left a comment
There was a problem hiding this comment.
Independent review (fresh-context reviewer, head 1486238): REPAIR_REQUIRED
Inspected:
- PR #11931 "fix(python): demote self.attr truthiness swaps in compound conditions", head
14862384a6808ce1d5b14b0847ecde539daabac7, basefa621a32eaf4c3dc6c17119021ea943641696aef, DRAFT, no labels,mergeable_state: blocked. One changed file:crates/ripr/src/analysis/language/python/truthiness_swap.rs(+823/-38). Diff computed by fetching the file at base and head and diffing them (the head SHA is not in the local clone). - Semantic owner:
truthiness_swap.rs, the #9186 truthiness-swap allow-list. New helpers at head includeidentifier:102(now accepts aself.prefix),split_boolean_condition:121,swapped_operand:200,self_attr_name:230,distinguishing_example:273,python_truthiness_swap_evidence:287,once_init_attr_mapping:383,class_body_lines/init_block(indent-based),init_params:485,assignment_span:517,line_writes_self_attr:547,exact_init_assign:556,constructor_attr_input:563,inline_constructor_arglist,bind_init_param:637;owner_reached_indirectly:873andcalls_unrecognized_callee:958gainedextra_callees. - Production path verified, not assumed:
crates/ripr/src/analysis/language/python/boundary.rs:159python_boundary_evidence->:167predicate_condition(:1112) ->:175python_truthiness_swap_evidence.predicate_conditionyields the full compound text forif self.port is not None and self.port != 80:,relational_operatorsskips!=, andoutside(truthiness_swap.rs:698) matches the compound as one literal span, so the compound path is reachable in production, not only through the unit helper. - Oracle read: nine new test functions -
split_boolean_condition_keeps_top_level_and_or_operands:1120,self_attr_compound_truthiness_swap_with_constructor_literals_is_weakly_exposed:1442,..._stays_exposed_on_a_falsy_constructor_argument:1455,..._stays_exposed_when_the_attr_is_rewritten:1470,compound_truthiness_swap_stays_exposed_when_two_operands_differ:1494,bare_parameter_compound_truthiness_swap_with_unseparated_calls_is_weakly_exposed:1522,..._stays_exposed_on_an_unknown_constructor_keyword:1552,..._stays_exposed_when_a_required_constructor_arg_is_missing:1569,self_attr_compound_keyword_constructor_literals_are_weakly_exposed:1585- plus the extendedparse_testmatrix. They reach the analyzer throughclassify_swap:1364->classify_change_with_source, withaddr_finding:1413anddiscriminator_names_self_port_zero:1424. - Governing issue #11890 (open): its repro (
src/addr.py+tests/test_addr.py, portsNoneand8080) matches the fixture constantsADDR_SOURCE/ADDR_TESTS:1391+, so the fixture is faithful to the reported case. - Governing spec:
docs/specs/RIPR-SPEC-0028-python-preview-static-facts.md, section "Predicate Swap Amendment (2026-10-30, #9186)" at:1558-1581. - Convention precedent from merged history:
b9436fc61(PR #11201, the #9186 implementation of this same rule) and siblings586a0d8a6(#11210),12496bda9(#11383),862ea14d8(#11674).
Blocking:
- The change ships outside the governing spec's closed allow-list, and none of the artifacts the repo ships with such a change are present.
docs/specs/RIPR-SPEC-0028-python-preview-static-facts.md:1558-1581states the demotion applies to "one single-operand test of an owner parameter" and that "the rule is a closed allow-list that keeps the existing verdict on anything unrecognized". This head widens the rule twice - to compoundand/orconditions with one differing operand (truthiness_swap.rs:121-228), and toself.<attr>operands bound once from__init__(:383-635). Both shapes are outside the spec's enumerated allow-list, so by the spec's own words the verdict should stayexposed; after this change it becomesweakly_exposed. Issue #11890 records the old scope in the same terms ("compound conditions, attribute operands ... fail open"), so the spec now misdescribes shipped behavior.
The repo's precedent for this exact rule settles what "in the same change" means. Merged commitb9436fc61("fix(python): a predicate swap no observed input separates is not exposed (#9186) (#11201)") landed in one squash:RIPR-SPEC-0028...md +25/-0,.ripr/traceability.toml +23/-0,changelog.d/python-truthiness-swap-9186.md +7/-0, fourfixtures/evidence-promotion-honesty-corpus/cases/python_truthiness_swap_*.jsoncases and fourfixtures/python_truthiness_swap_*workspaces with pinnedexpected/check.jsonandexpected/human.txt. The nearest siblings do the same:586a0d8a6(#11210) spec +12/-0, traceability +7/-0, changelog fragment;12496bda9(#11383) spec +16/-1, traceability +6/-0, fragment;862ea14d8(#11674) spec +1/-1, traceability +2/-0, fragment. This head changes exactly one file.
Concretely:.ripr/traceability.toml:3847-3853registers all seven existingtruthiness_swap.rs::tests::*tests for RIPR-SPEC-0028 and:3854-3864elevenclassify/tests.rs::truthiness_swap_*tests, but none of the nine tests this head adds is registered; and the fourfixtures/python_truthiness_swap_*workspaces registered at.ripr/traceability.toml:4098-4101have no counterpart pinning the new compound /self.<attr>shape.cargo xtask check-traceabilitywould not fail - it checks spec-to-behavior coverage (xtask/src/main.rs:6804-6810) - so this is a contract-parity gap the gates cannot see.
Repair: add the dated spec amendment section asb9436fc61did, register the new tests in the RIPR-SPEC-0028 behavior entry, add achangelog.d/fragment, and extend the fixture and evidence-promotion corpus set to the new demotion shape.
Non-blocking:
- Earlier ub-review finding (review 5725290527, older head
78bd1480) thatbind_init_paramaccepted unknown keyword names and ignored missing required parameters is REPAIRED here.bind_init_param(truthiness_swap.rs:637-692) now rejects a keyword that is not an__init__parameter (:665-668), a duplicate binding (:669-671), and positional-after-keyword (:662-664), and requires every required parameter to be bound or defaulted (:677-682). The tests at:1552and:1569pin both halves. - ub-review's question about annotated
__init__parameters still HOLDS and is benign; I checked it directly:init_params(:485-515) usesidentifier(name).filter(|plain| plain == name)?, andidentifier(:102-119) rejects an annotated parameter because:is not an identifier character, so it fails closed and is not demoted. Closed allow-list, not a promotion. - ub-review's parked follow-up (the extension duplicates Python source parsing already split across no_behavior and boundary) still HOLDS and is stronger now. About 350 lines of hand-rolled Python text analysis land in
truthiness_swap.rs-class_body_lines/init_blockrecover the class body and__init__by indentation,init_paramsre-parses the signature,assignment_spanre-implements assignment detection - while the repo already owns an AST parse atcrates/ripr/src/analysis/language/python/source_facts.rs:595-606(parse_module_result), which sibling PR #11932 in this same wave uses. A second, textual authority for "what is this class's__init__" now exists. Argument splitting does reuseno_behavior::{split_top_level_args, call_segment_keyword_name, matching_call_paren}, so the duplication is partial. - The "exactly one write to
self.<attr>" invariant is textual, so asetattr(self, "port", 0)call, aself.__dict__["port"] = 0write, and a statement that removes the attribute are not seen as writes byline_writes_self_attr(:547-554) orassignment_span(:517-545). A class that rebinds the attribute that way would still be treated as bound once from the constructor and could demote on a value it can actually change. Narrow, and in the false-confidence direction: a follow-up, not a block. - Oracle strength is good; I could not construct a self-confirming assertion. The positive test (
:1442) assertsExposureClass::WeaklyExposedAND a discriminator namingself.port == 0; the five fail-open controls (:1455falsy constructor argument,:1470laterself.portwrite,:1494two differing operands,:1552unknown keyword,:1569missing required argument) each assertassert_ne!(finding.class, ExposureClass::WeaklyExposed). One weakness:discriminator_names_self_port_zero(:1424-1439) also acceptsself.port = 0and searchesactivation.missing_discriminators,evidenceandmissing; the implementation produces the== 0form viadistinguishing_example(:273-282), so the loose branch is not exercised, but the test would also pass on an observed value rather than a named discriminator. - The compound demotion is sound as I read it: with exactly one differing operand and the remaining operands textually identical, the compound's truth value can differ only if the differing operand's truth value differs, which is exactly the condition checked at
truthiness_swap.rs:339-347. - The earlier author self-review (5725328182, this same head) has correct factual claims - I independently re-verified the
bind_init_paramrepair - and itsREVIEW_INCOMPLETEdisposition is right as far as hosted evidence goes, but it does not mention the spec, traceability and fixture parity gap above. docs/CHANGELOG_POLICY.mdasks for "one fragment file underchangelog.d/per PR" and lists user-visible output changes among the include-criteria; this head has none.
Hosted evidence for this head:
- The PR is a DRAFT with no labels, so the Rust lanes never routed:
msrv,source-identity,vscode,rust-coverage,rust-tests-junit,future-clippy,cargo-deny,dependency-review,macos-advisory,windows-advisory,windows-advisory-subset,Perl and release proofandRust-only feature laneare allskipped- unobserved, not green, and a draft can never beREVIEW_READY. - Green:
GitGuardian Security Checks,workflow policy and wheel applicability.CodeRabbitneutral.build and inspect Linux x64 wheelandub-reviewwerein_progressat review time. - No red appeared on this head, so the known main-red
analysis::language::python::guard_activation::tests::compare_literal_values_fails_open_on_undecoded_literalsis not attributed here. Basefa621a32...carries no comparable Rust check-run of its own, so there was no base lane to compare against.
Not run:
- No Rust toolchain on this host -
rustc,cargoandrustupare absent from PATH - so I could not runcargo test -p ripr --lib -- analysis::language::python::truthiness_swap,cargo clippy -p ripr --lib -- -D warnings,cargo xtask precommit,cargo xtask check-traceability,cargo xtask fixturesorcargo xtask goldens check. Every gate result in the PR body is a producer claim I could not reproduce, including the red-before witnesses the body attributes to7118be7310and78bd148089. - I could not execute the nine new tests, so the demote / stay-exposed assertions are verified by reading the code path only.
- I did not run the combined-tree (current main merged into this head) compile check that
docs/LEARNINGS.md2026-10-08 (#7150) asks for before merge: no toolchain, and this pass is read-only. - The change was read from REST
pulls/11931/filesand from the file fetched at base and head;gh pr diffunder-reports merge-commit PRs and GraphQLPullRequestChangedFilecarries nopatchfield.
Reviewed by an independent Mavis review agent on behalf of the maintainer; bound to head 14862384a6808ce1d5b14b0847ecde539daabac7. Not an approval.
|
Independent review 5725372423 (head Fence. Governing issue #11890 / wave pick ITEM 8 authorizes exactly What this PR does claim. Changelog. Non-blocking items (agree):
Hosted required |
There was a problem hiding this comment.
Decision
- Needs one verification check before upstream.
Verification questions
- Confirm the self-attribute route reaches constructor values only through an inline Class(...).method() receiver; receivers built elsewhere remain unreadable and therefore fail open.
Parked follow-ups
- The implementation uses a hand-written Python parser subset rather than reusing an existing AST boundary, increasing maintenance and scope risk.
Evidence gaps
- No completed cargo-test receipt is available for the changed truthiness-swap module, and the ripr sensor failed with exit code 2.
- Model proof intent was rejected by deterministic validation.
- The focused cargo-test receipt is absent, leaving execution of the changed-behavior oracle unconfirmed in this packet.
- Focused executable evidence for the repaired head is not present in the shared packet: ripr failed with exit code 2 and cargo-test has no receipt.
- The advertised focused cargo-test proof is not present in the supplied packet, and the ripr sensor failed with exit code 2.
|
ub-review 5725385391 verification (head
Packet gaps (missing cargo-test receipt, ripr exit 2) remain instrument/packet evidence, not a source-route defect. Local |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
merge-ready Head frozen at |
…ss swaps (#11890) (#11998) #11931 landed the compound and self.<attr> truthiness-swap demotion with its tests in truthiness_swap.rs only. This adds the RIPR-SPEC-0028 amendment, the traceability rows for its eight tests and the changelog fragment. The issue repro (self.port and ... -> self.port is not None and ...) re-checked on current main reads weakly_exposed. Claude-Session: https://claude.ai/code/session_018waZYroArgiNqfVvpNJa8b Co-authored-by: Claude <noreply@anthropic.com>
Summary
Extend the #9186 Python truthiness-swap allow-list so a single differing
and/oroperand can demoteexposedtoweakly_exposed, includingself.<attr>when class__init__assigns that attribute once from a constructor literal.Governing issue or accepted claim: #11890
Advances #11890
Acceptance delta (one sentence): A
self.port/self.port is not Noneswap inside a compound condition demotes when every strong constructor call is a readable literal (None/8080), names discriminatorself.port == 0, and staysexposedfor a falsy constructor argument, a laterself.portwrite, two swapped operands, an unknown constructor keyword, or a missing required constructor argument.Swarm / Source Boundary
This PR targets
EffortlessMetrics/ripr-swarm, the normal development trunk for trusted same-reporiprwork. Confirm the change belongs here:ripr-swarmSource-of-truth Links
Proposal:
Spec: RIPR-SPEC-0028 (Python preview static facts); #9186 truthiness-swap closed allow-list
ADR:
Plan item:
Governing issue or accepted claim: #11890
Acceptance delta (one sentence): Compound single-operand truthiness swaps, including
self.<attr>bound once from__init__constructor literals, demote with a named falsy-value discriminator; unreadable constructions (unknown keywords, missing required args) fail open.Candidate Relationships
Candidate branch (GitHub PR head is authoritative after publication):
cursor/python-truthiness-swap-self-attr-7b98Stack parent or prerequisite PR (if any): none
Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): none
Accepted winner and losing candidate disposition (when decided): n/a
Scope
Only
crates/ripr/src/analysis/language/python/truthiness_swap.rs(production helpers andmod tests). Both pick steps landed: (a) top-leveland/orwith exactly one differingparse_testoperand; (b)self.<attr>via a unique__init__self.x = paramwrite, reading inlineClass(...).method()constructor literals including omitted defaults.Scope Classification
This PR is scoped by:
Production delta:
python_truthiness_swap_evidencenow engages on a compound condition when joiners match and exactly one operand is a swapped single-operand test.self.<attr>is a tested name only when the class__init__assigns it once from a parameter and nothing else in the class writes it.Addr("h", 8080).authority(), including the__init__default when omitted.Addr(...)does not fail-open the existing indirect-reach check.bind_init_paramvalidates keyword names against__init__, rejects duplicates and positional-after-keyword, and requires every required parameter to be bound exactly once before reading the target.Evidence/support delta:
truthiness_swap.rsmod tests: Addr None/8080 demotes withself.port == 0;Addr("h", 0)stays exposed; a laterself.port = 0write stays exposed; two differing operands stay exposed; a bare-parameter compound demotes;Addr("h", extra=1)stays exposed;Addr(port=8080)without requiredhoststays exposed; keyword-orderAddr(port=8080, host="h")still demotes.Exposed/parse_testNone on7118be7310; the unknown-keyword and missing-required tests failed asWeaklyExposedon78bd148089; they pass after.Single acceptance criterion:
weakly_exposedwith discriminatorself.port == 0, and the named fail-open controls stay not-demoted.Non-goals:
cls.attr, locals holding the receiver, non-literal constructor arguments,*args/**kwargs__init__, or golden/corpus refresh.classify/*,python.rs,boundary.rs, or other fenced paths.Support-tier Impact
Claim/proof notes:
Policy Impact
Proof
Result, failures, or skipped proof:
cargo xtask precommit: pass (goldens check skipped: no output-surface or golden file changed vs origin/main).Claim Boundary
What may be claimed after this PR? A readable Python truthiness swap of one compound operand, including
self.<attr>with a unique__init__assignment and inline constructor literals, can demote toweakly_exposedwith a named falsy-value discriminator.What must not be claimed yet? That every attribute-in-compound shape is demoted; unreadable constructions, extra writes, receivers built elsewhere, unknown constructor keywords, missing required constructor args, and two swapped operands remain fail-open
exposed. No golden/corpus refresh. Hosted qualification is still missing at publication.Rollback
Revert the commits on this branch. Behavior returns to the #9186 bare-parameter, single-operand allow-list.
Spec-Test-Code Traceability
crates/ripr/src/analysis/language/python/truthiness_swap.rsmod testspython_truthiness_swap_evidencein the same fileStatic Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a — ordinary analyzer PR, no workflow or lane change.
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Gates
Local:
cargo fmt --check(via precommit),cargo clippy -p ripr --lib --tests -- -D warnings,cargo xtask precommit. Hosted matrix is the remaining qualification.Exact candidate SHA: 1486238 (GitHub PR head is authoritative after push).