Skip to content

fix(python): a unit-stepped while counter reaches its bound from an input past it (#9412) - #9720

Closed
EffortlessSteven wants to merge 3 commits into
mainfrom
claude/project-thread-s3tp41
Closed

EffortlessSteven wants to merge 3 commits into
mainfrom
claude/project-thread-s3tp41

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

  • def countdown(start): while start > 0: yield start; start -= 1 with the edit start >= 0: a test list(countdown(3)) == [3, 2, 1] kills the mutant, because the loop evaluates start at 0. The boundary rule only looked at call arguments, saw no input equal to 0, and called the change weakly_exposed.
  • New loop_walk.rs: when the compared operand is a parameter with exactly one body update, name -= 1 (or += 1 for </<=), at the body's own indentation, and the body has no break/return/continue/raise/try/await/del/global/nonlocal, an input past the bound also places the operand on it. Anything else (step of two, conditional step, early exit, a second update, a rebind) stays unwalked and fails closed to weakly_exposed. An input below the bound is not walked either.
  • Corpus: py-shapes-generator-bound moves gap to credited (correct, the test fails under the mutant) and leaves the known_false ledger. It is the only row that moves.

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 (Python preview verdict behavior); boundary activation per RIPR-SPEC-0028
Governing issue or accepted claim: #9412 (py-shapes-generator-bound known_false row)
Acceptance delta (one sentence): A changed while bound is credited when an exact test drives a unit-stepped counter through it, and the row leaves the known_false ledger.

Verification

  • cargo xtask precommit passes.
  • 830 Python unit tests pass, including a hit control (countdown(3) exposed), a below-bound control (countdown(-2) weak) and five fail-closed controls (step of two, conditional step, break, double update, rebind).
  • cargo xtask verdict-corpus check --language python passes on this tree.

Generated by Claude Code

…nput past it (#9412)

countdown(3) never binds `start` to 0, but `while start > 0` with
`start -= 1` evaluates the bound at 0 inside the loop. When the counter has
one unconditional unit step and the body cannot exit early, an input on the
far side of the bound counts as placing the operand on it. py-shapes-generator-bound
moves from gap to credited and leaves the known_false ledger.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVJ2F1oh39juHJ8AZR5fS3
@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 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 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 107 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: 978ad9fd-b600-45f7-bdb1-e5e869bb2976
📥 Commits

Reviewing files that changed from the base of the PR and between c724a95 and d16046f.

📒 Files selected for processing: 8
  • changelog.d/9412-python-while-counter-reaches-its-bound.md
  • crates/ripr/src/analysis/language/python.rs
  • crates/ripr/src/analysis/language/python/boundary.rs
  • crates/ripr/src/analysis/language/python/classify.rs
  • crates/ripr/src/analysis/language/python/loop_walk.rs
  • crates/ripr/src/analysis/language/python/tests.rs
  • fixtures/python-verdict-corpus/expected/rows/py-shapes-generator-bound.json
  • fixtures/python-verdict-corpus/known-false/py-shapes-generator-bound.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.

Confirmed findings

  • loop_walk is a new module with a narrow text-parsing surface. Only one public-API-adjacent call site (python_boundary_evidence). No public re-exports, no semver impact. Sibling walker paths (comprehensions, for-loops, async for) are not addressed by this PR and remain unwalked; this is consistent with the PR's stated scope (unit-stepped while counter).
  • An exception-capable generator can bypass the inferred boundary and still be classified as exposed.
  • The walk may ignore the fact that yielded work can be interleaved with updates from another coroutine or thread.

Verification questions

  • Confirm the advertised verification results are not substantiated by the supplied packet. Late cargo-test evidence is not available, and ripr failed, so the change should not be treated as fully verified until the deterministic test receipt lands or the failure is explained.
  • Confirm python_boundary_evidence gains owner_source: Option<&str> and line: usize. Only classify.rs (classify_change_for_owner) threads them; both are optional/positional and the new behavior is gated on owner_source.is_some() and operators.len()==1. Other callers (if any in sibling language modules) of the python boundary helper are unchanged because this signature is per-language.

Refuted

  • The missing cargo-test receipt proves the new tests fail.; refuted because: It only prevents independent verification; the source-level assertions are directionally consistent with the PR claim, while the supplied sensor record does not provide a contradictory test result.
  • body-EXITS tokenization could be fooled by string/comment contents on a real Python statement line; refuted because: The matcher trims a physical line and splits on non-word chars; any 'break'/'return' inside a string or comment on the same line as a statement would be on a separate physical line, and a same-line string 'return' does not contain the bare keyword as a token in a way that would alter control flow. Worst case is conservative (gap instead of exposed).
  • Text-based EXITS list treats any line whose words include one of break/return/continue/raise/try/nonlocal/global/await/async/del as disqualifying, including substrings like nonlocal_x or await_ via identifier split. Walker returns None, classification stays weakly_exposed (fail-closed). Substring tokens are not Python keywords so the false positive is harmless; verified by EXITS=const&words() split on non-alnum/underscore.

Evidence gaps

  • The PR body claims 830 Python tests and verdict-corpus verification pass, but the shared packet reports cargo-test as scheduled-late with no receipt and ripr failed.
  • Model proof intent was rejected by deterministic validation.

Parked follow-ups

  • loop_walk parser is text-based, not AST-based. It walks lines from owner_source using indentation and trimmed tokens, matching 'while ', ':', '-= 1', '+= 1' and an EXITS keyword list. This is a sibling-path concern: a future change that introduces an AST-based python walker (e.g., rustpython_parser) would supersede this; not a blocker but a known route divergence.
  • Fail-closed controls cover step-of-two, conditional update, break, double update, and rebinding cases, but do not explicitly include every syntax accepted by python_loop_step.

Copy link
Copy Markdown
Member Author

Review of record, head 94b0996.

Angles: correctness of the walk, fail-closed coverage, corpus truth, bot findings.

  • Correctness: the walk applies only to a while header with one relational operator, a plain-name left operand, an integer-literal right operand, and a counter whose single body update is name -= 1 (operators >/>=) or name += 1 (</<=) at the body's own indentation. An input on the near side of the bound adds the bound as a reached value; an input past it adds nothing. Body words break, return, continue, raise, try, await, async, del, global, nonlocal disable the walk. Identifier-split matching can only over-disable (a variable named try_count is not a token, try alone is), which fails closed.
  • Tests: hit control (countdown(3) exposed), below-bound control (countdown(-2) weak), and five fail-closed controls (step of two, conditional step, break, double update, rebind), all asserting weakly_exposed.
  • Corpus: py-shapes-generator-bound is the only moved row (gap to credited); the test fails under the mutant ([3, 2, 1, 0]), so credited is right. It leaves the known_false ledger. Check passes on this tree.
  • Bot review (github-actions): no blocking finding. Its "exception-capable generator" and "other coroutine or thread updates the counter" points need a callee that raises mid-loop or a shared mutable counter; a parameter rebound only by the loop's own step cannot be touched by another thread, and a raising callee fails the exact oracle under both versions. Not worth code. Its verification-gap note is about its own packet; precommit and the 830 Python tests ran locally on this head's base. The text-based walker (not AST) is the same approach the neighbouring guard and arm rules use.

No findings to fix. CodeRabbit and Gemini are quota-limited (missing, not clean).


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Head moved to d16046f: merged main, which moved the known_false ledger to one file per row (#9700). The only change from the reviewed head is that the row's entry is now its deleted file fixtures/python-verdict-corpus/known-false/py-shapes-generator-bound.toml instead of an inline table in spec-coverage.toml; the analyzer, tests and corpus row are unchanged, so the review of record above still applies. cargo xtask precommit and the Python corpus check pass on the merged tree. Re-applied merge-ready.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Superseded for the corpus row by #9726, which merged the same value (py-shapes-generator-bound credited, known-false file deleted). This PR also drew the line more tightly (a counter with a unit step and no early exit is walked; an input that never reaches the bound, a step of two, a conditional step or a break stays a gap), which #9726's blanket decline for rebound operands does not. I am not landing a second rule for the same row; the precision gap and the trap cases are filed as #9733 with this branch's approach as the sketch.


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.

2 participants