Skip to content

Collection-name uniqueness hard-rejects in create_node — can wedge sync on a benign duplicate name #2117

Closed

Description

@mstomar125

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

  1. mstomar125 commented on Aug 18, 2026

    @mstomar125
    ContributorAuthor

    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 in SqliteStore::create_node was never actually protecting anything on that path; it only ever fired for a caller that creates a collection node 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, and SqliteStore::update_node never had an equivalent check to begin with (so collection renames were already suggest-don't-block at the store layer — only create_node was 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_node no longer bail!s on a collection-name collision. The collision is still detected (via the existing get_collection_by_name lookup) but the write now proceeds unconditionally.
    • Both the new node and the pre-existing colliding node get a non-blocking _possible_duplicate marker (same OCC-bypassing, event-free set_property_bool mechanism NodeService::mark_possible_duplicates uses for person.email), declared as a local_only: true schema field on collection so it never leaves the device via sync — zero nodespace-sync changes required.
    • collection_ops::create_collection/rename_collection's own interactive AlreadyExists checks 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, mirroring person_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions