Skip to content

fix(sync): embed a caught-up project in the background, not in the watcher loop - #2046

Merged
phernandez merged 1 commit into
mainfrom
fix/1979-watch-live-edit
Nov 4, 2026
Merged

phernandez merged 1 commit into
mainfrom
fix/1979-watch-live-edit

Conversation

@phernandez

Copy link
Copy Markdown
Member

Closes #1979.

What was wrong

The watcher catches a newly attached project up inside its batch consumer (_watch_projects_cycle). That catch-up ran run_local_project_index_for_project with embeddings inline. Until it returned, no watch batch was handled for any project.

The removed lifecycle test showed it. I restored it locally and ran 25 copies, 8 at a time. In 8 runs the catch-up was still fetching the FastEmbed model ("Fetching 5 files", stuck at 1/5) when the 45 s deadline passed. The narwhal edit was never dropped. It was waiting behind the embedding.

In production, adding a large project, or a first model load, delayed live edits in every project until embedding finished.

Fix

  • File indexing stays in the catch-up, serialized with watch batches as before.
  • New BackgroundEmbeddingRuntimeFactory (in index/local_schedulers.py) wraps the watcher's project-index runtime. Its BackgroundBatchVectorSync hands each batch vector sync to background work, like the per-write vector scheduler, and retires cached searches when the vectors land.
  • initialize_file_indexing gives the watcher the wrapped factory. The startup scans already run as separate tasks and keep inline embedding.
  • If the process exits before a background embed runs, those notes have no vectors until the next reindex. The per-write vector scheduler behaves the same way.

Tests

  • tests/index/test_watch_catch_up_embeddings.py:
    • A real native watcher attaches a new project. The test holds the catch-up's vector sync on an event, writes live.md, and requires it to be indexed while embedding is still held.
    • With the plain factory this test times out. With the fix it passed 32 of 32 runs, 8 at a time.
    • Plus unit tests for the adapter: it returns before embedding, retires searches once vectors land, and works with no read cache or no vector sync.
  • tests/services/test_initialization.py now asserts the watcher gets the wrapped factory.

Not restored

I did not bring back test-int/mcp/test_new_project_watch_lifecycle.py. Under 8× load it passed and then hung at event-loop close: a leftover task didn't finish when cancelled. That happened 2 times in 56 runs, once on unmodified main code. It is a separate shutdown issue and would keep the test flaky. The new watcher test covers the #1979 behavior deterministically.

Checks

  • just fast-check
  • tests/index, tests/services, test-int/mcp on SQLite (-n 4)
  • The new test file on Postgres

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMYVL4TcbWdXhdvAzxfqjo

…tcher loop

The watcher catches a newly attached project up inside its batch
consumer. The catch-up embedded vectors inline, so while the model
loaded or a large project embedded, no watch batch was handled for any
project. A live edit in the first seconds after attach waited behind
it; the removed lifecycle test timed out on exactly that (#1979).

File indexing stays in the catch-up, serialized with watch batches.
The watcher's runtime factory now hands batch vector syncs to
background work, like the per-write vector scheduler, and retires
cached searches when the vectors land.

Closes #1979

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMYVL4TcbWdXhdvAzxfqjo
Signed-off-by: phernandez <paul@basicmachines.co>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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 ✅ Completed 2026-11-04T07:29:01.063713Z 9bfaece 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.

@phernandez
phernandez merged commit 26d0a96 into main Nov 4, 2026
51 checks passed
@phernandez
phernandez deleted the fix/1979-watch-live-edit branch November 4, 2026 07:52
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.

Watcher can miss a live edit in a newly attached project (flaky lifecycle test removed)

1 participant