Skip to content

RepoScanner._should_exclude substring check excludes any path containing an exclude pattern #23

Description

@gracejoi

backend/app/code/context/repo_scanner.py:187-205:

def _should_exclude(self, path: str, is_dir: bool = False) -> bool:
    name = os.path.basename(path)
    for pattern in self.exclude_patterns:
        if is_dir and fnmatch.fnmatch(name, pattern):
            return True
        if fnmatch.fnmatch(name, pattern):
            return True
        if fnmatch.fnmatch(path, pattern):
            return True
        # Check if pattern is in path
        if pattern in path:
            return True
    return False

The last branch — if pattern in path — turns every exclude pattern into a substring search. Combined with the defaults at lines 19-68 (which include "build", "dist", "venv", ".eggs", ".tox", "coverage"), a perfectly legitimate file path like:

  • app/services/agent_builder.py → excluded because "build" is a substring
  • app/utils/distance.py → excluded because "dist" is a substring
  • tests/test_envelope.py → excluded because "venv" is a substring

…is silently skipped during scanning. The ScanResult.skipped_files list (repo_scanner.py:139) gets polluted with these false positives, and downstream context retrieval in app.code.context.retriever operates on an incomplete view of the repo.

Severity: Medium — the fnmatch branches above this line already handle the legitimate cases (*.so, node_modules, *.pyc). The substring check is doing nothing useful and a lot of harm.

Suggested fix: delete the pattern in path branch outright. If you want pattern-against-segment matching, do it via path components:

parts = path.replace("\\", "/").split("/")
for pattern in self.exclude_patterns:
    if any(fnmatch.fnmatch(part, pattern) for part in parts):
        return True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions