Skip to content

fix(python): bound operator and elif nesting so deep files degrade instead of overflowing the stack - #4494

Merged
EffortlessSteven merged 7 commits into
mainfrom
claude/crash-hunt-gnmz68-python-depth
Sep 29, 2026
Merged

EffortlessSteven merged 7 commits into
mainfrom
claude/crash-hunt-gnmz68-python-depth

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Requested by Steven · project thread

Summary

Before: one deep Python file anywhere in the workspace aborted ripr check with thread 'main' has overflowed its stack (exit 134), even when the file was not in the diff. These shapes all triggered it:

  • a long operator chain (60,000 + 1);
  • a long unary chain (50,000 not);
  • a long elif chain (12,000 arms, including files that use CR-only line ends);
  • a chained parameterized lambda (lambda a, b: lambda a, b: ...);
  • an operator chain inside an f-string replacement field.

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_unsupported limitation with reason parse_budget: syntax tree depth estimate exceeded 256. Other Python files are still analyzed, and the outcome is partial_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 fact walker, at about 1,900 levels in debug;
  • dropping the AST, at about 13,000 to 22,000 levels.

The file is therefore refused before parsing. The existing single lexical scan in parse_budget.rs now also estimates syntax-tree depth:

  • Operator runs: binary operators and ternaries grow the run. Commas, comparisons, and/or, = and line ends start a new run, except inside an open lambda parameter list.
  • Prefix depth: prefix operators, lambda, await and trailers.
  • Statement depth: indentation plus the length of each open elif chain.
  • F-string fields: replacement fields are scanned as code from the f-string's own depth. Nested f-strings are capped at 8 levels.
  • Line ends: a bare \r ends lines and comments. In \r\n only the \n counts.

The refusal reuses the existing parse_budget limitation path, mirroring TypeScript's expression_nesting_budget.

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-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

  • One production behavior

Non-goals: changing the bracket budget.

Support-tier Impact

  • none

Policy Impact

  • none

Proof

On head 18fe04b (main merged):

cargo xtask precommit                                # rc 0
cargo clippy -p ripr --all-targets -- -D warnings    # rc 0
cargo test -p ripr --test python_parse_nesting       # 8 passed
cargo test -p ripr --lib python                      # 449 passed (on 4be22ae)

With the tree budget disabled, every nesting integration test aborts with a stack overflow.

False positives: I scanned 6,295 real .py files, 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

  • Tests:
    • analysis::language::python::parse_budget::tests::*
    • the 8 CLI tests in tests/python_parse_nesting.rs
  • Code: crates/ripr/src/analysis/language/python/parse_budget.rs
  • No existing spec covers the Python parse budget. The only nesting-budget spec is TypeScript's, RIPR-SPEC-0177.

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.

Gates

  • cargo fmt --check
  • cargo clippy -p ripr --all-targets -- -D warnings
  • cargo xtask precommit

🤖 Generated with Claude Code

https://claude.ai/code/session_01FTQw4QPFK98a1kLKHyKTJQ

…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
@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 Sep 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: c77d2369-573d-4e5d-afd7-387a521e667e

📥 Commits

Reviewing files that changed from the base of the PR and between 172b165 and 18fe04b.

📒 Files selected for processing (3)
  • crates/ripr/src/analysis/language/python.rs
  • crates/ripr/src/analysis/language/python/parse_budget.rs
  • crates/ripr/tests/python_parse_nesting.rs

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.

❤️ Share

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

Copy link
Copy Markdown
Member Author

Downstream candidate consumers

This PR remains the production owner for the Python deep-syntax repair. Its merge/acceptance feeds:

#4512 retained Python deep-syntax installed-candidate corpus
→ #4505 termination aggregate
→ #4522 currentness/source replay map
→ #2769 candidate qualification
→ ripr#1771/#1578 affected source/package repeats

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.

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review September 29, 2026 02:28
@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!

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T02:31:00.072587Z 421ad2e Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

@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

… 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

EffortlessSteven commented Sep 29, 2026 •

Copy link
Copy Markdown
Member Author

Rust gates fails at the formatting step on 4be22ae (run 36517829307). The diff is in crates/ripr/src/analysis/language/typescript/mod.rs, which this PR does not touch. Main (e005ab2) is itself misformatted there, after #4635 and a concurrent PR both added mod lines. The fix is #4739, which also carries a test compile fix main needs. Once it lands I will merge main into this branch and push, so the gates re-run against the fixed base.


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
…z68-python-depth

# Conflicts:
#	crates/ripr/src/analysis/language/typescript/tests_extract.rs

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.rs wiring and the 8 CLI tests in tests/python_parse_nesting.rs.
  • 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.rs conflict 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-targets rc 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

@EffortlessSteven
EffortlessSteven merged commit 29e64e0 into main Sep 29, 2026
24 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/crash-hunt-gnmz68-python-depth branch September 29, 2026 05:10
EffortlessSteven added a commit that referenced this pull request Sep 29, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants