Skip to content

fix: guard createASTCache against zero maxSize to prevent LRU cache crash#144

Merged
magyargergo merged 2 commits into
abhigyanpatwari:mainfrom
magyargergo:fix/lru-cache-zero-max-crash
Mar 6, 2026
Merged

fix: guard createASTCache against zero maxSize to prevent LRU cache crash#144
magyargergo merged 2 commits into
abhigyanpatwari:mainfrom
magyargergo:fix/lru-cache-zero-max-crash

Conversation

@magyargergo

@magyargergo magyargergo commented Mar 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Bug: gitnexus analyze --force crashes with TypeError: At least one of max, maxSize, or ttl is required on repos where no files pass the parseable filter (e.g., all files are in unsupported languages, all filtered by .gitignore, or native bindings fail to load)
  • Root cause: chunks.reduce((max, c) => Math.max(max, c.length), 0) returns 0 when chunks is empty, and createASTCache(0) passes max: 0 to new LRUCache() which throws
  • Fix: Clamp maxSize to at least 1 in createASTCache(), and add a progress message when no parseable files are found

Changes

File Change
src/core/ingestion/ast-cache.ts Add Math.max(maxSize, 1) guard
src/core/ingestion/pipeline.ts Add progress message when totalParseable === 0
test/unit/ast-cache.test.ts Add test for createASTCache(0) edge case

Test plan

  • New unit test verifies createASTCache(0) doesn't throw and clamps to 1
  • All 750 existing unit tests pass with zero regressions
  • Manual test: run gitnexus analyze --force on a repo with only unsupported language files

…rash

When a repo has no parseable files (e.g., unsupported languages or all
files filtered out), chunks.reduce returns 0, causing createASTCache(0)
to pass max:0 to LRUCache which throws TypeError. This clamps maxSize
to at least 1 and adds a progress message when no parseable files exist.
@vercel

vercel Bot commented Mar 2, 2026

Copy link
Copy Markdown

@magyargergo is attempting to deploy a commit to the NexusCore Team on Vercel.

A member of the Team first needs to authorize it.

@magyargergo

Copy link
Copy Markdown
Collaborator Author

This is a duplicate of #134

cc @GauravRatnawat

@magyargergo magyargergo merged commit 20e8c52 into abhigyanpatwari:main Mar 6, 2026
5 of 7 checks passed
@magyargergo magyargergo deleted the fix/lru-cache-zero-max-crash branch March 6, 2026 09:22
motolese pushed a commit to motolese/datamoto-gitnexus that referenced this pull request Apr 23, 2026
…-zero-max-crash

fix: guard createASTCache against zero maxSize to prevent LRU cache crash
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.

1 participant