Repository navigation
Deterministic collection ids to stop --auto-collection-routing creating duplicates (#1703) - #1704
Conversation
…cates (#1703) `--auto-collection-routing` minted a fresh random UUID for each collection node (`create_collection` used `Node::new`), so two independent imports of the same tree — different devices, re-import runs, or a concurrent double-create — produced different ids for the same-named collection. After sync those accumulated as duplicate collection nodes (tenant_demo: 98 nodes for 18 names). Collection names are globally unique, so derive the node id deterministically from the normalized name (UUIDv5). Independent stores now converge on ONE id per collection, so sync upserts them into a single node instead of piling up duplicates, and a concurrent double-create resolves to the same node. `create_collection` becomes an idempotent get-or-create: reuse an existing node with that id (a prior create, a synced copy, or a race winner) rather than erroring on the duplicate id. Tests: deterministic id is stable + case-insensitive; two independent stores converge on one collection id; re-resolving a path (and paths sharing a segment) creates no duplicate nodes. Full core lib suite (960) + daemon import round-trip green. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…h (review fix)
Adversarial review found the deterministic-id fix only covered the import path; the
interactive create (`ops::create_collection`, behind the Tauri/gRPC "New collection")
still minted a random UUID via `create_node_with_parent { id: None }`, so a UI-created
collection on one device still diverged from the same-named collection created on
another device or by import.
Pass `id: Some(deterministic_collection_id(&name))` there too, so all collection-create
paths converge on one id per name. The existing name-existence pre-check still rejects a
local duplicate. Adds a cross-path test: UI-create on store A and import resolve on store
B yield the same collection id.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Adversarial review + resolutionIndependent adversarial review verified the deterministic-id mechanism as safe and correct on the import path (all six checks CONFIRMED):
Gap found and fixed (commit 0c369a6): the fix originally covered only the import path — the interactive Known bounded limitation (documented): pre-existing legacy random-id collections aren't retro-actively re-id'd (forward-only), and the sidebar-membership facet of #1703 is tracked separately.
|
Addresses the duplicate-collections facet of #1703 (98 collection nodes for 18 names in
tenant_demo).Root cause
CollectionService::create_collectionminted a fresh random UUID (Node::new) for each collection node.resolve_path/bulk_resolve_collectionsdedup within a single store by name lookup, but two independent imports — a different device, a re-import on a fresh local db, or a concurrent double-create — each generate a different id for the same-named collection. After sync those distinct ids accumulate as duplicate collection nodes.Fix
Collection names are globally unique (documented invariant), so derive the collection node id deterministically from the normalized name (UUIDv5):
create_collectionbecomes an idempotent get-or-create by that id: reuse an existing node (a prior create, a synced copy, or a race winner) instead of erroring on the duplicate id. Independent stores now converge on one id per collection, so sync upserts them into a single node; a concurrent double-create resolves to the same node.resolve_pathstill finds pre-existing (random-id) collections by name and reuses them — only brand-new collections get deterministic ids.Scope
This PR fixes the duplicates facet. The second facet noted on the issue — imported sub-collections having no person
member_ofedge, so they don't surface in the sidebar — is a separate concern (the import path has no importer-identity context; it needs identity plumbing or a sidebar/reachability change). It's being ground-truthed against a fresh re-import + membership pass and will be split into a focused follow-up.Tests
deterministic_collection_idstable + case/whitespace-insensitive.nodespace-corelib suite (960) + daemonimport_round_tripgreen; clippy + fmt clean; pre-push gate (frontend + Rust + e2e) passed.🤖 Generated with Claude Code