Skip to content

refactor(067): eval live input resolution moves into rustev-surface behind Host (increment 2a) - #548

Merged
bartekus merged 1 commit into
mainfrom
impl/067-inc2a
Nov 7, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/067-inc2a

Conversation

@bartekus

@bartekus bartekus commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Spec 067 (approved), increment 2a of the plan: section 2 Territory and 3.2.3 ("the binding resolves the inputs with the function the CLI uses").

Summary

  • New crates/rustev-surface/src/live.rs (rustev_surface::live): the input resolution rustev eval live did inline, written against &dyn Host, as 063 3.9.3 moved the repeat renderings.
    • Inputs: the digest-binding read wrapper (SHA-256 of every consumed byte string, computed by a caller-supplied function; an input that changes while loading is refused), now host-generic.
    • resolve_inputs: live configuration (parsed by a caller closure, so the surface never depends on rustev-live), dataset, admission, evaluator config, adapter and their consistency, case ids, repeat config, candidates (plans, dependencies, sources, compile, conflicting descriptors, file caps), captures.
    • resolve_cases: bundles or snapshots, per-case inputs with the identity-mismatch checks (decision ids from a caller closure), probe snapshot bytes.
    • The two phases keep the CLI's exact check order: the runtime build and the per-binding cost-model check stay in the CLI between them.
    • The documents directory helper now lists through Host::list / Host::entry_kind instead of std::fs::read_dir (same rules: regular files only, sorted, count cap, a missing or dangling optional sources directory is empty).
  • rustev-surface stays in the pure set with its dependencies unchanged (no rustev-live, rustev-runtime, executor or hashing crate; the CLI passes its SHA-256 function). No manifest or Cargo.lock change. make boundaries passes.
  • CLI live.rs calls both phases and maps the surface's case types one to one onto rustev_live::run::{LiveCase, CaseInput, CaseOrigin}. Runtime, authorizer, journal, execution and outputs are unchanged.
  • tools/rustev-release/archive-policy.json lists the new surface file (031 additive edge).
  • Spec 067 Implementation record: an "Increment 2a" paragraph; implementation stays pending.

Evidence

  • cargo test -p rustev-surface, full cargo test -p rustev-cli (all eval live tests and goldens unchanged), cargo test -p rustev-live, cargo test -p rustev-conformance, cargo test -p rustev-release: pass.
  • cargo run -p rustev-boundaries, workspace clippy -D warnings, cargo fmt --check, cargo build -p rustev-wasm --target wasm32-unknown-unknown: pass.
  • No golden, plan golden, PlanId, schema or conformance case changes.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff, I'll focus on the backend conflict detection change, which is the most structurally significant behavioral difference between the old and new code paths.

Backend conflict detection regressed

Original CLI logic (after the candidate loop, iterating the accumulated rules vec):

for backend in rules {
    let id = backend.descriptor().backend_id.clone();
    if backends.insert(id, backend.descriptor().clone())
        .is_some_and(|old| old != *backend.descriptor())
    {
        return Err(invalid("live-config", "conflicting backend descriptors"));
    }
    rules_by_id.insert(backend.descriptor().backend_id.clone(), backend);
}

All rule backends from all candidates were gathered in one pass, then cross-checked for identical IDs with differing descriptors.

New surface logic (inside the per-candidate loop in resolve_inputs):

for descriptor in deps.descriptors.into_iter().skip(c.descriptors.len()) {
    …conflict check…
}

deps.descriptors holds descriptors loaded from the candidate's descriptor files. c.descriptors is the list of those same files. When those counts match (the common case), skip yields an empty iterator and the conflict check is a no-op for every candidate. Rule backends (captured by rules_hook into the external rules vec) are never checked here at all.

New CLI logic (no conflict check):

for backend in rules {
    rules_by_id.insert(backend.descriptor().backend_id.clone(), backend);
}

The second candidate's rule backend silently overwrites the first if they share an backend_id.

Concrete defect: two candidates providing rule backends with the same ID but different descriptors now produce no error; the last writer wins. The "conflicting backend descriptors" error that the original code was designed to surface for exactly this input is no longer reachable.

The relevant location in the new file is the for descriptor in deps.descriptors…skip(c.descriptors.len()) block (~line 310 in crates/rustev-surface/src/live.rs) and the unchecked insertion loop in the modified CLI (~line 196 in crates/rustev-cli/src/live.rs).

No other concrete defects found (SHA-256 digesting logic is correctly preserved; std::mem::take on sources_by_name before resolve_cases is safe since resolve_cases does not use that field; probe-bytes read ordering is equivalent to the original; symlink detection logic is consistent with how std::fs::read_dir behaved on dangling symlinks).

{"head": "c00c5f809d82b1cfa30ffc61d12c5d82eff3d16a", "verdict": "findings", "findings": [{"path": "crates/rustev-surface/src/live.rs", "line": 310, "severity": "medium", "category": "correctness", "summary": "The per-candidate backend conflict check iterates deps.descriptors.skip(c.descriptors.len()), which yields an empty iterator whenever the counts match (the common case) and never covers rule backends captured by rules_hook; two candidates with the same backend_id but different descriptors now silently overwrite each other in rules_by_id instead of producing the expected 'conflicting backend descriptors' error."}]}

Subject: 78dfabd...c00c5f8, diff digest 859eb36ee0b6d9e816c8f9f7615dbf847305f7aad2eddaf1192bb6f8b840b709, 1 call(s). An AI comment is not an approval.

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

bartekus commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Review note: the finding on crates/rustev-surface/src/live.rs:310 is a false positive.

rustev_surface::deps::load (crates/rustev-surface/src/deps.rs, unchanged by this PR) builds Deps::descriptors as "the descriptors, then each rules program's derived descriptor" (doc comment at line 22): it pushes one entry per --descriptor label (lines 65-66), then, for each rules label, the descriptor returned by the rules hook (lines 68-76). A candidate's c.descriptors is exactly the descriptor-label list passed as DepArgs::descriptors (CandidateFiles::deps, crates/rustev-surface/src/repeat.rs:393-399). So deps.descriptors.into_iter().skip(c.descriptors.len()) yields precisely the descriptors the rules hook derived from this candidate's rules programs, one per rules program, which is what the CLI compared before the move (backend.descriptor() of each RulesBackend the hook created; RulesBackend::descriptor is the value the hook returns, crates/rustev-cli/src/deps.rs rules_hook). When the counts match (a candidate with no rules programs) the iterator is empty because there are no rules backends to compare, as before. Two candidates whose rules programs share a backend_id with different descriptors are still refused with conflicting backend descriptors before any runtime is built; rules_by_id in the CLI is filled only after resolve_inputs returns Ok.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff. The core change moves live input resolution from crates/rustev-cli/src/live.rs into a new crates/rustev-surface/src/live.rs module written against &dyn Host. I'll examine each changed file for correctness and security issues.


crates/rustev-surface/src/live.rs — backend descriptor conflict detection

The original crates/rustev-cli/src/live.rs checked every backend returned by rules_hook for cross-candidate descriptor conflicts:

// original
for backend in rules {
    let id = backend.descriptor().backend_id.clone();
    if backends.insert(id, backend.descriptor().clone())
               .is_some_and(|old| old != *backend.descriptor()) {
        return Err(invalid("live-config", "conflicting backend descriptors"));
    }
    rules_by_id.insert(backend.descriptor().backend_id.clone(), backend);
}

The new surface code replaces this with:

// new surface (~line 290)
for descriptor in deps.descriptors.into_iter().skip(c.descriptors.len()) {
    …conflict check…
}

If deps.descriptors contains exactly the descriptors loaded from the files explicitly listed in c.descriptors (the common case), skip(c.descriptors.len()) produces an empty iterator, so the backends map is never populated and the conflict check never fires for any candidate.

The CLI-side loop that now builds rules_by_id from the rules vec also no longer includes any conflict check:

// new CLI (~line 212)
for backend in rules {
    rules_by_id.insert(backend.descriptor().backend_id.clone(), backend);
}

Concrete failure: two candidates carrying the same backend ID but different configurations would have the second silently overwrite the first in rules_by_id with no error returned. The runtime then uses one candidate's backend against another's compiled plan, violating the invariant the original error guard enforced.


Other changed files

  • crates/rustev-cli/src/live.rs: The sha256 extraction, Inputs→live::Inputs delegation, resolve_inputs/resolve_cases call sites, and case-type mapping all correctly reproduce the original behaviour.
  • crates/rustev-cli/src/repeat.rs: 2-line deletion consistent with the Host abstraction change; no issue.
  • specs/067-node-live-repeat-runs/spec.md: Implementation record added under a draft/in-progress spec; no acceptance item claimed; consistent with the lifecycle rules.
  • tools/rustev-release/archive-policy.json: src/live.rs correctly added to the rustev-surface package list.

{"head": "f04ff666ab44192a270345fc4afced9baae72ad0", "verdict": "findings", "findings": [{"path": "crates/rustev-surface/src/live.rs", "line": 290, "severity": "medium", "category": "correctness", "summary": "Backend descriptor conflict detection is broken: `deps.descriptors.into_iter().skip(c.descriptors.len())` produces an empty iterator when deps.descriptors holds exactly the explicitly listed descriptors, so the `backends` map is never populated and conflicting descriptors across candidates are never detected; the CLI's corresponding loop over `rules` also inserts into `rules_by_id` without any conflict check, so a second candidate's backend silently overwrites the first's with no error."}]}

Subject: b409354...f04ff66, diff digest 317470fce4e58a6e29d6037a2ed22587753529f70aadff1e0f561838b3219344, 1 call(s). An AI comment is not an approval.

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

bartekus commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Review note: on the repeated finding about the backend conflict check (live.rs ~290 at f04ff66): the pre-move CLI compared the descriptors of the RulesBackends its rules hook created for each candidate. The moved code compared deps.descriptors after the candidate's explicit descriptor files, which deps::load fills as 'the descriptors, then each rules program's derived descriptor' (deps.rs:22, 65-76), i.e. the same set; an empty iterator meant a candidate with no rules programs, where the CLI also compared nothing. Behavior was unchanged, but to make it evident ee14a4a collects the descriptors from the caller's rules hook as it derives them and compares exactly those, so the check now reads like the pre-move CLI loop.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff: a refactoring that extracts rustev eval live's input-resolution logic from crates/rustev-cli/src/live.rs into a new host-generic module crates/rustev-surface/src/live.rs.

Logic equivalence checks

  • source_time / compare_with_source guards: original compared config.evaluation_time == EvaluationTime::Source; new maps that to Config::source_time at the call site — equivalent.
  • Admission guard (is_none() ↔ !p.has()): equivalent.
  • Backend-conflict detection: original checked inside the CLI's rules_by_id insertion loop; new checks inside resolve_inputs via the per-candidate derived vec and the cross-candidate backends map. The CLI's post-resolution rules_by_id insertion no longer conflict-checks, correctly relying on resolve_inputs having done so already.
  • documents() file cap: list(dir, max_files + 1) followed by paths.len() > max_files in the loop — same semantics as the original read_dir + push-then-check pattern.
  • Probe bytes path: resolved.config.probe_snapshot is set from config.probe.snapshot.clone() — equivalent.
  • into_digests() call: inputs is consumed after resolve_cases borrows it by reference; sources_by_name is taken before resolve_cases with std::mem::take; both are safe with Rust's borrow rules.

Digest-binding integrity

The Inputs wrapper delegates list and entry_kind without digest-tracking — consistent with the original (which called std::fs::read_dir directly, also untracked). File-content reads are digest-bound through read_classified. No regression.

