Skip to content

Take the daemon's supported extension ids from build_shared_services - #3624

Merged
mstomar125 merged 3 commits into
mainfrom
issue-3414-supported-extension-ids
Oct 5, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-3414-supported-extension-ids

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Part of #3414 (the "Typed subtypes and edge fields" section, ADR-082 §2 and §5). This is the first of three PRs. The next ones add subtype behaviours and edge fields to the same DaemonExtensions value.

What changes

build_shared_services now takes a DaemonExtensions value. This replaces the open guard's fixed, empty supported set (ADR-083 §2) with a hook a composing build fills in.

  • DaemonExtensions (packages/daemon/src/services/extensions.rs):

    • none();
    • supported_extension(id);
    • supported_extensions();
    • check().

    DaemonExtensions::none() is core's daemon, and the four nodespaced entry points pass it.

  • SharedContext::extensions carries the value and replaces the #[cfg(test)] field. The guard in unsupported_required_extensions reads it, so every open checks it: get_or_open, the boot default, and create.

  • Startup check. build_shared_services checks the value first, before it reads settings or resolves the model, and returns DaemonExtensionsError to stop startup.

    • An id must be a lowercase ASCII letter followed by lowercase letters, digits, - or _.
    • The rule is nodespace_core::extensions::is_extension_id, which lives in core because the edge-field PR names edge-property buckets with the same ids.
  • Comments. extension_names.rs no longer says the build "supports none" unconditionally.

With DaemonExtensions::none(), behaviour is unchanged: the supported set is empty, exactly as the non-test branch of the removed supported_extensions() returned.

