Skip to content

Workspace scans descend into node_modules/.git; detect_framework walks twice #50

Closed

Description

@TMHSDigital

Summary

The workspace scans in detect_framework and read_workspace_context skip files under node_modules and .git but never prune those directories, so os.walk still traverses them. detect_framework also walks the whole tree twice, and the substring test ".git" in root wrongly skips directories such as .github.

Where

  • mcp-server/tools/detect_framework.py:67-68 (_scan_manifests then _scan_code)
  • mcp-server/tools/detect_framework.py:114-116 (_scan_manifests)
  • mcp-server/tools/detect_framework.py:143-145 (_scan_code)
  • mcp-server/tools/manifest_common.py:61-63 (read_workspace_context)

Details

for root, _dirs, files in os.walk(workspace_path):
    if "node_modules" in root or ".git" in root:
        continue
  • continue skips the files at that level, but _dirs is never edited, so every directory under node_modules and .git is still visited.
  • detect_framework calls two functions that each do a full os.walk of the same tree.
  • read_workspace_context (used by the scaffolder and manifest generator) has the same pattern and walks the whole tree whenever no manifest declares an author.
  • ".git" in root is a substring check on the full path. It also matches .github, .gitlab, and any workspace path that itself contains .git (for example a folder named foo.github.io), in which case every file is skipped.
  • Nothing bounds the walk, so pointing the tool at a very large directory makes the call slow.

Impact

Resources with NUI builds commonly contain node_modules with tens of thousands of directories, so framework detection and workspace-aware scaffolding pay for a full traversal (twice for detection) on the single-threaded stdio server. The substring bug silently drops signals and can make detection report "standalone" for every resource in a path containing .git.

Steps to reproduce

  1. Create a workspace with an fxmanifest.lua and a large web/node_modules tree.
  2. Time detect_framework(<dir>) and instrument os.walk: directories under node_modules are visited twice.
  3. Put a resource under a folder named x.github.io and run detect_framework on it: no signals are found.

Suggested fix

  • At the top of each walk, prune in place by exact name: dirs[:] = [d for d in dirs if d not in {"node_modules", ".git", "dist", "build", ".venv"}], and drop the substring check on root.
  • Merge _scan_manifests and _scan_code into one walk that handles both fxmanifest.lua and code extensions.
  • Optionally cap the number of files or directories scanned and note it in the output when the cap is hit.

Acceptance criteria

  • No walk descends into node_modules, .git or the other excluded directory names.
  • detect_framework traverses the tree once.
  • Directories such as .github and paths containing .git as a substring are scanned normally.

Getting started

  • Relevant files: mcp-server/tools/detect_framework.py, mcp-server/tools/manifest_common.py
  • How to run checks: there is no test suite yet; run the MCP server with cd mcp-server && pip install -r requirements.txt && python server.py, and CI checks live in .github/workflows/validate.yml
  • Related docs: Python os.walk documentation (in-place pruning of dirnames)

Filed by repo-audit/full-audit at 701824d. Severity: medium. Effort: S. audit-key: performance|mcp-server/tools/detect_framework.py|os.walk pruning

Activity

  1. TMHSDigital commented on Nov 21, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 66f04fe.

    Added walk_workspace(), which prunes node_modules, .git, dist, build, virtualenvs and pycache by exact name before descending; detect_framework now scores manifests and code in a single walk, and read_workspace_context uses the same walk.

    Verified: New tests assert exactly one os.walk traversal, that pruned directories are never visited, and that .github and paths containing ".git" (for example my.github.io) are scanned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueperformanceseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions