Skip to content

Python: a literal zero-argument patch does not hide an edit around it - #10212

Merged
EffortlessSteven merged 12 commits into
mainfrom
claude/project-thread-s3tp41
Oct 25, 2026
Merged

EffortlessSteven merged 12 commits into
mainfrom
claude/project-thread-s3tp41

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

  • A test that fixes a zero-argument call with with patch("m.time.time", return_value=<nonzero int or str>): no longer makes ripr abstain (mocked_module, then missing_import_graph on time.time()) when the edit is the text or +/- arithmetic around that call.
  • The exemption is a strict whitelist (new literal_patch.rs). The changed line, old and new, must be one return of an f-string or +/- expression over names, int/str literals, the patched call and int(<patched call>), with the same call and int() counts on both sides. The patched name must appear in the owner only on the changed line, and the owner or its class must not be a segment of the target. Anything else keeps the limit.
  • Moved rows (blessed): py-idioms-patch-clock-separator and py-idioms-patch-clock-offset, abstained to credited. Python missed_credit_ceiling 28 to 26.

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-0238 rule 8
Governing issue or accepted claim: #9271
Acceptance delta (one sentence): Two Python missed-credit rows (patch-clock-separator, patch-clock-offset) move from abstained to credited without letting a mock hide an edit.

Validation

  • cargo xtask precommit: pass.
  • cargo test -p ripr --lib python::: 1067 pass, including negative tests for each rejected shape.
  • cargo xtask verdict-corpus check --language python: false verdicts 0/245, contradictions 0; only the two rows moved.

Claim Boundary

Static abstention rule only; no runtime mutation outcome is claimed. The patch forms this recognizes are with patch(...) headers with one literal return_value; decorators, patch.object, as bindings, side_effect, autospec and other mock names keep mocked_module.


Generated by Claude Code

@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 25, 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 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 170 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: 1c40bc71-3d9d-4a79-bab7-f33153cf58de
Commits

Reviewing files that changed from the base of the PR and between 9f059f4 and da5dccd.

Files selected for processing: 12
  • changelog.d/9271-python-literal-clock-patch.md
  • crates/ripr/src/analysis/language/python.rs
  • crates/ripr/src/analysis/language/python/assertion_selection_tests.rs
  • crates/ripr/src/analysis/language/python/classify.rs
  • crates/ripr/src/analysis/language/python/literal_patch.rs
  • crates/ripr/src/analysis/language/python/literal_patch_tests.rs
  • crates/ripr/src/analysis/language/python/repo/evidence.rs
  • crates/ripr/src/analysis/language/python/static_limits.rs
  • docs/specs/RIPR-SPEC-0238-python-oracle-and-reach-rules.md
  • fixtures/python-verdict-corpus/expected/rows/py-idioms-patch-clock-offset.json
  • fixtures/python-verdict-corpus/expected/rows/py-idioms-patch-clock-separator.json
  • fixtures/python-verdict-corpus/spec-coverage.toml
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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 the two blessed fixture rows now set changed_since_labeling=true, so their oracle does not require the changed behavior to be distinguished from the old behavior.
  • Confirm the repository-evidence route passes an empty owner source, disabling the new literal-patch exemption even though the focused classification route passes actual owner source.
  • Confirm the new tests cover many rejected mock forms but do not cover sibling with-context-manager forms such as nested with, parenthesized with, or multiple patch headers beyond a flat comma list.
  • Confirm positive cases assert only that StaticLimitKind is None; they do not demonstrate that the exact assertion passes for the new owner and fails for the old owner.
  • Confirm the repo evidence path passes an empty owner source into the shared static-limit routine, so the new literal-patch exemption cannot activate in that path even when repository source is available elsewhere.
  • Confirm the repository-evidence route passes empty owner source, so literal_patch_calls always fails closed there; only the focused owner-change route can activate the new exemption.
  • Confirm the repository-evidence route deliberately passes an empty owner source, disabling literal-patch analysis for that route rather than proving the exemption.
  • Confirm the new focused tests exercise static-limit classification but do not execute old and new Python owners to demonstrate a red/green distinction.
  • Confirm the owner-wide name check is textual, so it can misclassify a same-spelled attribute or local as use of the patched callable, producing an unnecessary mocked_module limit.

Evidence gaps

  • The two blessed corpus rows record credited/exposed classifications but no execution-level red/green evidence that their assertions reject the pre-change behavior.
  • Model proof intent was rejected by deterministic validation.
  • The PR's validation claim is not independently supported by the available sensor receipts.

Copy link
Copy Markdown
Member Author

Independent bounded review: REPAIR_REQUIRED for the exemption safety contract; not merge qualification.

