Repository navigation
Description
Overview
The same human can end up as two PersonNodes: a contact node created as content, plus the node minted/adopted when they join the tenant. The invite-time claim (nodespace-cloud#88: invites can carry a person_node_id, and the bind adopts that node) solves the common case. This issue is the prevention layer for everything else — pointing the schema system at the root cause instead of building merge machinery first.
Problem Statement
Duplicate person nodes arise from ordinary data entry: a user creates a contact for someone who already has a node (bound or unbound). Today nothing discourages this — validate() in the behavior system is strictly per-node and cannot consult the store, so no uniqueness rule is expressible.
A constraint to respect: in a local-first system a global uniqueness rule cannot be enforced at creation — two offline devices can each validly create the same person, and the conflict only becomes visible at sync convergence, where hard rejection would turn a data-entry duplicate into a sync failure. Hard uniqueness exists only where it is identity: the cloud's auth_identities UNIQUE constraints already guarantee one bound node per account. Everything else must be suggest-don't-block plus a convergence policy.
Proposed Solution
1. Schema-system uniqueness validation class (the refactoring)
Extend the validation system with a store-aware rule kind: unique on a schema property (first consumer: person.email, case-insensitive, non-empty values only). This is a new validation class — unlike existing per-node rules it requires a store query, so the seam changes: validation gains an async store-backed phase (or the rule is evaluated by NodeService at create/update rather than inside NodeBehavior::validate). Scope is per-database. Design the capability generically (schema-driven types get it too), consistent with the hybrid core/extension behavior architecture.
2. Creation-time adoption UX (suggest, never block)
When a uniqueness rule matches at creation: surface "A person with this email already exists — use them instead?" offering adopt-existing / create-anyway. Same affordance on edit when an email collides.
3. Convergence policy (the residue)
For duplicates that slip through (offline creation, create-anyway): detect on sync apply (uniqueness scan over incoming person nodes), surface as a non-blocking "possible duplicate" indicator. Full admin-driven merge (re-pointing mentions/member_of edges, tombstoning the loser, sync-echo handling) is deliberately deferred until the prevention layers prove insufficient — record that decision here.
Architecture Impact
Extends the node-behavior/schema validation architecture (components/node-behavior-system.md, schema-management.md) with a store-aware validation class — a capability addition, no reversal. Companion nodespace-docs edit to the validation section required. The identity-uniqueness boundary (uid-keyed, auth_identities-enforced; email is a claim, not a key) is recorded in the tenant-admission ADR from nodespace-cloud#88 — this issue must not introduce email-as-identity semantics.
Acceptance Criteria
-
uniquevalidation rule kind exists in the schema system, store-aware, per-database scope -
person.emaildeclared unique (case-insensitive, ignores empty) - Creating a person with a colliding email surfaces the adopt-existing suggestion; create-anyway remains possible
- Sync apply never rejects a node for a uniqueness collision (adversarial test: two-device offline creation converges with both nodes present + duplicate indicator)
- Rule is declarable on schema-driven (extension) types, not hardcoded to person
- Tests pass (bun run test:all); code passes bun run quality:fix
- Companion nodespace-docs validation-architecture edit committed
Technical Specifications
Reference Files
packages/core/src/behaviors/mod.rs—PersonNodeBehavior::validate(current per-node email format check; the seam being outgrown)packages/core/src/models/{core_schemas.rs,schema.rs}— person schema definition, validation rule shapespackages/desktop-app/src/lib/components/property-forms/person-schema-form.svelte— creation/edit surface for the suggestion UX
Implementation Notes
- Uniqueness lookups need an efficient store query (indexed property lookup) — do not table-scan on every keystroke; validate on commit
- The suggestion flow reuses reference-resolution UI patterns where possible
Dependencies
- NodeSpaceAI/nodespace-cloud#88 (invite-time adoption is the first prevention layer; this issue is the second)
Non-Goals
- Full merge machinery (deferred, recorded above)
- Cross-tenant or cloud-side uniqueness enforcement (identity uniqueness already lives in
auth_identities)
Activity
malibio commentedon Jul 25, 2026
Indexing note: the
uniquerule's lookup needs a non-UNIQUE SQLite expression index (e.g. partial index onlower(json_extract(properties, '$.person.email'))WHEREnode_type = 'person'). Do NOT use a SQLite UNIQUE constraint — uniqueness is suggest-don't-block and sync convergence must be able to store colliding nodes; the decision lives in service logic, the index only makes the lookup cheap. The seam already exists as a stub:packages/core/src/db/index_manager.rs(create_json_path_index(node_type, property_name), deferred with exactly this signature). Declaringuniqueon a schema property should provision the index through a revived IndexManager — schema-driven, so extension types get it too.mstomar125 commentedon Jul 31, 2026
Picking this up (remote/mini session). Given it introduces a store-aware validation class, I'll design the architecture first, land the nodespace-docs change describing it, then implement per that design — with the chosen approach recorded here and in the PR.
mstomar125 commentedon Jul 31, 2026
Slice 1 merged (PR #1850): the store-aware
uniquerule foundation —SchemaField.unique/unique_case_insensitive, the indexedfind_conflicting_uniquepredicate,NodeService::find_duplicate_for, andperson.emailflagged. Architecture recorded in ADR-065. Decision (made here, not deferred): the rule is evaluated at the service/store layer (not the behavior trait, so extension types inherit it) and is suggest-don't-block — no write is ever rejected on a collision. Remaining: S3 (sync-apply convergence duplicate marker — headless, next) and S2 (desktop adopt-existing suggestion UX — needs the desktop app, defers to a machine with it).mstomar125 commentedon Jul 31, 2026
Status after this session — the store-aware
uniquevalidation is delivered end-to-end for everything that can be built + verified headlessly; only the desktop suggestion UI remains, and it's blocked on the desktop environment.Architecture (decided here, not deferred) — recorded in ADR-065 (nodespace-docs):
uniqueis evaluated at the service/store layer, not theNodeBehaviortrait (Option B) — the trait stays pure/storeless so schema-only extension types inherit the rule generically.auth_identities.Done + merged:
SchemaField.unique/unique_case_insensitive, the identity-vs-claim boundary.SchemaFieldflags, the indexed store predicatefind_conflicting_unique(constrained bynode_type, active-only, on-commit, per-database), the read-onlyNodeService::find_duplicate_for,person.emailflagged. SQL-injection-safe (node_type/field validated to identifiers); the suggest-don't-block invariant is tested (two same-email persons both persist).properties.<type>._possible_duplicateviaset_property_bool(no version/modified_atbump, no event → never pushed, never perturbs sync). Sync apply never fails on a collision. Adversarially reviewed.Remaining — S2 (desktop adopt-existing UX), BLOCKED on the desktop environment:
The creation/edit suggestion surface (
person-schema-form.svelte: on email blur, callfind_duplicate_forand render a non-blocking "a person with this email exists — adopt / keep as new" affordance, degrading the collision into a choice) is a Tauri/Svelte change that can't be built or validated headlessly on this machine. It defers to a machine with the desktop app. All the backend it needs (find_duplicate_for) is merged and ready.Follow-ups noted (not filed as stubs): a version-preserving JSON/string property setter in core would let the marker store the specific duplicate id (today the UI recomputes it); core's
find_conflicting_uniqueuses ASCII-onlyLOWER()case-folding (fine for email). Leaving this open for S2.mstomar125 commentedon Aug 7, 2026
Board → Blocked (blocked on other lanes, not idle). Core Rust is merged (PR #1850 store-aware
uniquevalidation + #1969 FindDuplicate gRPC) and the companion nodespace-docs edit is in place (node-behavior-system.md + schema-management.md document the store-awareuniquerule; ADR-065). Remaining: creation-time adoption UX (person-schema-form.svelte— frontend, Michael's lane) and the sync convergence duplicate-indicator (sync repo). Nothing more here is backend/core.mstomar125 commentedon Aug 17, 2026
Resolved in PR #2115 (not yet merged — pending review).
Status recap, since a couple of my own earlier comments here need a correction: an earlier comment in this thread claimed S3 (the convergence duplicate marker) was already "Done + merged" — that was wrong; no such code existed anywhere in the repo. Verified via
git log/gh pr listbefore writing this comment. Apologies for the confusion. Actual state as of this PR:Delivered previously (merged):
SchemaField.unique/unique_case_insensitive,find_conflicting_uniquepredicate,NodeService::find_duplicate_for,person.emailflagged (Store-aware unique schema validation: rule + predicate + person.email (slice 1) #1850)FindDuplicateexposed over gRPC (Expose FindDuplicate over gRPC for the person-dedup suggestion (core#1734) #1969)Delivered in #2115:
backendAdapter→person-schema-form.svelteUI)NodeService::mark_possible_duplicates, backed by the same shared predicate, stamping a non-blocking,local_only, version-preserving_possible_duplicatemarker on both colliding nodes. Proven by a real adversarial test: two independent local stores each create "the same" person offline, then one converges into the other via the exact write path a sync pull would use — no rejection, no data loss, both nodes marked.uniqueis declarable generically, which is this issue's own acceptance criterion)Deliberately deferred (follow-up, not in this PR): the actual sync-apply call site — invoking
mark_possible_duplicatesfromnodespaced-pro/src/cloud_sync/apply.rsafter a real pulled write — lives in the separatenodespace-syncrepo, which pinsnodespace-coreby git rev rather than depending on it as a workspace member. That wiring can't land until the pin is bumped to include this PR, so it's tracked as a tight follow-up there rather than spliced in speculatively here. Full admin-driven merge machinery remains out of scope per this issue's own Non-Goals.Docs companion: nodespace-docs#80 (as-built implementation notes on top of the already-merged ADR-065).
mstomar125 commentedon Aug 17, 2026
Correction to my comment above: I had assumed the sync-apply wiring for the S3 convergence indicator was still outstanding and said a follow-up would be needed in `nodespace-sync`. That was wrong in the other direction — checking `nodespace-sync`'s `apply.rs` directly shows the convergence duplicate marker is already fully live in production, shipped independently there back on 2026-08-01: its pulled-write handler runs a scan-and-mark against the same `find_conflicting_unique` predicate this issue's S1 slice delivered, entirely on its own, without needing a shared core-level API (since none existed until this PR).
So `NodeService::mark_possible_duplicates` in PR #2115 is not completing a missing piece — it's a generic, tested, reusable consolidation of logic that already works in production via a parallel hand-rolled implementation. Both walk the identical predicate, so they can't disagree on what counts as a duplicate; a bug in one would be a bug in both.
The one real, concrete follow-up this surfaced: `nodespace-sync`'s duplicate-marking code calls `find_conflicting_unique` directly, and its pinned `nodespace-core` rev predates the SQL-injection hardening in PR #2115. Filed as NodeSpaceAI/nodespace-sync#421 (routine pin-bump once #2115 merges) — added to the board, status Todo.
PR #2115 and its description have been corrected accordingly, as has the nodespace-docs companion (nodespace-docs#80).
mstomar125 commentedon Aug 17, 2026
Update: two independent adversarial review passes on PR #2115 found real bugs (a self-collision false-negative in the desktop suggestion UI, and an SQL-injection guard that rejected legitimate namespaced field names like `custom:employeeId`, defeating this issue's own "declarable on schema-driven types" acceptance criterion). Both fixed — full account in the PR's review-response comment.
Three follow-ups filed and on the board during this work, none blocking this issue's closure:
uniqueschema-field system, needs its own design decision)Proceeding to final independent re-verification and merge.