SHA-256 delegation

digest: fn(&[u8]) -> ContentDigest is a plain function pointer. The surface documents the expected format in its doc-comment but cannot enforce it at compile time. The CLI's sha256 function produces the correct format; the test's fake_digest is explicitly documented as a stand-in. This is a trusted internal boundary, not a security boundary exposed to untrusted input.

New dangling-symlink handling in documents()

The optional-directory path adds explicit entry_kind checks for Missing and dangling symlinks before calling list. The original relied on read_dir returning NotFound. The new logic is strictly more precise; no regression.

Spec and archive policy

Spec 067 is updated with an accurate implementation record matching the diff. archive-policy.json gains src/live.rs for rustev-surface. No ratification or authority changes are made.

Test

The unit test correctly covers the admission-check path and verifies digest binding for all consumed inputs; fake_digest using bytes.len() is sufficient here since the two test inputs have different lengths.

No concrete defects found.

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

Subject: b409354...ee14a4a, diff digest e0f2658d74aea70b104c36516fef5e638a5982b7b527232c3058776230367d7a, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 7, 2026
…ehind Host (increment 2a)

The CLI's eval live input resolution (live configuration, dataset,
admission, evaluator configuration, adapter, repeat configuration,
candidates, captures, bundles or snapshots, case inputs and the probe
snapshot) moves into rustev_surface::live, written against the surface
Host, in two phases that keep the CLI's check order around its runtime
and cost checks. The surface stays free of rustev-live, the runtime and
any executor, with its dependencies unchanged: the caller supplies the
SHA-256. CLI grammar, bytes, exit codes and goldens are unchanged.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff, which extracts live input resolution from crates/rustev-cli/src/live.rs into a new crates/rustev-surface/src/live.rs module, then wires the CLI through it.

Logic preservation check

The original Inputs struct's digest-binding and change-detection logic is faithfully reproduced in rustev_surface::live::Inputs. The read_classified impl correctly detects in-flight changes and collects digests. into_digests() replaces the original .digests.into_inner() call at line 368 — semantically identical.

Backend conflict check

Original code conflated descriptor comparison and backend-object deduplication in one loop. The refactored surface checks descriptors via the backends BTreeMap (identical comparison logic), while the CLI's outer rules vec + rules_by_id insert handles deduplication. The invariant is preserved: same id + different descriptor → error; same id + same descriptor → last write wins (safe because they are identical).

SHA-256 dependency isolation

The sha256 function stays in the CLI and is passed as a function pointer (fn(&[u8]) -> ContentDigest). The surface takes no sha2 dependency, consistent with the spec's claim that make boundaries passes.

candidate_files now goes through the digest-binding layer

In the original CLI, candidate_files received &inputs.reads (bypassing the wrapper), so those reads were not digest-bound. In the new surface, candidate_files(COMMAND, inputs, …) passes the Inputs wrapper, expanding digest coverage to candidate enumeration reads. This is a correctness improvement, not a defect.

documents overflow check

list(dir, max_files + 1) then pushing with if paths.len() > max_files triggers after the max_files + 1-th push, correctly detecting overflow. This matches the original read_dir loop behavior.

fake_digest in tests

The test-only digest maps content to its length. In the test, the two inputs ("caller parsed", 13 bytes; and the JSON dataset blob, a different length) produce distinct fake digests, so the collision scenario does not arise in the actual test, and the test correctly validates both the error path and digest recording.

Spec and archive policy

Increment 2a is correctly described in spec 067. The archive policy entry for src/live.rs is added in the right alphabetical position within rustev-surface's file list.

No concrete defects found.

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

Subject: a52d38b...0a5089b, diff digest e1ac00e1aaec288b566e34f8ce170f8cbc40a80560cada548c1c30f042c0edd9, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit e8f6653 Nov 7, 2026
26 checks passed
@bartekus
bartekus deleted the impl/067-inc2a branch November 7, 2026 22:04
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