Skip to content

perf(realtime): decide each excluded directory once, not once per file - #490

Open
fstrasz wants to merge 43 commits into
chunkhound:mainfrom
fstrasz:fix/realtime-excluded-dir-memo
Open

fstrasz wants to merge 43 commits into
chunkhound:mainfrom
fstrasz:fix/realtime-excluded-dir-memo

Conversation

@fstrasz

@fstrasz fstrasz commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #485; it needs #485's excludes_directory. Review this PR's two commits, c3fea4f and e430de2. The merge 6aba374 brings in #485's review fixes, and 4467926 brings in #485's pathspec 1.x fix (below).

Problem

Every realtime file event under an excluded directory runs the full ignore match for the file (IgnoreEngine.matches, Path.relative_to in _in_tree_path and _nearest_repo, pathspec), repeating the match that already excludes its directory. A burst under node_modules/ (an npm install, or a junction to a real node_modules tree: 48,255 events) paid that match once per file.

Fix

RealtimePathFilter keeps, per directory, whether it or a directory above it is excluded, judged where it sits in the tree. A file whose directory is known to be excluded is rejected without matching the file itself; the first file under a new directory costs one directory match per new level, and nothing below an excluded directory is matched at all. excludes_directory() uses the same memo.

This is the rule the startup scan already applies (file_patterns prunes an excluded directory and never descends into it) and the rule Git applies (a file cannot be re-included below an excluded directory). Since #485's review fixes, the engine gives that answer for the file itself, and it reports a directory excluded only when nothing beneath it can be included. So the memo changes no decision; it only saves repeated matching. #485's eleven git check-ignore cases pass on this branch, with the memo in the admission path.

The memo is kept only when the engine's rules cannot change while it lives: the Python engines, compiled once. The libgit2 evaluator rereads .gitignore files, so with gitignore_backend=libgit2 the filter asks it each time, as before this PR; libgit2 already treats a path under an ignored directory as ignored. With libgit2 this PR therefore saves nothing; the default Python backend keeps the saving.

The memo is bounded (8,192 directories, then it starts over) and belongs to the ignore engine that produced it: a different engine object starts with an empty memo, so a future ignore-source reload cannot serve stale decisions.

Measurements

Measured at c3fea4f, with the Python backend. A real RealtimeIndexingService wired like the MCP daemon (watchdog backend, a status callback that deep-copies each snapshot), on Windows with a 10-core CPU. A directory junction to a real node_modules tree (44,302 files) was created under the watched root. That produced 48,255 created events, all rejected as excluded before the queue. The measurement is the observer thread's handler time for the whole burst.

