Skip to content

fix(sync): index newly watched local projects after attachment - #1861

Open
TPSJASPER wants to merge 1 commit into
basicmachines-co:mainfrom
TPSJASPER:fix/1817-new-project-watch
Open

TPSJASPER wants to merge 1 commit into
basicmachines-co:mainfrom
TPSJASPER:fix/1817-new-project-watch

Conversation

@TPSJASPER

@TPSJASPER TPSJASPER commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Why

Fixes #1817

A project created in an empty folder is watched only after the next project reload. Files copied into it before that reload produce no watch events, so they stay unindexed until they change, bm reindex runs, or the server restarts. The watcher also filtered projects with the config snapshot it was created with, so a project added later could stay unwatched even after a reload.

What changed

  • _select_projects_to_watch re-reads the current ConfigManager config and keeps the existing locally-syncable and constrained-project rules.
  • WatchService tracks projects it has finished catching up by project external id, not by root path. Startup projects register from their existing initial scan.
  • After a new project's watch is attached, one project index pass runs before that cycle handles its event batches. It covers files copied before attachment that produced no events. A failed pass is recorded and retried on the next cycle; a pass interrupted by a stop stays pending.
  • A path change no longer triggers a full scan of the new root. bm project move rewrites the path before the user moves the files, so scanning the still-empty root would plan every old path as deleted and remove the project's index.
  • The reload timer waits while the catch-up pass is running and draining its buffered batches. watchfiles clears pending changes when stop is set, so closing the cycle underneath the scan would discard changes collected for every project. The wait is capped at one extra interval so a project with continuous writes cannot defer reloads forever.

The bm-project manual page describes the new-project catch-up pass.

Validation

  • New watcher regression tests: 11 passed, covering current-config selection, files copied while attaching, ignore rules, startup projects not scanned twice, per-project failure and retry, removed projects, restart during catch-up, a real watchfiles backfill plus live write, cancellation, path changes, and the reload wait.
  • Existing watcher, initialization and new-project MCP tests: 23 passed, 5 skipped.
  • Full tests/index suite on SQLite: 210 passed, 10 skipped, 1 deselected.
  • The new public MCP flow creates a project through bm_project, copies a nested Markdown file before attach, and finds it with bm_search.
  • ruff check, ruff format --check, ty check for the changed files, and git diff --check passed.
  • doctor --local completed sandboxed write, index and search in an isolated config directory.

The full-repository ty check still reports the same 8 environment diagnostics as the unmodified baseline (optional pymilvus/uvloop, Windows resource members); no ignores were added. The full test suite and Postgres tests were not run. The implementation was also replayed against origin/main with git apply --check.

Risks / rollback

The catch-up runs once per newly seen project identity after attachment; files written during the pass are still delivered by watch events. Startup still relies on its existing background initial scan rather than a second pass. Revert the commit to roll back.

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 basicmachines-co#1817

Signed-off-by: TPSJASPER <592827953@qq.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-25T08:23:17.174687Z
We couldn’t complete this review. Comment @codex review to try again.
48550d8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

Files copied into a just-created project are missed until the next watcher reload

1 participant