Skip to content

Collection-name possible-duplicate marking: rename path unmarked + lifecycle_status not filtered #2127

Closed

Description

@mstomar125

Context

Follow-up from #2117 (PR #2126, adversarial review). #2117 converted collection-name-collision handling in SqliteStore::create_node from a hard rejection to a suggest-don't-block _possible_duplicate marker (ADR-065 posture). The adversarial review of that PR surfaced two related, non-blocking gaps in the resulting mechanism, both deliberately deferred rather than folded into that PR to keep it scoped to the wedge fix:

Gap 1 — rename/update path never marks a collision

SqliteStore::create_node detects a name collision and marks both sides. SqliteStore::update_node has no equivalent check at all (and never did — this predates #2117). Concretely: nodespace-sync's apply_node_upsert has two branches — "node absent locally" (calls create_node, now marks) and "node already exists locally" (calls update_node directly, still doesn't mark). A sync-applied rename that introduces a fresh name collision with a different local collection is therefore silent: not rejected (fine, consistent with suggest-don't-block), but also not surfaced via the _possible_duplicate marker the create path now provides.

This is not a regression (renames were already unmarked before #2117 too — update_node simply never had detection), but #2117 does newly create an inconsistency: create-time collisions are now visible, rename-time ones are not.

Documented explicitly (not silently) by a test: update_path_introducing_a_name_collision_is_currently_unmarked in packages/core/tests/collection_name_convergence_test.rs.

Fix direction: add the same detect-before-write / mark-after-write logic create_node now has to SqliteStore::update_node (and its version-checked sibling) when the update changes content on a collection-typed node.

Gap 2 — get_collection_by_name doesn't filter by lifecycle_status

get_collection_by_name (packages/core/src/db/sqlite_store/relationships.rs) matches LOWER(title) with no lifecycle_status filter — unlike find_conflicting_unique (the ADR-065 person.email mechanism this fix's marker is modeled on), which explicitly restricts to lifecycle_status = 'active'. Practical consequence: archiving a collection to free up its name does not actually free it up — a new collection created with that same name will be (correctly, by current code) found colliding against the archived one and get permanently flagged _possible_duplicate, forever, with no way to distinguish "colliding with a live collection" from "colliding with an archived one."

This is pre-existing (the old hard-bail! had the identical gap — pre-#2117 it just meant you couldn't even create the new collection at all, a worse outcome). Not a regression from #2117, but #2117's new _possible_duplicate schema-field description was corrected during review to explicitly note this rather than overclaim an "active" restriction that the code doesn't back up.

Fix direction: add AND lifecycle_status = 'active' to get_collection_by_name's query, matching the pattern find_conflicting_unique already established. Note this method has other callers too (collection_ops::create_collection/rename_collection's interactive guards, CollectionService::resolve_path) — changing its filtering is a small, self-contained SQL change but touches shared, multi-caller code, so it deserves its own PR + test pass rather than being bundled into a wedge-fix PR.

Priority

Low — both are visibility/UX gaps, not correctness or data-loss issues, and neither risks wedging sync (the property that made #2117 urgent).

Activity

  1. mstomar125 commented on Aug 18, 2026

    @mstomar125
    ContributorAuthor

    Resolved via #2139 (in review).

    Gap 1 (rename path never marks a collision): SqliteStore::update_node and update_node_with_version_check now run the same detect-before-write / mark-after-write logic create_node uses (#2126), triggered when a write changes content on an (effectively) collection-typed node. The node's own id is excluded from the pre-write match so a no-op or case-only rename never self-marks, and marking only happens after a real write lands (skipped on a version conflict). Covers both entry points nodespace-sync's apply_node_upsert and other callers reach: the version-checked path (NodeService::update_node) and the plain path (NodeService::update_node_unchecked).

    Gap 2 (get_collection_by_name didn't filter by lifecycle_status): added AND lifecycle_status = 'active' to its query, matching the pattern find_conflicting_unique already established for ADR-065's unique mechanism. Archiving a collection now genuinely frees up its name — a new collection or a rename reusing that name against an archived collection is no longer detected as a collision.

    Also updated the doc comments (mark_collection_name_collision, CollectionNodeBehavior, the _possible_duplicate schema field description) that previously described both as known/deferred gaps.

    Four new/flipped regression tests in collection_name_convergence_test.rs cover both entry points of gap 1, the case-only-rename self-exclusion edge case, and gap 2 on both the create and rename paths. Full cargo test -p nodespace-core suite (1154 unit tests + integration + doc-tests) and cargo clippy --all-targets are clean.

    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