Skip to content

fix: limit AST recursion depth to 20 in Python parser (#1095)#1129

Open
ayush-kr-repo wants to merge 1 commit into
CodeGraphContext:mainfrom
ayush-kr-repo:fix/ast-recursion-depth-limit-1095
Open

fix: limit AST recursion depth to 20 in Python parser (#1095)#1129
ayush-kr-repo wants to merge 1 commit into
CodeGraphContext:mainfrom
ayush-kr-repo:fix/ast-recursion-depth-limit-1095

Conversation

@ayush-kr-repo
Copy link
Copy Markdown

Problem

Deeply nested, autogenerated, or cyclical Python source files trigger
Python's recursion limit in the AST parsing loop, causing the parser
pipeline to crash.

Fix

  • Added a MAX_DEPTH = 20 guard in _get_parent_context to stop
    traversing parent nodes beyond 20 levels
  • Added a depth counter in _calculate_complexity's traverse
    function to skip AST branches beyond 20 levels deep
  • Both guards log a warning via warning_logger when the limit is hit

Tests

Added 2 new tests in tests/unit/parsers/test_python_parser.py:

  • test_ast_recursion_depth_limit_parent_context — 25-level nested functions
  • test_ast_recursion_depth_limit_complexity — 25-level nested if-statements

All 5 tests passing locally.

Closes #1095

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 7, 2026

@ayush-kr-repo is attempting to deploy a commit to the shashankss1205's projects Team on Vercel.

A member of the Team first needs to authorize it.

@ayush-kr-repo ayush-kr-repo force-pushed the fix/ast-recursion-depth-limit-1095 branch from d99e9df to 9f34202 Compare June 8, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog tasks

Development

Successfully merging this pull request may close these issues.

Parser: Limit Maximum AST Recursion Depth

1 participant