Repository navigation
Description
Context
While proving the ADR-065 `unique`-rule no-rejection invariant (see #1734 / the PR that closed it), an adversarial review surfaced a separate, older, harder uniqueness mechanism that violates the same underlying principle for a different node type.
`SqliteStore::create_node` hard-rejects on collection-name collision:
```rust
if node.node_type == "collection" {
if let Some(existing) = self.get_collection_by_name(&node.content).await? {
anyhow::bail!("Collection with name '{}' already exists (id: {})", ...);
}
}
```
This predates ADR-065 and is unrelated to the schema-declared `unique` field mechanism — it's a hardcoded, type-specific check. But NodeSpace is local-first the same way for collections as for anything else: two offline devices can each validly create a collection with the same name. When one device's collection converges into a peer's store via a normal sync-apply `create_node` call (the same write path person nodes use), the peer does NOT have the pre-existing collection locally seen from the incoming device's perspective, so a collision can occur when the SAME name has already been created independently on both sides.
Confirmed via probe (not merged, but a real reproduction path exists): two offline devices each create a collection named "Work", then converging one into the other's store via the same `create_node` path `nodespace-sync`'s `apply_node_upsert` uses returns an error ("Collection with name 'Work' already exists"). In `nodespaced-pro/src/cloud_sync/apply.rs`, that error propagates out of `apply_node_upsert`, and per that function's own contract the sync cursor does not advance past a failed row — a benign duplicate collection name can wedge a sync cursor.
Ask
Decide and implement: either (a) convert collection-name uniqueness to the same suggest-don't-block posture as ADR-065 (e.g. auto-rename/dedupe on collision, or accept the duplicate and mark it, consistent with the rest of this codebase's local-first philosophy), or (b) if the product intentionally wants hard collection-name uniqueness (a deliberate, different design choice for collections specifically), document that decision explicitly and make sure `nodespace-sync`'s apply path handles the resulting error without wedging the cursor forever (e.g. treat it as a permanent/skippable failure rather than a retry-forever one).
This is NOT part of the `unique` schema-field mechanism (ADR-065) and does not require touching that code — it's a separate, pre-existing constraint on `SqliteStore::create_node` for the `collection` node type specifically.
Related
- Surfaced while implementing the `unique` schema-validation rule (ADR-065 in nodespace-docs)
Activity
mstomar125 commentedon Aug 18, 2026
Resolved via #2126 (in review).
Decision: option (a) — converted collection-name uniqueness to the same suggest-don't-block posture ADR-065 established for
person.email, rather than option (b) (documenting hard uniqueness as deliberate + hardening the sync-apply error path).Why (a) over (b): the officially-blessed collection-creation path (
CollectionService::create_collection) already derives a deterministic node id from the normalized name specifically so two devices creating "the same" collection converge onto one node — meaning the hard-rejection inSqliteStore::create_nodewas never actually protecting anything on that path; it only ever fired for a caller that creates acollectionnode directly with a non-deterministic id (an import, an agent tool, or critically a sync-pulled peer node, which always keeps the peer's own id). Nothing else in the codebase depends on hard collection-name uniqueness as a correctness invariant, andSqliteStore::update_nodenever had an equivalent check to begin with (so collection renames were already suggest-don't-block at the store layer — onlycreate_nodewas inconsistent). Given that, and that this codebase just spent real effort establishing suggest-don't-block as the consistent local-first pattern (ADR-065 + #2115), option (a) both fixes the wedge and removes a special-cased, inconsistent code path.What changed:
SqliteStore::create_nodeno longerbail!s on a collection-name collision. The collision is still detected (via the existingget_collection_by_namelookup) but the write now proceeds unconditionally._possible_duplicatemarker (same OCC-bypassing, event-freeset_property_boolmechanismNodeService::mark_possible_duplicatesuses for person.email), declared as alocal_only: trueschema field oncollectionso it never leaves the device via sync — zeronodespace-syncchanges required.collection_ops::create_collection/rename_collection's own interactiveAlreadyExistschecks are untouched — they're not on the sync-apply path and can't wedge a cursor.Reproduction: added
packages/core/tests/collection_name_convergence_test.rs, mirroringperson_duplicate_convergence_test.rs's two-device convergence style. Verified it fails against the pre-fix code with the exact error from this issue ("Collection with name 'Work' already exists"), and passes after the fix — confirming the wedge is actually gone, not just no-longer-reproduced.Full reasoning and diff in the PR description. Adversarial review in progress before merge.