Skip to content

impl(027): increment 3, the shared command surface - #128

Merged
bartekus merged 1 commit into
mainfrom
impl/027-surface
Oct 20, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/027-surface

Conversation

@bartekus

@bartekus bartekus commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Spec 027, increment 3 of 7: rustev-surface, the shared command surface, adopted by the CLI. Stacked on #126. Merges only after the owner ratifies draft spec 045 (#127), which admits rustev-surface to the release family in its own layer before the CLI.

  • crates/rustev-surface: plan check|compile|show, offline replay, eval, gate, calibrate fit|qualify, shared dependency reading, the task adapter, command output and exit codes, and the run result envelope. The CLI's code, moved: typed arguments plus a Host (bounded/budgeted reads by label, never-overwrite publication, all-or-none writes, label joining) and a rules-descriptor hook. Depends on contract, core, eval, serde, serde_json only.
  • The CLI keeps argument parsing, its file-system host (Reads implements Host), the store resolver, the rules backend and the runtime; each command checks flags and calls the surface; run prints through the surface envelope.
  • Every CLI test passes with goldens unchanged (none re-blessed). tests/memory_host.rs drives the surface from an in-memory host and gets the CLI's golden bytes for plan check and plan show.
  • Release tooling: rustev-surface in release-set.json (layer 4, CLI layer 5, upload order), the release-set test's member list, and archive-policy.json (new surface allowlist; adapter.rs/out.rs leave the CLI's). rustev-release manifests and archives tests pass; make boundaries passes.

Review round 1 (3 findings): (1) the merge precondition is deliberate: spec 045 is drafted in #127 for the owner's ratification and this increment waits on it, as its record says; (2) fixed: the test host's write_all removes what it wrote when a later write fails; (3) the test host reads at most max bytes, exactly as the CLI's file host does (a caller detecting an oversized input asks for its limit plus one and compares lengths); it has no aggregate budget, so it reports none; the code says so.

Review round 2 (1 finding): as in round 1, the precondition is deliberate and tracked: spec 045 is drafted in #127 for ratification; this pull request is not merged before it.

