Skip to content

Make daemon NodeService RPCs thin: delegate collection/lifecycle/version logic to core node_ops (B3 + B4) - #1244

Merged
malibio merged 1 commit into
mainfrom
worktree-issue-1241-thin-daemon-rpcs
May 30, 2026
Merged

malibio merged 1 commit into
mainfrom
worktree-issue-1241-thin-daemon-rpcs

Conversation

@malibio

@malibio malibio commented May 30, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1241

Summary

  • Refactor create_node, update_node, delete_node in packages/daemon/src/services/node_service.rs to delegate to nodespace_core::ops::node_ops::{create_node,update_node,delete_node} (ADR-031 / findings B3+B4 from Architectural audit (post-daemon + post-SQLite): structural findings & improvement plan #1228)
  • Remove inline collection resolution, lifecycle defaulting, and version auto-fetch from the three CRUD handlers — these now live exclusively in node_ops
  • Delete stale comment claiming routing through node_ops "would silently drop several fields" (verified false: node_ops::update_node covers all fields)
  • Add id and position fields to node_ops::CreateNodeInput so the daemon can delegate fully without losing wire-contract fields
  • 6 tests: 3 daemon unit parity tests + 3 gRPC integration tests (collection+lifecycle on create, auto-version-fetch on update, add/remove collection membership)

B4 deferral

The 3 CollectionService::new sites in the CRUD handlers (old lines 109, 203, 212) are gone. The remaining 11 sites in pure collection-management RPCs are deferred to #1243.

Test plan

  • cargo test -p nodespace-core -p nodespace-daemon — all pass
  • cargo clippy --all-targets -- -D warnings — clean
  • bun run test — 131 frontend test files, no regressions

🤖 Generated with Claude Code

…ode_ops (closes #1241)

- daemon: refactor create_node, update_node, delete_node to delegate to
  node_ops::{create_node,update_node,delete_node} — removes inline
  collection resolution, lifecycle defaulting, and version auto-fetch
  from the gRPC layer (B3+B4 from architectural audit #1228)
- core/node_ops: fix update_node to skip the NodeUpdate call when no
  field changes are present (only collection ops) — prevents "Update
  contains no changes" error on collection-only updates
- daemon/tests: add 3 parity tests asserting create+collection+lifecycle,
  auto-fetch version, and add/remove collection membership via gRPC
- agent/tools: add missing id/position fields to CreateNodeInput struct
  (required after InsertPosition enum was introduced in #1236)

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

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Scope note on B4 follow-up

The 11 remaining CollectionService::new sites in the daemon's collection-management RPCs (get_all_collections, get_collection_members, etc.) are intentionally deferred to #1243. Those RPCs are pure collection management operations where the current inline orchestration is correct — they don't mix node CRUD business logic with the adapter layer the way create/update/delete did.

The non-negotiable B3 deliverable (create/update/delete delegation) is complete in this PR. #1243 tracks the architectural cleanup of the collection RPCs.

@malibio
malibio merged commit 949c0d2 into main May 30, 2026
@malibio
malibio deleted the worktree-issue-1241-thin-daemon-rpcs branch May 30, 2026 07:19

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

This PR successfully achieves its primary goal: eliminating the three highest-risk violations of ADR-031 (daemon's thin-adapter contract) by delegating create_node, update_node, and delete_node to node_ops. The agent path and daemon path now share a single implementation. The change is a clear net improvement and most acceptance criteria are met.

One improvement-level finding worth addressing before merge, plus one gap in the issue's own acceptance criteria that should either be fixed in-PR or tracked explicitly.


Findings

Suggested Improvements

packages/core/src/ops/node_ops.rs, update_node — unit test coverage for the collection-only (no-field-change) path is missing from the unit test module

The new is_empty() guard added to update_node (line 243) is a behaviour change introduced in this PR, not carried forward from before. The integration test update_node_add_then_remove_collection_membership in grpc_round_trip.rs does exercise the content: None path end-to-end, which is good. However, the unit tests in node_service.rs's tests module (update_node_rpc_collection_add_then_remove) deliberately include a content: Some(...) change alongside the collection op to "so NodeUpdate is non-empty" — explicitly avoiding the is_empty branch. The pure collection-only case (no content/type/properties/lifecycle change, only add_to_collection populated) is only covered by the integration test, not the unit test. Given this is a new control-flow branch, a unit test for update_node_rpc_collection_add_then_remove without a content change would make the coverage complete at both levels.

packages/daemon/src/services/node_service.rs, imports — CreateNodeParams is no longer needed for the refactored handlers but still imported

CreateNodeParams at line 25 is only used at line 1109 (create_collection). That usage is legitimate, so this is not dead code — but worth double-checking with cargo clippy that no unused-import warning surfaces. If clippy is clean this is a non-issue.

packages/daemon/src/services/node_service.rs, update_node response — parent_id is hard-coded to String::new()

Lines 171–175: the update_node handler sets parent_id: String::new() in the NodeResponse. This is unchanged from origin/main (pre-refactor the same value was emitted), so it is not a regression introduced here. It is still a correctness gap: a caller that relies on parent_id in the update response will silently get an empty string. This is tracked as part of the broader thin-adapter cleanup (B5/B6), so acceptable to defer — but worth noting for #1242.

Nitpicks

Nit: packages/core/src/ops/node_ops.rs, create_node — lifecycle "active" special-case encoding

Lines 173–189: the if lifecycle_status != "active" guard hard-codes the default status string. This is pre-existing logic (not introduced by this PR) but it moved from the daemon into core in this change. The string "active" should ideally be a constant from the core models layer. Low priority since the issue scope is narrowly architectural, but worth a follow-up.

Nit: packages/daemon/tests/grpc_round_trip.rs, create_node_with_collection_and_lifecycle_status — test comment says "parity test" but doesn't assert parity with a direct node_ops call

The integration test verifies the RPC produces correct outputs but doesn't cross-check against a parallel node_ops::create_node call on the same service (unlike the unit test create_node_rpc_parity_with_node_ops in node_service.rs). Not a blocker — the unit test covers the parity assertion; the integration test independently validates the wire contract. Just worth aligning the comment to say "contract test" rather than "parity test" to avoid misleading reviewers.


Acceptance Criteria Verification

  • create_node, update_node, delete_node delegate to node_ops — inline collection/lifecycle/version logic removed from daemon
  • Inline CollectionService::new at original lines 109, 203, 212 are gone (confirmed: 11 remaining sites are all in pure-collection RPCs, not in the mutating handlers)
  • Errors map through ops_error_to_status (consistent with search RPC)
  • Stale comment at original lines 197–199 ("would silently drop several fields") is deleted; field parity confirmed by inspection (node_ops::update_node handles content, node_type, properties, lifecycle_status, add_to_collection, remove_from_collection)
  • Wire contract unchanged: NodeResponse/DeleteNodeResponse populated identically (parity test + re-fetch pattern preserved)
  • The 11 remaining collection-RPC CollectionService::new sites are not folded into core. The issue allows deferral with an explicit follow-up filed and referenced. No follow-up issue was filed for this. The commit message does not reference a follow-up tracking issue for B4's remaining 11 sites. This should either be addressed in-PR or a follow-up issue filed and referenced (e.g. "remaining 11 CollectionService::new sites in daemon — B4 follow-up") before merge to satisfy the acceptance criterion.
  • No #[allow(dead_code)], no #[deprecated], no lint suppression
  • cargo test and cargo clippy — not directly observable from review but the change is structurally sound; test suite structure matches the required parity tests

Summary verdict: Approve pending the B4 follow-up issue being filed and referenced (acceptance criterion is explicit that if the 11 sites are deferred, the follow-up must be filed and referenced). The core refactoring is correct, well-tested, and a clear architectural improvement.

@malibio

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Review feedback addressed

Addressed (2):

  • ✅ Added update_node_rpc_collection_only_no_field_changes unit test — exercises the is_empty() guard in node_ops::update_node with a pure collection-only update (no content/type/properties/lifecycle changes). This was the one new control-flow branch introduced in this PR that wasn't covered at the unit level.
  • ✅ Renamed "Parity test" doc comments in grpc_round_trip.rs to "Contract test" — those tests validate the wire contract, not parity against a direct node_ops call (the unit-level parity test in node_service.rs::tests::create_node_rpc_parity_with_node_ops does that).

Skipped (3):

malibio added a commit that referenced this pull request Jun 22, 2026
…ode_ops (closes #1241) (#1244)

- daemon: refactor create_node, update_node, delete_node to delegate to
  node_ops::{create_node,update_node,delete_node} — removes inline
  collection resolution, lifecycle defaulting, and version auto-fetch
  from the gRPC layer (B3+B4 from architectural audit #1228)
- core/node_ops: fix update_node to skip the NodeUpdate call when no
  field changes are present (only collection ops) — prevents "Update
  contains no changes" error on collection-only updates
- daemon/tests: add 3 parity tests asserting create+collection+lifecycle,
  auto-fetch version, and add/remove collection membership via gRPC
- agent/tools: add missing id/position fields to CreateNodeInput struct
  (required after InsertPosition enum was introduced in #1236)

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.

Make daemon NodeService RPCs thin: delegate collection/lifecycle/version logic to core node_ops (B3 + B4)

1 participant