Skip to content

impl(063): increment 1, capture on decide in the Node binding - #508

Merged
bartekus merged 4 commits into
mainfrom
impl/063-capture
Nov 5, 2026
Merged

bartekus merged 4 commits into
mainfrom
impl/063-capture

Conversation

@bartekus

@bartekus bartekus commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Spec 063 increment 1 (3.8): opt-in capture on decide in the Node binding, the only capture path for a host's shadow-then-switch on plan 3 decisions.

  • decide(request, { capture }) takes scope, maxBytes, createdAtMs, retain (digest_only default, embedded, external), lifetimeMs and hostCapMs. Invalid options throw CaptureConfigRefused (zero_limit, limit_too_large, invalid_scope, out_of_range) before the context fetch and admission.
  • The decision runs through Runtime::decide_with_capture; the bundle is assembled with assemble_with_sources from the plan handle's retained plan, descriptors and calibrations (src/capture.rs). The result gains capture: { status, bundle?, items?, error? }; external returns each item under its tagged digest. limit_exceeded drops the payload and leaves the decision, record and delivery unchanged; an assembly refusal sets error.
  • I-4: no captured byte reaches the sink, telemetry, gauges or an error message. A captured SinkFailure carries capture beside record.
  • Declarations by hand in index.d.ts (3.11); no generated declaration changes. The WebAssembly package is untouched (R-1); the CLI is unchanged (3.8.6).
  • Tests: integrations/rustev-node/test/capture.test.mjs covers the capture rows of section 5 (no capture, the refusals, limit_exceeded, digest-only replay, a withheld external item, the redaction canary, snapshot versus principal canary) plus embedded and external reproduced with zero backend calls and SinkFailure. Conformance cases runtime.capture-replay (embedded and external, semantic steps) and runtime.capture-generation on rust-api and native, with identical bytes.
  • Spec 063: the implementation record gains increment 1. The digest-only reason in 3.8.3 and section 5 now names spec 004's missing for an item, which replay has always reported, and spec 036's content-not-retained only for an acquisition page; no behavior changes. Acquisition pages join with increment 3.

Checks run locally: make gate; cargo fmt --all --check; cargo test -p rustev-node and -p rustev-conformance; clippy on both with -D warnings; the release addon; tsc --strict on index.d.ts; node --test integrations/rustev-node/test/*.test.mjs (62 passed, 0 failed, 4 skipped as before); run.mjs native.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (findings)

Review

Main defect: SinkFailure.record lost in capture+failure path

In integrations/rustev-node/src/lib.rs, the new capture+EvidenceNotDelivered branch (around the block that checks captured.is_some() && matches!(&r, Err(DecideError::EvidenceNotDelivered { .. }))) calls decided(r).err().expect("sink failure") only to extract error.reason, then returns:

return Ok(DecideResult {
    completion: "cancelled".into(),
    judgment: None,
    evidence: Uint8Array::new(vec![]),   // empty – record bytes discarded
    delivery: "null".into(),
    trace: None,
    capture: captured,
    failure: Some(error.reason),
});

The run-record bytes embedded in the napi error (normally what backs SinkFailure.record in the existing non-capture path) are silently dropped. The JS in index.js then executes:

if (r.failure != null) {
    const error = typed(new Error(r.failure));   // fresh Error, no record bytes
    if (r.capture != null) error.capture = r.capture;
    throw error;
}

No error.record = r.evidence assignment is present, so error.record will be undefined. The test in test/capture.test.mjs asserts:

assert.ok(error instanceof rustev.SinkFailure);
assert.ok(error.record);   // undefined → AssertionError → test fails
assert.ok(error.capture.bundle);

assert.ok(undefined) throws, causing the entire SinkFailure carries capture beside record test to fail.

Location: integrations/rustev-node/src/lib.rs (the new sink-failure-with-capture early-return block); secondary symptom in integrations/rustev-node/index.js (failure branch does not attach r.evidence to error.record).


{"head": "662461846a447a913415289581fec4cca8558fa1", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/lib.rs", "line": null, "summary": "In the capture+SinkFailure path, the run-record bytes are discarded (evidence set to empty) and the JS failure branch never assigns r.evidence to error.record, so SinkFailure.record is undefined and the test assert.ok(error.record) fails."}]}

Subject: 3ab57f8...6624618, diff digest ab46cd4879f2ceec59003ed7b16b060055433c7f68002f33698eadf0ebff3710, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 4, 2026 21:48 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (findings)

Review

Finding 1 — SinkFailure.record dropped in the capture failure path

File: integrations/rustev-node/src/lib.rs

When EvidenceNotDelivered occurs and capture is active, the new code path extracts only the NAPI error's reason string and returns a DecideResult with the evidence field deliberately set to empty:

let error = decided(r).err().expect("sink failure");
return Ok(DecideResult {
    evidence: Uint8Array::new(vec![]),   // empty — record bytes dropped
    failure: Some(error.reason),
    capture: captured,
    ...
});

The run record bytes that decided would have embedded in the native NAPI error are discarded here. The JS failure path then does:

if (r.failure != null) {
    const error = typed(new Error(r.failure));
    if (r.capture != null) error.capture = r.capture;
    throw error;
}

No error.record is set anywhere, r.evidence is empty, and typed receives a plain JS Error (not a native NAPI error) so it cannot extract record bytes from native metadata the way the non-capture SinkFailure path does. SinkFailure.record on the JS error will be undefined.

The test in integrations/rustev-node/test/capture.test.mjs asserts:

assert.ok(error instanceof rustev.SinkFailure);
assert.ok(error.record);       // fails: undefined is falsy
assert.ok(error.capture.bundle);

assert.ok(error.record) fails because undefined is falsy.


Finding 2 — Spec modification record omits rustev-surface

File: specs/001-boundaries-and-authority/spec.md

The added modification entry states:

records rustev-conformance's new path dependency on rustev-eval

But tools/rustev-conformance/Cargo.toml adds two new workspace dependencies:

+rustev-eval.workspace = true
+rustev-surface.workspace = true

rustev-surface is used in tools/rustev-conformance/src/capture.rs (rustev_surface::host::Memory and rustev_surface::replay::replay). The spec record is factually incomplete: rustev-surface is omitted even though it is an equally new addition.


{"head": "b25cc0e00cb9e85c5fe6b968921057726572d153", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/lib.rs", "line": null, "summary": "EvidenceNotDelivered capture path sets evidence to empty bytes, so SinkFailure.record is undefined on the JS side, causing assert.ok(error.record) in capture.test.mjs to fail."}, {"path": "specs/001-boundaries-and-authority/spec.md", "line": null, "summary": "The 2026-11-04 modification record mentions only rustev-eval as a new dependency added to rustev-conformance, omitting rustev-surface, which is equally new and actively used in the capture module."}]}

Subject: a3c1eab...b25cc0e, diff digest 226d78404c65e7edec8cea80a9c592903427240fb442da41937f53a035a93fa5, 1 call(s). An AI comment is not an approval.

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

bartekus commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Review note on the recurring AI finding at integrations/rustev-node/src/lib.rs (captured SinkFailure without record).

Not a defect. On the captured sink-failure path the native result carries failure: Some(error.reason), where error is the fail("SinkFailure", ..., { detail, recordHex }) error that decided() builds; its reason is that JSON message. index.js throws typed(new Error(r.failure)), and typed() parses the message and sets err.record from detail.recordHex (index.js lines 70-72), exactly as on the uncaptured path. The empty evidence field is never read on this path. capture.test.mjs's SinkFailure test asserts error.record and error.capture and passes locally (node --test integrations/rustev-node/test/*.test.mjs: 62 passed, 0 failed).

The second finding (the spec 001 record named only rustev-eval) was correct and is fixed in the next commit.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR for spec 063 increment 1 (capture on decide).

The main areas I examined: integrations/rustev-node/src/capture.rs, integrations/rustev-node/src/lib.rs, tools/rustev-conformance/src/runtime.rs, the conformance test harness, and the spec edits.


Finding: compile error in tools/rustev-conformance/src/runtime.rs

The run() function's spawned tasks changed their return type. Before, each task returned Result<Decided, DecideError>:

running.push(tokio::spawn(
    async move { rt.decide(&plan, req, &cancel).await },
));

After the PR, every task returns (Result<Decided, DecideError>, Option<CaptureOutcome>) (even the else branch returns (rt.decide(...).await, None)).

The result-processing code — shown as unchanged context in the diff — is:

let r = running
    .remove(0)
    .await
    .map_err(|_| format!("{id} never finished"))?  // unwraps JoinError → tuple
    .map_err(|e| format!("{id}: {e}"))?;           // ERROR: called on a tuple
let (r, captured) = r;

After the first .map_err(…)?, the value is (Result<Decided, DecideError>, Option<CaptureOutcome>). The second .map_err(|e| …)? is then called on this tuple; tuples do not implement Result traits, so this is a compile-time type error. The conformance tool cannot build, and all conformance cases exercised by the new capture test (capture_cases, the_manifest_runtime_cases_pass_through_the_runner) cannot run.

The fix is either to remove the second .map_err(…)? from the chain (letting r be the tuple, which is then correctly destructured by let (r, captured) = r;) or to restructure the await chain to handle the new return type explicitly.

{"head": "6a1204637213dd60ae503e29c525bcd26b72e1b6", "verdict": "findings", "findings": [{"path": "tools/rustev-conformance/src/runtime.rs", "line": null, "summary": "Task return type changed from Result<Decided, DecideError> to (Result<Decided, DecideError>, Option<CaptureOutcome>) but the unchanged processing chain calls .map_err(|e| …)? on the tuple produced after the first map_err/?, which is a compile-time type error because tuples do not implement the Result traits."}]}

Subject: a3c1eab...6a12046, diff digest 1d8547886e50e79b18c0735a2f3b91418d81d87985f1cbba0a073f37501e582a, 1 call(s). An AI comment is not an approval.

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

bartekus commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Review note on the AI finding at 6a12046 (tools/rustev-conformance/src/runtime.rs, the task's tuple return).

Not a defect. tokio::time::timeout(.., h).await is Result<Result<(Result<Decided, DecideError>, Option<CaptureOutcome>), JoinError>, Elapsed>. The first .map_err(..)? unwraps the timeout's Result, the second .map_err(..)? unwraps the JoinError Result, and only then is the tuple bound and destructured (let (r, captured) = r;). No map_err is applied to the tuple. The crate builds and cargo test -p rustev-conformance --locked passes locally on this head; CI's code job compiles it too.

@bartekus
bartekus added this pull request to the merge queue Nov 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 5, 2026
@bartekus
bartekus added this pull request to the merge queue Nov 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 5, 2026
@bartekus
bartekus added this pull request to the merge queue Nov 5, 2026
@bartekus
bartekus removed this pull request from the merge queue due to a manual request Nov 5, 2026
decide takes capture options (scope, maxBytes, createdAtMs, retention,
lifetime, host cap), checked before admission, and returns the replay
bundle and external items assembled from the plan handle's retained
dependencies. Nothing captured reaches the sink, telemetry, gauges or an
error message. Two conformance cases, runtime.capture-replay and
runtime.capture-generation, run on rust-api and native with identical
bytes. Acquisition pages join with increment 3.
…rds the lock change

rustev-contract's ranking_wire test counts fixtures/runtime's descriptors,
so the capture-generation fixtures move to fixtures/capture. Spec 001
records Cargo.lock's new rustev-conformance path dependency on
rustev-eval as build only.
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

AI review (findings)

Review

The PR implements spec 063 increment 1: caller-side capture on decide for the Node binding, including conformance infrastructure. The changes are architecturally coherent and the security controls (no caller-content in error messages, principal excluded from bundle, canary tests) are well-constructed. One concrete defect stands out.

Finding: Run record bytes discarded in capture + SinkFailure path

In integrations/rustev-node/src/lib.rs, when capture is active and EvidenceNotDelivered occurs, the code takes this branch:

let error = decided(r).err().expect("sink failure");
return Ok(DecideResult {
    completion: "cancelled".into(),
    judgment: None,
    evidence: Uint8Array::new(vec![]),   // empty; record bytes thrown away
    delivery: "null".into(),
    trace: None,
    capture: captured,
    failure: Some(error.reason),          // only the string reason survives
});

decided(r) with r = Err(EvidenceNotDelivered { record, .. }) constructs a NAPI SinkFailure error that carries the run-record bytes as a property (the same record that populates SinkFailure.record in the existing non-capture path). Here we extract only error.reason (a String) and discard the bytes entirely. evidence is set to an empty Uint8Array.

On the JavaScript side:

if (r.failure != null) {
  const error = typed(new Error(r.failure));   // only the reason string; no record bytes in scope
  if (r.capture != null) error.capture = r.capture;
  throw error;
}

typed receives a plain new Error(reason_string) with no byte payload. Neither r.evidence (empty) nor any other field of DecideResult carries the record bytes. Consequently SinkFailure.record will be undefined (missing).

The test at capture.test.mjs line 110 asserts:

assert.ok(error instanceof rustev.SinkFailure); assert.ok(error.record); assert.ok(error.capture.bundle);

assert.ok(error.record) will fail because record is undefined. Spec 063 §5 table also explicitly requires "SinkFailure carries capture beside record."

The fix is to pass the actual record bytes through DecideResult (e.g. a new field, or by reusing evidence with the record canonical bytes) so the JS side can attach them to the thrown SinkFailure.

No security issues were found: caller content is correctly excluded from error details, the principal handle is excluded from bundles, and the byte-size and timestamp bounds are validated before admission.

{"head": "3e1ce8cded1b46428f979a92da312254e00a9d00", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/lib.rs", "line": null, "summary": "In the EvidenceNotDelivered + capture path, only error.reason (a string) is extracted from the NAPI SinkFailure error; the run-record bytes are discarded and evidence is set to an empty Uint8Array, so SinkFailure.record arrives in JavaScript as undefined rather than the canonical record bytes, breaking the spec 063 §5 requirement and the assert.ok(error.record) assertion in capture.test.mjs."}]}

Subject: d108971...3e1ce8c, diff digest 745130ae9d1e5312ed1f8875b8a0d8f100806c02a1a4ad9149bf495e8f2870cf, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 5, 2026 04:41 — with GitHub Actions Inactive
@bartekus

bartekus commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Review note on the SinkFailure finding (integrations/rustev-node/src/lib.rs): not a defect. failure: Some(error.reason) carries the whole serialized SinkFailure error that decided(r) builds, and that error's detail.recordHex holds the canonical record bytes (the same path as the uncaptured case, 3.4.2). In index.js, decide passes r.failure to typed(), which parses it and sets err.record from recordHex, then attaches capture. The empty evidence field is never read on this path. test/capture.test.mjs ("SinkFailure carries capture beside record") asserts error.record and replays the captured bundle to reproduced.

@bartekus
bartekus added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit 06f2101 Nov 5, 2026
33 checks passed
@bartekus
bartekus deleted the impl/063-capture branch November 5, 2026 05:34

This branch was previously deployed

1 inactive deployment
statecraft-review-exception — 3e1ce8cd Deployed Nov 5, 2026 by bartekus via review-exception #3434
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