Skip to content

🐛 engram init --with-skills crashes with JavaScript heap out of memory #5

@mechtar-ru

Description

@mechtar-ru

Environment

  • Axolotl project size: 2.2 GB, 34,327 files
    • frontend/node_modules: 817 MB
    • frontend/release: 785 MB
    • frontend/jre: 127 MB (bundled JRE)
    • Actual source code: ~2 MB

Steps to Reproduce

NODE_OPTIONS="--max-old-space-size=8192" engram init --with-skills

Root Cause

File: engramx/dist/chunk-IIFAAYDO.js:1203-1244

The extractDirectory function has no maximum depth limit on recursive walk():

function walk(dir) {
  // ...
  if (visitedDirs.has(realDir)) return;
  visitedDirs.add(realDir);
  const entries = readdirSync(dir, { withFileTypes: true });
  for (const entry of entries) {
    if (entry.isDirectory()) {
      // Hardcoded exclusions only — no .engramignore support
      if (entry.name.startsWith(".") || 
          entry.name === "node_modules" || ...) {
        continue;
      }
      walk(fullPath);  // ← RECURSIVE, NO DEPTH LIMIT
    }
  }
}

Problems:

  1. NO maximum depth — crashes on deep directory trees
  2. realpathSync failure = silent termination of entire walk
  3. visitedDirs Set grows unbounded — symlinks to distinct dirs cause memory leak
  4. No .engramignore support — users can't exclude node_modules, release, jre

Stack Trace Evidence

InterpreterEntryTrampoline (repeats) ← call stack overflow from unbounded recursion

Suggested Fixes

  1. Add MAX_DEPTH constant with limit check in walk()
  2. Wrap readdirSync in try-catch
  3. Add .engramignore file support

Workaround

Not available — even 8GB heap limit is insufficient due to call stack overflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions