Repository navigation
Mark rename-path collection-name collisions and scope lookup to active collections - #2139
Conversation
…e collections (closes #2127) Follow-up to #2126 (create-path suggest-don't-block marking). Closes two deferred gaps its adversarial review surfaced: - SqliteStore::update_node and update_node_with_version_check now detect a collection-name collision the same way create_node does — before the write, excluding the node's own id so a no-op or case-only rename never self-marks — and mark both sides with the existing _possible_duplicate marker after a successful write. Covers both the version-checked path (NodeService::update_node, used by nodespace-sync's apply_node_upsert "node already exists locally" branch) and the plain update_node path (NodeService::update_node_unchecked). - get_collection_by_name now filters to lifecycle_status = 'active', matching the pattern find_conflicting_unique already established for the ADR-065 unique-field mechanism. An archived collection no longer holds its name, so archiving one and creating (or renaming) another collection onto that name is no longer detected as a collision. Updates the doc comments this touches (mark_collection_name_collision, CollectionNodeBehavior, the _possible_duplicate schema field description) that previously described both gaps as known limitations. Flips the test that documented the rename-path gap to assert the fixed behavior, and adds regression tests for the unchecked update path, case-only-rename self-exclusion, and archived-collection name reuse on both the create and rename paths. Co-Authored-By: Claude <[email protected]>
…hten tests - collection_ops::create_collection's AlreadyExists guard previously checked get_collection_by_name (now active-only per Gap 2), but the id it inserts under is deterministic_collection_id(name) — a pure hash of the normalized name, independent of lifecycle_status. Recreating a collection with an archived collection's exact name therefore passed the guard and then hit a raw primary-key-constraint violation on insert (NodeService::create_node has no get-or-create semantics for the collection type), surfacing as an opaque OpsError::Internal instead of a clean rejection. Fixed by checking node existence by the deterministic id directly (any node at that id, active or archived, already occupies it) rather than by name. - update_node's unwrap_or(current.content.clone()) now uses unwrap_or_else to avoid an unconditional clone on the common Some(content) path. - Documented the invariant the self-exclusion filter's correctness relies on (a self-match via LIMIT 1's unordered result can only occur when a genuine third-party collision would already have been caught earlier). - Added regression tests: create_collection_op_rejects_reusing_an_archived_collections_name (the PK-collision fix), and case_only_rename_never_self_marks_via_unchecked_path (closes a coverage gap where the two update entry points implement self-exclusion independently). Co-Authored-By: Claude <[email protected]>
|
Adversarial review complete — REQUEST CHANGES, addressed in the follow-up commit. Blocker found and fixed: Also addressed the review's minor findings:
Confirmed correct by the review and unchanged: Full suite ( |
Summary
Closes #2127.
Follow-up to #2126 (create-path suggest-don't-block marking for collection-name collisions). #2126's adversarial review deferred two related gaps to keep that PR scoped to the wedge fix; this PR closes both.
Gap 1 — rename path never marks a collision
SqliteStore::create_nodedetects a collection-name collision and marks both sides with the non-blocking_possible_duplicatemarker.SqliteStore::update_nodeandupdate_node_with_version_checkhad no equivalent check at all — this predates #2117/#2126, but #2126 newly made the asymmetry visible: create-time collisions are surfaced, rename-time ones silently weren't.Both
update_nodeandupdate_node_with_version_checknow run the same detect-before-write / mark-after-write logiccreate_nodeuses, triggered when the write changescontenton an (effectively) collection-typed node:mark_collection_name_collision's doc comment)."Foo"→"foo", which folds to the sameLOWER(title)) never matches and marks itself.update_node_with_version_checkskips it entirely on a version conflict (rows_affected == 0).apply_node_upsertand other callers reach: the version-checked path (NodeService::update_node, used by the sync-apply "node already exists locally" branch) and the plain path (NodeService::update_node_unchecked).Gap 2 —
get_collection_by_namedidn't filter bylifecycle_statusget_collection_by_namematchedLOWER(title)with nolifecycle_statusfilter, unlikefind_conflicting_unique(the ADR-065 person.email mechanism this marker is modeled on), which restricts tolifecycle_status = 'active'. Practical consequence: archiving a collection to free up its name didn't actually free it up — a new collection (or a rename) reusing that name would be found colliding against the archived one and get permanently flagged, with no way to distinguish "colliding with a live collection" from "colliding with an archived one."Added
AND lifecycle_status = 'active'toget_collection_by_name's query, matchingfind_conflicting_unique's pattern. This method has several other callers (collection_ops::create_collection/rename_collection's interactive guards,CollectionService::resolve_path/find_collection_by_path) — all of them only ever look up active collections in existing tests and callers, so this is a behavior-narrowing fix with no observed fallout, not a widening one.Also updated
Doc comments that described both gaps as known/deferred limitations:
mark_collection_name_collision's doc comment (now describes all three call sites),CollectionNodeBehavior's doc comment, and the_possible_duplicateschema field's description incore_schemas.rs.Tests
In
packages/core/tests/collection_name_convergence_test.rs:update_path_introducing_a_name_collision_is_currently_unmarked→update_path_introducing_a_name_collision_is_now_marked) to assert the fixed behavior via the version-checked path.unchecked_update_path_introducing_a_name_collision_is_marked— same scenario throughNodeService::update_node_unchecked(the plainSqliteStore::update_nodepath).case_only_rename_never_self_marks— regression for the self-exclusion fix.archived_collection_does_not_block_or_mark_name_reuse— regression for gap 2, covering both the create path and the rename path reusing an archived collection's name.All 9 tests in that file pass, along with the full
collection_membership_test.rssuite (32 tests, unaffected by thelifecycle_statusfilter since all existing lookups are against active collections) and the fullcargo test -p nodespace-coresuite (1154 unit tests + all integration binaries + doc-tests, 0 failures).cargo clippy -p nodespace-core --all-targetsis clean.cargo fmtclean.Test plan
cargo test -p nodespace-core --test collection_name_convergence_test— 9/9 passcargo test -p nodespace-core --test collection_membership_test— 32/32 passcargo test -p nodespace-core(full suite) — 0 failurescargo clippy -p nodespace-core --all-targets— cleancargo fmt -p nodespace-core -- --check— clean🤖 Generated with Claude Code