Repository navigation
Commit 1e6084d
fix(mcp): make the file watcher honour workspace filters and harden the shared engine (#25)
* fix(mcp): make the watcher honour workspace filters; harden the shared engine
Generated files kept out of the initial index were let straight back in by
the MCP file watcher, and each event they caused cost several full-graph
scans. On an 8 GB machine running several agent sessions that showed up as
sustained watcher work and memory pressure (#23).
Watcher
- One exclusion rule. The watcher carried its own ten-entry SKIP_DIRS list
and was never given the index config, so --exclude and .codegraphignore
applied to the initial index only. is_excluded_entry() now states the
indexer's rule once; the indexer's walk and a new WorkspaceFilter both use
it. The watcher checks every ancestor of an event path, since an event
names only the file and the walk only ever reached a file through its
parents. default_exclude_dirs is a strict superset of the old SKIP_DIRS,
so nothing the watcher skipped before is admitted now.
- One pass per batch. process_changes ran a full-graph property("path")
query for every deleted file, vanished file, changed file, its dependents
and each dependent. It now builds one path-to-nodes map per batch, and a
delete for a file the index never held takes no lock at all. Vector
re-embedding is batched the same way (update_files_vectors), replacing a
full node walk per changed file.
- Symlinked workspaces. The indexer stores paths as the workspace was given;
FSEvents reports the resolved location (/var -> /private/var, or any
symlinked folder). Every lookup by event path missed, so on such a
workspace an edit re-parsed a file without removing its old symbols and a
delete removed nothing: the graph only grew. Present in 0.20.1. Event
paths are now translated into the indexed form at intake, and the filter
matches roots both as given and resolved.
- Orphan vectors. remove_file_vectors ran before the nodes were deleted and
only drops vectors whose node is already gone, so it could not see the
file it was called for. One prune_orphan_vectors after the batch covers
deletions and the vectors left behind by re-parsing, which nothing
cleaned up before.
- A delete-only batch now rebuilds the indexes too. This is index hygiene:
search resolves results against the graph, so deleted symbols were not
visible before either.
Graph-only
- index_workspace and the daemon-attach path initialised the memory manager,
which loads the embedding model, before anything checked --graph-only. The
existing comment on the graph-only branch already promised the model would
never load; it now doesn't. Memory tools are unavailable in graph-only
mode, the state the RAM gate already leaves them in on low-memory hosts.
Shared engine
- Resource settings. An auto-spawned engine was passed only the model name,
so a client's --exclude, --max-files and --graph-only were dropped.
engine_args() forwards the engine-level settings, EngineConfig carries
graph_only, and a graph-only engine no longer loads the shared model.
--profile is deliberately not forwarded: it filters one client's tool list,
and a shared engine would impose it on every other client.
- One load per workspace. Two attaches to a cold workspace both built a full
backend, each indexing and starting a watcher, and the loser returned its
own unregistered copy, serving that connection from it for its whole life.
The registry now holds a per-workspace OnceCell.
- One engine per socket. Concurrent auto-starts were guarded only by a
socket probe taken before a model load that can take minutes; the second
engine then removed the first one's live socket to bind its own, leaving
the first running and unreachable. Reproduced: two clients, two engines.
An exclusive lock (std File::try_lock) is now taken before anything is
loaded and held for the engine's lifetime.
Verified end to end against the shipped 0.20.1 binary and this build, each
watcher test with a positive control (a fresh, non-excluded file must still
be picked up). Unit tests cover the filter (including an explicit symlink,
since Linux CI has no /var -> /private/var), most-specific-root selection,
max depth, the engine lock and the forwarded arguments.
Not addressed: .gitignore is honoured by neither the watcher nor the initial
index, which stay consistent; supporting it means adding the ignore crate.
Reported and diagnosed by Christopher Schulze in #23, whose analysis of the
watcher filter, the per-event scans, graph-only ordering and the shared
engine's dropped settings was accurate on every point.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017rVbt7rENTwXkdHt3Bpgb5
* no-mistakes(review): Locate deleted-directory events in symlinked workspaces
* no-mistakes(document): Document watcher ignore rules and graph-only memory tools
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 64f4f30 commit 1e6084d
8 files changed
Lines changed: 658 additions & 234 deletions
File tree
- crates/codegraph-server/src
- ai_query
- mcp
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
812 | 812 | | |
813 | 813 | | |
814 | 814 | | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
815 | 833 | | |
816 | 834 | | |
817 | 835 | | |
| |||
841 | 859 | | |
842 | 860 | | |
843 | 861 | | |
| 862 | + | |
| 863 | + | |
844 | 864 | | |
845 | | - | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
846 | 869 | | |
847 | 870 | | |
848 | 871 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
18 | 173 | | |
19 | 174 | | |
20 | 175 | | |
| |||
492 | 647 | | |
493 | 648 | | |
494 | 649 | | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
500 | 653 | | |
501 | 654 | | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
| 655 | + | |
522 | 656 | | |
523 | 657 | | |
524 | 658 | | |
| |||
532 | 666 | | |
533 | 667 | | |
534 | 668 | | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | 669 | | |
542 | 670 | | |
543 | 671 | | |
| |||
662 | 790 | | |
663 | 791 | | |
664 | 792 | | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
665 | 909 | | |
666 | 910 | | |
667 | 911 | | |
| |||
0 commit comments