Skip to content

impl(011): increment 6, the Node binding's local-embed feature and synthetic conformance parity - #485

Merged
bartekus merged 1 commit into
mainfrom
impl/011-node-local-embed
Nov 4, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/011-node-local-embed

Conversation

@bartekus

@bartekus bartekus commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Spec 011 increment 6 (3.17.1, 3.17.5): the Node binding's optional local-embed feature and synthetic conformance parity. 011 stays implementation: pending; no platform is qualified and nothing joins the release family (release-set.json is unchanged).

What changes

  • integrations/rustev-node: Cargo feature local-embed, off by default, an optional path dependency on rustev-backend-embed-linear with its synthetic feature (a synthetic bundle constructs on any target, A-73; an onnx bundle is still refused unqualified_platform). The package exports LocalEmbedBackend.open(config) (bundle verified off the JavaScript thread), features(), and Engine.create({ localEmbedBackends }), which registers an opened backend like the rules backend. Setup refusals are ConfigRefused with the 011 3.7.2 code and the item; without the feature open rejects feature_disabled. Unknown config members are refused (so embeddingCache is refused until the backend's config takes the cache, 3.14).
  • tools/rustev-conformance: a local_embed case block and runner (src/local_embed.rs) that takes the opened backend as a seam, so the suite never depends on the backend crate. New case local-embed.support-routing: the increment 5 synthetic bundle, four package cases and one blank message (text_empty -> backend_unavailable), judgments and run records compared byte for byte. run.mjs native runs it; on a build without the feature it checks feature_disabled (so every native matrix target checks 3.17.1's negative case), and --local-embed runs the parity.
  • The Rust API side runs in the backend's tests (tests/support_routing/conformance.rs, which also blesses the case), added to make conformance. make bindings builds the binding with the feature last (after platform staging) and runs test/local-embed.test.mjs and run.mjs native --local-embed.
  • Specs: 011 record paragraph and its extends edges for integrations/rustev-node/ and tools/rustev-conformance/ (as 011 section 2 says the feature change declares them); a 027 record bullet (no 027 text change).

Generated, review the source rather than the bytes: tools/rustev-conformance/cases/** (from tests/support_routing/conformance.rs and tests/manifest.rs), tools/rustev-conformance/expected/local-embed/** and fixtures/local-embed/** (same test), .statecraft/derived/**.

Not in this change

  • The binding's build with local-embed on each native matrix target (011 3.2.3, counts toward qualifying a platform) needs a bindings.yml change, which goes in its own pull request with the owner's Environment approval. Here it was built on darwin-arm64 only.
  • The service transports join the case with 011 3.17.3 (rustev-serve local-embed).

Checks run locally (darwin-arm64)

See the follow-up comment for the full list and results.

@bartekus
bartekus force-pushed the impl/011-node-local-embed branch from 9bea9a1 to 3cff723 Compare November 3, 2026 21:14
@bartekus

bartekus commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Local checks on darwin-arm64 at 3cff723:

  • make gate: pass. spec-spine couple against the merge base: OK, 41 paths, no drift.
  • cargo fmt --all --check: pass. cargo clippy -p rustev-node -p rustev-conformance -p rustev-backend-embed-linear --all-targets -D warnings: pass; cargo clippy -p rustev-node --features local-embed --all-targets -D warnings: pass.
  • cargo run -p rustev-boundaries: no violation. cargo tree -p rustev-node -e normal,build: no ort, tokenizers or embed crate without the feature; with it, ort only through rustev-backend-embed-linear, no download feature.
  • cargo test -p rustev-conformance, cargo test -p rustev-backend-embed-linear (46 passed, 1 ignored bless), cargo test -p rustev-node with and without the feature: pass.
  • Release addon without the feature: node --test test/local-embed.test.mjs (4 pass, 4 skipped by design), run.mjs native: 193 cases, 0 failures (the local-embed case checks feature_disabled).
  • Release addon with local-embed: node --test test/local-embed.test.mjs 7 pass; run.mjs native --local-embed: 1 case, 0 failures (byte parity with the Rust API); full run.mjs native: 193 cases, 0 failures.
  • tsc --noEmit --strict on index.d.ts and gen-types.mjs --check: pass.
  • scripts/check-authored-content.sh: clean.
  • spec-spine verify 027, verify 001: passed. verify 011: not declared (011 has no verify:cli block yet; it joins make verify after the gate).
  • The whole make bindings (WebAssembly half) was not run locally; CI's bindings job runs it.

@bartekus

bartekus commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Held until the 0.4.0 candidate commit is cut: merging adds LocalEmbedBackend, features() and localEmbedBackends to the public @rustev/rustev API, and 0.4.0 excludes spec 011. After #480 (0.4.0, every PlanId changes) merges, this branch is rebased and its fixtures re-blessed.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff for bugs, security problems, and inconsistencies.

integrations/rustev-node/src/local_embed.rs

The open function shadows config correctly: the serde_json::Value parameter is consumed into c: Config, then a new EmbedConfig is built and named config, which is moved into spawn_blocking. No issue. The deny_unknown_fields struct rejects unknown configuration members as the spec requires. The spawn_blocking correctly offloads I/O off the JavaScript thread.

integrations/rustev-node/index.js

localEmbedSet validates maxConcurrency in [0, 0xffff_ffff] before casting to u32. Null/non-object configs are caught before the native call. The localEmbedSet(options.localEmbedBackends) argument is inserted in the correct position matching the updated Rust Engine::create signature. settled is a function declaration and is hoisted correctly within nativeAdapter.

integrations/rustev-node/index.d.ts

LocalEmbedBackend's private constructor() aligns with the runtime guard. The features() return type matches the napi Features struct (camelCase conversion by napi). Uint8Array for descriptor matches the getter.

tools/rustev-conformance/src/local_embed.rs

run creates a new_current_thread tokio runtime and uses block_on. It is only called from synchronous #[test] functions so there is no nested-runtime panic risk. Each block_on call correctly drives the backend's async work. The Ack sink accepts both RUN and RUN_V3 schema strings, matching the JS test's acceptsRun3: true.

backends/rustev-backend-embed-linear/tests/support_routing/conformance.rs

contained(&case.bundle) validates the path before repo().join(...), and the BUNDLE constant is a safe relative path. The keep function correctly gates on RUSTEV_BLESS and panics with a clear message when a file is stale. bundle_files reads manifest.json twice (once to parse, once for the content bytes), which is harmless redundancy but not a defect. The mirrors assertions correctly verify that all three semantic steps carry model-derived output and that the blank-message case's requests all fail backend_unavailable with zero-unit cost.

tools/rustev-conformance/js/run.mjs

The --local-embed flag validation correctly restricts the flag to the native surface only. The localEmbedCase function's descriptor comparison adds \n to the backend's Uint8Array before comparing against the fixture (which was stored with line()). The settled helper is correctly shared between the existing runtime-case path and the new local-embed path.

Spec edits

Spec 011 Increment 6 and spec 027 revision notes are consistent with each other and with the code. The extends declarations with nature: additive correctly scope the authority without claiming to amend spec 027's normative text.

No concrete defects found.

{"head": "3cff7239c2736197e3776aae44bfb1c4a2d92a5c", "verdict": "no-findings", "findings": []}

Subject: 2f7b8e6...3cff723, diff digest 93ac2f1837c18b2954204a39f0b5ac9f9e0741896aabba1d815ac86f1baf4fc9, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security issues, and inconsistencies.

Core logic (Rust)

integrations/rustev-node/src/local_embed.rs: the open path under #[cfg(feature = "local-embed")] correctly offloads to spawn_blocking, maps setup errors to ConfigRefused with the 3.7.2 code, and uses deny_unknown_fields on the internal Config struct—unknown members are refused, not silently dropped. No issue.

tools/rustev-conformance/src/local_embed.rs: the run function creates a fresh new_current_thread Tokio runtime. All callers are #[test] (not #[tokio::test]), so no existing runtime is present—correct. The 30-second timeout requires enable_time(), which is set. The Ack sink accepts both RUN and RUN_V3 to match acceptsRun3: true on the JS side. No issue.

JavaScript (index.js / run.mjs)

localEmbedSet synchronously validates the backend handle via WeakMap and validates maxConcurrency bounds before calling into native code. localEmbedCase in run.mjs correctly writes the judgment.json before calling settled (which does not). Sequential for-loop over requests is consistent with the Rust runner and the manual-clock requirement. No issue.

Missing committed artifact

backends/rustev-backend-embed-linear/tests/support_routing/conformance.rs calls keep("cases/local-embed/local-embed.support-routing.json", ...) in every_local_embed_case_produces_its_expected_bytes. In non-bless mode keep reads that file and panics if it is absent. All fixture files the case JSON must reference by SHA-256 (fixtures/local-embed/*.json) are new files in this PR, so the case JSON cannot pre-exist in the base commit with the correct hashes. Yet tools/rustev-conformance/cases/local-embed/local-embed.support-routing.json is not among the PR's changed paths: it was not committed.

Consequence 1: cargo test -p rustev-backend-embed-linear --locked --test bundle support_routing::conformance:: (now part of make conformance) panics at the keep call.

Consequence 2: tools/rustev-conformance/src/lib.rs aggregate() now iterates ["cli", "local-embed", "runtime"]; the comment says "a missing one is an error naming it, never a silently smaller manifest," so cargo test -p rustev-conformance also fails.

{"head": "6666751b6b08f19607447f33f724be67c70dea1f", "verdict": "findings", "findings": [{"path": "backends/rustev-backend-embed-linear/tests/support_routing/conformance.rs", "line": 177, "summary": "The case file tools/rustev-conformance/cases/local-embed/local-embed.support-routing.json is not committed: keep() panics in non-bless mode because every fixture file the case must reference by SHA-256 is new in this PR, so the file cannot pre-exist with correct content, breaking both make conformance and cargo test -p rustev-conformance."}]}

Subject: 5d9923e...6666751, diff digest c7319e4d2eed595223ce3a3cec1d52fc670e6fd6880559bbb5d74ed3c1e649d3, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 4, 2026 02:10 — with GitHub Actions Inactive
@bartekus
bartekus force-pushed the impl/011-node-local-embed branch from 6666751 to 8cc1075 Compare November 4, 2026 03:09
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security problems, and inconsistencies.

Spec / governance changes (specs/011, specs/027): The extends additions in spec 011 correctly use nature: additive for directories owned by spec 027, and the spec 027 changelog correctly attributes the change. No governance violation found.

integrations/rustev-node/src/local_embed.rs: Config uses #[serde(deny_unknown_fields)] as required by spec; unknown members are refused, not silently ignored. bundle_dir validation is delegated to EmbedLinearBackend::open (returns bundle_missing for relative paths). workers: c.workers as usize and max_queued: c.max_queued as usize are within-range casts; out-of-range values are caught by the backend and surfaced as manifest_invalid. The spawn_blocking correctly moves I/O off the JavaScript thread.

integrations/rustev-node/index.js: localEmbedSet correctly uses WeakMap to keep native handles private. The localEmbedBackends[i].backend / maxConcurrency validation is correct. Argument order in the Engine.new napi call now matches the updated Rust signature (local_embed as 4th parameter, after rules).

tools/rustev-conformance/src/local_embed.rs: Sequential blocking per-request execution is correct for a manual-clock conformance runner. The local new_current_thread Tokio runtime is built inside a sync test, so block_on is safe.

Missing committed case file — concrete defect:

tools/rustev-conformance/src/lib.rs now iterates ["cli", "local-embed", "runtime"] in aggregate(), and its inline comment says a missing directory is an error, not a silent gap. The case file this directory must contain — tools/rustev-conformance/cases/local-embed/local-embed.support-routing.json — is generated by the bless path of every_local_embed_case_produces_its_expected_bytes (keep(&format!("cases/local-embed/{ID}.json"), …)), but it is not present in the PR diff. By contrast, every other bless output of the same test (fixtures/local-embed/… and expected/local-embed/…) is in the diff. Without this case file committed:

  1. aggregate() will error when make conformance runs cargo test -p rustev-conformance --locked.
  2. the_manifest_local_embed_cases_pass_through_the_rust_api will either fail at manifest().unwrap() or at assert!(ran >= 1, …).
{"head": "8cc1075033652608d36e8eb2039e6ea8ec4dc724", "verdict": "findings", "findings": [{"path": "tools/rustev-conformance/src/lib.rs", "line": 111, "summary": "aggregate() now iterates 'local-embed' and treats a missing directory as an error, but tools/rustev-conformance/cases/local-embed/local-embed.support-routing.json (generated by the bless path of every_local_embed_case_produces_its_expected_bytes) is absent from the PR, causing cargo test -p rustev-conformance --locked and the manifest test to fail."}]}

Subject: 52dd6b1...8cc1075, diff digest e8dd81a9d07977f0f76ee9deeeffe158fa911909dffb839d456b313c0ba4dcee, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 4, 2026 03:20 — with GitHub Actions Inactive
@bartekus

bartekus commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Review note on 8cc1075: the finding on tools/rustev-conformance/src/lib.rs is a false positive. tools/rustev-conformance/cases/local-embed/local-embed.support-routing.json is in this PR (gh pr diff 485 --name-only lists it); the review does not see it because tools/rustev-conformance/cases is in review.exclude as generated output, checked by the suite's bless check instead. cargo test -p rustev-conformance --locked passes on this head. No change.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security problems, and inconsistencies.

Missing case file

tools/rustev-conformance/src/lib.rs adds "local-embed" to the aggregate() directory scan, which requires tools/rustev-conformance/cases/local-embed/ to exist and be non-empty. The PR commits the fixture files (fixtures/local-embed/) and the expected output files (expected/local-embed/), all of which the keep() function writes in conformance.rs. That same keep() call also writes the case file:

keep(
    &format!("cases/local-embed/{ID}.json"),
    &line(serde_json::to_vec_pretty(&case_file).unwrap()),
);

That path (tools/rustev-conformance/cases/local-embed/local-embed.support-routing.json) is not among the changed paths in this PR. In non-bless CI runs, every_local_embed_case_produces_its_expected_bytes will panic at fs::read(&p).unwrap_or_else(|e| panic!("{rel}: {e}; bless it")), and the_manifest_local_embed_cases_pass_through_the_rust_api will fail at manifest().unwrap() (if aggregate() errors because the directory is absent) or at assert!(ran >= 1, ...) (if the directory exists but is empty).

run creates a Tokio runtime that panics if called from an async context

tools/rustev-conformance/src/local_embed.rs creates a new_current_thread() runtime and immediately calls block_on inside run. Calling block_on while already inside a Tokio runtime panics. The current callers in conformance.rs are synchronous #[test] functions so this doesn't trigger today, but pub fn run(…) has no guard or documentation preventing an async caller, and rustev-conformance is a library crate. This is a latent soundness issue that will surface if any future async test or integration calls local_embed::run.

No other concrete defects found. The JS-layer validation of localEmbedSet, the ConfigRefused mapping, the deny_unknown_fields deserialization, the spawn_blocking placement for the bundle-open I/O, the localEmbedOnly filter in run.mjs, and the authority/provenance claims (model-derived, never authorization) all appear correct.

{"head": "8cc1075033652608d36e8eb2039e6ea8ec4dc724", "verdict": "findings", "findings": [{"path": "backends/rustev-backend-embed-linear/tests/support_routing/conformance.rs", "line": null, "summary": "The case file `tools/rustev-conformance/cases/local-embed/local-embed.support-routing.json` is absent from the PR; `keep()` writes it alongside the committed fixtures and expected outputs, but it is not in the changed paths, so both conformance tests fail in non-bless CI: `every_local_embed_case_produces_its_expected_bytes` panics reading the missing file and `the_manifest_local_embed_cases_pass_through_the_rust_api` fails at `assert!(ran >= 1)`."},{"path": "tools/rustev-conformance/src/local_embed.rs", "line": 109, "summary": "`run` creates a `new_current_thread` Tokio runtime and calls `block_on`, which panics if the caller is already inside a Tokio runtime; the function is `pub` with no guard or documentation against async callers."}]}

Subject: 52dd6b1...8cc1075, diff digest e8dd81a9d07977f0f76ee9deeeffe158fa911909dffb839d456b313c0ba4dcee, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 4, 2026 04:40 — with GitHub Actions Inactive
@bartekus
bartekus force-pushed the impl/011-node-local-embed branch from 8cc1075 to 640dd2f Compare November 4, 2026 04:59
…nthetic conformance parity

rustev-node gains spec 011's optional local-embed feature (3.17.1):
LocalEmbedBackend.open, features() and the localEmbedBackends option of
Engine.create, which registers an opened local backend like the rules
backend. Without the feature open rejects ConfigRefused feature_disabled.
The shared conformance suite gains the local-embed.support-routing case
(3.17.5), compared byte for byte through the Rust API and the native
binding built with the feature; make bindings builds it last.
@bartekus
bartekus force-pushed the impl/011-node-local-embed branch from 640dd2f to d31f55e Compare November 4, 2026 05:00
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff for bugs, security issues, and inconsistencies.

Governance / spec claims

specs/011-semantic-backend/spec.md adds two extends entries claiming additive ownership of integrations/rustev-node/ and tools/rustev-conformance/ against spec 027-node-and-wasm-bindings. Spec 011 is already approved (present in the base derived registry), so the additive claims are well-formed. No issue.

specs/027-node-and-wasm-bindings/spec.md receives a revision note dated 2026-11-03 (no text change). Consistent with the extends / nature: additive pattern. No issue.

integrations/rustev-node/src/local_embed.rs

  • open_local_embed takes serde_json::Value and deserializes to an inner Config struct with #[serde(deny_unknown_fields)]. Unknown fields (e.g. embeddingCache) are refused with out_of_range; the test at line 94 of local-embed.test.mjs confirms this. No silent-ignore risk.
  • Blocking setup (EmbedLinearBackend::open) is correctly moved off the JS thread with spawn_blocking. The await chain is sound.
  • Both #[cfg] branches compile cleanly: the non-feature path returns feature_disabled without touching the unlinked crate.

integrations/rustev-node/index.js

  • localEmbedSet validates maxConcurrency with Number.isInteger and < 0 (negative integers pass Number.isInteger; the separate check is not redundant) and > 0xffff_ffff. Correct.
  • LocalEmbedBackend uses a private Symbol token to prevent direct construction; WeakMap stores the native handle. When a handle is registered on an Engine, LocalEmbedSet::add clones the Arc, so the backend lives as long as the engine regardless of GC pressure on the JS wrapper.
  • localEmbedSet is always passed (never omitted) in the Engine.new call; the new local_embed parameter is last and Option<&…>, so existing callers that predated it (e.g. the spec-049 JS test, which goes through Engine.create) are unaffected.

tools/rustev-conformance/src/local_embed.rs

  • run() creates a new_current_thread Tokio runtime. Called only from synchronous #[test] functions; no risk of nested-runtime panic.
  • The 30-second timeout on each rt.decide prevents hangs.
  • descriptors.contains(backend.descriptor()) guards against a mismatched plan/backend at the seam boundary.

tools/rustev-conformance/js/run.mjs

  • The realpathSync(join(root, le.bundle)) call canonicalises the bundle path before handing it to the native binding, which requires an absolute path. Relative paths would fail realpathSync before reaching the backend.
  • In localEmbedCase, settled is reused for SinkFailure / rejection handling, consistent with the existing runtimeCase. Judgment bytes are written only when d.ok?.raw.judgment is truthy (judged completion), matching the Rust runner.
  • --local-embed is accepted only with native; the guard (flag !== undefined && !(localEmbedOnly && surface === 'native')) is correct.

backends/rustev-backend-embed-linear/tests/support_routing/conformance.rs

  • keep() constructs paths from fixed constants (SUITE, ID, CASES, BLANK) plus fixture-map keys set in the same file. No path-traversal risk.
  • The double-run assertion (assert_eq!(run(…), out) a second time) soundly checks bitwise repeatability of the synthetic encoder (spec 3.19.1).
  • mirrors() asserts that every package case has three model-derived requests with non-zero charges, and that the blank-message case has BackendUnavailable with zero charge on all requests. These are meaningful invariants, not vacuous.

Security / principle-VI conformance

The local_embed.rs comment states the backend supplies model-derived logits, not authorization. LocalEmbedHandle and LocalEmbedSet carry no Permitted type or authorization surface. Consistent with constitution principle VI.

No concrete defects found.

{"head": "d31f55eaa532767c7aa3b77a92eea71612fefa6c", "verdict": "no-findings", "findings": []}

Subject: 52dd6b1...d31f55e, diff digest 99066c201f6f16c024013cbf091caaa8ff11ed231e0d29f6018d97e707af7753, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit d2f054b Nov 4, 2026
63 of 66 checks passed
@bartekus
bartekus deleted the impl/011-node-local-embed branch November 4, 2026 06:19
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