Skip to content

Decompose NodeService god-object into focused sub-services (facade delegation) - #1240

Merged
malibio merged 3 commits into
mainfrom
worktree-issue-1238-decompose-nodeservice
May 30, 2026
Merged

malibio merged 3 commits into
mainfrom
worktree-issue-1238-decompose-nodeservice

Conversation

@malibio

@malibio malibio commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Closes #1238

@malibio

malibio commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This PR successfully executes the mechanical decomposition of the 11,891-line NodeService god-object into focused sub-modules using the impl NodeService across-files pattern. The workspace compiles clean, all 132 doc tests pass, and the 47 integration tests in mod.rs pass unchanged. The approach — splitting into impl NodeService blocks across files sharing the parent module's namespace via use super::* — is sound and keeps the facade pattern intact without needing a separate context struct.

The deferred Phase 4 (hierarchy extraction pending #1237) is clearly documented in a section comment at line 1175 of mod.rs.

One acceptance criterion from the issue was partially honored but not fully implemented; the remaining findings are nits or minor improvements.


Requirements Check

  • ✅ Every pub async fn signature is byte-identical; all external consumers (daemon, agent, cli, playbook, tests) compile without call-site changes.
  • ✅ Internal logic lives in focused sub-modules per the table in the issue; mod.rs is the facade + hierarchy (deferred) + tests.
  • ✅ Each sub-module file is independently readable and under the ~2k-line guideline: crud.rs (2,034), relationship.rs (910), schema.rs (454), bulk.rs (596), query.rs (322), embedding.rs (229).
  • ✅ Shared state consolidated in NodeService struct fields, all pub(crate); no field duplication across sub-services.
  • ⚠️ Partial — with_execution_context / playbook wrapper (see Critical finding below).
  • ✅ with_client unchanged and still pub.
  • ✅ No #[allow(dead_code)], no #[deprecated], no backward-compat shims, no commented-out code.
  • ✅ All logging via tracing; no println! in production code (the occurrences found are inside /// doc-comment code examples only).
  • ✅ cargo clippy -p nodespace-core --lib --tests -- -D warnings clean. The bench target fails with "unclosed delimiter" on performance.rs:30, but this is a pre-existing defect on main (unchanged file, same error on origin/main) — not introduced by this PR.

Testing

  • ✅ 132 doc tests: test result: ok. 132 passed; 0 failed — baseline preserved.
  • ✅ 47 #[tokio::test] + #[test] in mod.rs: all pass. The integration test block at the end of mod.rs is intact.
  • ✅ Full workspace build succeeds (cargo build --workspace).
  • ⚠️ cargo test --workspace result pending (long-running, kicked off asynchronously); the sub-module structure does not change any daemon/agent/cli call sites so regressions are not expected.

Findings

Important Issues

[Improvement] packages/core/src/services/node_service/mod.rs:1140 — with_execution_context visibility partially satisfies the issue but misses the stated intent

The issue acceptance criterion reads:

with_execution_context removed from NodeService public API; playbook context handled by a playbook-layer wrapper; playbook/actions.rs:434 updated accordingly.

The PR changes visibility from pub → pub(crate), which prevents external crates from calling it. That is correct and the only production caller (playbook/actions.rs:434) still compiles because it is in the same crate. However, pub(crate) still exposes this method to every module inside nodespace-core, not just the playbook module. The issue explicitly offered two acceptable options: a PlaybookScopedNodes forwarding struct in packages/core/src/playbook/, or a pub(crate) fn scoped_for_playbook with a doc comment restricting it to the playbook module only.

The current implementation chose neither — there is no playbook-layer wrapper and no doc comment narrowing the intended audience. Any future developer inside nodespace-core (e.g., an import or schema module) can now reach with_execution_context, which continues the pattern the issue wanted to eliminate. The issue specifically required: "Either way, the public API must no longer advertise playbook execution context as a first-class concern."

Suggested fix (minimal): rename to scoped_for_playbook and add a doc comment stating it is only for use by crate::playbook. This both satisfies the spirit of the acceptance criterion and makes the constraint self-documenting without requiring the full forwarding struct. Alternatively, add a pub(super) restriction by moving it to a submodule — but pub(crate) with a rename + doc note is the pragmatic path.

[Improvement] packages/core/src/services/node_service/mod.rs:1 — Module-level doc comment not updated

The //! header on mod.rs was copied verbatim from the original node_service.rs and still says "Node Service - Core CRUD Operations" with bullet points listing all concerns as if this file owns them. The file is now a facade + hierarchy (deferred) + tests. The stale header will mislead future developers into thinking mod.rs directly contains CRUD, bulk, and query logic.

Suggested fix: Update the header to describe the module's actual current role: facade, shared state definition, hierarchy methods (temporary, Phase 4), and test suite. Link to the sub-modules.

Nitpicks

Nit: packages/core/src/services/node_service/mod.rs:2062 — CompletenessResult is pub but has no external caller and no re-export

CompletenessResult is declared pub struct but check_node_completeness has no callers outside nodespace-core, and the struct is not re-exported from services/mod.rs or lib.rs. It is reachable only because node_service is a pub mod. Either add it to the re-export list in services/mod.rs (if it is intended to be part of the public API) or make it pub(crate). Leaving it pub with no re-export is a minor inconsistency.

Nit: packages/core/src/services/node_service/relationship.rs:515,547,843 — Inline crate::models::schema::SchemaRelationship paths

All other sub-modules resolve types via use super::*, which pulls in mod.rs's imports. But SchemaRelationship and RelationshipCardinality are not in mod.rs's use list (use crate::models::{...} omits schema::), so relationship.rs accesses them as fully-qualified inline crate::models::schema::... paths. This is functional but inconsistent with the rest of the file style. Consider adding use crate::models::schema::{RelationshipCardinality, SchemaRelationship}; to mod.rs imports so relationship.rs can use them naturally.

Nit: packages/core/src/services/node_service/crud.rs:477 — ensure_date_exists is pub but belongs to the facade surface

ensure_date_exists is called from packages/core/src/markdown/mod.rs:926, which is within the same crate. It is pub (not pub(crate)). This is not wrong — it is accessible via the NodeService facade — but it is inconsistent with the pattern of making helpers pub(crate). Since markdown/mod.rs calls it directly on a NodeService ref, this is fine as-is; just noting the inconsistency for the eventual Phase 4 cleanup pass.


Recommendation

APPROVE

The core decomposition goal is achieved: a 11,891-line god-object is split into six focused sub-modules, all tests pass at baseline, the workspace compiles clean, and no behavior changes were introduced. The with_execution_context visibility improvement (pub → pub(crate)) is a step in the right direction even if not the full wrapper extraction the issue specified. That remaining gap and the stale module doc comment are worth a follow-up issue rather than blocking this PR, as neither affects correctness or the public API contract.

Follow-up recommended: open a focused issue for (1) renaming with_execution_context → scoped_for_playbook with restricting doc comment, and (2) the pre-existing performance.rs bench delimiter error.

@malibio

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Addendum — workspace test results

cargo test --workspace completed: 6 failures in packages/agent/tests/ollama_integration.rs — all in test_skill_pipeline_* and test_pipeline_* tests that require a running Ollama instance or a downloaded GGUF model (the resolve_engine helper is supposed to skip when neither is available, but on this machine the GGUF path returns Ok with a non-existent path, causing the skip gate to miss and the test to fall through to an assertion failure).

These tests are unchanged in this PR (git diff origin/main...HEAD -- packages/agent/tests/ollama_integration.rs produces no output), and the same failures reproduce on origin/main in this environment. They are a pre-existing infrastructure issue unrelated to the NodeService decomposition.

All crate-level tests (nodespace-core, nodespace-daemon, nodespace-cli) pass. The original recommendation stands: APPROVE.

@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.

Decomposition is mechanically correct and well-executed. All tests pass at baseline (132 doc tests, 47 integration tests in mod.rs). The two findings worth following up: (1) with_execution_context should be renamed scoped_for_playbook with a restricting doc comment to fully satisfy the issue's intent on removing execution context as a first-class public concern — current pub(crate) is a step in the right direction but leaves the method discoverable crate-wide; (2) the mod.rs module-level doc comment still describes the old monolithic file. Neither is a blocker. See full review comment for details. Recommendation: APPROVE.

@malibio

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed

✅ Addressed (3/3 recommendations):

  1. with_execution_context → scoped_for_playbook — renamed with a doc comment explicitly restricting use to `crate::playbook`. Updated the one call site in `actions.rs`. Fully closes the acceptance criterion.

  2. Stale module-level doc comment — replaced with accurate description of what `mod.rs` owns (facade + deferred hierarchy + tests + sub-module declarations).

  3. CompletenessResult visibility — kept as `pub` (required because `check_node_completeness` is a `pub async fn`) and added to the `services::mod.rs` re-export chain so it's actually reachable by callers.

⏭️ Skipped (1 nit):

  • SchemaRelationship import path in relationship.rs — use super::* already makes it available; the inline path is a minor style preference with no correctness or readability impact.

All tests still green: 866 integration + 132 doc.

Michael Libio and others added 3 commits May 30, 2026 08:34
Phases 1-3 and 5 of the decomposition plan. Phase 4 (Hierarchy extraction)
is deferred pending #1237 merge to avoid collision on the retry-loop cleanup.

`packages/core/src/services/node_service.rs` (11,891 lines) split into:

- `node_service/mod.rs` (2,789 lines): struct definition with all fields as
  `pub(crate)`, construction (`new`, `seed_*`), accessors (`store()`,
  `behaviors()`, `with_client`), all hierarchy methods (Phase 4 deferred),
  `NodeAccessor` impl, shared helper fns, all tests unchanged
- `node_service/crud.rs` (2,036 lines): create/get/update/delete + all CRUD
  private helpers (validation, schema defaults, lazy migration, compute_title)
- `node_service/relationship.rs` (910 lines): mention ops + typed relationship
  CRUD + populate_mentions helper
- `node_service/schema.rs` (454 lines): schema queries, task-node ops,
  get_all_schemas, get_schema_with_relationships, check_node_completeness
- `node_service/bulk.rs` (596 lines): bulk_create, bulk_create_hierarchy*,
  bulk_update, bulk_delete
- `node_service/query.rs` (322 lines): query_nodes, query_nodes_simple,
  property filter helpers
- `node_service/embedding.rs` (228 lines): embedding waker + queue methods
  (all behind `#[cfg(feature = "nlp")]`)

Phase 5: `with_execution_context` changed from `pub` to `pub(crate)` — the
only caller (`playbook/actions.rs`) is in the same crate so no call-site
changes needed.

All external callers (daemon, agent, cli, playbook) unchanged — facade keeps
every `pub async fn` with byte-identical signatures.

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

- Rename with_execution_context → scoped_for_playbook with a doc comment
  restricting use to crate::playbook; update the one call site in actions.rs.
  Fully closes the acceptance criterion for the playbook-context concern.
- Update module-level doc comment in mod.rs to reflect its actual role as
  facade + deferred hierarchy + tests (not "Core CRUD Operations").
- Add CompletenessResult to the services::mod.rs re-export; it was pub but
  not exported, leaving check_node_completeness's return type unreachable
  to external callers.
- Fix stale field comment referencing old method name.

Co-Authored-By: Claude <[email protected]>
After rebasing onto main (which merged #1237), propagate the
SQLite-era cleanup into the decomposed sub-modules:

- crud.rs: remove 5×50ms retry loop from create_node_with_parent
  sibling validation; single check is correct under SQLite ACID semantics
- mod.rs (create_parent_edge): remove 10×100ms retry + 20×50ms
  position-verification loops; replace with a single move_node call and
  trust the result (SQLite commits before returning)

No behavior change — these loops were dead code under SQLite as
established by #1237.

Co-Authored-By: Claude <[email protected]>
@malibio
malibio force-pushed the worktree-issue-1238-decompose-nodeservice branch from b340e50 to 9ee928a Compare May 30, 2026 06:36
@malibio
malibio merged commit 7a861f4 into main May 30, 2026
@malibio
malibio deleted the worktree-issue-1238-decompose-nodeservice branch May 30, 2026 06:36
malibio added a commit that referenced this pull request Jun 22, 2026
…legation) (#1240)

* Decompose NodeService god-object into focused sub-modules (closes #1238)

Phases 1-3 and 5 of the decomposition plan. Phase 4 (Hierarchy extraction)
is deferred pending #1237 merge to avoid collision on the retry-loop cleanup.

`packages/core/src/services/node_service.rs` (11,891 lines) split into:

- `node_service/mod.rs` (2,789 lines): struct definition with all fields as
  `pub(crate)`, construction (`new`, `seed_*`), accessors (`store()`,
  `behaviors()`, `with_client`), all hierarchy methods (Phase 4 deferred),
  `NodeAccessor` impl, shared helper fns, all tests unchanged
- `node_service/crud.rs` (2,036 lines): create/get/update/delete + all CRUD
  private helpers (validation, schema defaults, lazy migration, compute_title)
- `node_service/relationship.rs` (910 lines): mention ops + typed relationship
  CRUD + populate_mentions helper
- `node_service/schema.rs` (454 lines): schema queries, task-node ops,
  get_all_schemas, get_schema_with_relationships, check_node_completeness
- `node_service/bulk.rs` (596 lines): bulk_create, bulk_create_hierarchy*,
  bulk_update, bulk_delete
- `node_service/query.rs` (322 lines): query_nodes, query_nodes_simple,
  property filter helpers
- `node_service/embedding.rs` (228 lines): embedding waker + queue methods
  (all behind `#[cfg(feature = "nlp")]`)

Phase 5: `with_execution_context` changed from `pub` to `pub(crate)` — the
only caller (`playbook/actions.rs`) is in the same crate so no call-site
changes needed.

All external callers (daemon, agent, cli, playbook) unchanged — facade keeps
every `pub async fn` with byte-identical signatures.

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

* Address review: rename scoped_for_playbook, fix CompletenessResult, update doc

- Rename with_execution_context → scoped_for_playbook with a doc comment
  restricting use to crate::playbook; update the one call site in actions.rs.
  Fully closes the acceptance criterion for the playbook-context concern.
- Update module-level doc comment in mod.rs to reflect its actual role as
  facade + deferred hierarchy + tests (not "Core CRUD Operations").
- Add CompletenessResult to the services::mod.rs re-export; it was pub but
  not exported, leaving check_node_completeness's return type unreachable
  to external callers.
- Fix stale field comment referencing old method name.

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

* Post-rebase: apply #1237 retry-loop removal to sub-modules

After rebasing onto main (which merged #1237), propagate the
SQLite-era cleanup into the decomposed sub-modules:

- crud.rs: remove 5×50ms retry loop from create_node_with_parent
  sibling validation; single check is correct under SQLite ACID semantics
- mod.rs (create_parent_edge): remove 10×100ms retry + 20×50ms
  position-verification loops; replace with a single move_node call and
  trust the result (SQLite commits before returning)

No behavior change — these loops were dead code under SQLite as
established by #1237.

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.

Decompose NodeService god-object into focused sub-services (facade delegation)

1 participant