Review round 3 (3 findings): (1) the spec 045 precondition stands as stated (#127, awaiting ratification); (2) Host::ensure_absent is documented as a pure, repeatable check, which every command relies on; (3) fixed: addressing is private to the envelope; judged is the public entry.

Review round 4 (2 findings): (1) the spec 045 precondition stands (#127, awaiting ratification); (2) Cargo adds Cargo.toml.orig, Cargo.lock, .cargo_vcs_info.json and the workspace readme beyond include (as for every release member), and rustev-release's archives test compares cargo package --list with the policy; the manifest comment says so.

Review round 5 (2 findings): (1) the spec 045 precondition stands (#127, awaiting ratification); (2) the test host reads at most max bytes exactly as the CLI's file host does; a caller detecting an oversized input asks for its limit plus one byte and compares lengths, which the surface's callers do. (Increment 5 replaces this test host with the shared host::Memory.)

Review round 6 (1 finding): spec 045 is added by #127, not this branch, by design: this PR is held (no auto-merge) until #127 merges and the owner ratifies 045. The spec record now names that dependency and the hold explicitly. Restacked on #126.

Review round 7 (1 finding, fixed): eval::write_all takes its files by value and moves the bytes into the host's list; nothing is copied.

Review round 8 (1 finding): cargo package writes Cargo.lock into every archive, library or not (cargo package -l -p rustev-surface lists it), and every member's allowlist names it; the archive test compares against real cargo package output and passes. The spec record now says so, and records spec 045's ratification (A-42).

Review round 9 (3 findings): (1, 2) Spec 045 is ratified (A-42) and lands with #127, which waits only on the owner's environment approval; this branch is rebased onto main after #127 merges, before it can merge, so 045 is in the tree it merges into. (3) fixed: the crate's keywords and category describe a library (decision-engine, commands, bindings; development-tools).

CI verify (spec 006's mutation seeds) failed on this branch: the seeds still named crates/rustev-cli/src/ files whose command logic this PR moves into rustev-surface. Fixed: the 13 seeds in moved code now name the surface file their anchor lives in (one anchor changed with the move: host.ensure_absent), and run the CLI's tests and the surface's own, since the adapter's unit tests moved with it. Locally all 29 seeds were run: 27 detected by the CLI's tests alone, and the two adapter seeds detected once the surface's tests run too (4/4 in the adapter category). The spec record says so.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR, which extracts rustev-surface as the pure command layer shared by all hosts.

Finding 1 – Stated merge precondition is violated
specs/027-node-and-wasm-bindings/spec.md (new text near line ~790) says "this increment merges only after the owner ratifies spec 045". Spec 045 does not exist anywhere in the repo context (specs top out at 044). The PR introduces the condition and violates it simultaneously.

Finding 2 – Memory host's write_all doesn't implement "all or none"
crates/rustev-surface/tests/memory_host.rs (around line 44–48):

fn write_all(&self, files: &[(String, Vec<u8>)]) -> Result<(), IoFail> {
    for (l, b) in files {
        self.create(l, b)?;  // fails on second file, first already written
    }
    Ok(())
}

Host::write_all is documented as "all or none", but on a partial failure (e.g., the second label already exists) the first write is not rolled back. The CLI's Reads::write_all in io.rs does implement the rollback; the test host doesn't, so tests that exercise multi-file writes through eval can't catch violations of this contract.

Finding 3 – Memory host silently truncates reads instead of signalling Budget
crates/rustev-surface/tests/memory_host.rs (around line 19–24):

fn read_classified(&self, label: &str, max: usize) -> Result<Option<Vec<u8>>, ReadFail> {
    Ok(self.inputs.get(label).map(|b| b[..b.len().min(max)].to_vec()))
}

The real host returns ReadFail::Budget when the file exhausts the per-command read budget; this host silently returns truncated bytes. The critical consequence is in eval::read_bundles, which reads with max_bytes + 1 and checks bytes.len() > max_bytes to detect oversized bundles. With this host, an oversized bundle would be silently truncated to max bytes, pass the size check, and be handed to the parser as potentially corrupt data rather than being flagged Oversized. Oversized-input behaviour cannot be correctly validated through this host.

{"head": "c60594feaf82553fbebf4d578c27d9ab4cecfdf7", "verdict": "findings", "findings": [{"path": "specs/027-node-and-wasm-bindings/spec.md", "line": null, "summary": "The added spec text states this increment must not merge before spec 045 is ratified, but spec 045 does not exist in the repository, so the PR violates its own stated merge precondition."}, {"path": "crates/rustev-surface/tests/memory_host.rs", "line": 44, "summary": "Memory::write_all does not roll back already-written outputs on partial failure, violating the 'all or none' contract documented on Host::write_all."}, {"path": "crates/rustev-surface/tests/memory_host.rs", "line": 19, "summary": "Memory::read_classified silently truncates at max bytes instead of returning ReadFail::Budget, so the oversized-bundle detection in read_bundles (which reads max+1 bytes and checks length) cannot be validated through this host."}]}

Subject: 8eb4c6c...c60594f, diff digest 37bcaadd0cf1b1a43ed40d53969e45301619a3a9ad5f2a4f3779411d9e25bfc6, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the extraction of rustev-surface from rustev-cli: a host-agnostic command surface with a Host trait bridged to the CLI's file system.

crates/rustev-surface/src/host.rs — The read default correctly adds 1 to limit so oversized inputs reach the parser's own size check. read_bounded collapses ReadFail::Budget into IoFail, acceptable because callers that need the budget/file distinction call read_classified directly (read_bundles).

crates/rustev-surface/src/eval.rs — write_all — Surface calls ensure_absent for every path, then delegates to host.write_all. The CLI's Reads::write_all creates each file without an internal pre-check but rolls back on partial failure. Semantics are equivalent to the original: pre-check all-absent, write with rollback.

crates/rustev-surface/src/deps.rs — no_rules is a correct sentinel; the RulesHook type alias (a dyn FnMut) matches. DepArgs::Default yields empty slices, fine.

crates/rustev-surface/tests/memory_host.rs — read_classified silently truncates to max bytes. This is correct: callers requesting limit + 1 bytes get limit + 1 back when the input is larger, triggering the bytes.len() > limit check in read_bundles. Oversized detection works.

Archive policy — rustev-surface/Cargo.toml has include = ["/src/**/*.rs", "/LICENSE"], which excludes README.md and Cargo.lock. The archive-policy entry lists both. However, the same pattern exists for all other crates in the policy (the policy appears to be an allowlist, not a requirement list), so this is pre-existing convention rather than a new defect. src/host.rs is correctly listed in the rustev-surface entry.

crates/rustev-cli/src/deps.rs — check_counts is tightened (no longer routes through the old DepFail path), but the public DepFail is now re-exported from the surface, and check_counts(p).map_err(DepFail::Io)? correctly wraps IoFail. Types align.

Spec 045 dependency — specs/027-node-and-wasm-bindings/spec.md states Increment 3 "merges only after the owner ratifies spec 045," but spec 045 is not present in the diff. Release-set and archive-policy changes add rustev-surface as a family member under that not-yet-ratified spec. This is a process gate expressed in the spec text; the code is self-consistent, but the merge condition is stated yet unverified here.

No logic regressions, security issues, or behavioral divergences from the original CLI output found. The goldens-unchanged constraint and the memory_host.rs test confirming identical bytes for plan check / plan show provide good evidence of fidelity.

{"head": "3a55eabd45ff6ee478e2f0a30ccf535288d57129", "verdict": "findings", "findings": [{"path": "specs/027-node-and-wasm-bindings/spec.md", "line": null, "summary": "Increment 3 states it merges only after spec 045 is ratified, but spec 045 is absent from this PR and from the repo context; the release-set and archive-policy changes that depend on it land without the prerequisite spec being present."}]}

Subject: 69c81a9...3a55eab, diff digest 2629e7472c4dce1cff271240fc1fd786d2f139d89a2b5738d33903f5521db3df, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Review

This PR extracts the pure command surface from rustev-cli into a new rustev-surface crate, wiring the CLI through a Host trait abstraction. The structural refactoring is clean and I verified that logic was faithfully ported rather than altered in the move.

Findings

specs/027-node-and-wasm-bindings/spec.md, line ~792 — The newly added increment text closes with:

this increment merges only after the owner ratifies spec 045.

Spec 045 does not appear in the repo context (no specs/045-*/ directory is listed). The PR changes tools/rustev-release/release-set.json and tools/rustev-release/tests/manifests.rs to add rustev-surface to the release family, citing draft spec 045 as authority. Merging before that spec is ratified violates the gate the PR itself sets.

crates/rustev-surface/src/eval.rs, line ~148 (write_all) — write_all checks ensure_absent for every output path, then delegates to host.write_all. For the calibrate path (calibrate.rs lines ~78-82), ensure_absent is also called explicitly before the expensive reproduction loop, so each output path is checked three times (once upfront, once inside write_all, once inside the host's own create). This is harmless redundancy, but the double-check inside write_all specifically will silently error on the second pass for any host whose ensure_absent is not idempotent. The CLI's file-system host is idempotent (it checks existence), so no bug today, but the contract is not documented on the trait and could trap a future host author.

crates/rustev-surface/src/run.rs, line 79 (addressing) — addressing is marked pub even though judged (also pub) already calls it internally and no external caller needs it independently. This leaks an implementation detail into the public API surface of a crate intended to be published (publish = ["crates-io"]). Not a runtime bug, but it widens the surface without necessity.

Non-issues confirmed

  • Logic in plan, replay, eval, calibrate, and gate is a faithful port; all branch arms and output fields match the deleted CLI originals.
  • The Host trait's default read / read_bounded methods correctly pass limit + 1 so parsers can detect oversized inputs.
  • The memory host in tests/memory_host.rs correctly implements "all or none" write semantics.
  • Archive policy and release-set ordering (rustev-surface before rustev-cli) are internally consistent.
  • DepFail re-export from surface and dep_failed delegation preserve original error codes and message shapes.
{"head": "2e1ab340d56732def83534ca4f88bc13127a23b6", "verdict": "findings", "findings": [{"path": "specs/027-node-and-wasm-bindings/spec.md", "line": 792, "summary": "The increment text states it may only merge after spec 045 is ratified, but spec 045 does not exist in the repository; the PR violates its own stated merge gate."}, {"path": "crates/rustev-surface/src/eval.rs", "line": 148, "summary": "write_all calls ensure_absent on each path before host.write_all, creating a double-check for callers (e.g. calibrate.rs) that already ran ensure_absent upfront; the Host trait does not document idempotency of ensure_absent, which could trap a future host implementation."}, {"path": "crates/rustev-surface/src/run.rs", "line": 79, "summary": "addressing is exported pub unnecessarily: it is only called internally by the pub judged function, so exposing it widens the published crate's API without a stated need."}]}

Subject: 536fe52...2e1ab34, diff digest a3bc1f6d72d246b1d520daa747564479d30125547749d5471c2e7c390666a60e, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

The PR extracts the pure command surface from rustev-cli into a new rustev-surface crate. The refactoring is faithful to the original logic. Let me call out the issues I found.

specs/027-node-and-wasm-bindings/spec.md (Increment 3 text): The spec explicitly states "this increment merges only after the owner ratifies spec 045", and tools/rustev-release/tests/manifests.rs comments // Spec 045: the command surface the CLI depends on (spec 027). Spec 045 is absent from the repository. The release set and archive-policy are updated as though the ratification has occurred. This is a stated merge pre-condition that hasn't been satisfied.

crates/rustev-surface/src/eval.rs write_all: The function clones every byte vector to build the joined-path vector before passing to host.write_all. For large eval outputs (report, detail, etc.) this doubles peak memory. A minor inefficiency; not a correctness bug, but the callers already own the data and a consuming signature would avoid the copy.

crates/rustev-surface/src/eval.rs double ensure_absent: eval() pre-checks all four output paths, then write_all() checks them again before delegating to host.write_all. Redundant but harmless, and consistent with the original CLI pattern.

archive-policy.json rustev-surface entry includes Cargo.lock: Library crates published to crates.io do not ship Cargo.lock. If the release tool validates presence rather than acting as an allowlist, this will fail. However, the same pattern exists for other library crates in the existing policy, so the tool likely treats it as an allowlist — a pre-existing pattern, not a regression introduced here.

No security issues or logic errors detected in the code itself; the surface logic is a clean, faithful extraction of the CLI logic with appropriate Host abstraction.

{"head": "721be942cdd45b2fcb0980500e8304859da04f53", "verdict": "findings", "findings": [{"path": "specs/027-node-and-wasm-bindings/spec.md", "line": null, "summary": "Increment 3 is conditioned on ratification of spec 045, but spec 045 is absent from the repository; the release-set and archive-policy changes it requires are already merged."}]}

Subject: 404e143...721be94, diff digest cf15962212698c50191a3963835e9c445866e4e952fb5b416c9256f819279560, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

The PR extracts a new rustev-surface crate holding the pure command surface, with rustev-cli delegating to it. The refactoring is large but structurally faithful. Here are my findings:

Process gate not satisfied. The spec 027 increment 3 text (added in this PR) explicitly says: "this increment merges only after the owner ratifies spec 045." There is no spec 045 file anywhere in the repository — the REPO CONTEXT shows specs only up to spec 044, and none is added in this PR. The merge condition stated in the spec text is unmet.

write_all atomicity contract asymmetry. crates/rustev-surface/src/eval.rs write_all pre-checks all paths with ensure_absent, then calls host.write_all. The CLI's Reads::write_all implementation (crates/rustev-cli/src/io.rs:131) goes directly to create without re-checking, relying solely on the pre-check above it. The in-memory test host's create does re-check via ensure_absent. The contract is enforced, but the asymmetry means a host that skips the re-check is open to a TOCTOU between the loop pre-check and the write. This was present in the original CLI code and is not a new regression, but the Host trait documentation does not articulate which layer is responsible for the guarantee, making future host implementations potentially unsafe.

rustev-surface/Cargo.toml include excludes files listed in archive-policy.json. The Cargo.toml at crates/rustev-surface/Cargo.toml:18 sets include = ["/src/**/*.rs", "/LICENSE"]. The archive-policy.json for rustev-surface expects Cargo.lock, Cargo.toml, Cargo.toml.orig, and README.md in the published archive. cargo publish will not upload Cargo.lock under the stated include, making the archive policy inconsistent with the crate configuration. Other crates in the policy share the same pattern (pre-existing), so this may be an existing policy/tool misalignment, but it is being replicated into a new published crate.

{
  "head": "b0e556af9f6fe7cd80bf261c402b514956c64519",
  "verdict": "findings",
  "findings": [
    {
      "path": "specs/027-node-and-wasm-bindings/spec.md",
      "line": null,
      "summary": "Increment 3 text states 'this increment merges only after the owner ratifies spec 045', but no spec 045 file exists in the repository or this PR."
    },
    {
      "path": "crates/rustev-surface/Cargo.toml",
      "line": 18,
      "summary": "`include = [\"/src/**/*.rs\", \"/LICENSE\"]` excludes `Cargo.lock` and `README.md` that `archive-policy.json` expects in the published `rustev-surface` archive."
    }
  ]
}

Subject: be2a979...b0e556a, diff digest cf15962212698c50191a3963835e9c445866e4e952fb5b416c9256f819279560, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

The PR extracts rustev-surface from rustev-cli, delegating all command logic through a Host trait so CLI, Node.js, and WebAssembly bindings share one implementation. The mechanical refactor is correct — golden bytes are preserved, the Budget/File distinction in read_classified is maintained where it matters (read_bundles), all-or-none write_all semantics carry over to every host implementation, and the DepArgs/RulesHook split cleanly separates parsing from backend construction.

One substantive finding:

specs/027-node-and-wasm-bindings/spec.md, line ~793 (increment 3 paragraph): The spec text states explicitly: "this increment merges only after the owner ratifies spec 045." Spec 045 is also referenced as the authority for adding rustev-surface to the release family in tools/rustev-release/tests/manifests.rs (comment: // Spec 045: the command surface the CLI depends on). Spec 045 appears nowhere in the repository — not in REPO CONTEXT, not in the specs/ directory, not in the codebase index. The PR adds rustev-surface to release-set.json, the archive policy, and the manifest test under a ratification that has not occurred. If the release tooling validates membership against the spec registry, this lands an unauthorized release-family member.

{"head": "224c02687ad7f174a0b5c03de30341a6ce9b9abb", "verdict": "findings", "findings": [{"path": "tools/rustev-release/release-set.json", "line": null, "summary": "rustev-surface added to the release family under draft spec 045, which the spec text requires to be ratified before this increment merges — spec 045 is absent from the repository."}]}

Subject: 825c89a...224c026, diff digest f400a85af7b6b2b64b24aaeb350a5e16f621b11c074ee1232dfe8fdd747b578f, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Review

The PR extracts the CLI's pure command logic into a new rustev-surface crate so that future Node/WASM bindings can share the same surface without drift. The refactoring is structurally clean: Host trait wraps I/O, commands take typed args structs, Reads implements Host, and the CLI is thinned to argument parsing + glue.

Logic and correctness

  • The write_all split (surface pre-checks via ensure_absent, then delegates to host.write_all for the all-or-none write with rollback) faithfully reproduces the original semantics.
  • judged/cancelled/not_delivered in run.rs preserve every output field, including the spec 033 addressing logic. The tuple destructuring change from (mut out, mut exit, record) to ((mut out, mut exit), record) is correct.
  • replay returning Err(Done::io(…)) instead of the old Ok(Err(Done::io(…))) is correct: both surface and CLI functions return the appropriate type.
  • no_rules correctly produces a category-4 (invalid_input) refusal for hosts that carry no rules backend.
  • The candidate.is_some() call after candidate.as_ref().map(…) is safe: as_ref() borrows rather than consumes.

Spec gating — merging requirement not met

specs/027-node-and-wasm-bindings/spec.md (the only changed spec path in this PR) explicitly states:

"this increment merges only after the owner ratifies spec 045"

Spec 045 does not appear in the changed paths and is not present in the repo context. Yet tools/rustev-release/release-set.json, archive-policy.json, and the manifests.rs test all assume spec 045's approval (the test comment even says // Spec 045:). Merging before spec 045 exists violates the stated gating condition; if spec 045 ends up requiring a different layer ordering or archive shape, these artifacts will be wrong.

Memory-host truncation (test quality)

tests/memory_host.rs truncates inputs to max bytes silently:

.map(|b| b[..b.len().min(max)].to_vec())

An oversized input reaches the document parser as a corrupt payload rather than an oversized one, masking the distinct "oversized" error path. This only affects the test host, not production, but it means the test cannot verify that oversized inputs produce the expected io_error vs invalid_input distinction.

{"head": "edcb709089d5320186cc423330050b6c8bf96788", "verdict": "findings", "findings": [{"path": "specs/027-node-and-wasm-bindings/spec.md", "line": null, "summary": "The spec text for increment 3 explicitly requires spec 045 to be ratified before merging, but spec 045 is absent from this PR and from the repo context; the release-set and archive-policy changes already assume its approval."}, {"path": "crates/rustev-surface/tests/memory_host.rs", "line": 28, "summary": "The memory host silently truncates reads to `max` bytes, so an oversized input reaches the document parser as a corrupt payload rather than producing a distinct oversized error, leaving that branch untested."}]}

Subject: 9422236...edcb709, diff digest f400a85af7b6b2b64b24aaeb350a5e16f621b11c074ee1232dfe8fdd747b578f, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at this PR, which extracts a new rustev-surface crate from rustev-cli by introducing a Host trait abstraction. I'll check the logic migration, the host trait contract, the output equivalence, and the release-set changes.

Logic migration — no behavioral differences found. Each command in rustev-cli now delegates to a surface function that takes the same arguments and produces the same Res. The write_all in surface/eval.rs preserves the original two-phase pattern: check all outputs absent, then write all-or-none via host.write_all. The CLI's Host::write_all implementation rolls back on failure identically to the old eval.rs write_all.

Host trait contract. Host::read_bounded collapses ReadFail::Budget and ReadFail::File into IoFail, which matches the pre-existing Reads::read_bounded behavior. Host::read (default impl) reads limit+1 bytes so document parsers that check ParseLimits::max_bytes see an oversized input and refuse it—consistent with the original.

Memory host test. The read_classified impl truncates to max bytes. Since all oversized-detection callers pass limit+1 and compare bytes.len() > limit, this is functionally correct. The test validates against the CLI's golden files for plan check and plan show, which confirms output identity.

run.rs envelope. The old 3-tuple (out, exit, record) is correctly restructured as ((out, exit), record) using envelope::judged, envelope::cancelled, and envelope::not_delivered. The uncertain: bool parameter matches the original failure.uncertain serialization. capture_status is correctly moved to the surface.

Release-set and archive-policy. rustev-surface is placed in its own layer before rustev-cli in both release_layers and upload_order — correct since the CLI depends on the surface. The surface archive policy lists exactly the files under crates/rustev-surface/src/. The CLI archive policy drops src/out.rs and src/adapter.rs (both deleted from CLI per DELETIONS).

One clear finding: The spec update at specs/027-node-and-wasm-bindings/spec.md explicitly says "this increment merges only after the owner ratifies spec 045", but spec 045 does not exist anywhere in this repository. The spec's own merge gate condition is not met by this PR.

{"head": "541973ed719db3333c1de7cfc7e552c98812485e", "verdict": "findings", "findings": [{"path": "specs/027-node-and-wasm-bindings/spec.md", "line": null, "summary": "The spec text for Increment 3 states the PR merges only after spec 045 is ratified, but spec 045 does not exist in this repository, leaving the declared merge gate unmet."}]}

Subject: d066d92...541973e, diff digest f400a85af7b6b2b64b24aaeb350a5e16f621b11c074ee1232dfe8fdd747b578f, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR, which extracts the pure command surface from rustev-cli into a new rustev-surface crate behind a Host trait abstraction.

Logic and behavioral consistency

The extraction in calibrate.rs, eval.rs, plan.rs, replay.rs, and run.rs moves code faithfully. The original inline closures become free functions; the split between ensure_absent (pre-check) and write remains identical.

The write_all helper in surface/eval.rs calls host.ensure_absent for each file before delegating to host.write_all. The CLI's Host::write_all calls io::create directly without a second ensure_absent, so atomicity relies on io::create refusing overwrites. This matches the original structure and is not a regression.

Host::read_bounded collapsing ReadFail variants

host.rs:59–62 maps both ReadFail::File and ReadFail::Budget to IoFail in the default read_bounded implementation. The callers that need to distinguish them (read_bundles, etc.) call read_classified directly, not read_bounded, so budget-exhaustion detection is preserved where it matters.

Run envelope (run.rs)

The tuple restructuring from (out, exit, record) to ((out, exit), record) is unpacked correctly at the call site in crates/rustev-cli/src/run.rs. not_delivered borrows record before it is moved into the tuple's second position — valid under Rust's lifetime rules.

Archive policy

rustev-surface gains src/adapter.rs and src/out.rs (moved from CLI); the CLI entry drops them and src/out.rs. File lists, byte limits, release-set layer order (surface before CLI), and upload order are all consistent.

Cargo.lock

rustev-backend-rules appears under rustev-surface's dependencies entry in the lock file. In Cargo's lock format, dev-dependencies are included in the same dependencies list, so this correctly reflects the [dev-dependencies] in Cargo.toml.

Test memory_host.rs

The in-memory host implements all Host methods correctly, including "all-or-none" rollback in write_all. include_bytes! paths resolve correctly relative to the crate root.

No bugs, security issues, or behavioral inconsistencies found.

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

Subject: 90c1fd7...fbbdc17, diff digest 3d850e2eeb1d85975a9097b428d77279c7a7e9f938239da3b9603e280388f0c1, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR: extraction of CLI command logic into a new host-agnostic rustev-surface crate.

Architecture / logic

The refactor is structurally sound. The surface's write_all (surface/eval.rs:156–166) pre-checks ensure_absent for every output and then delegates the atomic write to host.write_all. The CLI's Reads::write_all (io.rs:128–140) rolls back already-written files on failure, faithfully reproducing the original behavior. The judged/cancelled/not_delivered envelope helpers in run.rs correctly return (Out, u8) pairs consumed by the destructuring in cli/run.rs:352.

archive-policy.json — incorrect Cargo.lock entry for rustev-surface

The rustev-surface entry in archive-policy.json lists "Cargo.lock" in its files array (it was copied verbatim from the rustev-cli prefix block that became the template for the new entry). rustev-surface is a pure library crate: its Cargo.toml declares no [[bin]] targets. Cargo does not include Cargo.lock in the published archive of library crates. If tools/rustev-release/tests/archives.rs validates the exact published-archive file set against this policy, the test will fail for rustev-surface because Cargo.lock will be absent from the actual archive.

Ownership of src/host.rs in the CLI archive

crates/rustev-cli/src/host.rs is imported by lib.rs (mod host;) and by run.rs (use crate::host::{self, SCOPE_FLAGS};), but it does not appear in the rustev-cli files list in archive-policy.json before or after this PR. This is a pre-existing gap, not introduced here, but worth noting since without it the CLI binary cannot be built from its published archive.

Everything else checked

  • Double ensure_absent (once at command start, once inside write_all) is intentional per the spec comment and correct.
  • Host::read default calls read_bounded(label, limit+1), and oversized detection falls to the document parser's ParseLimits, consistent with the original CLI behavior.
  • DepFail, IoFail, ReadFail re-exports preserve all match arms and output codes exactly.
  • memory_host.rs correctly truncates at max bytes without a budget concept, matching the spec's in-memory semantics.
  • Release-set layering (rustev-surface before rustev-cli) is correct.
{"head": "5a8b9d5a39633265d7b5cd7361877e7ca06beef6", "verdict": "findings", "findings": [{"path": "tools/rustev-release/archive-policy.json", "line": null, "summary": "rustev-surface is a library crate but its archive-policy entry lists \"Cargo.lock\", which Cargo does not include in published library-crate archives; if the archive test validates exact file membership this entry will fail."}]}

Subject: 5b772dc...5a8b9d5, diff digest 3d850e2eeb1d85975a9097b428d77279c7a7e9f938239da3b9603e280388f0c1, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception October 20, 2026 19:35 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown

AI review (findings)

The PR extracts the command surface logic from rustev-cli into a new rustev-surface library crate. The refactoring is mostly clean, but I found a few notable issues:

1. Spec sequencing violation in release artifacts

specs/027-node-and-wasm-bindings/spec.md (added text) explicitly states: "this increment merges after that change" referring to spec 045 (noted as ratified 2026-10-20). Spec 045 (specs/045-command-surface-release-layer/) is not present in the repo, yet this PR already adds rustev-surface to tools/rustev-release/release-set.json and tools/rustev-release/archive-policy.json. The release tooling changes require spec 045's authority to be in place first; merging them now contradicts the spec's own ordering requirement.

2. Forward reference to missing spec in test comment

tools/rustev-release/tests/manifests.rs:83 adds // Spec 045: the command surface the CLI depends on (spec 027). referencing a spec that has no corresponding entry in the repo. This is inconsistent and will be misleading until spec 045 lands.

3. Misleading crate keyword

crates/rustev-surface/Cargo.toml:12 sets keywords = ["decision-engine", "cli"]. The cli keyword on crates.io is conventionally used for binary/command-line tools, but rustev-surface is a pure library. This will affect discoverability and categorization on crates.io.

4. Redundant ensure_absent pre-check in calibrate::fit

crates/rustev-surface/src/calibrate.rs:72-75 manually calls host.ensure_absent for each FIT_OUTPUTS entry before the expensive reproduce/fit_temperature work. That's the correct fail-fast pattern. However, eval::write_all (which fit then calls) repeats ensure_absent for the same paths (eval.rs:147-149), creating a double check. Not a bug, but redundant surface-level validation that could be confusing.

{"head": "a22b5b0cd9e13cf35979d71cfd3ada2d8b80d465", "verdict": "findings", "findings": [{"path": "tools/rustev-release/release-set.json", "line": 17, "summary": "rustev-surface is added to the release family before spec 045 exists in the repo; the spec.md for this increment explicitly states it must merge after spec 045 lands."}, {"path": "tools/rustev-release/tests/manifests.rs", "line": 83, "summary": "Comment references spec 045 which is absent from the repository, creating a stale forward reference."}, {"path": "crates/rustev-surface/Cargo.toml", "line": 12, "summary": "The 'cli' keyword is misleading for a library crate and will miscategorize it on crates.io."}]}

Subject: 40bf9f8...a22b5b0, diff digest 6477206e2aca806fdc7b1fc65a010b178449e1a5a2d714cf9e53bb203f073bec, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception October 20, 2026 19:47 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR, which extracts rustev-cli's command logic into a new rustev-surface crate behind a Host trait.

Structural correctness: The refactoring is mechanically sound. The Host trait correctly abstracts file I/O, write_all preserves the original all-or-none semantics (surface checks ensure_absent for all paths, then delegates to host.write_all which implements rollback), and the double ensure_absent pattern (pre-flight in eval/calibrate::fit + just-before-write in write_all) is intentional and matches the original CLI.

Type safety for resolver: The CLI's new call sites pass resolver.as_ref() to surface functions taking &dyn Resolver. This compiles only if resolver(p) returns Box<dyn Resolver> (not Option<…>), making .as_ref() give &Box<dyn Resolver> → &dyn Resolver. The unchanged replay.rs's resolver function and the old evaluate call both used .as_ref() the same way, so the types are consistent.

Spec ordering violation: specs/027-node-and-wasm-bindings/spec.md Increment 3 text (added by this PR) explicitly states "this increment merges after that change", referring to spec 045 (specs/045-command-surface-release-layer/). That spec is not present in the base commit (not in REPO CONTEXT). Yet this PR adds rustev-surface to release-set.json and the manifests.rs assertion under a comment citing spec 045 as the authority. The release-family membership and the authorizing spec are being landed in the wrong order.

{"head": "e1728ff20a0099f614538847b5694ec6dfd3cff0", "verdict": "findings", "findings": [{"path": "specs/027-node-and-wasm-bindings/spec.md", "line": null, "summary": "Increment 3 text added by this PR states it must merge after spec 045 (specs/045-command-surface-release-layer/), but that spec does not exist in the base commit; release-set.json adds rustev-surface to the release family without the authorizing spec present."}]}

Subject: c606867...e1728ff, diff digest ed9380c37add1310824295624fdb14b587f99cdbad3b6f0d665401c9158858ac, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

This PR extracts rustev-cli's command surface into a new rustev-surface library crate, wiring the CLI to delegate through a Host abstraction. I reviewed it for correctness, behavior parity, and consistency.

Behavior parity — every refactored command preserves the original logic: split_named, read_doc, check_case_ids, read_bundles, write_all, refused, load_refused, dep_failed, addressing, judgment_bytes, record_bytes, capture_status, and the replay/gate/calibrate paths all match the deleted CLI originals. The double ensure_absent (once up front, once inside write_all) is the same redundant-but-safe pattern as before.

Host trait — the required write_all with all-or-none rollback is correctly implemented in both the Reads file-system host and the memory host in the test. read_bounded losing the Budget/File distinction in ReadFail is intentional and consistent with single-file read sites that do not need to distinguish them; read_bundles still calls read_classified directly for budget tracking.

Archive and release metadata — rustev-surface is inserted in its own release layer before rustev-cli in release-set.json, archive-policy.json, and the manifest test. The surface's allowlist correctly includes Cargo.lock (per the spec note for libraries in the family). The removed files (src/adapter.rs, src/out.rs) are absent from the CLI's archive entry and present in the surface's.

run.rs restructure — the old 3-tuple (Out, u8, record) is now ((Out, u8), record). All three match arms (Rejected early-return, Judged/Cancelled, EvidenceNotDelivered) produce the right shape for the new destructure ((mut out, mut exit), record). The &record borrow in not_delivered ends before record is used in the outer tuple.

no_rules hook — public and correctly invoked only when args.rules is non-empty; a host that passes it still compiles definitions with no rules descriptors.

No bugs, security problems, or behavioral inconsistencies found.

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

Subject: d4fc8eb...33d6a2d, diff digest ed9380c37add1310824295624fdb14b587f99cdbad3b6f0d665401c9158858ac, 1 call(s). An AI comment is not an approval.

Base automatically changed from impl/027-schema to main October 20, 2026 20:26
@bartekus
bartekus enabled auto-merge (squash) October 20, 2026 20:28
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

The PR extracts the pure command surface from rustev-cli into a new rustev-surface crate, introducing a Host trait that abstracts over I/O. I reviewed the code for behavioral divergences from the original, security issues, and consistency problems.

Architecture: The Host trait correctly abstracts reads (bounded, classified by budget vs. file failure), writes (all-or-none), ensure_absent, and path joining. The CLI's Reads impl delegates to existing functions; types (IoFail, ReadFail) are moved to the surface and re-exported from the CLI — no type identity breaks.

Behavioral fidelity:

  • write_all in eval.rs preserves the original two-phase pattern: ensure_absent all outputs up front, then host.write_all (all-or-none with rollback). The CLI's Host::write_all uses create + std::fs::remove_file rollback, matching the original.
  • read_doc, check_case_ids, read_bundles, read_side, and all command functions are faithful translations.
  • run.rs: The ((mut out, mut exit), record) destructuring is correct; the borrow of record in envelope::not_delivered(base, &record, ...) ends before record is moved into the tuple's second slot.

Dependencies: rustev-surface's Cargo.lock entry lists rustev-backend-rules only as a dev-dependency — no runtime/executor leaks into the library. ✓

Memory host test: read_classified truncates at max rather than indicating over-limit separately. Since Host::read always passes limit + 1, an oversized document returns limit + 1 bytes which the document parser refuses as oversized. Behavior matches the file host for test purposes.

Release metadata: rustev-surface correctly inserted as its own release layer before rustev-cli in release-set.json and tests/manifests.rs. Archive policy moves src/adapter.rs and src/out.rs to rustev-surface, removes them from rustev-cli, and adds the previously-missing src/host.rs to rustev-cli — all consistent with the actual file deletions in DELETIONS.

No behavioral changes, security issues, or spec inconsistencies found.

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

Subject: 2cda285...b3ae816, diff digest ed9380c37add1310824295624fdb14b587f99cdbad3b6f0d665401c9158858ac, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

The PR extracts CLI command logic into crates/rustev-surface, wrapping it behind a Host trait so the same code can serve the CLI, a future native binding, and a WASM package. I reviewed for correctness, security, and consistency between the surface and the original CLI code.

Host::read over-read is intentional. The default read calls read_bounded(label, limit + 1) so that an oversized document reaches the document parser, which enforces the precise limit. This matches the original CLI pattern; not a bug.

write_all double-checks ensure_absent. Both callers (e.g. calibrate::fit) check up-front, and eval::write_all checks again just before calling host.write_all. This preserves the existing "check before work, check before write" TOCTOU-mitigation pattern. Correct.

read_bounded collapses budget errors to IoFail. Places that need the budget/file distinction call read_classified directly (read_bundles); the default read_bounded is only used where both errors map to the same Done::io. Consistent with the original.

Memory host write_all borrows. create borrows and drops before the rollback body borrows borrow_mut(); no simultaneous borrow. Fine.

Archive policy. rustev-surface lists all ten src/*.rs files, matching include = ["/src/**/*.rs"] in its Cargo.toml. rustev-cli correctly drops src/adapter.rs (deleted) and src/out.rs (deleted). rustev-backend-rules appears only as a dev-dependency in the surface's Cargo.toml; its presence in the Cargo.lock package entry is standard (Cargo.lock lists all deps together). No discrepancies found.

Release-set ordering. rustev-surface is placed in its own layer before rustev-cli and before rustev-cli in upload_order, satisfying the dependency requirement.

No bugs, security problems, or inconsistencies found.

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

Subject: 2cda285...d3d5a34, diff digest b098a51a705d95d3b2c0e85de59f438de45ccf6b3404527ae938aaaee1df689b, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus merged commit 1473a77 into main Oct 20, 2026
7 checks passed
@bartekus
bartekus deleted the impl/027-surface branch October 20, 2026 23:11
bartekus added a commit that referenced this pull request Oct 21, 2026
Spec 027, increment 4 (first change): the shared conformance suite, its
manifest, and the Rust runner over every CLI golden. Stacked on #128.

- `tools/rustev-conformance` (`publish = false`; excluded from the
release set as repository tooling): `cases/manifest.json`
(`rustev.conformance-manifest/1`) with 29 cases, one per CLI golden,
each listing argv, exit code, inputs (repo path, name, SHA-256) and
outputs (stdout or a written file, the golden by repo path and SHA-256,
normalizations). CLI goldens are referenced in place, never copied.
- Cases are harvested from the CLI tests that pin the goldens
(`RUSTEV_HARVEST=1`; `make conformance-harvest`): inputs as they were
before the invocation, under `fixtures/<case>/`.
- Normalizations are the goldens' own (`receipt`, `timing`), in one file
shared by the CLI tests and the runners.
- `make conformance` (no Node toolchain) runs every case through
`rustev_cli::execute` in a fresh directory and compares outputs and exit
codes; tests also check full golden coverage, digests, that `plan_id` is
compared as bytes, and that a differing output or exit code is reported.
- Runtime cases as data, `eval`/`gate` on the packaged tasks, and the
bindings' surfaces follow in later changes.

Second change (runtime cases as data, 3.12.4), folded in: five cases
under `cases/runtime/` mirroring `admission.rs`, `budget.rs`,
`retry.rs`, `time.rs` and `cancel.rs` (each names its test). A case
declares plan/descriptor/calibration fixtures (built from spec 002's
builders), runtime bounds, a scripted backend per registration (per-task
answer sequences, cost, remote end, cancel answer, release answers),
requests, and manual-clock driver steps. `rustev_conformance::runtime`
interprets it with Rust seams; results and record bytes are committed
under `expected/runtime/` and compared without normalization, and the
test checks each expected record against what the mirrored test asserts.
The manifest is now the aggregate of `cases/cli/` and `cases/runtime/`
(drift-checked).

Review round 1 (3 findings): (1) `sha2` is a normal dependency of
`rustev-cli`, so its tests can use it; the harness says so. (2) Fixed:
the files an invocation wrote are read as soon as it ends, so a file the
test writes later is never taken for an output. (3) Fixed: a
normalization that does not apply is reported as such, not as a
difference; test added.

Review round 2 (5 findings): fixed: the harvest probes no normalization
and then each one `normalize::NAMES` lists (one list beside `apply`);
the scripted answer clamps the attempt number to the script; the
coverage count counts JSON goldens only. Answered: the first golden a
test pins names its case, and a reordering that renames it is reported
by the manifest drift check (the harness says so); the refusal fixture
with a repeated `name` key is refused by the bounded parser (duplicate
keys are a category 1 refusal), which the case's golden shows and the
runner reproduces.

Review round 3 (5 findings): (1) fixed: the harvest snapshots the whole
scratch directory before the invocation and takes as written only files
new or changed against it. (2) fixed: a directory entry error panics
instead of being skipped. (3) fixed: the CLI call changes the working
directory under a process-wide lock through a guard that restores it on
drop, panic included. (4) fixed: an output file that cannot be read is
reported with its error; only a missing file is "no output". (5) The
`#[path]` inclusion of spec 002's shared builders is the repository's
existing pattern (the CLI's tests include them the same way): source
inclusion needs no crate edge and the builders' dependencies are this
crate's dev-dependencies; the module is renamed `builders` so it no
longer shadows `core`, and the code says so. A re-harvest leaves every
case unchanged except two replay bundles whose recorded run timing is
wall-clock; the committed ones stay. Restacked on #128.

Review round 4 (7 findings): (1) fixed: a case file that exists but does
not parse fails the harvest instead of being replaced. (2) Every
committed digest is 64 hex characters (all 322 checked), including
actionable.plan.json's. (3) The duplicate `name` in
`refusal-01/cat-01.definition.json` is the point of that case: it is
category 1's parse refusal, and its golden reads `bounds: duplicate key
"name" at byte 761`; the bounded parser refuses duplicate keys rather
than taking the last. (4, 5) fixed: a case's paths and input names must
be relative paths of normal components (`contained`), so nothing is read
or written outside its directory; tested. (6) fixed: a release answer
that gates again is a script error, failed like a missing answer, so a
gate never waits forever. (7) fixed: receipt normalization replaces only
a receipt the output has.

Review round 5 (4 findings): (1) Repeated: the duplicate `name` in
`refusal-01/cat-01.definition.json` is the case: the bounded parser
refuses duplicate keys (its golden reads `bounds: duplicate key
"name"`); serde_json's last-wins never runs. (2) fixed: a missing case
directory or unreadable entry fails aggregation naming it. (3) fixed:
the working-directory guard reports a failed restore while a panic
unwinds instead of panicking twice. (4) fixed: each run's scratch
directory is unique (process id and time) and created fresh.

Review round 6 (2 findings): (1) Repeated a fourth time, so a test now
pins it: `the_duplicate_key_case_is_the_parsers_refusal_of_it` checks
that `refusal-01`'s definition carries the top-level `name` twice (`x`,
then `support-routing`) and that its golden is the bounded parser's
refusal (`duplicate key \"name\"`); serde_json's last-wins never
applies, because the bounded scan refuses duplicates first. (2) fixed:
an output's stream-or-file error names which rule it broke (an unknown
stream, both set, or neither).

Review round 7 (3 findings): (1) fixed: the harvest tries every
combination of the known normalizations, fewest first, so a golden
needing `receipt` and `timing` together is found. (2) Repeated a fifth
time, and the test added last round answers it: the bounded parser
refuses the duplicate before serde_json would see it, and the case's
golden is that refusal (`duplicate key \"name\"`), pinned by
`the_duplicate_key_case_is_the_parsers_refusal_of_it`. (3) fixed: on a
divergence the scratch directory is kept and its path printed.

Review round 8 (3 findings): (1) Repeated a sixth time; unchanged
answer: the fixture's duplicate `name` is the case, and
`the_duplicate_key_case_is_the_parsers_refusal_of_it` pins that its
golden is the bounded parser's refusal. (2) fixed: an output's `file`
must be a contained relative path too, like an input name. (3) fixed:
the runtime runner's scratch directory is unique per case and run and is
kept, with its path printed, when a case diverges.

Review round 9 (3 findings, none a defect; the code now says why): (1)
Repeated a seventh time: the duplicate `name` is the case under test,
pinned by `the_duplicate_key_case_is_the_parsers_refusal_of_it`. (2)
`runtime.deadline` sets no request deadline on purpose: the support
plan's own `deadline_ms` (2000) applies, and the case passes with
`deadline_expired` true; the field's documentation says so. (3) An
ignoring backend's never-ending future is the behavior under test: the
runtime polls a cancelled attempt once (spec 003, 3.7.3), records
`not_observed` and ends the decision without it; `runtime.cancel` passes
on both runners. A comment at that arm says so.

Split (the AI review was cancelled at its 15-minute limit twice): this
PR is now increment 4's first change, the suite, its Rust runner and the
29 CLI cases; the runtime cases (`src/runtime.rs`, `tests/runtime.rs`,
`cases/runtime`, `fixtures/runtime`, `expected/runtime` and their
dependencies) move to a second PR stacked on this one, and #130 is
restacked on that.

Review round 10 (6 findings): (1, 6, and a defect they pointed at)
fixed: the harvest no longer probes combinations of normalizations; each
output gets exactly the normalizations its shape calls for
(`normalize::applicable`: `receipt` when it has a top-level `receipt`,
`timing` when it has `timing`). Probing let a run fast enough to time
every step at 0 match with no normalization, or with a no-op one, and
record a case that later runs would fail. A full re-harvest records
every case exactly as committed. Normalizing also sets only fields an
output has, never adding a `timing` key. (2) By design: an `--out` that
already exists is an input; the no-clobber cases need it there for the
CLI to refuse it, and the code says so. (3) The shared
`normalize_timing` is the one the CLI goldens now pass with; a
difference would fail those tests, not pass silently. (4) fixed: a case
file left from an earlier harvest must record the same inputs this
harvest copied, or the harvest fails and says to rebuild. (5) fixed: the
comment no longer says "both" directories.

Review round 11 (4 findings): (1) Repeated: the shared
`normalize_timing` is in this PR
(`tools/rustev-conformance/src/normalize.rs`) and is what the CLI's
timing-normalized goldens pass with; a difference fails those tests by
name. (2) fixed: the command words before the first flag are never
probed as paths. (3) fixed in what it guards: `normalize.rs` states it
may use only what both crates depend on, and both crates compile it, so
a stray import fails a build at once. (4) Not so: both record goldens
are covered as the written outputs of the `lodging.run` and
`support.run` cases, and the coverage test passes. A full re-harvest
still records every case as committed.

Review round 12 (1 finding, repeated, and wrong): the coverage set holds
every golden any output pins, and each `run` case pins two (its printed
output and its record), so all 31 goldens are covered by 29 cases; the
test passes in CI. It now also asserts by name that both record goldens
are covered.
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