Before (#485 head) With this commit
Handler time, 48,255 events 66.86 s 53.44 s
Per event 1.386 ms 1.107 ms

The rest of each event's cost is the status snapshot published for every filtered event (#489). With both changes the same burst takes 27.52 s, or 0.57 ms per event.

Test

tests/realtime/test_realtime_excluded_dir_memo.py: 200 file events under node_modules/pkg*/lib/ with a counting engine.

  1. Before: 200 engine matches. After: at most 2. All 200 are still rejected, and src/app.js is still admitted.
  2. test_libgit2_backend_sees_a_removed_ignore_rule: with gitignore_backend=libgit2, ignore foo/, see a file under it, remove the rule, and check that a new file in foo/ is admitted. It fails at c3fea4f and passes at fix(realtime): admit file events before resolving and skip linked directories in walks #485's head and at e430de2.

pathspec 1.x

🤖 Generated with Claude Code, reviewed by FStrasz

fstrasz and others added 4 commits November 6, 2026 10:27
`npm install` links a local `file:` dependency into node_modules/ as a
junction (a symlink elsewhere). The ignore engine resolved every path
before matching, so a file behind that link was matched at its target,
outside the root, where no root-relative rule such as `node_modules/**`
applies. Realtime then indexed it:

- A directory created above the link was walked with rglob, which
  descends the junction, and its files passed the filter and were stored
  under node_modules/.
- A directory event for the link itself was resolved to the target and
  walked from there; every file failed at the store step ("not in the
  subpath").

The startup scan already prunes excluded directories by their in-tree
path, so only realtime was affected.

Ignore rules now match a path by its location under the root, falling
back to the resolved path only when it is not lexically under the root.
A created directory that an ignore rule excludes is dropped before it is
resolved or walked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`npm install` links a local `file:` dependency into node_modules/ as a
junction (a symlink elsewhere). The ignore engine resolved every path
before matching, so a file behind that link was matched at its target,
outside the root, where no root-relative rule such as `node_modules/**`
applies. Realtime then indexed it:

- A directory created above the link was walked with rglob, which
  descends the junction, and its files passed the filter and were stored
  under node_modules/.
- A directory event for the link itself was resolved to the target and
  walked from there; every file failed at the store step ("not in the
  subpath").

The startup scan already prunes excluded directories by their in-tree
path, so only realtime was affected.

Ignore rules now match a path by its location under the root, falling
back to the resolved path only when it is not lexically under the root.
A created directory that an ignore rule excludes is dropped before it is
resolved or walked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ectories in walks

293f8a6 made the ignore engine match a path by its location under the
root, and dropped an excluded created directory before walking it. Two
other realtime paths still resolved or followed a directory link (an npm
junction under node_modules/, or a symlink) before asking where it sits.

A. Admission before resolve. SimpleEventHandler resolved every file
   event's path before the admission filter. A file under
   root/node_modules/@scope/pkg/ then reached the filter as the link's
   target outside the root, where no root-relative rule applies, so it was
   admitted and failed at the store ("not in the subpath"). Resolving
   first also cost about 0.67 ms per event, paid for every event,
   including the ones the filter then rejected.

   File events, both sides of a move, and created directories are now
   judged on their absolute, unresolved path. A rejected event is never
   resolved, and source and filtered events are recorded with that
   unresolved path. Only an admitted path is resolved, and it is still
   queued in resolved form.

   The service's event bookkeeping (source and filtered recording, and
   event-pressure tracking) normalised every path through
   normalize_realtime_path, which resolves it. A path already spelled
   under the watch root is now kept as is there. Anything else is
   normalised as before. The key differs from full normalisation only for
   a path through a link whose target is also in the tree, or one the
   filesystem spells differently (8.3 short names, letter case).

   An admitted path whose resolved form is outside the root is now
   rejected and recorded as filtered. This is an intended behaviour
   change: it makes realtime match the default startup scan. The Rust
   scanner does not follow directory symlinks or junctions, so it never
   indexes such a file. Realtime used to queue it, and the store then
   failed on it ("not in the subpath", about 4 s per file). Example:
   root/vendor/pkg linked to a directory outside the root, where vendor/
   is not excluded. Deletes of previously indexed files keep their
   existing admission exception.

C. Realtime walks. _polling_snapshot and _collect_supported_files used
   rglob, which descends junctions. Both now share one os.walk that
   prunes a directory when the ignore rules exclude it at its in-tree
   path, and also when it is a directory link. os.walk already skips
   symlinks. Junctions are detected by their mount-point reparse tag
   only, because OneDrive and deduplication placeholders are reparse
   points too and are ordinary directories. This also matches the
   default Rust scan. The polling snapshot keeps its 5000-file cap and
   its error tolerance.

   Pruning by directory exposed an older matching bug. IgnoreEngine and
   the config-exclude check matched a directory by its bare name as well
   as its "dir/" form. Under git's whitelist idiom ("/*", then "!/src/"),
   the bare "src" matches "/*" but not the dir-only re-include, so src/
   was reported excluded while every file in it was included. A pruning
   walk then never saw src/ at all. A directory is now matched in its
   "dir/" form only, as git does. Default excludes such as
   **/node_modules/**, node_modules/ and node_modules still match it. The
   Python fallback walker, which prunes through the same engine, gets the
   same correction.

Measured on Windows with stock watchdog. A junction to a 48,253-entry
node_modules was created under the watched root, with the handler wired
as the running service wires it: its source, filtered, admission and
queue callbacks, plus a status callback that deep-copies each snapshot,
as the MCP daemon's does. Both runs handled the first 5,000 of the
48,255 events, because the 293f8a6 run would take about 8 minutes in
full:
  293f8a6: 0 queued, 52.67 s, 10.53 ms per event
  this fix: 0 queued,  6.54 s,  1.31 ms per event
For 200 rejected events, Path.resolve was called 1,400 times at
293f8a6 and 0 times with this fix. Without the status callback the fix
measures 0.73 ms per event; per-event status snapshots, which have no
throttle today, account for the rest.

Linking an included root/vendor/pkg to an outside directory of .py
files, and then writing one more file through the link, queued nothing
under the link or its target. An in-tree control file was still queued.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every file event under an excluded directory ran the full ignore match for
the file, repeating the match that already excludes its directory: about
0.43 ms per event, 20 s for the 48,255 events a junction to a real
node_modules tree produces.

RealtimePathFilter now keeps, per directory, whether it or a directory
above it is excluded. A file whose directory is known to be excluded is
rejected without matching the file. This is the rule the startup scan
already applies (it never descends into an excluded directory) and the
rule Git applies (a file cannot be re-included below an excluded
directory), so realtime and the scan now agree on that case too.

The memo is bounded (8,192 directories, then it starts over) and belongs
to the ignore engine that produced it: a different engine starts with an
empty memo. excludes_directory() uses it as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@VakninAriel VakninAriel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — PR #490

Verdict: 🚫 Request Changes

Summary

Bursts of realtime events beneath excluded directories repeatedly paid for the same ignore matching on every file. Stacked on #485, this PR caches ancestor-directory decisions and rejects file events early when an ancestor is cached as excluded.

What's good

  • The memo has an explicit reset threshold to limit accumulated cache state; its engine-change reset specifically avoids reusing decisions across replacement ignore-engine objects.
  • The added burst test uses a counting wrapper around the real ignore engine and includes an admitted src/app.js control, checking reduced matcher work without treating rejection of every path as success.

Freshness warning: Package freshness checked 2026-11-11T15:38:58.574960+00:00: STALE: included heads/eligibility changed; see overview and freshness audit before posting. This report applies only to its pinned SHA.

Severity Count
🔴 Critical 0
🟠 High 0
🟡 Medium 3
🟢 Minor 0

Findings

🟡 [Preserve re-included descendants in pruning and per-file admission] (#1 · Medium)

Location: chunkhound/services/realtime_path_filter.py — lines 239–242

With the default Python ignore backend, src/.gitignore containing ** followed by !keep.py leaves src/keep.py unignored by Git and by direct file matching. The existing nested-pattern transformation also matches the src/ directory candidate. The new ancestor check interprets that result as an excluded subtree and returns False before checking keep.py. Watchdog and Watchman updates to this valid supported file are therefore dropped, leaving indexed content stale or absent. This is not re-inclusion beneath a genuinely excluded parent: a directory's own .gitignore governs its contents, not that directory itself. The full diff also retains #485's walker pruning of foo/** plus !foo/bar.py at pipeline.py:56-60; #490 now rejects the previously admitted individual bar.py event as well. Both are the same invalid assumption that a directory match proves no descendant may be included.

Suggested fix:

Preserve .gitignore scope when evaluating directory exclusions: rules inside a directory must not exclude the directory itself. Establish a reliable subtree-exclusion decision before using it for either walker pruning or file-event admission, accounting for descendant negations. Cover nested ** / !keep.py and root foo/** / !foo/bar.py contracts.

🟡 [Invalidate directory exclusions when the live libgit2 policy changes] (#2 · Medium)

Location: chunkhound/services/realtime_path_filter.py — lines 164–168

With gitignore_backend=libgit2, first ignore foo/ and process a directory or file beneath it, populating an excluded memo entry. Remove foo/ from .gitignore and then create or modify a supported file there. pygit2 observes the new rules through the same evaluator object, but this cache resets only when engine identity changes. The cached ancestor True is reused at lines 177-180 before direct file matching, so newly unignored files remain rejected until cache eviction or filter recreation. Before this commit, directory checks and file admission queried the live engine each time.

Suggested fix:

Associate memo entries with an explicit ignore-policy generation and invalidate on rule changes; alternatively disable this memo for live libgit2 evaluators until reliable invalidation is available. Cover removal of an ignore rule while retaining the same evaluator object.

🟡 [Recheck an admitted alias after resolving its canonical target] (#3 · Medium)

Location: chunkhound/services/realtime/events.py — lines 270–274

The full diff inherits #485's alias bypass. With alias.py pointing to excluded ignored/secret.py, unresolved admission accepts the alias and _queue_admitted resolves it but checks only root containment. Created work for the excluded canonical target reaches add_file/process_file without another ignore check. The new directory memo does not fix this: the alias lives at the root, so its ancestor check does not inspect ignored/. Explicitly excluded content can be indexed and searched.

Suggested fix:

Keep early lexical rejection, then recheck policy on a changed canonical target before create/modify work is queued. Carry the #485 correction into this stack and preserve the previously-indexed deletion exception.

Review metadata and audit

Draft review for human approval. Nothing has been posted to GitHub.

Pinned head SHA: c3fea4f7f82263199ba3ff8c272e1e9114bdc18d

Package freshness checked 2026-11-11T15:38:58.574960+00:00: STALE: included heads/eligibility changed; see overview and freshness audit before posting. This report applies only to its pinned SHA.

PR: #490

Title: perf(realtime): decide each excluded directory once, not once per file

Author: fstrasz · Branches: fix/realtime-excluded-dir-memo → main

Diff merge base: 42c5711

Review scope: Full pinned main-based merge-base 42c5711..c3fea4f diff, including inherited #485 event/link handling, walking and ignore-engine changes. The final commit a902b55..HEAD adds the directory memo in realtime_path_filter.py and its test. The subtree-exclusion finding combines inherited #485 walker pruning with the memo's new expansion into individual file admission. Stale libgit2 memoization is incremental; the alias-target bypass is inherited #485 behavior reproduced at this head.

Eligibility: Resource/correctness fix: memoize excluded directories and align negated-file admission with scan/Git behavior.

Overall assessment (audit only)

Three actionable Medium findings cover invalid subtree exclusion (inherited walker pruning plus newly expanded file admission), stale live-libgit2 exclusions, and the inherited #485 canonical-target alias bypass. The verified Minor mypy diagnostic is nonblocking debt, not a behavioral finding. Full-diff attribution now includes the inherited defects rather than approving them implicitly.

Strength evidence

  • {"strength_index": 0, "path": "chunkhound/services/realtime_path_filter.py", "source": "pr-490.pinned.diff", "detail": "_DIR_DECISIONS_MAX is 8192; _directory_excluded clears decisions when the projected addition exceeds the threshold and resets the memo on engine identity change. The retained same-object invalidation finding still applies."}
  • {"strength_index": 1, "path": "tests/realtime/test_realtime_excluded_dir_memo.py", "source": "pr-490.pinned.diff", "detail": "test_files_under_an_excluded_directory_skip_per_file_matching rejects 200 node_modules events, asserts engine.calls <= 2, and admits src/app.js. It does not cover descendant negations or ignore-rule reloads."}

Finding #1 evidence

  • Final audit reran the production walker on #490: foo/** plus !foo/bar.py remains excluded from discovery. Actual head/parent ignore-admission trace additionally confirmed foo/bar.py passes #485/#491 file admission but fails #490. Probe /tmp/chunkhound-final-audit-memo.py exited 0; include/native stage intentionally not executed.
  • Pinned source realtime_path_filter.py:239-242 newly returns before file matching; ignore_engine.py:634-646 transforms nested ** to src/** and src/**/**.
  • Reconciler reran /tmp/chunkhound-pr-490-astra-a1-p1llmzw0/check_memo.py using uv and actual Python ignore engines: Git unignored files: src/keep.py; head: rejected; parent: passed ignore stage. Direct engine matching returned None for keep.py in both. Include evaluation was intentionally intercepted; this is an ignore-admission reproduction, not end-to-end indexing.

Reviewer keys: astra

Finding #2 evidence

  • Pinned ignore_engine.py:791-808 queries the retained pygit2 repository’s live path_is_ignored method. The new memo’s only policy reset is identity comparison at realtime_path_filter.py:164-168.
  • Reconciler reran the reviewer’s actual-engine parent-versus-HEAD script: after removing foo/, HEAD excludes_directory=True while direct engine=None; parent excludes_directory=False and direct engine=None. The installed pygit2 backend is 1.19.0; no mocked policy answers were used.

Reviewer keys: astra

Finding #3 evidence

  • Pinned events.py and pipeline.py are unchanged from #485. Final audit ran the actual #490 handler and production ignore-admission stage: alias.py queued (created, ignored/secret.py), while direct canonical admission rejected it. /tmp/chunkhound-final-audit-memo.py exited 0. Prior #485 real-watchdog probe established reachable file-symlink creation; this is not an event beneath an unwatched directory symlink.

Reviewer keys: astra

Verification

  • Reconciler verified both runner jobs succeeded, valid/error-free settled provenance, pinned worktree HEAD and metadata head, SHA256 of each complete report, and all captured assistant-message provider/model/responseModel identities; the two backend response models are distinct.
  • Reconciler: from /tmp/chunkhound-pr-reviews-20261111/pr-490, timeout 30s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync python /tmp/chunkhound-pr-490-astra-a1-p1llmzw0/check_memo.py exited 0 and reproduced both behavioral parent-versus-HEAD differences. Script inspected before rerun; temporary local Git repositories and actual ignore engines only, no native substitution. The nested whitelist check stops before include evaluation to avoid unavailable native dependencies.
  • Astra: timeout 120s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync mypy chunkhound --cache-dir=/tmp/chunkhound-pr-490-astra-a1-p1llmzw0/mypy-cache exited 1: 995 errors in 90 files. git show HEAD^:chunkhound/services/realtime_path_filter.py > /tmp/chunkhound-pr-490-astra-a1-p1llmzw0/parent_filter.py followed by the same mypy command with --shadow-file chunkhound/services/realtime_path_filter.py /tmp/chunkhound-pr-490-astra-a1-p1llmzw0/parent_filter.py exited 1: 994 errors in 89 files. Reconciler inspected both logs.
  • Sonnet: timeout 120s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync mypy chunkhound --cache-dir=/tmp/chunkhound-pr-490-sonnet-a1-dlycaf1x/mypy-cache exited 1: 995 errors in 90 files; identified the same new union-attr diagnostic without a baseline run.
  • Astra: timeout 90s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest -p no:cacheprovider --basetemp=/tmp/chunkhound-pr-490-astra-a1-p1llmzw0/pytest-ignore tests/ignore/test_repo_aware_engine.py tests/ignore/test_git_parity_nested.py tests/ignore/test_libgit2_backend_parity.py -q exited 0: 3 passed in 0.10s.
  • Astra: git diff --check 42c5711 c3fea4f exited 0; final worktree status clean. Reconciler compared full and incremental diff scopes and relevant ignore-engine dependencies.

Limitations

  • Astra targeted command: timeout 90s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest -p no:cacheprovider --basetemp=/tmp/chunkhound-pr-490-astra-a1-p1llmzw0/pytest-filter tests/realtime/test_realtime_excluded_dir_memo.py tests/realtime/test_realtime_repo_boundary.py tests/realtime/test_realtime_ignore_parity.py -q exited 2 with 3 collection errors from missing chunkhound_native.chunkhound_native; no tests ran.
  • Sonnet reported uv run --no-sync pytest -p no:cacheprovider --basetemp=<tmp>/bt tests/realtime/test_realtime_excluded_dir_memo.py tests/realtime/test_realtime_ignore_parity.py tests/realtime/test_realtime_repo_boundary.py tests/realtime/test_filter_consistency_realtime_cleanup.py -q: four collection errors for the same missing native extension; no tests ran. The temporary path is abbreviated as in the report.
  • No full service/indexing integration test passed for these regressions; the actual-engine checks prove exclusion/admission differences and source tracing establishes downstream dropped events. Windows behavior and performance claims not measured. No full suite, native builds, installations, network access or environment repair.
  • CI is a captured snapshot, not a fresh run or a guarantee of current branch status.
  • Model identities are verified declarations supplied by the reconciler; the renderer does not inspect raw reports or provenance events.

Disposition of discarded / merged findings

  • Final audit moves the identical, baseline-proven mypy candidate to nonblocking_observations while preserving all evidence. Callers already check the engine; no supported None/race trigger or newly-red enforced typecheck gate was demonstrated. Do not equate added diagnostics on an already-failing baseline with a user-facing bug; consistent with #489, #485, #509 and #510.
  • Final full-diff audit includes both #485 defects after checking the actual head. Re-inclusion pruning is combined with finding 1 because it shares the invalid subtree assumption; inherited canonical-target bypass is a separate finding. Production watcher/ignore probes exited 0. Deduplicate shared overlap keys when commenting on the stack jointly.
  • Rejected Sonnet’s missing-test-coverage candidate as a standalone finding: absent tests for private memo details are not an introduced user-facing bug. Suggested regression coverage is instead tied to the two demonstrated behavioral contracts.
  • Sonnet’s claim that memo staleness is no worse because engines never reload is disproved for the supported libgit2 backend by same-object live-rule repro. Likewise the intended rejection of files beneath truly excluded directories does not justify rejecting a directory based on its own nested .gitignore; Astra’s valid whitelist counterexample is substantiated.
  • Inherited #485 traversal already exposes the nested-pattern directory mismatch during some scans, but prior per-file realtime admission passes the valid whitelist case. Retained finding is the new expansion into individual file-event rejection in #490, not a duplicate claim that #490 originally created the underlying pattern transformer.

Nonblocking observations (audit only)

  • {"title": "Narrow the optional engine before calling matches", "severity": "Minor", "path": "chunkhound/services/realtime_path_filter.py", "line_start": 188, "line_end": 188, "description": "The new helper captures self._engine as Any | None but calls engine.matches without narrowing away None. The required project mypy command adds a union-attr diagnostic on this line. A shadow comparison with this file at the parent revision reduces the total from 995 errors in 90 files to 994 errors in 89 files, isolating this introduced typechecking failure. No runtime race or data loss is claimed.", "suggested_fix": "Pass the already-checked non-None engine into _directory_excluded, or explicitly guard/assert the captured engine before using it.", "evidence": ["Both models reported realtime_path_filter.py:188: Item \"None\" of \"Any | None\" has no attribute \"matches\" [union-attr].", "Reconciler inspected /tmp/chunkhound-pr-490-astra-a1-p1llmzw0/mypy.log and mypy-parent.log: the head contains this diagnostic; the parent-shadow log does not. Totals are 995/90 versus 994/89."], "reviewers": ["sonnet", "astra"], "id": 3}

Independent reviewer provenance

  • sonnet — provider: amat-tfy; requested model: standard-chat-dev/claude-sonnet-5.5; verified response model: aws-aidev-models/us.anthropic.claude-sonnet-5-5. Identity evidence · Raw report
  • astra — provider: amat-tfy; requested model: frontier-chat-dev/gpt-6-astra; verified response model: gpt-6-astra. Identity evidence · Raw report

CI snapshot

Captured: 2026-11-11T14:18:23.581921+00:00. Eligibility green: True. Counts: {"SKIPPED": 2, "SUCCESS": 23}

Reviewed by Ariel Vaknin via pi.dev

fstrasz and others added 5 commits November 12, 2026 08:56
…cluded

Review of the stacked PRs (chunkhound#490, chunkhound#491) found that a file a .gitignore
negation re-includes was dropped by realtime:

  .gitignore      foo/**  then  !foo/bar.py   -> foo/bar.py
  src/.gitignore  **      then  !keep.py      -> src/keep.py

git does not ignore either file, the full scan indexes both, and event
admission accepted them, but excludes_directory() reported foo/ and src/
excluded, so the polling walk and new-directory expansion pruned them and
never saw the file. IgnoreEngine matched a directory in its "dir/" form,
and pathspec matches "foo/" against a contents pattern such as foo/** (or
the root-relative src/** of a nested "**") through an empty tail. Main had
the same wrong answer; this PR made it load-bearing by pruning on it.

A directory match now means its whole subtree is excluded, which is how
every caller uses it (the realtime walk and directory events, the Python
full-scan walker and its os.walk fallback, repo-root detection). Per spec,
in precedence order, a directory is excluded when:

- git excludes the directory itself: the last pattern matching it is not
  a negation, testing "dir/" against patterns written with a trailing "/"
  and the bare "dir" against the rest. foo/ and foo match foo; foo/**
  matches only what is inside it. A directory a negation re-includes is
  still excluded when an ancestor is, as in git.
- or a pattern covers its contents ("dir/" matches, e.g. foo/** or the
  default **/node_modules/**) and no negation in that spec could match
  beneath it. A negation could when it is unanchored (!keep.py, !*.md),
  starts with **/, or its literal prefix lies above or below the
  directory. Config excludes have no negations, so node_modules is still
  pruned without being walked.

So foo/** then !foo/bar.py leaves foo/ walkable, and each file is decided
on its own. The whitelist idiom (/* then !/src/) keeps src/ walkable.

To tell foo/ from foo/** the .gitignore transform now emits dir-only
patterns with their trailing "/" instead of "/**". pathspec matches the
same files for both, except that **/ no longer matches top-level files,
which git does not ignore either.

Files follow git as well: a file a negation re-includes stays excluded
when a parent directory is excluded. "foo/" then "!foo/bar.py" therefore
keeps foo/bar.py excluded in the walk, in event admission and in the
Python full scan, as git does; before, the engine admitted it.

The libgit2 backend's config-exclude layer uses the same rule; libgit2
already applies git semantics to .gitignore directories.

Tests compare the full scan, the polling walk and event admission with
git check-ignore for the two review cases, the dir-only case and the
whitelist idiom, and check that the walk never enters node_modules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SimpleEventHandler admits a file event by the path the event names, then
queues the resolved path, checking only that it stays under the root. A
file link alias.py -> node_modules/pkg/secret.py was admitted as alias.py
and queued as secret.py, which no later step rechecks, so an excluded file
was indexed.

When resolving changes the path, the target now has to pass the same
policy before created or modified work is queued (a created directory is
checked with excludes_directory). The cheap admission on the unresolved
path stays as it was, so a rejected event is still never resolved. A
delete is not rechecked, so a previously indexed path is still cleaned up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of b359531 found that a negation re-including a directory inside
a contents pattern opened files git ignores:

  foo/**  then  !foo/bar/             -> git ignores foo/bar/x.py
  /a/**   then  !/a/b/                -> git ignores a/b/x.py
  /s/**   with  s/.gitignore !/keep/  -> git ignores s/keep/a.py

foo/** still matches the file itself; !foo/bar/ only re-includes the
directory. pathspec has no notion of that: it matches "!foo/bar/" (as
"!foo/bar/**") against every file below, so the file was re-included.
Before b359531 the walk pruned foo/ and hid this; once foo/ became
walkable, polling and admission gained foo/bar/x.py while the full scan
(git ls-files) left it out.

Files and directories are now decided as git decides them whenever a
negation in the spec matches the path:

- each pattern is matched against the path itself, without pathspec's
  "and everything beneath" tail (the ps_d group in pathspec 0.12), and a
  directory pattern only against directories; the last match wins;
- a path is excluded regardless when a directory above it is excluded.

A path no negation matches keeps pathspec's answer, which is then git's.
The same exact matching decides when a directory is excluded, and the
"contents covered" pruning rule now counts only file patterns, so a
directory pattern such as foo/**/ no longer prunes foo/ itself.

This also brings these cases in line with git (checked against
git ls-files -o --exclude-standard): "*.md then !keep/", "* !*/ !*.py",
"* !**/ !*.py", "* !/**/ !*.py", and "a/b/ then !a/".

The .gitignore transform again emits a directory pattern "foo/" as
"foo/**", byte for byte as before b359531, and carries the "was a
directory pattern" flag beside the compiled spec instead of in the
string. b359531's trailing "/" changed what **/ and /**/ match for the
full scan; that change is reverted (those two still differ from git as
they always have).

Reading pathspec's pattern objects (include, regex, source, ps_d tail)
fails loudly in a guard test, and at runtime degrades to pathspec's own
answers with no pruning and logs one warning, rather than silently
restoring the old behaviour.

Git's answer for each directory is memoized per compiled spec. The rules
never change for the spec's lifetime, so the memo needs no invalidation;
it is bounded and cleared when full. With 1,806 patterns including
"* !*/ !*.py", 2,000 file decisions take about 1.8 s against 1.7 s on
a902b55, and 2,000 directory checks 0.9 s against 1.6 s.

The git-oracle test gains the three review cases, the directory
re-include of a file pattern and the three whitelist variants.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cluded-dir-memo

Brings in chunkhound#485's review fixes. A directory match now means its whole
subtree is excluded, so a file a .gitignore negation re-includes
(foo/** then !foo/bar.py, or src/.gitignore ** then !keep.py) is no
longer rejected by this PR's ancestor check. A file link whose target is
excluded is rechecked before it is queued. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of c3fea4f found that with gitignore_backend=libgit2 the
directory memo outlived an edited .gitignore: ignore foo/, see a file
under it, then remove foo/ from .gitignore, and a new file in foo/ stayed
rejected. pygit2 rereads .gitignore files through the same evaluator
object, but the memo reset only when the engine object changed.

The memo is now used only when the engine's rules cannot change while it
lives (the Python engines, compiled once). With the libgit2 evaluator the
filter asks the engine each time, as before c3fea4f; libgit2 already
treats a path under an ignored directory as ignored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fstrasz

fstrasz commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All three findings are fixed:

  1. Re-included descendants (finding 1) are fixed in fix(realtime): admit file events before resolving and skip linked directories in walks #485 (b359531, 6e32b20), merged here in 6aba374. A directory match now means nothing beneath it can be included, so this PR's ancestor check rejects a file only when git ignores it. foo/** then !foo/bar.py, and a nested ** then !keep.py, are two of the eleven cases fix(realtime): admit file events before resolving and skip linked directories in walks #485 compares with git check-ignore. Event admission in those cases goes through this PR's ancestor check, and all eleven pass on this branch.
  2. libgit2 policy changes (finding 2) are fixed in e430de2. The memo is now used only when the engine's rules cannot change while it lives, which holds for the Python engines (compiled once). With libgit2 the filter asks the engine each time, as before this PR; libgit2 already treats a path under an ignored directory as ignored. So with libgit2 this PR no longer saves the per-file match; the default Python backend keeps the saving. test_libgit2_backend_sees_a_removed_ignore_rule ignores foo/, sees a file under it, removes the rule, and checks that a new file in foo/ is admitted. It fails at c3fea4f and passes at a902b55.
  3. Alias recheck (finding 3) is fixed in fix(realtime): admit file events before resolving and skip linked directories in walks #485 (e888fd2), merged here.

The realtime and ignore tests (tests/realtime, tests/ignore and the test_realtime_* modules) were run serially on Windows: 193 passed, 56 skipped, none failed. Upstream's CI workflow on our fork at this head is green on every job: https://github.com/fstrasz/chunkhound/actions/runs/43259497053 (one macOS job was cancelled for runner capacity on the first attempt and passed on the rerun).

The description is updated to match.

🤖 Generated with Claude Code, reviewed by FStrasz

fstrasz and others added 3 commits November 17, 2026 06:21
Brings in the 21 PRs merged to main since this branch was cut (chunkhound#469 through chunkhound#534). No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the 24 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the 24 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz and others added 5 commits November 18, 2026 21:46
The watchdog handler already drops a dir_created event when the new
directory is excluded, so an excluded tree is never walked. The Watchman
adapter admitted every dir_created event, so a directory created under
node_modules/ (or any other excluded path) still became dir_index work
on the Watchman backend. It now applies the same excludes_directory
check. dir_deleted is still always admitted, so cleanup is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nk-spelled root in the tree

Review follow-up.

excludes_directory swallowed an ignore-engine error and returned False,
so the failure was invisible and the filter never marked itself
degraded. should_index and excludes_directory now share one guard,
_ignore_rule_matches: the first evaluation error marks the engine
degraded and warns once, whichever caller hit it, so is_degraded reports
it and cleanup keeps rows it can no longer prove are excluded. A filter
with no engine and no recorded failure still means no rule applies.

Watchman builds event paths from the root as it was requested, while
the ignore engine works on the resolved root. When the requested root
is spelled through a link (/var is /private/var on macOS), a path was
not lexically under the engine's root, so it was resolved and a link
under node_modules/ was judged at its target again. RealtimePathFilter
now respells such a path onto the resolved root before matching. Only
the root part changes, so links below the root are still judged where
they sit.

Also documents both cases in _in_tree_path (a link-spelled root, and
`..` collapsed lexically as Git does), and comments the test's private
_winapi junction helper and the rglob walk the walk test relies on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cluded

Review of the stacked PRs (chunkhound#490, chunkhound#491) found that a file a .gitignore
negation re-includes was dropped by realtime:

  .gitignore      foo/**  then  !foo/bar.py   -> foo/bar.py
  src/.gitignore  **      then  !keep.py      -> src/keep.py

git does not ignore either file, the full scan indexes both, and event
admission accepted them, but excludes_directory() reported foo/ and src/
excluded, so the polling walk and new-directory expansion pruned them and
never saw the file. IgnoreEngine matched a directory in its "dir/" form,
and pathspec matches "foo/" against a contents pattern such as foo/** (or
the root-relative src/** of a nested "**") through an empty tail. Main had
the same wrong answer; this PR made it load-bearing by pruning on it.

A directory match now means its whole subtree is excluded, which is how
every caller uses it (the realtime walk and directory events, the Python
full-scan walker and its os.walk fallback, repo-root detection). Per spec,
in precedence order, a directory is excluded when:

- git excludes the directory itself: the last pattern matching it is not
  a negation, testing "dir/" against patterns written with a trailing "/"
  and the bare "dir" against the rest. foo/ and foo match foo; foo/**
  matches only what is inside it. A directory a negation re-includes is
  still excluded when an ancestor is, as in git.
- or a pattern covers its contents ("dir/" matches, e.g. foo/** or the
  default **/node_modules/**) and no negation in that spec could match
  beneath it. A negation could when it is unanchored (!keep.py, !*.md),
  starts with **/, or its literal prefix lies above or below the
  directory. Config excludes have no negations, so node_modules is still
  pruned without being walked.

So foo/** then !foo/bar.py leaves foo/ walkable, and each file is decided
on its own. The whitelist idiom (/* then !/src/) keeps src/ walkable.

To tell foo/ from foo/** the .gitignore transform now emits dir-only
patterns with their trailing "/" instead of "/**". pathspec matches the
same files for both, except that **/ no longer matches top-level files,
which git does not ignore either.

Files follow git as well: a file a negation re-includes stays excluded
when a parent directory is excluded. "foo/" then "!foo/bar.py" therefore
keeps foo/bar.py excluded in the walk, in event admission and in the
Python full scan, as git does; before, the engine admitted it.

The libgit2 backend's config-exclude layer uses the same rule; libgit2
already applies git semantics to .gitignore directories.

Tests compare the full scan, the polling walk and event admission with
git check-ignore for the two review cases, the dir-only case and the
whitelist idiom, and check that the walk never enters node_modules.

Ported to chunkhound#481 from b359531, found in review of chunkhound#490/chunkhound#491 and carried by
chunkhound#485/chunkhound#490/chunkhound#491. Conflict resolution: IgnoreEngine.matches and
RepoAwareLibgit2Evaluator._cfg_excluded take b359531's rule-based decision;
the lines it replaces here are main's originals rather than the stack's
interim "dir/ form only" lines (a902b55, not in chunkhound#481). The tests are adapted
to chunkhound#481's code: the walk test that needs pipeline._walk_files (chunkhound#485) is left
out, and the git-agreement test also sends a created-directory event for each
directory holding a file git includes, and requires it to be expanded rather
than dropped, which is the case this port fixes in chunkhound#481.

(cherry picked from commit b359531)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of b359531 found that a negation re-including a directory inside
a contents pattern opened files git ignores:

  foo/**  then  !foo/bar/             -> git ignores foo/bar/x.py
  /a/**   then  !/a/b/                -> git ignores a/b/x.py
  /s/**   with  s/.gitignore !/keep/  -> git ignores s/keep/a.py

foo/** still matches the file itself; !foo/bar/ only re-includes the
directory. pathspec has no notion of that: it matches "!foo/bar/" (as
"!foo/bar/**") against every file below, so the file was re-included.
Before b359531 the walk pruned foo/ and hid this; once foo/ became
walkable, polling and admission gained foo/bar/x.py while the full scan
(git ls-files) left it out.

Files and directories are now decided as git decides them whenever a
negation in the spec matches the path:

- each pattern is matched against the path itself, without pathspec's
  "and everything beneath" tail (the ps_d group in pathspec 0.12), and a
  directory pattern only against directories; the last match wins;
- a path is excluded regardless when a directory above it is excluded.

A path no negation matches keeps pathspec's answer, which is then git's.
The same exact matching decides when a directory is excluded, and the
"contents covered" pruning rule now counts only file patterns, so a
directory pattern such as foo/**/ no longer prunes foo/ itself.

This also brings these cases in line with git (checked against
git ls-files -o --exclude-standard): "*.md then !keep/", "* !*/ !*.py",
"* !**/ !*.py", "* !/**/ !*.py", and "a/b/ then !a/".

The .gitignore transform again emits a directory pattern "foo/" as
"foo/**", byte for byte as before b359531, and carries the "was a
directory pattern" flag beside the compiled spec instead of in the
string. b359531's trailing "/" changed what **/ and /**/ match for the
full scan; that change is reverted (those two still differ from git as
they always have).

Reading pathspec's pattern objects (include, regex, source, ps_d tail)
fails loudly in a guard test, and at runtime degrades to pathspec's own
answers with no pruning and logs one warning, rather than silently
restoring the old behaviour.

Git's answer for each directory is memoized per compiled spec. The rules
never change for the spec's lifetime, so the memo needs no invalidation;
it is bounded and cleared when full. With 1,806 patterns including
"* !*/ !*.py", 2,000 file decisions take about 1.8 s against 1.7 s on
a902b55, and 2,000 directory checks 0.9 s against 1.6 s.

The git-oracle test gains the three review cases, the directory
re-include of a file pattern and the three whitelist variants.

Ported to chunkhound#481 from 6e32b20, found in review of b359531 on chunkhound#490/chunkhound#491 and
carried by chunkhound#485/chunkhound#490/chunkhound#491. The engine change applies unchanged. In the
git-agreement test, the case table and the switch to "files" (.py and .md)
come from 6e32b20; the created-directory check added when b359531 was
ported to chunkhound#481 is kept.

(cherry picked from commit 6e32b20)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e workspace

Review of chunkhound#481 found that a repository linked into the workspace lost its
own ignore rules. With workspace/linked pointing at a checkout outside the
workspace, files under linked/ fell back to the workspace policy, so a
pattern from the linked repository's .gitignore no longer applied.

The ignore engine now matches a path where it sits in the workspace, but
both repo-aware evaluators still resolved their repository roots. The
in-tree path workspace/linked/x was never under the resolved root of the
linked repository, so no repository was found for it. Before chunkhound#481 the path
was resolved too, which found the repository but judged links below the
root at their targets.

Each repository is now kept as (where it sits under the workspace, its
resolved root). The nearest repository is chosen by in-tree location, so
a linked repository nested in a workspace that is itself a repository
still wins over the workspace. The path is then mapped onto the chosen
repository's resolved root, where that repository's engine (or its libgit2
handle) matches it. A path under no in-tree location, such as one that was
already resolved, is looked up among the resolved roots as before. Both
evaluators share one helper for this.

Reproduced on Windows with a junction: build_repo_aware_ignore_engine_from_roots
with the repository at workspace/linked, and build_repo_aware_ignore_engine,
whose os.walk detection finds the repository through the junction at
workspace/linked. In both, linked/private.secret.py was not excluded
before this change and is excluded after it. A file the repository does
not ignore stays included.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz and others added 2 commits November 19, 2026 06:44
Review of chunkhound#481 found that a symlinked file was judged only where it sits.
With src/a.py -> vendor/x.py and vendor/ ignored, src/a.py was rejected
before chunkhound#481, because the ignore engine resolved every path, and admitted
after it. The watchdog handler resolves a file event before admission and
still rejected it, but the polling snapshot and the new-directory expansion
pass the unresolved path to should_index, so they would index the ignored
file's content under the link's name.

That is not intended. The default startup scan does not follow links and
never indexes a symlinked file. So should_index now judges a path where it
sits and, when resolving it changes it (the file or a directory between it
and the root is a link), judges the resolved target as well. This is the
rule the stacked PRs apply in the event handler (e888fd2). A link under an
excluded directory is still rejected where it sits, before its target is
looked at, and only a path that passed is resolved, which costs no more than
before chunkhound#481, when every path was resolved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nternals

Review of chunkhound#481 found that test_pathspec_contract.py asserted pathspec's
internal pattern fields (dir_only, include, exact), so a harmless refactor
could break it. Its purpose is to fail first when a pathspec release changes
the pattern objects ChunkHound reads, which would otherwise degrade the
ignore rules to pathspec's own matching with only a logged warning.

It now builds a tiny repository whose .gitignore pairs a directory pattern
and a contents pattern with negations that git and pathspec alone decide
differently (dir/ then !dir/keep.py; contents/** then !contents/sub/), and
compares the engine's decision for each file with git check-ignore. The
degraded fallback re-includes both files, so the test fails if the rules
cannot be read. It uses two git processes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz and others added 18 commits November 19, 2026 06:47
…valuator

Review of chunkhound#481 noted that RepoAwareLibgit2Evaluator kept both _cfg_spec and
_cfg_rules. The spec is compiled once and the rules are read from it, and
since b359531 nothing reads _cfg_spec after construction: across the
package and the tests its only use was building _cfg_rules on the next
line. It is no longer stored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pathspec contract test wrote the paths to git check-ignore in text
mode. On Windows that writes "\r\n", so git read each path with a trailing
"\r" and printed it quoted, and the comparison failed on spelling rather
than on what git decided. The paths now go in and out NUL-separated (-z),
as bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ories stay pruned

The ignore engine reads pathspec's compiled regexes to decide directories as
git does. It knew only pathspec 0.12's spelling of the tail, the group named
ps_d, that makes a match on a directory also match everything beneath it.
pathspec 1.x spells it "(?:(?P<ps_d>/)|$)" (file or directory) and a bare
"(?P<ps_d>/)" (directory). Under 1.x, any plain or glob line (Thumbs.db,
*.log, /build) therefore degraded its whole spec: no directory was pruned,
and every file was decided by pathspec's own match_file. The lock pins
0.12.1, so CI does not see this, but pathspec>=0.12.1 lets a fresh install
resolve 1.x.

pathspec 1.x also applies its regexes with re.search, and some are
unanchored ("*" compiles to "."). 0.12 anchors every regex, so re.search is
right for both, and the rules now use it at all three sites.

- Both versions' tails map to the end of the path.
- The fallback names the pattern and the installed pathspec version.
- Contract tests read every .gitignore form from the installed pathspec, and
  a Thumbs.db + node_modules/ test keeps ignored directories pruned.

Ported from fstrasz/chunkhound 0b13ace, without that fork's lock change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ories stay pruned

The ignore engine reads pathspec's compiled regexes to decide directories as
git does. It knew only pathspec 0.12's spelling of the tail, the group named
ps_d, that makes a match on a directory also match everything beneath it.
pathspec 1.x spells it "(?:(?P<ps_d>/)|$)" (file or directory) and a bare
"(?P<ps_d>/)" (directory). Under 1.x, any plain or glob line (Thumbs.db,
*.log, /build) therefore degraded its whole spec: no directory was pruned,
and every file was decided by pathspec's own match_file. The lock pins
0.12.1, so CI does not see this, but pathspec>=0.12.1 lets a fresh install
resolve 1.x.

pathspec 1.x also applies its regexes with re.search, and some are
unanchored ("*" compiles to "."). 0.12 anchors every regex, so re.search is
right for both, and the rules now use it at all three sites.

- Both versions' tails map to the end of the path.
- The fallback names the pattern and the installed pathspec version.
- Contract tests read every .gitignore form from the installed pathspec, and
  a Thumbs.db + node_modules/ test keeps ignored directories pruned.

Ported from fstrasz/chunkhound 0b13ace, without that fork's lock change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ories stay pruned

The ignore engine reads pathspec's compiled regexes to decide directories as
git does. It knew only pathspec 0.12's spelling of the tail, the group named
ps_d, that makes a match on a directory also match everything beneath it.
pathspec 1.x spells it "(?:(?P<ps_d>/)|$)" (file or directory) and a bare
"(?P<ps_d>/)" (directory). Under 1.x, any plain or glob line (Thumbs.db,
*.log, /build) therefore degraded its whole spec: no directory was pruned,
and every file was decided by pathspec's own match_file. The lock pins
0.12.1, so CI does not see this, but pathspec>=0.12.1 lets a fresh install
resolve 1.x.

pathspec 1.x also applies its regexes with re.search, and some are
unanchored ("*" compiles to "."). 0.12 anchors every regex, so re.search is
right for both, and the rules now use it at all three sites.

- Both versions' tails map to the end of the path.
- The fallback names the pattern and the installed pathspec version.
- New test: a Thumbs.db + node_modules/ .gitignore keeps ignored directories
  pruned. With the git comparison already in the file, it runs against the
  installed pathspec, whichever version that is.

Ported from fstrasz/chunkhound 0b13ace, without that fork's lock change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… fix/watcher-link-position (chunkhound#485)

Ordinary merge, so the stack carries chunkhound#481's review fixes (c3a7aeb,
5b188ad, 10d03a2, cdfbf58, 4f42f38, ad130d3, 7b755eb, d450191).
The two branches share only 0ab907b/293f8a6d; chunkhound#485's b359531,
6e32b20 and 81f1715 are parallel ports of chunkhound#481's 535466f, 5122b33
and d450191. Five files conflicted:

1. chunkhound/utils/ignore_engine.py (6 hunks): took chunkhound#481's side.
   chunkhound#485's file was a subset of it: chunkhound#481 adds the linked nested
   repository lookup (_repo_locations, _nearest_repo), the in-tree root
   respelling note and the config-exclude rules refactor. chunkhound#485's own
   ignore_engine change from a902b55 (match a directory in its "dir/"
   form only) is already in chunkhound#481's side. Dropped: chunkhound#485's "(TFS 65863)"
   comment tag.
2. chunkhound/services/realtime_path_filter.py (2 hunks): took chunkhound#481's
   side. It reports ignore-engine errors on directories instead of
   returning False (_ignore_rule_matches), respells a link-spelled root
   (_engine_path) and judges a linked file by its target in should_index.
   chunkhound#485's side was the older form of the same code.
3. chunkhound/services/realtime/events.py (1 hunk): took chunkhound#485's side.
   It contains chunkhound#481's change (excludes_directory before queuing a new
   directory) and builds on it: admission on the unresolved path,
   _queue_admitted and _target_admitted (a902b55, e888fd2).
4. tests/ignore/test_pathspec_contract.py (add/add, 3 hunks): took
   chunkhound#481's side, which compares the engine with git check-ignore instead
   of reading pathspec internals (4f42f38, 7b755eb, review request).
5. tests/realtime/test_filter_consistency_realtime_cleanup.py (6 hunks):
   union. chunkhound#481's side, plus chunkhound#485's tests copied verbatim from 81f1715:
   _linked_package_layout and the four tests after it, then
   test_polling_walk_does_not_enter_excluded_node_modules, _file_symlink
   and test_file_alias_to_excluded_target_is_not_queued, with their
   imports (os, typing.Any, pipeline._walk_files). Kept chunkhound#481's newer
   test_scan_walk_and_admission_agree_with_git_on_reincluded_files (it
   also checks new-directory expansion). Dropped chunkhound#481's comment that the
   walk "still descends the link with rglob": chunkhound#485 replaced rglob with a
   pruning os.walk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…luded-dir-memo (chunkhound#490)

Ordinary merge of chunkhound#485 after chunkhound#481 was merged into it, so chunkhound#490 carries
chunkhound#481's review fixes. Three files conflicted:

1. chunkhound/utils/ignore_engine.py: took the chunkhound#485 side. chunkhound#490's file was
   identical to chunkhound#485's head 81f1715 (4467926 is a parallel port of the
   same pathspec 1.x fix), so the conflict came only from the two ports.
2. tests/ignore/test_pathspec_contract.py: took the chunkhound#485 side, for the
   same reason.
3. chunkhound/services/realtime_path_filter.py: hand-merged. Started from
   the chunkhound#485 side (chunkhound#481's rewrite: _ignore_rule_matches, _engine_path,
   _admits) and added chunkhound#490's directory memo to it: _DIR_DECISIONS_MAX,
   _dir_decisions, _dir_decisions_engine, _keep_dir_decisions (off for
   the libgit2 evaluator), _in_tree_under_root and _directory_excluded.
   Two choices that the merge needed and neither side made:
   a. The memo now runs inside _ignore_rule_matches, for directories and
      for a file's parent, instead of inside excludes_directory and
      should_index. An engine error in the memo therefore marks the filter
      degraded and warns once, as chunkhound#481 made every other evaluation do;
      chunkhound#490's version returned False from excludes_directory silently.
   b. _directory_excluded matches each directory as _engine_path spells
      it, as every other match does since chunkhound#481. Without that, a root
      spelled through a link (/var vs /private/var on macOS) would send
      the memo's matches to the link targets, which
      test_linked_package_is_excluded_when_the_root_is_spelled_through_a_link
      checks against.
   _in_tree_root is defined once; both sides defined it identically.

No test ran on this merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hunkhound#485 review)

The code that derives git's directory and re-include decisions from
pathspec's compiled patterns (_GLOB_CHARS through _spec_excludes_file)
moves unchanged from ignore_engine.py into gitignore_rules.py; the moved
259 lines are byte-identical. ignore_engine.py imports the four names it
uses. No test imports a moved name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…unkhound#485 review)

ignore_engine reads pathspec's compiled regexes, which are not public API.
pyproject bounds pathspec to the majors the contract test covers
(>=0.12.1,<2); uv.lock changes in metadata only and still resolves 0.12.1.
A new pathspec-1x job installs the newest 1.x over the lock and runs
tests/ignore and the realtime cleanup tests, so a 1.x release that changes
the regex shape fails CI instead of silently disabling pruning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ls (chunkhound#485 review)

events._in_tree_path shared a name, not a contract, with
ignore_engine._in_tree_path. It becomes path_utils.lexical_absolute_path,
next to normalize_realtime_path, and events.py calls it. Behaviour is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hunkhound#485 review)

_walk_files reached into a SimpleEventHandler's private _path_filter, and
its two callers built a handler only for that filter and its
_should_index. _polling_snapshot and _collect_supported_files now build a
RealtimePathFilter on the resolved root, as SimpleEventHandler did, and
pass it in. The one direct test call passes the filter.

_normalize_mutation_path's docstring now says the in-tree spelling is for
status bookkeeping only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ink's target

chunkhound#481's RealtimePathFilter.should_index also requires a link's resolved
target to pass the policy, which is right for indexing. chunkhound#485 admits a
watchdog delete on the unresolved path through the same predicate, so
after chunkhound#481 was merged in, deleting alias.py -> node_modules/pkg/secret.py
was filtered and never queued, breaking chunkhound#485's contract that a delete is
still queued for cleanup
(test_file_alias_to_excluded_target_is_not_queued).

should_index gains check_target (default True). _should_admit_event
judges a "deleted" event with check_target=False; created and modified
events still require the target to pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fstrasz

fstrasz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

VakninAriel, following up on your 11-12 review. All three findings are fixed on this branch
(details):

  1. Re-included descendants: fixed in fix(realtime): admit file events before resolving and skip linked directories in walks #485 (b359531, 6e32b20) and merged here. A directory is reported
    excluded only when nothing beneath it can be included, as with git, so the ancestor check rejects a file only
    when git ignores it. test_scan_walk_and_admission_agree_with_git_on_reincluded_files compares the walk and
    admission with git check-ignore, including your foo/** then !foo/bar.py case and a nested ** then
    !keep.py.
  2. libgit2 policy changes: fixed in e430de2. The memo is used only when the engine's rules cannot change while
    it lives; with libgit2 the filter asks the engine each time. test_libgit2_backend_sees_a_removed_ignore_rule
    covers it.
  3. Alias recheck: fixed in fix(realtime): admit file events before resolving and skip linked directories in walks #485 (e888fd2) and merged here; test_file_alias_to_excluded_target_is_not_queued.

The branch has since had main merged in and #485's pathspec 1.x fix (4467926); CI is green on 4467926. Does
that resolve the three findings?

🤖 Generated with Claude Code, reviewed by FStrasz

fstrasz and others added 2 commits November 25, 2026 02:51
…ec-1.x CI job (chunkhound#485 review)

Item 2: the Watchman adapter now passes check_target=False for deletes,
as the watchdog handler does. A delete reads no content, so the target of a
link on its way does not decide it.

Item 1: a test shows a delete of an excluded, indexed file is admitted and
its row removed when the root is spelled through a link or in another case:
normalize_path_for_lookup resolves the path and the base before comparing.

Item 4: the pathspec-1.x job installs pathspec==1.1.1 instead of the newest 1.x.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d-dir-memo

Merge the chunkhound#485 review fixes (Watchman delete admission, pathspec 1.1.1 pin).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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.

2 participants