Skip to content

impl(063): increment 4a, the store seam and plan.invalidate in the Node binding - #524

Merged
bartekus merged 9 commits into
mainfrom
impl/063-store
Nov 6, 2026
Merged

bartekus merged 9 commits into
mainfrom
impl/063-store

Conversation

@bartekus

@bartekus bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Spec 063 increment 4, part a (3.4, 3.6): the store seam and plan.invalidate in the Node binding, with the three runtime.store-* conformance cases. Stacked on #519 (increment 3, which brings the shared callback machinery); review only the commits after it. Part b (host-seam tests and the Valkey-shaped double) is stacked on this one. It is split out to keep each PR under about 1,500 changed lines excluding generated files.

  • The seam, src/store.rs. EngineOptions.store installs the host store through RuntimeBuilder::store.
    • Contract. Parsed as the closed StoreContract: nine non-empty strings, or ConfigRefused invalid_store_contract, before any thread. prepare keeps store_missing and store_contract_mismatch.
    • Calls. Each method runs through src/callback.rs (3.4): non-blocking threadsafe function, one-shot reply, queue slot released when the runtime stops waiting, abandonedPending and late-discard counting.
    • Decision calls. The runtime bounds them by the decision deadline and cancellation, and the raised signal is forwarded to the host as an abort.
    • Bounded answers (3.6.3). Generations, counts and budgets must be safe integers. get bytes may be at most 4 MiB (RECORD_V1), and a put answer must be one of its four words. Anything else is a StoreFailure under the plan's on_store_failure, never a hit. So are a throw, a full queue (host_seam_queue_full), a deadline, a cancellation and a late settlement.
  • plan.invalidate({ principalHandle?, timeoutMs? }) calls Runtime::invalidate, which invalidates the memory tiers, then the store.
    • Timeout. The store call has no decision deadline, so timeoutMs (1 to 600,000, default 30,000) bounds it on the engine's clock, passed through a task-local scoped to that call. At the timeout the host signal is aborted and the slot released.
    • Result. A failed or timed-out store call resolves persistent: 'pending', complete: false; it is not an exception. A plan without an optimization namespace resolves null.
  • Gauges. gauges().seams gains store with abandonedPending; shutdown's abandonedPending includes it.
  • Declarations by hand: RuntimeStore, StoreCall, Generations, InvalidationResult, EngineOptions.store, PlanHandle.invalidate.
  • Edits to shared files are additions only: a trailing optional store argument on Engine.create, and the store installed in the runtime builder.
  • Conformance (3.13.2). Both runners gain a scripted store (src/store.rs, scriptedStore in run.mjs). The script declares per-decision failures, restarts (a new runtime or engine over the same store) and invalidations before a decision; the invalidation result is an output, <decision>.invalidation.json. Store cases run their requests in order, each to its end. There are no new driver steps, so the serve runner's exhaustive match is untouched. Fixtures are in fixtures/store/. Three cases run on rust-api and native with identical bytes, each expected record checked against its mirrored test:
    • runtime.store-restart-hit: cold misses, then a restarted engine hits with age_ms 1000 and the cold attempt as source, then an advanced generation misses with generation_advanced.
    • runtime.store-failure-policy: fail_closed read failure refused, no dispatch; execute_independent and continue_without_cache miss; a write failure keeps the output.
    • runtime.store-invalidation: a failed store invalidation leaves the selection pending and unavailable; a later one completes {generation 1, removed 3}; then a miss and rewrite, then a hit.
  • Differences from the mirrored tests, recorded in the spec:
    • The restart case advances the generation through plan.invalidate on a restarted engine with entries kept, not by editing the store.
    • The invalidation case starts from a failed Runtime::invalidate, since invalidate_plan has no Node equivalent.
    • Call counts that the outputs do not show are not compared.
  • Spec 063: the implementation record gains increment 4.

Checks run locally on this branch: make gate; cargo build --workspace --locked; cargo test -p rustev-node -p rustev-conformance --locked; clippy on both with -D warnings; cargo fmt --all --check; the release addon, copy-addon.mjs, tsc --noEmit --strict on index.d.ts; node --test integrations/rustev-node/test/*.test.mjs; run.mjs native.

@bartekus bartekus added the m5 Opened by the M5 worker; M1 arms label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

AI review (findings)

Looking at the diff, I'll focus on the new integrations/rustev-node/src/store.rs file, the JavaScript seam, the spec update, and the conformance infrastructure.

Key observations:

1. Unused import at end of store.rs

integrations/rustev-node/src/store.rs ends with:

use std::future::Future;

at module scope (line ~368, after the closing brace of invalidation_json). Future is nowhere directly referenced in this file: BoxFuture comes from rustev_core::seams::BoxFuture (already imported), poll_fn is called as std::future::poll_fn(...) by path, and .await does not require the trait in scope. Under clippy -D warnings (which make code enforces), an unused import is an error. This would break ci-gate.

2. abort.armed not cleared on callback failure

In call():

if r.is_ok() {
    abort.armed = false;
}

When pending resolves with Err (the JS callback itself threw or rejected), the host has already settled and there is nothing to abort. The drop fires the abort signal spuriously. The host ignores it (the signal is already past), so there is no data corruption, but it is a wasted cross-thread call on every host-side error. Low severity / no incorrect output.

3. expires_ms cast without number() saturation

In put():

js.expires_ms = Some(terms.expires.as_ms() as f64);

All other u64 → f64 conversions in this file go through number() which saturates at MAX_SAFE. This one does not. For expiry timestamps derived from large absolute times the cast could silently lose precision before the value reaches JavaScript. The TTLs in the test fixtures are small, so the existing conformance output is unaffected; a host that inspects expiresMs for very distant expiries could receive an imprecise value. Low severity.

Primary finding worth flagging:

The unused import is the only defect the supplied evidence concretely supports as a CI-breaking regression.

{"head": "8a05904a48bf7a679df1fd84f4f24e4912810c73", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/store.rs", "line": 368, "severity": "medium", "category": "correctness", "summary": "Unused `use std::future::Future;` at module scope will be flagged by `clippy -D warnings`, causing `make code` and `ci-gate` to fail."}]}

Subject: 5e6a223...8a05904, diff digest 10ffc3f2cb34fc37dc78fd5fd4c6ab8ef29e0b270c2ae50de949b51e650d64c7, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 6, 2026 01:37 — with GitHub Actions Inactive
bartekus added a commit that referenced this pull request Nov 6, 2026
…aborted

Only a call left unsettled at a timeout or cancellation aborts its host
signal (AI review on #524).
@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Review note: observation 2 is fixed in the latest commit: any settlement, resolved or rejected, now disarms the abort, and only a call left unsettled at a timeout or cancellation aborts its host signal.

The flagged finding (1) is a false positive. use std::future::Future; is used: t.as_mut().poll(cx) on the timer (a Pin<Box<dyn Future>>) needs the trait in scope. cargo clippy -p rustev-node --all-targets --locked -- -D warnings passes on this branch, and removing the import fails to compile with "no method named poll". seams.rs and source.rs use the same pattern.

Observation 3 is not a defect. expires is a Timestamp, bounded by MAX_TIMESTAMP_MS (year 9999, about 2.5e14 ms), which is far below 2^53, so as f64 is exact. number() saturates the u64 budgets and generations, which have no such bound.

@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Correction to my review note above: finding 1 was right that the import is redundant. Future is in the Rust 2024 prelude, so the build passes without it; I was wrong to say removing it fails to compile. It is removed in the latest commit. Clippy did not flag it, so it would not have broken ci-gate, but it is gone. Observations 2 (fixed) and 3 (not a defect) stand as written.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security problems, and inconsistencies across the Node.js store seam (spec 063 increment 4).

JS/TS layer (index.d.ts, index.js)

The types and seam wiring are consistent. storeSeam correctly maps JS → Rust field names (camelCase ↔ snake_case via napi-rs conventions). The bytesOrNull and safe-integer boundary checks in Rust cover the cases the JS layer could violate. The delete stub returning {} and .map(|_| ()) on the Rust side is correct.

Rust store.rs

The call() function's timeout/cancel/abort logic is sound: AbortOnDrop fires on drop when armed, the poll_fn disarms it on successful settlement, and INVALIDATE_TIMEOUT_MS is correctly scoped to the spawned task via task_local!. The safe() integer bounds check is correct — MAX_SAFE as f64 = 9007199254740991.0 is exactly representable. The number() saturation is used consistently for all u64→f64 casts going to JS except one (see finding below).

src/lib.rs — doc comment placement

The new invalidate function is inserted immediately before decide. In Rust, all contiguous /// lines before an item attach to that item. The diff shows three unchanged context lines (the tail of decide's original doc comment: "completion), the run record and the delivery…this promise only awaits it.") immediately preceding the new invalidate-specific /// lines, with no blank line separator. The result is that invalidate acquires "completion), the run record and the delivery; an unresolved outcome is a value, never a rejection. The decision runs on the engine's own runtime; this promise only awaits it. plan.invalidate (063 3.6.4)…" as its full doc comment — text from two different functions conflated — while decide loses those trailing lines from its own doc.

store.rs — expires_ms saturation

js.expires_ms = Some(terms.expires.as_ms() as f64) uses a bare as f64 cast, while every other u64→f64 conversion in the same put method uses number() (which saturates at MAX_SAFE). For realistic expiry timestamps the values fit comfortably within safe-integer range, so no precision is lost in practice, but the inconsistency is a latent defect.

Conformance scripts

The JS JSON.stringify insertion order (complete, generation, persistent, removedBytes, removedEntries) matches the Rust serde_json BTreeMap alphabetical order, so both runners produce byte-identical output. The scriptedStore in run.mjs and ScriptedStore in src/store.rs implement equivalent generation semantics (namespace + scope generation tracking, conditional put-if-absent, scope-scoped invalidation). The \u0000 separator in JS keys is safe given opaque, Rustev-derived namespace/keyId strings.

Spec document

The specs/063-node-binding-parity/spec.md change adds an increment note dated 2026-11-06. The frontmatter is not shown in the diff; lifecycle fields are not visible here and are enforced elsewhere.

{"head": "5638821bcff82ea6197231f33af663d9416c37ad", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/lib.rs", "line": 881, "severity": "low", "category": "correctness", "summary": "The new `invalidate` function's doc comment inherits the trailing lines of `decide`'s doc comment because all contiguous `///` lines before the `#[napi]` attribute attach to `invalidate`, producing a misleading combined comment and stripping those lines from `decide`'s doc."}, {"path": "integrations/rustev-node/src/store.rs", "line": 253, "severity": "low", "category": "correctness", "summary": "`js.expires_ms` is set with a bare `as f64` cast (`terms.expires.as_ms() as f64`) rather than the `number()` saturation helper used for every other u64→f64 field in the same `put` method, creating an inconsistency that would silently lose precision for expiry values exceeding 2^53 ms."}]}

Subject: 5e6a223...5638821, diff digest a3a2314f5fe3a54d8a37b7bcbd24a6b8110500bcc32773830c0afca242d4ba45, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 6, 2026 01:47 — with GitHub Actions Inactive
bartekus added a commit that referenced this pull request Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing this PR, which implements spec 063 increment 4: the host RuntimeStore seam and plan.invalidate for the Node.js binding, plus matching conformance cases.

Code paths examined:

  • integrations/rustev-node/index.d.ts — TypeScript API surface
  • integrations/rustev-node/index.js — storeSeam, scriptedStore, PlanHandle.invalidate
  • integrations/rustev-node/src/store.rs — HostStore, StoreCallJs, abort handling, timeout logic
  • tools/rustev-conformance/src/store.rs — ScriptedStore, invalidation_bytes
  • tools/rustev-conformance/js/run.mjs — storeCaseWith, scriptedStore
  • tools/rustev-conformance/tests/runtime.rs — case generation and byte comparison

No high-severity or medium-severity defects found. Specific checks:

  • Abort-on-drop wiring: AbortOnDrop.armed is cleared on settlement; it fires on timeout/cancel drop. Correct.
  • Timeout scoping: INVALIDATE_TIMEOUT_MS task-local is set for the duration of runtime.invalidate and read by HostStore::call only when call.remaining_ms is None. Correct.
  • safe() / number() guards: generation, count, and budget values are saturated/validated at MAX_SAFE = 2^53 − 1. Correct.
  • Byte limit: 4 MiB check on get response exits before to_vec(). Correct.
  • put answer validation: StoreFailure on unknown answer strings. Correct.
  • JSON key ordering: invalidation_bytes uses serde_json BTreeMap (alphabetic), JS JSON.stringify uses insertion order complete, generation, persistent, removedBytes, removedEntries — these match, so byte outputs agree between runners. Correct.
  • Sequential execution in store cases: Rust uses until("the decision's end", ...), JS uses await plan.decide(...). Consistent.
  • scriptedStore.invalidate scope removal: JS checks k.startsWith(namespace + '\0') and e.scope === selector.scope; Rust retains n != namespace || sc != scope. Logically equivalent. Correct.

One low-severity finding:

index.d.ts declares traceparent?: string on StoreCall (line ~135), but storeSeam in index.js never populates it and StoreCallJs in Rust has no corresponding field. Host stores can never observe a traceparent even when one exists on the decision context. The optional marker makes this type-consistent, but it means the tracing integration promised by the type is silently absent.

{"head": "e85ffcf6272bda69ee2716ff0a5e662a115c3275", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/index.d.ts", "line": 135, "severity": "low", "category": "correctness", "summary": "StoreCall.traceparent is declared optional in the TypeScript interface but is never populated by storeSeam or present in StoreCallJs; host stores can never receive a traceparent for distributed tracing even when a decision context carries one."}]}

Subject: 5e6a223...e85ffcf, diff digest d6ce5634a4abfdb100e58141ca421dfd9fc0120b77d4a1dcd68a3feaedc2c44e, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 6, 2026 01:55 — with GitHub Actions Inactive
@bartekus
bartekus force-pushed the impl/063-acquisition branch from 5e6a223 to 7ee17b8 Compare November 6, 2026 01:56
bartekus added a commit that referenced this pull request Nov 6, 2026
…aborted

Only a call left unsettled at a timeout or cancellation aborts its host
signal (AI review on #524).
bartekus added a commit that referenced this pull request Nov 6, 2026
@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Review note: the StoreCall.traceparent finding is a known limitation, not a defect. Spec 063 3.6 declares it optional, but rustev_runtime::StoreCall (the call the runtime makes for a decision) carries only remaining_ms and cancel: no decision id, so the binding has no trace context to look up (sources get one through CallContext.trace_id). Passing a traceparent to the store would need a runtime change, which is out of this increment's territory. The declaration stays optional and is never set.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

AI review (findings)

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

integrations/rustev-node/index.d.ts
The new StoreCall interface declares traceparent?: string (line ~137 in the added block), but neither StoreCallJs in src/store.rs nor the base object constructed in storeSeam's method wrapper ({ remainingMs: ..., signal }) ever populates this field. Hosts will always receive undefined for traceparent. Since the field is optional the runtime still functions correctly, but the declaration implies a value the runtime never provides, which is misleading to implementors.

integrations/rustev-node/src/store.rs

  • blank() correctly omits traceparent (not in StoreCallJs), consistent with the never-populated declaration above.
  • The call() method's poll_fn polls pending, then timer, then signal in that order and disarms AbortOnDrop on settlement. The timer/cancellation paths leave abort.armed = true so the host signal is raised on drop. This is correct.
  • safe() bounds generation/count answers to MAX_SAFE, number() saturates at MAX_SAFE before sending to the host: safe integer round-trip is maintained. ✓
  • INVALIDATE_TIMEOUT_MS task-local is only set by plan.invalidate; a store call that has no remaining_ms and is not in an invalidate path gets timeout = None (no deadline). The only code path that produces a store call without remaining_ms is plan.invalidate, which always sets the task-local first. ✓

integrations/rustev-node/index.js

  • storeSeam put reconstructs terms.generations from c.namespaceGeneration/c.scopeGeneration before passing them to the host. ✓
  • bytesOrNull returns undefined for null/undefined host bytes (maps to Option::None in Rust → cache miss), and throws a TypeError for non-Uint8Array values, which the method wrapper turns into a StoreFailure. ✓
  • invalidate output key ordering (complete, generation, persistent, removedBytes, removedEntries) matches the alphabetical order serde_json uses without preserve_order. Golden files confirm. ✓

tools/rustev-conformance

  • Rust and JS scripted stores agree on generation semantics, begin/failure application, and remove_on_invalidate semantics. ✓
  • store_mirrors assertions match the golden files for all three cases. ✓
  • Rust conformance runner's until("the decision's end", ...) correctly serialises each store-case request before the next begins. ✓
{"head": "e3de14f992fece3f880f0561ea40d62c36f15d29", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/index.d.ts", "line": null, "severity": "low", "category": "correctness", "summary": "StoreCall declares traceparent?: string but neither StoreCallJs nor the JS base object ever populates this field, so host implementations always receive undefined for traceparent."}]}

Subject: 7ee17b8...e3de14f, diff digest d6ce5634a4abfdb100e58141ca421dfd9fc0120b77d4a1dcd68a3feaedc2c44e, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 6, 2026 02:03 — with GitHub Actions Inactive
@bartekus
bartekus force-pushed the impl/063-acquisition branch from 7ee17b8 to 3659cfb Compare November 6, 2026 08:00
bartekus added a commit that referenced this pull request Nov 6, 2026
…aborted

Only a call left unsettled at a timeout or cancellation aborts its host
signal (AI review on #524).
bartekus added a commit that referenced this pull request Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff, I see one concrete gap between the TypeScript contract and the runtime implementation, and one latent asymmetry in the conformance test double. Everything else — the callback lifecycle, AbortOnDrop, generation bounds checking, the safe() / number() conversion, the JSON key ordering between Rust's BTreeMap and the JS insertion order — is internally consistent and correct.

Finding 1 — StoreCall.traceparent declared but never populated

index.d.ts adds the interface:

export interface StoreCall {
  remainingMs?: number;
  signal: AbortSignal;
  traceparent?: string;   // ← promised to callers
}

The JS method wrapper inside storeSeam constructs the base object the host receives:

const method = (fn) => async (call) => {
  const signal = calls.start(call.callId);
  try {
    return await fn(call, { remainingMs: call.remainingMs ?? undefined, signal });
    //                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    //                       no traceparent field
  } finally { calls.end(call.callId); }
};

StoreCallJs in src/store.rs has no traceparent field, so host store implementations always receive traceparent: undefined. The TypeScript type declares it may be present, but it cannot be — a host that reads call.traceparent to propagate distributed-tracing context will silently see undefined on every call.

Finding 2 — JS conformance scriptedStore uses a null-byte composite key; Rust uses typed tuples

tools/rustev-conformance/js/run.mjs:

const key = (a, b) => `${a}\u0000${b}`;

Filtering in invalidate:

if (k.startsWith(key(namespace, '')))   // == `${namespace}\u0000`

If a namespace value ever contained \u0000, entries from a different namespace could be included in or excluded from the wrong invalidation sweep. The Rust ScriptedStore uses BTreeMap<(String, String), …> with typed tuple keys and is not affected. For current Rustev-derived identifiers this is hypothetical, but the two runners diverge on that input class.

{"head": "26e71c9d505867e883a957c741b9941309867788", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/index.d.ts", "line": 134, "severity": "medium", "category": "correctness", "summary": "StoreCall declares traceparent?: string but the storeSeam method wrapper never populates it, so host store implementations always receive undefined for traceparent regardless of the runtime trace context."}, {"path": "tools/rustev-conformance/js/run.mjs", "line": 660, "severity": "low", "category": "correctness", "summary": "scriptedStore uses a null-byte composite key separator (key = `${ns}\\u0000${id}`) without input validation; a namespace or keyId containing \\u0000 would cause incorrect namespace filtering in invalidate(), whereas the Rust ScriptedStore uses typed tuple keys and is not affected."}]}

Subject: 3659cfb...26e71c9, diff digest 70cdc792a2e954a6dabae1b567381771eb66c74862ae1590513db2c0a7b2bf24, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception November 6, 2026 08:20 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/063-acquisition branch from 3659cfb to fc0df79 Compare November 6, 2026 09:02
@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Review note: both findings on 77ea8c4 are fixed in 9e151ab. 357c3dd6ee98: expires_ms is clamped to the safe-integer range before it crosses (it is an i64, so both bounds). fc2990c53b60: the JS scripted store refuses an unknown put_answer with a failure, as the Rust scripted store does. #525 and #526 are restacked on it.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

AI review (findings)

Looking at the diff, I'll review the core implementation in integrations/rustev-node/src/store.rs, the JS seam in index.js, the TypeScript declarations in index.d.ts, the conformance infrastructure, and the spec change.

integrations/rustev-node/index.d.ts — StoreCall.traceparent declared but never populated

The new StoreCall interface declares traceparent?: string:

export interface StoreCall {
  remainingMs?: number;
  signal: AbortSignal;
  traceparent?: string;
}

However, StoreCallJs in src/store.rs has no traceparent field, and the method() adapter in index.js constructs the base object as:

const base = { remainingMs: call.remainingMs ?? undefined, signal };

No traceparent is ever added. The native StoreCallJs struct also lacks the field, so call.traceparent can never be anything but undefined when any store method is called. Host store implementations that read call.traceparent for context propagation in distributed tracing will silently receive undefined even when the decision has a traceparent available. This is a concrete mismatch between the declared interface and the implementation.

Everything else checked:

  • safe() range bound: MAX_SAFE as f64 = exactly 9007199254740991.0 (2^53-1 is representable in f64), so the range check is correct.
  • AbortOnDrop drop ordering: abort is dropped before pending, so the host signal is raised before the callback slot closes — consistent with the spec.
  • Unbounded call when remaining_ms is None and INVALIDATE_TIMEOUT_MS unset: only reachable from PlanHandle::invalidate, which always wraps in the task-local scope.
  • JS and Rust scripted stores agree on generation-check-then-conflict-check ordering in put.
  • Invalidation JSON key ordering: both sides produce alphabetical order (complete, generation, persistent, removedBytes, removedEntries), matching the golden files.
  • The store_cases_produce_their_expected_bytes conformance test correctly routes store*.plan.json to fixtures/store/ and other fixtures to fixtures/runtime/.
  • Sequential-decision enforcement (until("the decision's end", ...) after each Start for store cases) is correct for 063 3.13.2.
{"head": "9e151ab7e3b0340717768680b2e99365b29a39e1", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/index.d.ts", "line": 137, "severity": "medium", "category": "correctness", "summary": "StoreCall declares `traceparent?: string` but StoreCallJs has no such field and the storeSeam method adapter never populates it; host store implementations reading call.traceparent for context propagation will always receive undefined."}]}

Subject: d5593f6...9e151ab, diff digest ab05dc20cdcd8c739247fa39a3c396ab7a609660d1fa430559b15b6d8f00bc78, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception November 6, 2026 09:46 — with GitHub Actions Error
@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Review note: finding 8bc18d34bc07 on 9e151ab is the traceparent false positive answered twice before. The field is in spec 063 3.6's own declaration (interface StoreCall { remainingMs?: number; signal: AbortSignal; traceparent?: string }), and it is optional because the runtime store call carries no decision context to take one from; removing it would contradict the spec, and filling it needs a runtime change outside this increment. It is medium and correctness, so it needs the owner exception.

@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

M1: agreed on the traceparent finding. Spec 063 3.6 declares the field optional, and rustev_runtime::StoreCall carries no decision context, so the binding has nothing to forward; filling it needs a runtime change outside this increment. I approve the review exception on the main-based run once #519 merges and this is retargeted.

Base automatically changed from impl/063-acquisition to main November 6, 2026 10:59
…de binding

EngineOptions.store installs the host store (063 3.6) with its closed
contract checked before any thread; each method is an asynchronous host
callback (3.4) whose answers are bounded (safe integers, 4 MiB, four put
words), anything else a StoreFailure. plan.invalidate bounds its store
call by timeoutMs on the engine's clock and resolves pending, never an
exception. Scripted store in both conformance runners and the three
runtime.store-* cases.
…aborted

Only a call left unsettled at a timeout or cancellation aborts its host
signal (AI review on #524).
…store refuses an unknown put answer (AI review on #524)
@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

M5: rebased onto main at df67bc5 (#519 merged); clean, with make refresh and make gate run at every commit. Re-bless found nothing new. Locally at c68c263: make code, make gate, node tests 81 pass, run.mjs native 225 cases 0 failures, verify 027 passed. The record reads increments 1, 2, 3a, 3, 4 in order. #525 and #526 are restacked on it. The traceparent finding will reappear on this run for the owner exception you mentioned.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff, which adds the host-store seam (spec 063 §3.6–3.7) to the Node.js binding, the scripted-store conformance infrastructure, and the golden expected files.

Contract and saturation checks (Rust seam)

integrations/rustev-node/src/store.rs introduces safe() to validate that every number arriving from the host is a safe integer, and number() to saturate every u64 sent to the host. Both helpers are used consistently for all values in get, put, and invalidate store calls.

invalidation_json – missing saturation

The one exception is the plan.invalidate result returned to JavaScript:

// integrations/rustev-node/src/store.rs (invalidation_json, near end of file)
serde_json::json!({
    "generation": r.generation,
    "removedEntries": r.removed_entries,
    "removedBytes": r.removed_bytes,
    "persistent": persistent,
    "complete": r.complete,
})

r.generation, r.removed_entries, and r.removed_bytes are raw u64 values emitted directly into JSON without passing through number(). Spec §3.6.3 requires every number crossing the JS boundary to be a safe integer (≤ 2^53−1), and number() exists precisely for this. For the golden-file fixtures all three values happen to be tiny (0–2), but a large namespace invalidation could produce a removed_bytes that exceeds MAX_SAFE and then silently loses precision in JavaScript.

JS runner / Rust runner key ordering

The JS runner writes invalidation JSON with JSON.stringify using the insertion order complete, generation, persistent, removedBytes, removedEntries. The Rust invalidation_bytes comment correctly notes it uses BTreeMap (no preserve_order), which sorts alphabetically to the same order. Golden files confirm the two match.

Scripted-store semantics

The JS and Rust scripted stores are consistent: both key entries by (namespace, keyId), both track namespace and scope generations, both apply begin(id) before restart/invalidation/decision, and both wait for each decision to finish before the next starts (JS: await plan.decide(...) serialises naturally; Rust: the until(...) call after Step::Start when a store is present).

Abort-on-drop and timeout

AbortOnDrop::drop fires when the host call is abandoned at timeout or cancellation (armed = true) and skips the abort when the call settled (armed = false). The INVALIDATE_TIMEOUT_MS task-local correctly bounds the store call made inside plan.invalidate, which has no decision deadline.

No high or medium severity defects found.

{"head": "c68c2634d98f513a8ee8dbb0e034973e350dad5e", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/store.rs", "line": null, "severity": "low", "category": "correctness", "summary": "invalidation_json serialises r.generation, r.removed_entries, and r.removed_bytes as raw u64 without applying number() saturation to MAX_SAFE; spec 063 §3.6.3 requires all numbers crossing the JS boundary to be safe integers, and number() exists for this purpose but is not applied to these three fields."}]}

Subject: df67bc5...c68c263, diff digest ab05dc20cdcd8c739247fa39a3c396ab7a609660d1fa430559b15b6d8f00bc78, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception November 6, 2026 11:11 — with GitHub Actions Error
@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Review note: finding 424970cfb0ad on c68c263 is fixed in 10815b9: invalidation_json caps generation, removedEntries, removedBytes and the persistent generation and removed at MAX_SAFE before they cross. #525 and #526 are restacked on it.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for the Node.js persistent-store seam (spec 063 increment 4).

Store seam wiring (Rust/JS consistency): The JS storeSeam and Rust HostStore both implement the same four-method contract (get/put/delete/invalidate). The generation/bounds/encoding logic matches between the two layers.

Abort on drop: AbortOnDrop::drop uses NonBlocking mode and silently drops the error when the NAPI queue is full. The host callback continues running unaborted in that edge case, but the slot is already released so its eventual settlement is discarded. This is best-effort and consistent with the documented contract.

JSON key ordering for conformance: invalidation_bytes (Rust) uses serde_json without preserve_order, which sorts keys via BTreeMap. The JS JSON.stringify uses insertion order. Both emit keys in the order complete, generation, persistent, removedBytes, removedEntries and inner generation, removed — alphabetical and insertion order coincide, so the bytes agree.

plan.invalidate timeout scope: INVALIDATE_TIMEOUT_MS is correctly scoped into the spawned task via task_local!, and HostStore::call reads it only when call.remaining_ms is None (i.e. the invalidation path, not a live decision). The AbortOnDrop aborts the host signal on drop, which fires when the timer wins the race.

traceparent discrepancy (concrete defect): StoreCall in index.d.ts declares traceparent?: string. StoreCallJs in src/store.rs has no traceparent field, so the native layer never supplies it. The JS method wrapper constructs base = { remainingMs: ..., signal } with no traceparent key. A host that inspects call.traceparent for distributed tracing will always see undefined. The TypeScript contract advertises a capability the runtime never delivers.

Sequential-decision wait in conformance runner: until("the decision's end", || h.is_finished()).await? after Step::Start when store.is_some() correctly enforces sequential execution before store.begin(id) advances the failure cursor. The JS side's for loop over rt.requests with sequential await achieves the same ordering.

Scripted-store put logic: Both the Rust (ScriptedStore) and JS (scriptedStore) scripted stores implement the same generation-check → conflict-check → store logic, including the put_answer override and the "unknown answer → StoreFailure" path. The remove_on_invalidate flag is honoured identically.

No security vulnerabilities or authority/ratification issues found.

{"head": "10815b98a279ea8dff8f35010e5a1a3a6b9672a9", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/index.js", "line": 311, "severity": "low", "category": "correctness", "summary": "The storeSeam method wrapper builds `base` as `{ remainingMs, signal }` and never populates `traceparent`, so the host's StoreCall always receives `traceparent: undefined` even though the TypeScript interface declares it as an optional field the runtime may supply."}]}

Subject: df67bc5...10815b9, diff digest 2d84a87369b3f56ffbf1db981ba42707e338c05002b232ea1031beab66e75f0d, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 6, 2026 11:19 — with GitHub Actions Inactive
@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Review note: finding fcf46e70c5c9 on 10815b9 is the traceparent field again, now classed low and correctness; the answer is as before (spec 063 3.6 declares it optional, and rustev_runtime::StoreCall carries no decision context to forward). It is not low and other, so it is for the owner exception M1 mentioned.

@bartekus

bartekus commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

M5: #524 is green at 10815b9 (ci-gate pass). Ready for you to arm. #525 and #526 stay stacked on it.

@bartekus
bartekus added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit a9eeb9f Nov 6, 2026
25 of 26 checks passed
@bartekus
bartekus deleted the impl/063-store branch November 6, 2026 18:11

This branch was previously deployed

1 inactive deployment
statecraft-review-exception — 10815b98 Deployed Nov 6, 2026 by bartekus via review-exception #3574
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

m5 Opened by the M5 worker; M1 arms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant