Skip to content

fix(lint): isolate Python parser recursion limits - #914

Open
Afloat16 wants to merge 9 commits into
NVIDIA:mainfrom
Afloat16:fix/script-lint-parser-limits-20261126
Open

Afloat16 wants to merge 9 commits into
NVIDIA:mainfrom
Afloat16:fix/script-lint-parser-limits-20261126

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Current integration update — 2026-12-01

Source: c1913a1783dd3f180813dc2556ac26ceead79f3e; integrated main: 108fab86c5c0a8e1548289c036f0977a8c934bf3 (1.3.1 release preparation).

Resolved the CHANGELOG conflict by preserving the complete published 1.3.1 history and keeping this PR's entry under Unreleased. All PR-specific source and regression-test blobs are identical to previous head efe7edc26fe223aa2fdafb2dbf62eab72336bbb2. The merge preserves both parents and carries the required DCO sign-off.

Validation for this merge: whitespace checks, released-history preservation, and exact source/test blob comparisons passed. GitHub now reports the PR as conflict-free. Current-source integration checks await maintainer workflow approval; the earlier test results below retain their original revision scope.

Previous integration update (main ad4a12f)

Source: efe7edc26fe223aa2fdafb2dbf62eab72336bbb2; integrated main: ad4a12f0e17fe42e8f6839e41b6799ab8990bcf3. Resolved the CHANGELOG conflicts after the 1.3.0 release and stable-CI update. The released history and new upstream entry are preserved, with this PR’s change under Unreleased. The PR-specific source and regression-test files are unchanged from the previous head.

Focused validation: 36 passed, on tree 445f8ad55a566d8baeb1182238b3a2b9f0c5c2ba before the final CI-only main update. That final update changes only CI files and CHANGELOG; the tested runtime and regression files are unchanged. The updated CI modules passed 240 tests on the final #905 integration tree, and those CI blobs are identical in all 11 refreshed branches. Repository Ruff and whitespace checks passed.

Current-head upstream workflows require maintainer approval. Earlier results below apply to their recorded revisions.

Original contribution and validation before this integration update

Current review follow-up (2026-11-30)

Current source: 8a37e96, including main d218ef8. The changelog conflict is resolved with both entries preserved. The healthy-script regression now checks that the required flat_script and missing_shebang findings are present, without coupling this parser-limit regression to the entire advisory inventory. The Python-version-sensitive parse oracle is unchanged.

Current-source verification: 36 passed in tests/validators/test_script_lint.py; make lint, changed-file Ruff formatting and whitespace checks passed. The new upstream CI run and companion workflows are awaiting approval. Earlier verification below applies to its named source.


Current source and main refresh — 2026-11-30

Current source: 12cf60dd436681b05e405690097c735d66ce418a, including main 8b057485209ae956f4d520b8132bbe5c004f5988 in a signed-off merge. Both sides’ changelog entries are retained, and the original contribution implementation and regression files are unchanged.

Validation of this source completed with 36 passed, 0 failed, plus whole-repository lint, the OSS-boundary scan, wheel/sdist builds and final source/tree/lockfile checks on Ubuntu 24.04 / Python 3.12 with the locked full extras.

These are focused checks on the current main merge. Earlier results below retain their stated source revisions. Upstream workflow approval and final maintainer review remain pending.


Earlier main refresh and validation — 2026-11-29

Current source: 39d1e3113ca098bab52d3e7e2f85a34988fd0833. The signed-off merge includes main da729c85676fc965ff81e710af89953126b44041. The only manual conflict resolution was in CHANGELOG.md: the script lint parser recursion entry remains a separate bullet under Unreleased → Fixed, and all main entries are preserved. The original contribution changes and regression coverage remain intact.

At this exact source, focused contribution and integration validation completed with 36 passed, 0 failed. Whole-repository make lint, OSS-boundary checks, make build (wheel and sdist), and final source/tree/lockfile checks also passed on Ubuntu 24.04 with Python 3.12 and the locked full extras.

These are focused checks on the new main merge. The earlier complete-suite results below retain their stated source revisions.


Summary

An approximately 50–80 KB generated Python script with a 10,000-term attribute or addition chain can exceed the Python AST constructor's recursion limit. The exception leaves ast.parse before a tree exists, aborting advisory lint and discarding findings for healthy files in the same skill or folder.

Report a parser_limit advisory for that file and continue linting the remaining scripts. The finding names the affected path and explains that the Python parser could not inspect it. The parser limit itself, syntax-error handling, and advisory severity policy remain unchanged; unexpected parser exceptions still propagate.

This is distinct from #760, which made traversal of successfully parsed ASTs iterative and explicitly left parser-error handling unchanged.

Verification

  • Four real large-expression cases and two deterministic per-file parser failures reproduce the abort on unchanged production. The unexpected-error control passes before and after the fix.
  • The real-input regressions use the active Python parser as an independent oracle, so supported versions that can construct the tree still receive normal lint checks. Deterministic injection pins failure isolation on every version without adding skips or changing recursion limits.
  • The script-lint module, existing CLI/pre-commit lint checks, and publication-evidence tests pass: 71 passed.
  • Whole-repository make lint equivalent, changed-file Ruff formatting, and git diff --check pass.
  • make build passes, producing the wheel and source distribution.
  • Complete required gates passed on exact published head 5b4e14636b8d43c6e90bb13803e7cc44d5c55b6d: make lint, make test, and make build. Ubuntu 24.04, Python 3.12, Node 22, and the locked full project extras; pytest reported 45,546 passed, 338 existing skips, 19 existing deselections. No assertions or default test-selection rules were changed.

Checklist

  • I am familiar with the Contributing Guidelines.
  • Added focused regressions and compatibility controls.
  • Updated documentation for the visible parser-limit advisory and continued checks.
  • Ran make lint.
  • Ran make test.
  • Ran make build.
  • No credentials, private datasets, or proprietary benchmark content were added.

Release Impact

  • Updated CHANGELOG.md.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@rng1995

rng1995 commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks @Afloat16 for this contribution. I prepared and verified a signed-off merge against main at 86f1f141. The only conflict is in CHANGELOG.md.

Please enable Allow edits from maintainers in the PR sidebar so I can push the prepared merge. You can also merge main into this branch and keep the script lint parser recursion entry as a separate bullet under ## Unreleased → ### Fixed, preserving the entries from main.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
auto-merge was automatically disabled November 29, 2026 12:34

Head branch was pushed to by a user without write access

@Afloat16

Copy link
Copy Markdown
Contributor Author

Merged current main in signed-off commit 39d1e311. The script lint parser recursion entry is kept separately under Unreleased → Fixed, with all main entries preserved. Only the changelog conflict needed manual resolution; the original contribution patch and regression coverage are retained.

Validation of this exact merged source passed 36 passed, 0 failed, whole-repository lint, OSS-boundary checks, wheel/sdist builds and final clean-source checks. The description now distinguishes these new focused results from the earlier complete-suite results. Fresh upstream workflows still await maintainer approval.

The requested main sync is ready for your final review.

Keep both sides of the changelog conflict and retain the contribution's implementation and regression coverage.

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I reproduced this on main: a skill with a.py, b.py (10,000-term addition chain, about 80 KB) and c.py makes validate --checks lint die with RecursionError: maximum recursion depth exceeded during ast construction, exit 1 and no report at all. At this head the same run exits 0 with nine lint advisories: the usual four for a.py and c.py plus one MEDIUM parser_limit for b.py, and the JSON report carries it. The six new tests fail on main's source and the whole module passes at head (36 passed).

The narrow except is the right one. On 3.12 and 3.13 ast.parse raises RecursionError during AST construction; on 3.14 the same shapes parse (the limit there is the real C stack, so it only trips around 100k terms in the main thread or at 5k in a small-stack thread) and when it does trip it is still a RecursionError ("Stack overflow ... during compilation"). Over-nested parentheses are a SyntaxError ("too many nested parentheses") and already return silently, so nothing new is swallowed and unexpected exceptions still propagate, which the third test pins.

Two small notes inline, neither blocking. I also timed hostile inputs: the deep scripts fail in milliseconds on 3.12 and 3.13, and on 3.14 the 10,000-term inputs parse fine and lint in well under 100 ms, so there is no slow path for a crafted script. CHANGELOG entry is under Unreleased / Fixed and the only conflict with main is CHANGELOG.md, so it needs one more merge before it can go in.

Comment thread tests/validators/test_script_lint.py Resolved
Comment thread tests/validators/test_script_lint.py Resolved
Signed-off-by: Afloat <ShuffleMonkey@163.com>
@Afloat16

Copy link
Copy Markdown
Contributor Author

Updated in 8a37e9610672. The healthy-script cases now require flat_script and missing_shebang as a subset, so unrelated advisory additions do not break this parser-limit regression. The existing version-sensitive ast.parse oracle and successful-parse branch are unchanged, and the expression has not been enlarged.

All 36 script-lint tests pass, together with lint and changed-file formatting. The CHANGELOG conflict is resolved against current main with both entries retained. Could you approve the new workflows and re-review the follow-up?

Retain the pull request contribution and current upstream changes.
Resolve the CHANGELOG conflict by preserving both sets of entries.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Preserve the published 1.3.0 history and the new stable-CI release note,
and place this pull request's change under Unreleased. Keep the reviewed
source and test changes.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Keep the published 1.3.1 release history and this pull request's change
under Unreleased. The reviewed source and test changes are unchanged.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Integrate main 9747bc1 while retaining the original contribution and its regression coverage. Keep the release note as a separate Unreleased Fixed bullet and preserve all main entries.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@rng1995

rng1995 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

@Afloat16 Please resolve merge conflicts and provide permission for me to merge your PR.

Keep the contribution under Unreleased and retain the complete published release history.

Signed-off-by: Afloat <ShuffleMonkey@163.com>

This branch has not been deployed

No deployments
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.

3 participants