Repository navigation
fix(python): bound operator and elif nesting so deep files degrade instead of overflowing the stack - #4494
Conversation
…stead of overflowing the stack The #4109 parse budget counted only bracket nesting. rustpython's LR parser builds `x + 1 + 1 + ...`, `not not ... x`, attribute/call/ternary/lambda chains and long `elif` chains without deep parser recursion, but the AST is one level per operator or arm. The source-fact walker and the AST's own Drop both recurse per level, so any discovered Python file with such a chain aborted `ripr check` (exit 134), even when the file was not in the diff. The same pre-parse scan now also estimates syntax-tree depth: binary operators and ternaries nest an operand run, prefix operators and trailers deepen one operand, sibling separators (`,`, `=`, comparisons, `and`/`or`) and logical line ends restart the run, and statement nesting is indentation plus open `elif` chain length. Past 256 levels the file is refused before parsing with `parse_budget: syntax tree depth estimate exceeded 256`, which rides the existing language_scope_unsupported disclosure, so neither the walker nor the drop ever sees the deep tree. Measured (Linux debug, 2 MiB stack): fact extraction overflowed near 1,900 levels; AST drop alone near 13,000. The highest estimate over ~9,500 real Python files on this host (stdlib, pip/uv site-packages, repo fixtures) stayed under 128; none trip 256. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FTQw4QPFK98a1kLKHyKTJQ
|
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 reachedNext included review available in 53 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Downstream candidate consumersThis PR remains the production owner for the Python deep-syntax repair. Its merge/acceptance feeds: A terminal PR disposition is necessary but not sufficient. #4512 must execute the exact installed candidate with nonzero operator/unary/elif rows, supported controls, an unchanged hostile neighbor, unaffected-file evidence, removal controls and the named limitation. The PR's current local/hosted proof remains implementation evidence. If this PR is deferred/excluded, #2766 must record the explicit public non-claim and #4505/#4522 must represent the Python family as excluded—not silently skipped or passed. If its head/schema/budget changes before merge, invalidate the corresponding corpus expectations and successor proof. |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 421ad2edea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… the tree budget
Three shapes bypassed the pre-parse syntax-tree depth estimate and still
aborted `ripr check` with a stack overflow on an unchanged discovered file:
- parameterized lambda chains (`lambda a, b: lambda a, b: ...`): the `,`
and `=` in a parameter list reset the operand segment, dropping the
lambda prefix depth. Open lambda parameter lists now suppress segment
separators until their `:`.
- operator chains inside f-string replacement fields: string bytes were
only bracket-counted. Fields (including `\{` openers and fields left open
by the closing quote) are now re-scanned as bracketed code at the
f-string's own depth; nested f-string recursion is bounded.
- CR-only line endings: only `\n` ended comments and logical lines, so a
bare `\r` file hid elif chains and made a comment swallow the file. A
bare `\r` now ends both; `\r\n` is still counted once.
The integration workspace dir is now unique per call so two same-length
sources cannot race on one temp dir.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FTQw4QPFK98a1kLKHyKTJQ
cargo fmt --check fails on main since #4635 and #4526 landed together; every PR that merges main then fails Rust gates. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018NAFFrPW4WcWsg7fGWfGAS
|
Generated by Claude Code |
…only helper #4635 made line_for_offset(&str) a #[cfg(test)] oracle while #4593 added a non-test caller in title_argument, so main does not compile outside tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018NAFFrPW4WcWsg7fGWfGAS
…to claude/crash-hunt-gnmz68-python-depth
…z68-python-depth # Conflicts: # crates/ripr/src/analysis/language/typescript/tests_extract.rs
EffortlessSteven
left a comment
There was a problem hiding this comment.
Exact-head self-review of 18fe04b: clean.
- Inspected
parse_budget.rs: operator-run, prefix and statement-depth estimation, and the 4be22ae additions:- Lambda parameter lists: they suppress segment resets until their
:in the same bracket frame. A dict or slice colon inside a default opens its own frame. - F-string fields: replacement fields are rescanned as code from the f-string's depth, nesting is capped at 8, and
{{/}}are literals. - Bare
\r: it ends lines and comments, and CRLF is counted once. - The
python.rswiring and the 8 CLI tests intests/python_parse_nesting.rs.
- Lambda parameter lists: they suppress segment resets until their
- Oracle: every nesting test aborts with the tree budget disabled. The sibling-lambda, flat-field, literal-brace, CR and CRLF cases pin the no-false-refusal side. On a corpus of 6,295 real files the maximum estimate is 87, against a budget of 256.
- The main merge resolved the
tests_extract.rsconflict to main's version. The diff against main is only this PR's three files. - Local on this head: precommit rc 0 (on a647ff8, with identical PR files), clippy
-p ripr --all-targetsrc 0, and 8 nesting tests pass. - CI:
Ripr Rust Small Result,Rust gates, the Rust-only feature lane, ub-review and cargo-deny are green. No conflict with main. - Review status: the Codex and Devin findings are fixed in 4be22ae, and all threads are resolved. No Codex or Devin re-review has run on this head. Gemini is out of quota and CodeRabbit is rate-limited, so those reviews are missing, not clean.
Generated by Claude Code
…reaches them (#4435) (#4802) * fix(rust): follow the module tree before seeding diff findings (#4435) Lands the reviewed #4556 candidate (head 428a950) on current main. The code is identical to that head; the CHANGELOG entry moves to the end of "### Fixed" to avoid the conflict with #4494. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JZW7dmiWcz2Wjj7vBiGuNx * fix(rust): close three module-graph false-verdict paths from #4802 review - A macro call inside a body, or nested in a std macro's arguments, can expand to `#[path = "..."] mod name;`; only std macros that cannot emit items keep a scan complete. Previously only item-position calls counted. - A declared `[lib] path` replaces `src/lib.rs` as the library root, so a module only the unused default root declares is an orphan. - Every member package that compiles an external root keeps its tests in Draft scope, not just the first one found. Each has a regression test that fails with its fix removed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JZW7dmiWcz2Wjj7vBiGuNx * docs(spec): map module-tree seeding into RIPR-SPEC-0153 and traceability The spec still said a `[lib]` path outside `src` was not recognized. It now describes the #4435 module-tree rule, its fail-closed unknowns, the evidence tests and the two new producers. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JZW7dmiWcz2Wjj7vBiGuNx * fix(rust): record the unreached-module limitation only for files the layout rule seeds An unreached fixture or `tests/data` source was evidence before #4435 and never seeded, so the module tree takes nothing from it. It no longer earns a `language_scope_unsupported` limitation that made a clean run read as partial. Pinned by diff_analysis_limits_only_orphans_the_layout_rule_would_seed, which fails without the filter. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JZW7dmiWcz2Wjj7vBiGuNx --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Steven · project thread
Summary
Before: one deep Python file anywhere in the workspace aborted
ripr checkwiththread 'main' has overflowed its stack(exit 134), even when the file was not in the diff. These shapes all triggered it:+ 1);not);elifchain (12,000 arms, including files that use CR-only line ends);lambda a, b: lambda a, b: ...);The existing 128-bracket budget (#4109) did not see any of them.
After: the same repos exit 0. The deep file is reported as a
language_scope_unsupportedlimitation with reasonparse_budget: syntax tree depth estimate exceeded 256. Other Python files are still analyzed, and the outcome ispartial_with_limitations.How: the parser survives 100,000 levels, but two later stages recurse once per level and overflow first on a 2 MiB thread:
The file is therefore refused before parsing. The existing single lexical scan in
parse_budget.rsnow also estimates syntax-tree depth:and/or,=and line ends start a new run, except inside an open lambda parameter list.lambda,awaitand trailers.elifchain.\rends lines and comments. In\r\nonly the\ncounts.The refusal reuses the existing
parse_budgetlimitation path, mirroring TypeScript'sexpression_nesting_budget.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Governing issue or accepted claim: 0.11 crash/panic/hang hunt (project thread above).
Acceptance delta (one sentence): no Python operator, unary, elif, lambda or f-string nesting shape aborts the process; over-budget files degrade with a named limit.
Candidate Relationships
Candidate branch:
claude/crash-hunt-gnmz68-python-depth. I searched open PRs for Python stack overflow, nesting and recursion and found none equivalent. The Python line index is a separate change (#4580, merged).Scope Classification
Non-goals: changing the bracket budget.
Support-tier Impact
Policy Impact
Proof
On head 18fe04b (main merged):
With the tree budget disabled, every nesting integration test aborts with a stack overflow.
False positives: I scanned 6,295 real
.pyfiles, covering the CPython stdlib, site-packages and the repo fixtures. None reaches the 256 budget, and the highest estimate is 87.Claim Boundary
May claim: Python operator, unary, elif, lambda-parameter and f-string-field depth no longer aborts ripr. Must not claim: facts for files over the budget. Those files are declined, and the decline is disclosed.
Rollback
Plain revert.
Spec-Test-Code Traceability
analysis::language::python::parse_budget::tests::*tests/python_parse_nesting.rscrates/ripr/src/analysis/language/python/parse_budget.rsStatic Language Check
killed,survived,untested,proven, andadequate.Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.Gates
cargo fmt --checkcargo clippy -p ripr --all-targets -- -D warningscargo xtask precommit🤖 Generated with Claude Code
https://claude.ai/code/session_01FTQw4QPFK98a1kLKHyKTJQ