Skip to content

[BUG] File size threshold too conservative — large files silently skipped, breaking analysis completeness #163

Description

@Wolfvin

Problem

CodeLens silently skips files above hardcoded size thresholds to avoid a tree-sitter segfault (tracked in #116):

  • JavaScript: files > ~100 lines → skipped
  • Python: files > ~200 lines → skipped

This is the most critical correctness gap in CodeLens today. The files most worth analyzing are exactly the ones getting skipped.

Tested on Wolfvin/Regrets:

  • scripts/regret.js: 2,731 lines — cyclomatic complexity 338, cognitive 936 — the most important file in the repo → skipped
  • scripts/validate.py: main function cyclomatic 300 — skipped
  • ~40% of the codebase invisible to complexity, entrypoints, dead-code, smell

Result: complexity reports 1,865 functions but the real count is higher. The "untamable" hotspots it finds are from smaller files — the actual worst offenders are invisible.

Root Cause

See #116 — Python GC can collect a tree-sitter Tree while a Node is still alive, causing SIGSEGV. The current fix was to skip large files entirely, which trades correctness for stability.

Goal

Fix the underlying segfault so large files can be analyzed safely, then remove or substantially raise the threshold.

The known fix pattern (from base_parser.py): store a _last_tree reference on the parser instance to prevent GC collection. If this is already in place for small files, it should work for large files too — verify why it is not applied uniformly.

Proposed Fix

  1. Audit base_parser.py and all parser subclasses — confirm _last_tree is set before returning any Node objects
  2. Stress-test with files 500–5000 lines: parse → walk nodes → no SIGSEGV
  3. If fix holds: remove the file size threshold entirely, or raise to a practical limit (e.g. 10,000 lines) with a warning, not a silent skip
  4. If segfault persists on very large files: replace silent skip with explicit warning in output:
    { "skipped": [{ "file": "scripts/regret.js", "reason": "file_too_large", "lines": 2731 }] }
    So the caller knows coverage is incomplete — silent skip is the worst outcome

Definition of Done

  • Root cause of segfault on large files confirmed (GC issue or other)
  • _last_tree fix applied uniformly across all parser classes
  • Verified: files up to 3,000 lines parse without SIGSEGV (use scripts/regret.js from Wolfvin/Regrets as test fixture — 2,731 lines, JS)
  • File size threshold removed or raised to ≥ 5,000 lines
  • If threshold kept: silent skip replaced with explicit skipped[] list in JSON output
  • complexity on Wolfvin/Regrets now detects scripts/regret.js:main (cyclomatic ~338) as a hotspot
  • No regression on existing tests

Why This Is P1

Without this fix, CodeLens gives false confidence. A health check that misses 40% of the codebase — specifically the most complex 40% — is worse than no health check, because it implies coverage it doesn't have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions