Repository navigation
Embedding provenance (local vs remote) for cloud sync (#182/#183) - #1418
Conversation
|
REQUEST CHANGES ⏳ Initial review, top commit This is the right fix for the push↔pull loop / write-amplification I flagged on #179 (and nice that the post-#180 pass found and filed it as #182/#183). The mechanism is clean and I verified the parts that usually go wrong:
One blocking issue — the migration story: 🟡 The column is added with no DDL migration, which breaks existing
For the dev harnesses that wipe DBs, fine. But the community desktop app's real user DBs aren't reset (that's the whole point of the lazy node-migration design), and they already carry
Net: the provenance fix itself is correct, well-indexed, and well-tested — it cleanly kills the re-push loop. The thing to resolve before merge is whether an existing DB survives this column add; as written, without a migration, it doesn't. |
The Pro daemon's embedding push sweep reads `embeddings_modified_since`
and pushes everything; the pull writes received vectors back into the
same table with `modified_at = now`. So a PULLED vector immediately
re-armed the push sweep and bounced back to cloud — write amplification,
and on heterogeneous devices an unbounded push↔pull loop (echo
suppression rested entirely on bit-exact f32 vector equality).
Add an `origin` column to the local `embedding` table ('local' = generated
here, 'remote' = pulled from another device) and:
- `upsert_embeddings` writes `origin = 'local'` (generation path, unchanged
callers); new `apply_remote_embeddings` writes `origin = 'remote'` for the
daemon's pull to use.
- `embeddings_modified_since` filters `origin = 'local'`, so the push sweep
never re-pushes a vector this device merely received. This breaks the
loop: once a device pulls a remote vector, that row stops being pushed,
so the fleet converges instead of ping-ponging.
- `idx_emb_modified` leads with `origin` so the filtered sweep stays an
index range scan (no filesort); the EXPLAIN-plan test is updated.
Migration: `packages/core` ships in the community desktop app, whose user
DBs are NOT reset, and schema.sql is CREATE-IF-NOT-EXISTS — so an existing
`embedding` table wouldn't get the column (every write + the push sweep
would hit `no such column: origin`). `migrate_embedding_origin` runs at
store init: ALTER TABLE ADD COLUMN guarded by a `pragma table_info` check,
plus DROP+rebuild of `idx_emb_modified` so it picks up `origin`. Idempotent;
no-op on fresh DBs.
Tests: remote-applied embedding is readable via get_embeddings but excluded
from the push sweep (loop broken, asserted); and a legacy pre-`origin` DB
with an existing row is upgraded in place (column added + defaulted to
'local', index rebuilt, idempotent). cargo test + clippy clean.
Part of NodeSpaceAI/nodespace-sync#182 / #183 (core half; sync half wires
the pull to apply_remote_embeddings + awaits sweep aborts).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed — force-pushed `47eb7e7`. You're right, and good catch on the shared-DB stance — 🟡 Migration. Added
Added a test that builds a legacy pre- 27 embedding tests + |
|
APPROVE ⏳ Re-review at your request, now at The migration concern is fully and correctly addressed: ✅
So a legacy ✅ And it's tested — Backfilling legacy rows to Good to merge — clean fix for the #179 re-push loop, and now safe for existing DBs. |
…#1418) The Pro daemon's embedding push sweep reads `embeddings_modified_since` and pushes everything; the pull writes received vectors back into the same table with `modified_at = now`. So a PULLED vector immediately re-armed the push sweep and bounced back to cloud — write amplification, and on heterogeneous devices an unbounded push↔pull loop (echo suppression rested entirely on bit-exact f32 vector equality). Add an `origin` column to the local `embedding` table ('local' = generated here, 'remote' = pulled from another device) and: - `upsert_embeddings` writes `origin = 'local'` (generation path, unchanged callers); new `apply_remote_embeddings` writes `origin = 'remote'` for the daemon's pull to use. - `embeddings_modified_since` filters `origin = 'local'`, so the push sweep never re-pushes a vector this device merely received. This breaks the loop: once a device pulls a remote vector, that row stops being pushed, so the fleet converges instead of ping-ponging. - `idx_emb_modified` leads with `origin` so the filtered sweep stays an index range scan (no filesort); the EXPLAIN-plan test is updated. Migration: `packages/core` ships in the community desktop app, whose user DBs are NOT reset, and schema.sql is CREATE-IF-NOT-EXISTS — so an existing `embedding` table wouldn't get the column (every write + the push sweep would hit `no such column: origin`). `migrate_embedding_origin` runs at store init: ALTER TABLE ADD COLUMN guarded by a `pragma table_info` check, plus DROP+rebuild of `idx_emb_modified` so it picks up `origin`. Idempotent; no-op on fresh DBs. Tests: remote-applied embedding is readable via get_embeddings but excluded from the push sweep (loop broken, asserted); and a legacy pre-`origin` DB with an existing row is upgraded in place (column added + defaulted to 'local', index rebuilt, idempotent). cargo test + clippy clean. Part of NodeSpaceAI/nodespace-sync#182 / #183 (core half; sync half wires the pull to apply_remote_embeddings + awaits sweep aborts). Co-authored-by: Mayank Tomar <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
What
Core half of the fix for NodeSpaceAI/nodespace-sync#182 + #183, found in the post-#180 bug-finding pass. The embedding push sweep re-pushed vectors a device merely pulled (the pull's
upsert_embeddingsstampsmodified_at = now, re-arming the push cursor) → write amplification, and on heterogeneous devices an unbounded push↔pull loop (the only echo suppression was bit-exact f32 vector equality).Changes
Add an
origincolumn to the localembeddingtable —'local'(generated here) vs'remote'(pulled from another device):upsert_embeddingswritesorigin = 'local'(the generation path; callers unchanged). Newapply_remote_embeddingswritesorigin = 'remote'— the daemon's pull will use it.embeddings_modified_sincefiltersorigin = 'local', so the push sweep never re-pushes a received vector. This breaks the loop: once a device pulls a remote vector, that row stops being pushed, so the fleet converges instead of ping-ponging — and fixes the per-sweep write amplification.idx_emb_modifiednow leads withoriginso the filtered sweep stays an index range scan (no filesort); the EXPLAIN-plan test is updated to the new query shape.Greenfield: the column is added to
CREATE TABLE(no migration — DBs reset per project convention; harnesses wipe DBs).Verification
get_embeddings, but excluded fromembeddings_modified_since(the push sweep) → never re-pushed. Plus the existing round-trip + index-plan assertions, updated fororigin = 'local'.cargo test(26 embedding tests) +cargo clippy --libclean. Additive.Part of NodeSpaceAI/nodespace-sync#182 / #183 (core half; the sync half wires the pull to
apply_remote_embeddingsand awaits sweep aborts for #183-C1).