Acceptance mapping (#3414, typed subtypes and edge fields)

  • build_shared_services takes the supported extension ids, replacing the step-3 guard's fixed empty set. A database that lists a supported id opens.
  • Core fixture: a marked database opens with a supported id (extension_points_fixture::a_database_requiring_a_supported_extension_opens).

Tests

packages/daemon/tests/it/extension_points_fixture.rs is new and added to WATCHED_PATHS. It drives the hook through build_shared_services itself.

  • Each test points NODESPACE_HOME at a temp dir and NODESPACED_MODEL_PATH at a file that does not exist. No test reads the user's state or loads a model, even under a mutant that skips the check.
  • a_database_requiring_a_supported_extension_opens: ["fixture"] opens, and ["fixture","other"] is refused for other alone.
  • core_refuses_a_database_requiring_any_extension: DaemonExtensions::none() refuses ["fixture"].
  • an_invalid_extension_id_stops_startup.

Unit tests:

  • services::extensions::tests::check_rejects_the_first_invalid_supported_id;
  • nodespace_core::extensions::tests::an_extension_id_is_….

The existing required_extensions_tests now build their contexts through DaemonExtensions::supported_extension.

Mutation check. Every new test was checked against at least one mutant, and all 10 mutants were killed:

Mutant Killed by
build_shared_services stores none() instead of the caller's value a_database_requiring_a_supported_extension_opens
startup check removed an_invalid_extension_id_stops_startup
guard ignores the supported set a_database_requiring_…_opens
guard refuses nothing core_refuses_…, a_database_requiring_…_opens
check() accepts every id check_rejects_…, an_invalid_extension_id_stops_startup
check() looks at only the first id check_rejects_…
id may start with any character an_extension_id_is_… (daemon, then again after the move to core)
id tail unchecked an_extension_id_is_… (daemon, then again after the move to core)

Local runs (crate-scoped, under the machine slot):

  • cargo clippy -p nodespace-core -p nodespace-daemon -p nodespace-cli -p nodespace-proto --all-targets -- -D warnings -D clippy::unused-async;
  • cargo nextest run -p nodespace-daemon extension_points_fixture required_extensions services::extensions: 11/11 pass;
  • cargo nextest run -p nodespace-core --lib extensions:: required_extensions: 16/16 pass;
  • cargo fmt --check, check-pro-boundary, check-node-type-literals, check-extension-api-version, and bun test scripts/check-extension-api-version.test.ts (30/30);
  • the src/tests/extension-api Vitest suite: 47/47.

Extension API

2.3 → 2.4 (minor). This adds a daemon hook (ADR-082 §8: a new hook is minor).

  • Add nodes.updateNode to the host API and resolve subtype viewers through isA #3622 took 2.3 on main while this PR was open, so the bump is on top of it. That bump is the separate commit 657470c0.
  • The bump touches the Rust constant, its pin in app-lib/src/extensions/fixture_tests.rs, the TypeScript constant, and the re-recorded surface snapshot. Only version changed there.
  • The new daemon fixture is added to WATCHED_PATHS, and the script's test expects it.
  • Breaking for a caller of build_shared_services(): it now takes an argument, so pass DaemonExtensions::none(). SharedContext has a new required field, extensions. ADR-082 §5 lists both as unversioned library API.

Repo-wide checks after rebasing onto #3622:

  • bun test scripts/: 1441/1441;
  • the full frontend suite: 5875/5875 across 322 files;
  • the src/tests/extension-api suite: 50/50.

Documentation

Companion docs PR: NodeSpaceAI/nodespace-docs#109, branch issue-3414-typed-subtypes (architecture/extension-points.md). It adds a Daemon section, the startup-refusal row, the watched fixture and version 2.3, and narrows the "Not built yet" item. It grows with the next two PRs.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review: PR #3624

Review Type: Initial Review. There were no earlier reviews or comments, and the PR is one commit (937dc7e8).
Depth: Medium. Covers correctness, the shape of the extension-point API, test isolation, and versioning under ADR-082 §8.
Method: Read-only. Nothing was built or run.

Code Review Summary

This is a small, well-targeted change and a clear net positive. It replaces the #[cfg(test)]-split supported set with one DaemonExtensions value, passed from build_shared_services into SharedContext. Test builds and production builds now run the same guard code.

  • Behaviour with DaemonExtensions::none() is unchanged. The supported set is empty, exactly as the removed non-test branch returned &[]. Every production caller passes none(): the four nodespaced entry points in main.rs.
  • Every path honours the declared set. The guard has a single call site, unsupported_required_extensions (assembly.rs:175). Both build_database_services and the registry listing (database_manager.rs:480) read it, so open, the boot default, create and list all apply the declared set.
  • Versioning matches ADR-082 §8, both the bump and the WATCHED_PATHS change.

There are no blockers. Three cheap improvements are worth making before the follow-up PRs grow this type.

Requirements Check

These are the parts of #3414's "Typed subtypes and edge fields" section that this PR claims.

Criterion Status Evidence
build_shared_services takes the supported extension ids, replacing the step-3 guard's fixed empty set ✅ assembly.rs:297-300 takes and checks the value. SharedContext::extensions (assembly.rs:92) carries it, and the guard reads it at assembly.rs:181.
A database that lists a supported id opens ✅ extension_points_fixture::a_database_requiring_a_supported_extension_opens
Core fixture: a marked database opens with a supported id (ADR-082 §9, "a fixture for each row of §5") ✅ The same test, driven through the public build_shared_services and DatabaseManager
Behaviour unchanged with DaemonExtensions::none() ✅ An empty Vec gives the same filter result as the removed &[]. core_refuses_a_database_requiring_any_extension pins this.
A new hook is a minor version bump (ADR-082 §8) ✅ 2.2 → 2.3 in Rust, TypeScript, the pin test and the surface snapshot. ADR-082 §5 (last paragraph) calls build_shared_services and SharedContext "core library API that is not an extension point", so changing their signatures does not force a major bump. BaseServices is untouched.
The new fixture is added to WATCHED_PATHS in the same change ✅ check-extension-api-version.ts and its test
Subtype behaviours, edge fields — Deliberately left to the follow-up PRs, so not counted here

Project rules (CLAUDE.md): all met.

  • ✅ No issue numbers in code comments.
  • ✅ No Pro wording outside extension_names.rs.
  • ✅ No compatibility shim. The cfg(test) field is deleted rather than kept alongside the new one.

Test isolation (env vars under nextest): safe when run the way the repo runs it.

  • Nextest runs each test in its own process.
  • IsolatedDaemonHome points NODESPACED_MODEL_PATH at a missing file before build_shared_services runs.
  • resolve_model_path (assembly.rs:741) returns None when the explicit path is missing. It does not fall back to <home>/.nodespace/models.
  • So no test here can load a model, even under a mutant that skips check().
  • rust:test:workspace, test:changed and the merge gate all use nextest. The new doctests (cargo test --doc) do not touch the environment.

One caveat applies to plain cargo test; see finding 2.

Findings

Critical Issues

None.

Suggested Improvements

🟡 1. Mark DaemonExtensionsError #[non_exhaustive] now
📁 packages/daemon/src/services/extensions.rs:69-70

New variants are already planned:

  • The PR body says the next two PRs add subtype behaviours and edge fields to this same value.
  • ADR-082 §2.1 requires startup to reject "a behaviour registered for a type core already defines".

As written, this is a public, exhaustive enum, and the watched fixture names its variant. Adding a variant later breaks any exhaustive match in the composing build. Under §8 that should be a major bump, yet each follow-up will want a minor one.

#[non_exhaustive] makes each new variant purely additive. The repo already uses it for this reason: WriteVerificationFault in packages/core/src/services/node_service/mod.rs:1443-1446. It is a one-line change, and much cheaper now than after nodespace-sync has written a match against the enum.

Principle: Open/Closed. Design a versioned error type for growth you already know is coming.

🟡 2. Make IsolatedDaemonHome safe when tests share a process
📁 packages/daemon/tests/it/extension_points_fixture.rs:31-66

This is fine under nextest. Under plain cargo test -p nodespace-daemon --test it, though, the three tests share one process and run on parallel threads. The race goes like this:

  1. Test A's Drop restores NODESPACE_HOME and NODESPACED_MODEL_PATH to their original values, which on a developer machine are usually unset.
  2. This can land after test B's IsolatedDaemonHome::new() but before B reaches resolve_model_path().
  3. B then resolves dirs::home_dir()/.nodespace/models/nomic-embed-text-v1.5.Q8_0.gguf, which exists on a development machine.
  4. build_shared_services spawns the real model load. B's model_task.is_none() assertion only fails after the load has already started.

The model-path window is narrow, because it is the synchronous start of build_shared_services, but it is real. The wider exposure is the rest of each test: build_database_services resolves nodespace_dir()/daemon.toml on every open (assembly.rs:495, assembly.rs:644). A restore that lands mid-test points those resolutions at the user's real home.

The precedent, resolve_with in assembly.rs, holds the variables for one synchronous call. This guard holds them across a whole async test.

Fix (a few lines): inside IsolatedDaemonHome, take a guard on a process-wide static ENV_LOCK: std::sync::Mutex<()>. Make it poison-tolerant with .lock().unwrap_or_else(PoisonError::into_inner). This serializes these tests when they share a process and costs nothing under nextest.

Principle: defensive test isolation. "No test can load the real model" should not depend on which runner is used when making it unconditional is this cheap.

🟡 3. Exercise the hook's whole public surface in the watched fixture, or make it smaller
📁 packages/daemon/tests/it/extension_points_fixture.rs (against packages/daemon/src/services/extensions.rs:47,56)

ADR-082 §8 relies on fixtures that "use every Rust extension point with its full signature", so that a rename or retype trips the version gate.

Used by the fixture Not used by the fixture
none() DaemonExtensions::check()
supported_extension() supported_extensions()
build_shared_services() reading SharedContext::extensions
DaemonExtensionsError::InvalidExtensionId

Both unused methods are pub and documented for callers ("Checks everything this value adds, as the daemon does at startup"). Renaming check() would change no watched file, so the gate would let through a change that silently breaks nodespace-sync.

Either fix closes the gap:

  • add a short fixture test that calls check() and reads shared.context.extensions.supported_extensions(); or
  • make whichever of the two is not meant for composing builds pub(crate).

Principle: the version gate only protects what the fixtures exercise.

Nitpicks

🟢 Nit: duplicate ids in the supported list
📁 packages/daemon/src/services/extensions.rs:39-41
The doc says "Declaring an id twice is the same as declaring it once". That holds for the guard, but supported_extensions() returns the id twice. Pushing an id only when it is not already present makes the accessor match the doc. read_required_extensions already removes duplicates on its side.

🟢 Nit: duplicated helper
📁 extension_points_fixture.rs:80 duplicates database_requiring from required_extensions_e2e.rs:53
The copy drops the original's assertion that the fixture closed cleanly (no -wal file). Both modules live in the same it binary. Keeping the watched fixture self-contained is a fair reason not to share the helper. If you keep the copy, consider keeping the WAL assertion too so the two cannot drift apart in meaning.

🟢 Suggestion for the follow-up PRs: reserve core's edge keys in the bucket-name rule
📁 packages/core/src/extensions.rs:16
is_extension_id lives in core so the edge-field PR can reuse it to name the properties.<id>.* bucket. Under ADR-083 §2, core stores order as a bare key on has_child and member_of, and stores schema-declared edgeFields as bare keys too. is_extension_id("order") returns true. So edge-field registration, or this predicate, will need to reject an id that collides with a core edge key. This is not an issue in this PR.

🟢 Suggestion for later: where the version constant lives
EXTENSION_API_VERSION is defined in nodespace-app-lib (app-lib/src/extensions/mod.rs:52), and nodespace-daemon does not depend on app-lib. Now that a daemon hook is versioned, a daemon-only consumer can only check the version by linking the Tauri library. ADR-082 §8's single core pin means this is not a correctness gap today.

If the Pro daemon crate wants its own compile-time check, consider moving the constant to a crate both already depend on, such as nodespace-proto, and re-exporting it from app-lib. That would also mean updating RUST_VERSION_FILE in the check script.

Recommendation

APPROVE. The change is correct, minimal, and a clear improvement: the test-only split in the guard is gone, and the hook matches ADR-082 §5 and §8 and ADR-083 §2.

Findings 1–3 do not block merging, and all are cheap. Finding 1 is worth doing in this PR, before the follow-ups add variants.

As the PR body notes, coordinate the 2.3 bump with #3622: whichever lands second bumps to 2.4.


Automated pragmatic code review (medium depth). Read-only: nothing was built or run.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125
mstomar125 force-pushed the issue-3414-supported-extension-ids branch from 1d293d0 to 26f9fcb Compare October 5, 2026 13:53
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address review (round 1)

I addressed the APPROVE review's three 🟡 findings and two of its nits in 26f9fcbd. The branch is also rebased onto main after #3618 and #3621. There were no conflicts, and clippy and the tests are green again.

✅ Addressed

  • 🟡 DaemonExtensionsError is now #[non_exhaustive], so the next PRs' refusal variants are minor changes.

  • 🟡 IsolatedDaemonHome holds a process-wide static ENVIRONMENT: Mutex<()> that tolerates poisoning. Tests sharing one process (plain cargo test) take turns with NODESPACE_HOME and NODESPACED_MODEL_PATH, so none can resolve the real model path while another restores the environment.

  • 🟡 The watched fixture now exercises the public surface:

    • DaemonExtensions::check(), both directly and through the startup refusal;
    • supported_extensions();
    • SharedContext::extensions, asserted equal to the declared ids after build_shared_services.

    A rename of any of these now trips the version gate.

  • Nit: supported_extension keeps one entry per id, matching its doc. New test: declaring_an_id_twice_declares_it_once.

  • Nit: the fixture's database_requiring again asserts the database closed cleanly (no -wal).

⏭️ Deferred

  • Nit: is_extension_id("order") is true. It is not a problem for supported ids, and the edge-field PR rejects order as a bucket id, since it is core's key on member_of.
  • Nit: moving EXTENSION_API_VERSION out of app-lib so a daemon-only consumer can read it. That is out of scope here. The version-check script already watches the daemon fixture, so the gate holds. It could be a follow-up if a daemon-only build appears.

Mutation check of the new and changed assertions

  • Keeping duplicates is caught by declaring_an_id_twice_declares_it_once.
  • build_shared_services dropping the caller's value is still caught by a_database_requiring_a_supported_extension_opens.

Local runs after the rebase

  • cargo clippy -p nodespace-core -p nodespace-daemon -p nodespace-cli --all-targets -D warnings: clean.
  • Daemon extension_points_fixture / required_extensions / services::extensions: 12/12.
  • Core extensions::: 16/16.
  • fmt, Pro boundary and the extension-API version check: all pass.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The changes are an attribute, a three-line dedupe and test-only hardening. They are low-risk and add no new design.

🤖 Generated with Claude Code

mstomar125 and others added 3 commits October 5, 2026 16:52
build_shared_services takes a DaemonExtensions value. Its
supported_extension(id) declares an extension id the daemon supports, so a
database whose settings node lists that id in required_extensions opens.
DaemonExtensions::none() is core's own daemon and supports none, as before.

- SharedContext carries the value as `extensions`, replacing the test-only
  supported set; the open guard reads it.
- build_shared_services checks the value before it builds or reads anything,
  and refuses an id that is not a lowercase letter followed by lowercase
  letters, digits, '-' or '_'. The rule is nodespace_core::extensions::
  is_extension_id.
- A fixture in the daemon's integration tests drives the hook through
  build_shared_services with an isolated home and no embedding model; it is
  added to WATCHED_PATHS.
- EXTENSION_API_VERSION 2.3: a new daemon hook (minor).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- DaemonExtensionsError is non_exhaustive, so a later hook can add a way to
  be refused as a minor change.
- supported_extension keeps one entry per id, as its doc says.
- The fixture's environment guard holds a process-wide lock, so tests that
  share a process (plain cargo test) cannot resolve the model path from an
  environment another test is restoring.
- The fixture checks DaemonExtensions::check, supported_extensions and
  SharedContext::extensions, and that a marked database closed cleanly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main reached 2.3 with the host API's nodes.updateNode, which took the minor
this change first claimed. The daemon hook is a further minor change.

Co-Authored-By: Claude Opus 5.5 <[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.

1 participant