Repository navigation
fix(sync): catch up newly watched projects during ignored activity - #1866
Merged
Merged
Conversation
The watcher selected projects from the config snapshot it was created with, so a project added later could stay unwatched. Re-read the current config on every selection. A watch attaches after the project's first scan; files copied before attachment produced no events. Once a new root is watched, run one project index pass before handling its event batches, retry a failed pass on the next cycle, and keep it pending while a restart is requested. Track projects by identity, not root, so a path change does not rescan an empty directory and delete the existing index. A reload waits for the catch-up drain so watchfiles does not discard buffered batches; startup projects keep their existing initial scan and are not scanned twice. Fixes #1817 Signed-off-by: TPSJASPER <592827953@qq.com> Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Files copied into a newly created project's empty folder before the next watcher reload produce no events and stay unindexed. The watcher also uses a startup config snapshot that can exclude projects added later.
Fixes #1817. Carries forward @TPSJASPER's #1861, cherry-picked with original authorship and sign-off.
What Changed
bm_project, copies a note, checks search, then edits the file and checks search again while hidden-file activity continues.Implementation Details
The catch-up starts only after
awatchhas attached its watches. Running in the event consumer prevents the scan and event batches from overlapping. Project identities track completed catch-up, so changing an existing project's path does not scan a still-empty move destination and delete its index.The new integration test found an additional gap in the original contribution: watchfiles suppresses batches whose events are all filtered. Continuous hidden-file activity can therefore suppress both observable batches and timeout yields, preventing catch-up indefinitely. New-project cycles receive raw batches and filter them locally. Only an actual quiet batch clears the drain guard.
The integration test uses the real MCP lifespan and normal database initialization, rather than API overrides or application mocks. Its only environment overrides select production runtime behavior; a bounded poll waits for observable search results. Existing inline tests remain available for fast feedback.
Testing
uv run pytest tests/index -q -o addopts= --tb=short: 221 passed.uv run pytest tests/index/test_watch_new_projects.py tests/mcp/test_new_project_watching.py tests/services/test_initialization.py tests/index/test_watch_service.py -q -o addopts= --tb=short: 33 passed.uv run pytest test-int/mcp/test_new_project_watch_lifecycle.py -q -o addopts= --tb=short: passed on SQLite with continuous hidden-file activity.BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest test-int/mcp/test_new_project_watch_lifecycle.py tests/index/test_watch_new_projects.py tests/services/test_initialization.py -q -o addopts= --tb=short: 24 passed.just fast-check: lint, format and full typecheck passed.just doctor: sandboxed write, index and search passed.git diff --check: passed.Risks / Follow-ups
New projects receive one project-wide scan after watch attachment, which can delay event processing while that scan runs. Reload deferral remains bounded as in the contributor's implementation. This changes local watching only; hosted indexing is unaffected. Existing project path moves retain their current behavior.