Skip to content

fix(pipeline): honor discovery exclusions in pkgmap/envscan repo walks#793

Closed
Sowiedu wants to merge 1 commit into
DeusData:mainfrom
Sowiedu:fix/repo-walk-exclusions
Closed

fix(pipeline): honor discovery exclusions in pkgmap/envscan repo walks#793
Sowiedu wants to merge 1 commit into
DeusData:mainfrom
Sowiedu:fix/repo-walk-exclusions

Conversation

@Sowiedu

@Sowiedu Sowiedu commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #792.

Problem

The auxiliary filesystem walks in pkgmap (cbm_pkgmap_scan_repo, called from merge_pkg_entries() at the parallel-extract join) and envscan only skip hardcoded directory names (cbm_should_skip_dir() / a private is_ignored_dir() list). They never consult the project's gitignore-derived exclusion list that discovery honors. On a repo with a large gitignored artifact tree this walk dominates the entire pipeline: with a 1.6M-file gitignored tile directory, index_repository takes 15–18 minutes (silent between two log lines, looks like a hang) instead of ~3 seconds.

Fix

  • New helper cbm_pipeline_relpath_is_excluded() (in path_alias.c) that prefix-matches a repo-relative path against the pipeline ctx's excluded-dirs list.
  • cbm_pkgmap_scan_repo() now takes the ctx's excluded_dirs/excluded_count and consults the helper before descending, in addition to the existing cbm_should_skip_dir() and Windows reparse-point checks.
  • The envscan walker does the same via cbm_scan_project_env_urls_excluded(); the original cbm_scan_project_env_urls() remains as a wrapper (NULL exclusions) so existing callers are unaffected.

Hardcoded skip lists are kept as a fast path; the exclusion check only adds prefix comparisons on directory descent.

Verification

On the affected repo (~1,000 source files + 1,638,518-file gitignored map-import/output/, Windows 11/NTFS):

before after
full index 15–18 min 3.0 s
incremental no-op ~7 min 0.4 s

Synthetic check: repo with a gitignored bigdir/ of ~20k files — the walk no longer descends into it (verified via timing and open-handle inspection with Sysinternals handle64). Graph output is unchanged on repos without large ignored dirs (node/edge counts identical before/after on the same tree).

Diagnosis details, handle dumps, and the elimination path are in #792.

@Sowiedu Sowiedu requested a review from DeusData as a code owner July 3, 2026 05:56
Signed-off-by: Patrick <11910229+Sowiedu@users.noreply.github.com>
@Sowiedu Sowiedu force-pushed the fix/repo-walk-exclusions branch from cdf33d5 to 9eb5916 Compare July 3, 2026 06:11
@phpmac

phpmac commented Jul 3, 2026

Copy link
Copy Markdown

v12 pls audit

@DeusData DeusData added bug Something isn't working stability/performance Server crashes, OOM, hangs, high CPU/memory priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. labels Jul 3, 2026
@DeusData

DeusData commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Thanks for the focused fix. Triage: high-priority performance/stability PR for #792.

Review will focus on whether pkgmap/envscan now share the same exclusion model as discovery, and whether the regression fixture proves a large ignored artifact tree is skipped rather than merely making this one repo faster. This should stay scoped to exclusion propagation and progress/degradation behavior.

@DeusData

DeusData commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Thank you — of the several ignore-semantics PRs open right now, this is the one closest to the root cause: reusing discovery's materialized exclusion decisions instead of re-implementing matching per walker is exactly the right foundation, and the boundary-correct prefix match checks out. Three asks before merge:

  1. A small regression test (repo rule: reproduce-first) — e.g. an excluded dir containing a package.json that pkgmap must not scan.
  2. A body correction: cbm_scan_project_env_urls currently has no production callers (the envscan half keeps tests compiling but can't have contributed to the hang), and the PR also fixes the path-alias walk, which deserves to be named — it's likely essential to your 3.0s result.
  3. If cheap for you: the incremental path (pipeline_incremental.c's ctx lacks excluded_dirs, so merge_pkg_entries still walks unexcluded on real incremental reindexes) — otherwise we'll file it as an immediate follow-up so the 15-minute walk can't survive there.
    With Windows support: CGO/tree-sitter build fails — WSL2 workaround included #1 this merges quickly — it's priority/high for good reason. Thanks again for the thorough diagnosis in pkgmap/envscan repo walks bypass gitignore exclusions - 15+ min apparent hang on repos with large ignored artifact dirs #792.

Update: to keep momentum on the bug backlog, we're going to carry the changes above over the line ourselves shortly — a distilled follow-up on current main implementing the notes in this thread, with you credited as Co-authored-by on the commit, and this PR closed referencing it. If you'd prefer to push the update yourself, just reply within the next couple of days and we'll gladly take yours instead. Thanks again for the contribution!

@DeusData

DeusData commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Thank you — of all the ignore-semantics work in flight, yours was the one closest to the root cause: reusing discovery's materialized exclusion decisions instead of re-implementing matching per walker was exactly right, and your boundary-correct prefix predicate carried over verbatim. We took it over the line with the missing regression tests (control-first so they can't pass vacuously), the incremental-path plumbing (your fix's one gap — the ctx used by incremental reindexes didn't carry the exclusions, tracked as #804), and a small narrative correction (envscan's walker has no production callers). Merged as 2e7c64b (PR #811) with you credited as co-author — closes #792 and #804. Thanks again for the excellent diagnosis in #792!

@DeusData DeusData closed this Jul 4, 2026
stjordanis pushed a commit to stjordanis/codebase-memory-mcp that referenced this pull request Jul 4, 2026
…n walks

The auxiliary filesystem walks (pkgmap manifest scan, tsconfig/jsconfig
path-alias discovery, env-URL scan) ignored the directory subtrees that
discovery had already excluded (gitignore + skip dirs). On a huge
monorepo with a gitignored vendored tree this kept the pkgmap walk busy
for ~15 minutes re-traversing directories the index never uses (DeusData#792).

Distills PR DeusData#793 by Patrick (@Sowiedu): a shared root-anchored,
'/'-boundary exclusion predicate (cbm_pipeline_relpath_is_excluded) in
pipeline_internal.h, exclusion parameters threaded through
cbm_pkgmap_scan_repo / cbm_pkgmap_build_from_repo, find_alias_files /
cbm_load_path_aliases_excluded and cbm_scan_project_env_urls_excluded,
NULL-exclusion wrappers preserving the old signatures, and the borrowed
excluded_dirs/excluded_count pair on cbm_pipeline_ctx_t.

Beyond DeusData#793:
- Thread the excluded list into pipeline_incremental.c's extract ctx
  and its path-alias load as well, so incremental runs stop walking
  excluded trees too (DeusData#804).
- Add regression tests: boundary semantics of the exclusion predicate,
  plus walk-level exclusion tests for pkgmap, path-alias, and envscan
  (each with an unexcluded control run so they cannot pass vacuously).
  All are red against the unfixed sources.
- Correct the envscan narrative: cbm_scan_project_env_urls has no
  production callers today; the exclusion plumbing is kept for
  consistency and exercised by tests.

Closes DeusData#792. Closes DeusData#804.

Co-authored-by: Patrick <11910229+Sowiedu@users.noreply.github.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. stability/performance Server crashes, OOM, hangs, high CPU/memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pkgmap/envscan repo walks bypass gitignore exclusions - 15+ min apparent hang on repos with large ignored artifact dirs

3 participants