Exact base acb0f4d; head 1d59da6; tree 81269a3ef4bd3618fdbf3a57c1ae3562e94a25f9. Head re-read unchanged. Canonical writer remains EffortlessSteven / claude/project-thread-s3tp41. Existing review 5641590842 contains verification questions, Gemini/CodeRabbit receipts are quota failures, and no equivalent completed counterexample proof or review threads were returned.

Blocking contract defect at literal_patch.rs:62-74,112-115: equal call/int counts do not ensure a visible edit. Under patch("m.time.time", return_value=1), old return time.time() + time.time() and new return time.time() - time.time() + 2 both produce 2. At clock value 5 they produce 10 and 2. The exact production literal_patch_calls accepts both shapes (Some(["time.time()", "time()"])). The spec claim that addition/subtraction keeps the edit visible is therefore false.

Additional bounded gap at literal_patch.rs:175-190: a body containing the admitted patch plus stamp.__globals__['stamp'] = lambda: 3 is also accepted by the helper. Keyword filtering does not identify every dynamic namespace replacement. Final related-test selection/credit for this form remains unverified; this is helper-admission evidence only.

Passed evidence: compiled/executed exact literal_patch.rs with installed rustc 1.95.0, existing rustpython_parser dependency, minimal owner/test/import scaffolding and equivalent expression parser. Positive control and both negative challenges returned Some. Python unittest.mock assertions verified patched old=new=2 and alternate old=10,new=2. Initial harness setup using Mod::parse failed compilation; corrected Suite::parse harness compiled/executed exit 0. No candidate source edits or author-branch writes. Review tree clean. These establish a helper safety-contract defect, not a final analyzer false-credit verdict.

Reconciliation: repo-evidence passes old=None and empty owner source, so it deliberately fails closed. Textual name checks can conservatively abstain. Blessed-row execution discrimination, full CLI verdict, hosted qualification and additional context-manager cases remain unverified here; no full qualification rerun or dispatch.

Canonical owner's next action: repair the same candidate's arithmetic admission, add production-path negative cases for arithmetic collision and dynamic namespace replacement, correct the visibility claim, then request affected-head review. No Ready/merge recommendation.

…est bodies

Review found equal call counts do not keep an edit visible (v + v against
v - v + 2 agree at v = 1) and that a test line can rebind names. Require the
patched call exactly once with the same sign, plain assert/assignment test
lines only, and correct the spec claim.

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

Copy link
Copy Markdown
Member Author

Repair pushed (head 01cabf6) for the REPAIR_REQUIRED review of 1d59da6. Both findings reproduce and are fixed in the same candidate.

  • Arithmetic collision (literal_patch.rs): confirmed. time.time() + time.time() and time.time() - time.time() + 2 both give 2 at return_value=1, and equal call counts do not make the edit visible. The helper now requires the patched call exactly once on each side with the same sign (and the same int(...) wrapping), so the line is s*v + K and an edit that changes K changes the pinned value as it would without the patch. A sign flip, which a constant can offset (12 - v against 10 + v at v = 1), now keeps the limit too. The spec's "keeps the edit visible" claim is replaced with this exact condition.
  • Namespace rebinding: confirmed. The earlier keyword filter only looked at lines that mention a substitution. Every other test-body line must now be a plain assert ... or name = ... with no dunder access, lambda, import, exec/eval, globals/locals/vars or sys.modules, so stamp.__globals__['stamp'] = lambda: 3 and similar keep mocked_module.
  • Production-path negatives: an_arithmetic_collision_at_the_fixed_value_keeps_the_limit and a_test_that_rebinds_names_keeps_the_limit drive static_limit_for_focused_change end to end; the earlier reviewer counterexamples (max/min, //, *, %, indexing, int to float wrapper, assignment plus branch, float and zero stand-ins) are tests too.
  • Verification questions from the bot review: the repo-evidence route passes no old line and an empty owner source on purpose, so it fails closed there; the moved rows carry changed_since_labeling because the labeling run was made before this change, and their truth is the independent runtime mutant kill recorded in each case; the owner-wide name check is textual and may abstain conservatively, never credit.

cargo xtask precommit passes; python lib tests 1124 pass; python corpus false verdicts 0/245. Main moved the blessed missed-credit count to 24, so the ceiling is 24. merge-ready re-applied.


Generated by Claude Code

A third review showed a test could rebind the owner behind the patch with a
semicolon, a chained or attribute assignment, a helper call, a default
argument or a shadowed patch. Parse the test and admit only asserts,
name assignments and patch blocks over names, constants, operators and
calls of the owner or a safe builtin, with patch bound exactly once.

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

@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 exemption compares call counts and signs but does not compare the int-wrapper bit; old int(time.time()) and new time.time() can therefore share the same count tuple.

Verification questions

  • Confirm repository-evidence classification passes an empty owner source into the shared static-limit routine, preventing the literal-patch exemption from activating on that route.
  • Confirm positive tests assert only the absence of a static limit and never execute the selected assertion against old and new owner behavior.
  • Confirm the documented contract says the same int(...) wrapping is required, but the implementation's shape equality does not enforce that wording.
  • Confirm the two moved fixture rows demonstrate credited outcomes but do not directly prove the old assertion fails while the new assertion passes.

Refuted

  • A literal mock exemption could unsafely cross a worker or async handoff boundary.; refuted because: No such boundary exists in the changed Rust/Python analyzer paths; the implementation performs synchronous source parsing and classification only.

Parked follow-ups

  • The helper recognizes only flat single-header patch contexts; nested, parenthesized, and comma-separated headers remain rejected by the strict header parser.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.
  • Fixture expectations changed the two rows to credited with changed_since_labeling=true, but no fixture assertion demonstrates the corresponding old/new behavior distinction.
  • The diff supplies focused negative tests for mock forms, arithmetic collisions, owner-name reuse, and namespace rebinding, but no executed cargo-test receipt is available.
  • The mandatory late cargo-test receipt is not present in the supplied packet.

Copy link
Copy Markdown
Member Author

Head 54507f0 pushed (merge of main plus the AST test-body whitelist), merge-ready re-applied.

Third review round and the bot's int-wrapper finding. The int-wrapper finding is refuted: the shape tuple (count, wrapped, sign) compares the wrapped count on the old and new line, so an int(...) added or removed around the patched call is rejected (negative test: int→float wrapper edit). The same round found real false credits, all fixed and each pinned by a negative test:

  • The test body is now an AST whitelist: one plain function, no decorators, defaults, *args or nested defs, and only assert, simple assignment, pass, a docstring, or one with patch(<dotted>, return_value=<nonzero Int/Str literal>) block of those.
  • Hostile bodies now fail closed: ;, chained and attribute assignment, helper calls such as rig(), and a shadowed patch.
  • patch must be bound exactly once from unittest.mock/mock.
  • The patched call must appear once with the same sign and wrapping on both sides.

Local proof. The Python corpus check passes (0/245 false, ceiling 24) and the Python lib tests pass (1171). Local precommit stops only at (a) the rust_qualified_foreign_receiver golden, which is Rust drift from main and fixed by #10253, and (b) the offline anyhow fixture prep, which hosted CI fetches. Neither touches this diff.

CodeRabbit and Gemini are rate-limited, so those provider reviews are missing, not clean.


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 positive tests assert only StaticLimitKind::None; none demonstrates that the selected assertion passes for the new owner and fails for the old owner.
  • Confirm the added tests cover rejection shapes extensively, but positive cases check only absence of a static limit rather than old-owner failure and new-owner success.
  • Confirm the new fixture rows are credited without an executable assertion demonstrating old-owner failure and new-owner success.

Refuted

  • The helper's scope is duplicated across routes and risks inconsistent policy.; refuted because: The patch logic is centralized in literal_patch.rs; route-specific source availability is an explicit input boundary, and all static-limit routes call the shared routine.

Parked follow-ups

  • The strict production whitelist rejects many hostile test bodies, but focused tests do not cover nested, parenthesized, or multiple with-context-manager forms.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.

…ched call

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

Copy link
Copy Markdown
Member Author

Head 0f066fe, merge-ready re-applied. A fourth independent false-credit pass on 54507f0 found one verified bypass: an empty-string stand-in (return_value="") contributes nothing to the value, so moving the patched call among string parts (f"{time.time()}{prefix}" → f"{prefix}{time.time()}", and two + forms) was credited. Fixed by rejecting an empty string stand-in alongside Int 0, with an_empty_string_stand_in_keeps_the_limit covering all three reorders. Python corpus still 0/245 false, ceiling 24.

The same pass also checked unary minus, async tests, sign flips, int-wrap changes, dropped or duplicated calls, walrus, lambda, comprehension, IfExp, subscript, f-string specs and conversions, multi-line returns, float/bool/negative stand-ins, aliased or second patch bindings, and multi-item or nested with. All keep the limit. Two residuals are noted and not fixed: a module-level redefinition of patch in the test module (the binding check reads imports only), and a patch target in a different module with the same last two segments. Both need a hostile test file and only matter if the shadowing is real; I'll file them as an issue if the maintainers want them closed.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Reply to the ub-review verification questions (head 0f066fe):

  • Old-owner failure / new-owner success. The two corpus rows carry a committed truth of discriminated from the corpus's own mutation labels (mutated_line), and verdict-corpus check compares ripr's outcome to that truth, so the credit is checked against an independent oracle (0/245 false). The unit tests assert the static limit only, because the limit is the decision this change makes; it does not claim the assertion passes or fails.
  • Nested, parenthesized and multi-item with. The fourth review pass ran multi-item and nested with and the parenthesized/multi-line returns through the real code. All keep the limit. They are covered by the whitelist rejecting any other body shape, and the negative tests listed in the earlier comment.
  • Filed residuals: Python literal-patch exemption: module-level patch shadowing and cross-module target are not detected #10267.

Generated by Claude Code

Copy link
Copy Markdown
Member Author

Ripr Rust Small Result failed on 0f066fe at goldens check only: 13 Python fixtures and rust_qualified_foreign_receiver lack the Next: lines from RIPR-SPEC-0319 (#9449). That drift reproduces on main (8d5d0d0) and on this branch with main merged, in fixtures this diff doesn't touch. The fix of record is #10269 (re-blesses all 14; #10273 duplicates it). Nothing to change here: once #10269 lands I'll merge main, re-apply merge-ready, and continue to the review of record and merge.


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 2 potential issues.

Devin Review

A stand-in equal to a neighbouring string made a reorder invisible.

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

Copy link
Copy Markdown
Member Author

Head 60b5764, merge-ready re-applied.

Devin finding (string stand-in equal to a neighbouring operand hides a reorder): valid, fixed. The shape now records the patched call's index among the line's operands, and old and new must agree, so f"{prefix}{time.time()}" → f"{time.time()}{prefix}" and the + form keep the limit even when the test passes prefix == return_value. Operands added after the call are still an ordinary edit. a_reorder_around_an_equal_stand_in_keeps_the_limit pins both. Python lib tests 1177 pass; Python corpus 0/245 false, ceiling 24, and the two clock rows stay credited.

Devin ceiling note: not a defect. The PR text's 28→26 was written before main moved; the committed value is the re-measured current count (26→24 after merging main, then 24 held). The corpus check enforces equality, so the committed 24 is the checked number.


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 positive Rust tests assert only StaticLimitKind::None and do not execute the selected assertion against old and new owner behavior.
  • Confirm the exemption is evaluated per related candidate, but acceptance is aggregated across candidates; an unrelated non-exempt mocked candidate sets mocked=true and retains the limit.
  • Confirm the focused route supplies owner source, while the repository-evidence route supplies an empty string, so the same mocked change is classified differently by route.

Refuted

  • The exemption can activate in the repository-evidence route despite unavailable owner source.; refuted because: Both repository-evidence and generic static-limit callers explicitly pass empty owner_source; literal_patch_calls returns None when owner_source is empty.
  • The repository-evidence route accidentally enables the exemption without repository owner source.; refuted because: It passes an empty owner source, and literal_patch_calls rejects empty owner_source, so this route fails closed.
  • The PR description still reports the missed-credit ceiling as 28 to 26, while the committed ledger changes 26 to 24.

Parked follow-ups

  • The two moved corpus rows now request discrimination and are credited against an existing oracle, but the new Rust unit tests assert only absence of a static limit.
  • The seeded thread identifies module-level patch shadowing and same-last-two-segment patch targets as residual risks, with issue #10267 filed.
  • Behavior-level discrimination is evidenced by the corpus truth rather than by executing the selected Python assertion in the Rust unit tests; the seeded review explicitly answered this concern, but no new independent execution proof is present.
  • The seeded thread identifies module-level patch shadowing and same-segment target-module ambiguity as residual bypass risks.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.

Copy link
Copy Markdown
Member Author

Review of record, head 60b5764.

Required check: Ripr Rust Small Result is green on this exact head (run 40177662836).

Review angles and findings:

  • Correctness and false credit, five rounds. Independent reviewers, the external bounded review, a fourth fresh-eyes pass and Devin each found real false credits, all repaired and pinned by negative tests:
    • arithmetic collisions (v+v vs v-v+2);
    • a hostile test body (;, chained or attribute assignment, helper call, default argument, shadowed patch);
    • zero and empty-string stand-ins;
    • an equal-stand-in reorder, now rejected by comparing the call's index among the operands.
  • Tests and oracle grip. 1177 Python lib tests pass. The Python corpus has 0/245 false verdicts and the two clock rows are credited against the corpus's own mutation truth. The unit tests assert the static limit, not Python execution.
  • Spec and contract. RIPR-SPEC-0238 rule 8 states the plain-AST contract; the changelog fragment names release(0.11): execution roadmap and ranked blockers for the hard cut #9271.

Not covered: CodeRabbit and Gemini reviews are missing (rate limited), not clean. Two residuals, a module-level patch redefinition and a patch target that shares only its last two segments, are filed as #10267. Both need an unusual test file. All review threads are replied to and resolved.


Generated by Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVJ2F1oh39juHJ8AZR5fS3
@EffortlessSteven
EffortlessSteven merged commit 6657a7a into main Oct 25, 2026
52 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/project-thread-s3tp41 branch October 25, 2026 10:54
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