Skip to content

B4 follow-up: fold remaining 11 CollectionService::new daemon sites into core (collection_ops) - #1261

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1243-collection-ops
May 30, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1243-collection-ops

Conversation

@malibio

@malibio malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #1243

…tion_ops (closes #1243)

Introduces `packages/core/src/ops/collection_ops.rs` with typed input/output structs
and thin async functions wrapping `CollectionService`. Each of the 11 collection RPC
handlers in the daemon now delegates to a single `collection_ops::*` call instead of
constructing `CollectionService` inline, consistent with the ADR-031 thin-adapter rule.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This PR correctly addresses all 11 acceptance criteria sites. Every daemon collection RPC handler now delegates to a collection_ops function instead of constructing CollectionService inline, and the new module lives in the right location (packages/core/src/ops/). The change is a clear net positive — the daemon is measurably thinner, and the orchestration logic is now available to any future caller without copying. No blocking issues.

Two targeted improvements are worth addressing before merge: a leaked store bypass that defeats the abstraction for one handler, and inconsistently-typed error semantics in the two mutation ops.


Findings

Suggested Improvements

[Improvement] get_collection_members_recursive daemon handler leaks store access that should live in collection_ops

packages/daemon/src/services/node_service.rs, lines 953–965

The handler calls collection_ops::get_collection_members_recursive to get IDs, then immediately reaches back through self.node_service.store() to do a batch node fetch and proto mapping. This is the exact pattern the PR is meant to eliminate: the daemon is still orchestrating storage calls directly.

The get_collection_members_recursive op should return Vec<Node> (not Vec<String>), matching the shape of get_collection_members. The daemon handler would then be the standard one-call-plus-proto-map pattern, consistent across all 11 handlers.

The current output type is also a semantic mismatch with its sibling: GetCollectionMembersOutput returns Vec<Node> while GetCollectionMembersRecursiveOutput returns Vec<String>. A caller looking at the two types will reasonably expect them to be structurally parallel.

[Improvement] ValidationFailed is the wrong carrier for duplicate-name errors in create_collection / rename_collection

packages/core/src/ops/collection_ops.rs, lines 264 and 303

The ops functions return OpsError::ValidationFailed for the duplicate-name guard, and the daemon handlers special-case that variant to produce Status::already_exists. This is semantically incorrect and architecturally fragile:

  1. ValidationFailed is documented in ops/mod.rs for invariant violations (invalid parent, circular reference, hierarchy violation). A name conflict is a resource-existence conflict, not a validation failure of the submitted data.
  2. The daemon's match arm applies to all ValidationFailed variants from both functions — any future validation failure (e.g. an empty name, an illegal character) would incorrectly be mapped to ALREADY_EXISTS instead of INVALID_ARGUMENT.
  3. The match arm is duplicated across two handlers; every future caller must remember to re-implement this special-case.

The correct fix is to add an OpsError::AlreadyExists { id: String } variant (or reuse OpsError::NotFound's mirror) and map it to Status::already_exists in ops_error_to_status centrally. The daemon handlers would then be uniform .map_err(ops_error_to_status)? calls.


Nitpicks

Nit: packages/core/src/ops/collection_ops.rs, lines 15–110

All input/output structs are missing #[derive(Debug)]. Every struct in node_ops and rel_ops derives Debug. Consistency matters here because the ops layer is the primary logging/inspection boundary.

Nit: packages/core/src/ops/collection_ops.rs, lines 277–282

crate::services::CreateNodeParams and crate::services::InsertPositionOwned are referenced with full crate paths despite both being in scope via the crate's re-exports. crate::models::NodeUpdate at line 310 has the same issue. The existing imports at the top of the file should be expanded rather than using inline qualified paths.

Nit: packages/core/src/ops/collection_ops.rs — no unit tests

node_ops has a #[cfg(test)] block covering its error-mapping paths. collection_ops has none. The issue acceptance criteria don't explicitly require new tests, but the create_collection duplicate-name guard and the rename_collection self-rename pass-through are the two non-trivial logic branches added here and are exactly the kind of unit-testable decision points node_ops covers.

…complete recursive op

- Add OpsError::AlreadyExists variant; map to Status::already_exists in ops_error_to_status,
  eliminating the fragile ValidationFailed special-cases in create_collection and rename_collection
- Move get_nodes_by_ids batch-fetch inside collection_ops::get_collection_members_recursive so
  the daemon handler receives Vec<Node> directly; output is now consistent with get_collection_members
- Add #[derive(Debug)] to all collection_ops input/output structs
- Add unit tests for duplicate-name guard and self-rename pass-through in collection_ops

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit e211388 into main May 30, 2026
@malibio
malibio deleted the worktree-issue-1243-collection-ops branch May 30, 2026 13:02
malibio added a commit that referenced this pull request Jun 22, 2026
…nto core (collection_ops) (#1261)

* B4 follow-up: fold 11 CollectionService::new daemon sites into collection_ops (closes #1243)

Introduces `packages/core/src/ops/collection_ops.rs` with typed input/output structs
and thin async functions wrapping `CollectionService`. Each of the 11 collection RPC
handlers in the daemon now delegates to a single `collection_ops::*` call instead of
constructing `CollectionService` inline, consistent with the ADR-031 thin-adapter rule.

Co-Authored-By: Claude <[email protected]>

* Address review findings: AlreadyExists error variant, Debug derives, complete recursive op

- Add OpsError::AlreadyExists variant; map to Status::already_exists in ops_error_to_status,
  eliminating the fragile ValidationFailed special-cases in create_collection and rename_collection
- Move get_nodes_by_ids batch-fetch inside collection_ops::get_collection_members_recursive so
  the daemon handler receives Vec<Node> directly; output is now consistent with get_collection_members
- Add #[derive(Debug)] to all collection_ops input/output structs
- Add unit tests for duplicate-name guard and self-rename pass-through in collection_ops

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

B4 follow-up: fold remaining 11 CollectionService::new daemon sites into core (collection_ops)

1 participant