Skip to content

impl(061): increment 5, host baselines, reproducibility and selection in the CLI - #495

Merged
bartekus merged 1 commit into
mainfrom
impl/061-inc5
Nov 5, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/061-inc5

Conversation

@bartekus

@bartekus bartekus commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Spec 061 (host-scored repeat sets, A-77), increment 5: baseline record, eval reproducibility and gate select over host sets, with the mixed-provenance refusals (3.6.2, 3.7, 3.9).

Stacked on #492 (increment 4).

  • crates/rustev-cli/src/host_sets.rs: schema-only provenance routing before any parse (a mix is invalid_input, mixed-provenance, nothing written), import output read-back, and the host baseline, reproducibility and selection commands. A candidate that no longer re-assembles is the library's unknown (reconcile), not a refusal.
  • crates/rustev-cli/src/repeat.rs: three early returns into the host path; spec 029's path and outputs are unchanged when inputs are Rustev-evaluated (every existing repeat test and seed anchor untouched).
  • Spec 061 record paragraph.
  • Tests: crates/rustev-cli/tests/host_sets.rs, goldens under crates/rustev-cli/tests/golden/host/ (exit codes 0, 11, 12, 13 and every mixed-provenance row).

@bartekus bartekus added the statecraft:stacked-ci Run the full CI matrix on a stacked pull request label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (findings)

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

crates/rustev-cli/src/host_sets.rs — select skips baseline verification

The reproducibility function correctly calls bound_baseline, which calls host_select::verify_baseline before computing anything:

// reproducibility (line ~350 in host_sets.rs)
let (baseline, base) = bound_baseline(&s, p)?;   // verifies baseline ↔ import

The select function reads the same two artefacts but omits the verification step entirely:

// select (line ~430 in host_sets.rs)
let baseline: HostBaseline = s.doc(p.req("baseline"))?;
let base = ImportFiles::read(&s, p.req("baseline-eval"))?;
// ← no verify_baseline / bound_baseline call
let selection = host_select::evaluate_selection(
    &gate, &baseline, &base.evidence(&base_runs), &candidates,
)?;

The spec text in the same PR states that the host path "verifies the host baseline against its import output" and bound_baseline is specifically defined as "The host baseline and its import output, verified (3.7.4)." The tampered-baseline test exists only for reproducibility (a_host_baseline_and_its_reproducibility); host_selection_exit_codes has no equivalent tamper test for select. A modified baseline document that changes pooled metrics or band widths would be accepted silently by select and used to evaluate candidates, potentially reversing a selection outcome.

No other concrete defects found. (The TOCTOU pattern in ImportFiles::read — Path::exists() before s.doc — is a local-filesystem CLI limitation, not a security boundary. The schema_of returning Ok(None) on parse failure is consistent with the spec's "none when the file has no schema string" intent and falls through to the Rustev path which fails with its own error.)

{"head": "a69546e9efa3f9b8a5955427676720acdd1a209c", "verdict": "findings", "findings": [{"path": "crates/rustev-cli/src/host_sets.rs", "line": null, "summary": "The `select` function reads the baseline and its import output but never calls `host_select::verify_baseline` (via `bound_baseline`), so a tampered baseline is accepted silently for selection, unlike `reproducibility` which explicitly verifies via `bound_baseline` before proceeding."}]}

Subject: 0e4a27d...a69546e, diff digest 2fee3fd62c7baa54049a06c6a694d87bb4f59c59ce1f375f9823222b9ad67e5c, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

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

host_sets.rs — schema_of
Uses REPLAY_V1.max_bytes.saturating_add(1) as the read bound for all schema-string probes regardless of document type. The intent is a lightweight schema-only read (3.6.2), not a full parse, so this is an intentional simplification. No defect.

host_sets.rs — ImportFiles::read optional-file checks
views and per-scorer scores-{id} files are detected with std::path::Path::new(&path).exists() rather than through s.reads, inconsistent with schema_of which uses s.reads.read_bounded. In practice Reads::default() wraps the same filesystem so the results agree. The TOCTOU window between .exists() and the subsequent s.doc() call could produce an IO error on a racing deletion, but not a security concern. This inconsistency predates this PR in pattern (import already writes per-scorer files); no new defect introduced.

host_sets.rs — select, write-before-check on code 11 / 12
s.write(...) runs unconditionally after evaluate_selection, even for none-qualified (11) and unknown (12) outcomes. The existing gate select path in spec 029 follows the same convention, and the test does not assert absence of the output file for those codes. Consistent with existing behavior.

host_sets.rs — select, fallthrough on directories error
If crate::repeat::directories fails (e.g., candidates directory absent), the host path returns None and the Rustev path handles the error. The comment acknowledges this explicitly. The subsequent Rustev path will fail on the same missing directory; minor UX imprecision, not a defect.

host_sets.rs — reproducibility, variable e shadowing in closure
The closure parameter |e| inside exceedances.iter().map(|e| …) correctly shadows the outer e: HostSetEvidence. Rust resolves this unambiguously; no bug.

repeat.rs — compare dispatch guard
crate::host_sets::reproducibility is guarded by p.spec.path == ["eval", "reproducibility"], preventing the host path from being invoked for eval diff. The eval diff path falls through to the Rustev handler, which refuses a host-schema baseline by schema (tested in host_and_rustev_documents_are_never_mixed). Consistent with spec text.

Spec 061 increment 5 text
Matches the implementation: schema-read routing, host path in host_sets.rs, baseline-binding verification in both reproducibility and selection, re-assembly check on the run, host-asserted on all outputs, correct exit codes (0 / 11 / 12 / 13), and the described test coverage. No inconsistency.

No concrete defects found.

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

Subject: a89466b...f486fe2, diff digest ed28a5362fdd4afd5d89efb07422ce71d77ac8a5003f3ef82c49b8b4ca2948b0, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff for spec 061 increment 5: host baselines, reproducibility, and selection in the CLI.

crates/rustev-cli/src/host_sets.rs

  • schema_of reads with REPLAY_V1 size bounds purely to cap memory before extracting the schema key — semantically reasonable even though the files are not replay documents.
  • provenance_of returns Ok(None) when all queried files are absent (each schema_of returns Ok(None)). This silently falls through to the Rustev path, which will then produce its own error. That is the design intent and consistent with how other routing works.
  • ImportFiles::read uses std::path::Path::new(&views).exists() followed by a read (TOCTOU). This is a CLI tool on trusted local files; the race is not exploitable in this context and matches existing patterns in the codebase.
  • The reproducibility function correctly passes base.repeat (baseline's repeat config) to host_select::reproducibility, which is where band parameters live.
  • The select function does not explicitly call reassemble per candidate; it delegates to host_select::evaluate_selection, which surfaces a failed-reassembly candidate as unknown. The test with a post-import file modification (changed/faster/run-0.host-run.json) confirms exit 12 and a reconcile message — matching the spec's intent.
  • The s.absent guard runs after provenance routing, so the output-exists check is not reachable on a mixed-provenance error. The tampered-baseline test verifies no output is written on invalid_input.

crates/rustev-cli/src/repeat.rs

  • The compare routing guard p.spec.path == ["eval", "reproducibility"] correctly prevents eval diff with host documents from reaching host_sets::reproducibility. The eval diff test in host_and_rustev_documents_are_never_mixed confirms the refusal.
  • Visibility changes (pub(crate) on NOT_REPRODUCIBLE and directories) are minimal and appropriate.

specs/061-host-scored-repeat-sets/spec.md

  • Increment 5 prose accurately describes the implemented behavior: schema-first routing, mixed-provenance refusal before any write, invalid_input on baseline verification failure, reassembly refusal for reproducibility, library-delegated unknown for candidates, assertion: "host-asserted" on all outputs including exceedances, and eval diff refusal by schema. No contradictions with the normative text found.

Golden files — the stdout and JSON goldens are consistent with the described behaviors (exit codes 0/11/12/13, host-asserted assertions, reconcile in unknown output, no tampered output written).

No concrete defects found.

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

Subject: 6309789...20be5c6, diff digest ed28a5362fdd4afd5d89efb07422ce71d77ac8a5003f3ef82c49b8b4ca2948b0, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the PR for spec 061 Increment 5. The changes add host-baseline, reproducibility, and selection CLI paths in host_sets.rs, dispatch logic in repeat.rs, and new golden fixtures.

Finding: schema_of applies REPLAY_V1.max_bytes as the read and parse cap for all document types

crates/rustev-cli/src/host_sets.rs — schema_of function (the new block near the top of the diff):

let Some(bytes) = s
    .reads
    .read_bounded(path, REPLAY_V1.max_bytes.saturating_add(1))
    …
Ok(
    rustev_contract::bounded::parse_bounded::<Schema>(&bytes, &REPLAY_V1)
        .ok()
        .map(|d| d.schema),
)

REPLAY_V1 is a replay-document limit, but schema_of is called on host-baseline documents, host-repeat-report documents, and cases files — all of which carry their own (potentially larger) byte limits. When any of those documents exceeds REPLAY_V1.max_bytes, parse_bounded fails and .ok() converts it to None. provenance_of then calls schemas.extend(...), silently drops the absent schema, and may resolve a single-provenance verdict from the remaining inputs only. That can cause the mixed-provenance guard (3.6.2, I-1) to pass undetected: e.g. a large host-baseline file paired with a Rustev-schema repeat.json would see only the Rustev schema, return Ok(Some(Provenance::Rustev)), and fall through to Ok(_) => return None rather than emitting invalid_input mixed-provenance. The wrong limit should be replaced by one appropriate to each document kind, or by reading only enough bytes to locate the schema key.

No other concrete defects were found. The exit-code mapping, lifetime structure of NamedHostCandidate, the bound_baseline verification path, and the guard on p.spec.path == ["eval", "reproducibility"] in compare all appear correct.

{"head": "8f1f6144d2651f276b605e8aec15942550ee00d9", "verdict": "findings", "findings": [{"path": "crates/rustev-cli/src/host_sets.rs", "line": null, "summary": "schema_of uses REPLAY_V1.max_bytes to read and parse baseline, repeat-report, and cases documents; any file that legitimately exceeds that replay-document limit has its schema silently dropped, allowing a mixed-provenance input to bypass the invalid_input guard."}]}

Subject: 0bfea28...8f1f614, diff digest ed28a5362fdd4afd5d89efb07422ce71d77ac8a5003f3ef82c49b8b4ca2948b0, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (no-findings)

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

host_sets.rs — schema_of: Reads REPLAY_V1.max_bytes + 1 bytes then checks > REPLAY_V1.max_bytes to detect oversize; this correctly distinguishes "exactly at limit" from "over limit". The absent-file Ok(None) path is deliberate.

host_sets.rs — provenance_of: Absent files contribute no schema (via Option::extend). If all probed files are absent one_provenance(&[]) is called, which likely returns Ok(None), falling through to the Rustev path where a file-not-found error follows. Acceptable.

host_sets.rs — ImportFiles::read: The std::path::Path::new(&path).exists() TOCTOU for optional views/scores files is not a security issue in a CLI context. Scorer IDs come from EvaluatorConfig and feed into format!("scores-{id}") without sanitization; a malicious or corrupt config could construct an unexpected path, but since the user supplies the config file themselves this is not an exploitable attack surface.

host_sets.rs — select: Swallows the directories error and returns None, routing to the Rustev path. If the candidates directory is missing but baseline schemas are known, Rustev's path would then report the directory error — slightly confusing but intentional per the comment.

host_sets.rs — exit-code mapping: The _ => "unknown" arm covers code 12 correctly. Any hypothetical library code outside {0, 11, 12} would map to "unknown" and still write an output file; the library spec constrains it to those three values so this is not a bug.

repeat.rs — compare guard: The let chain (p.spec.path == [...] && let Some(r) = ...) correctly limits the host-sets dispatch to eval reproducibility only, leaving eval diff to fall through to Rustev's parser, which refuses a host schema naturally (consistent with spec text).

Spec text vs. code: "Leaves a candidate that does not re-assemble to the library, which makes it unknown" — select does not call reassemble on candidates; evaluate_selection handles it internally. reproducibility does call reassemble on the run explicitly and refuses on failure. Both match the spec's stated distinction. Baseline verification runs in both reproducibility and select before any write, consistent with "nothing written" on a tampered baseline.

Golden files and test coverage: The golden stdout values (recorded.stdout, reproducible.stdout, not-reproducible.stdout, none-qualified.stdout, selected.stdout, unknown.stdout) match the status strings and assertion: "host-asserted" fields produced by the code. The not-reproducible.stdout correctly includes "assertion":"host-asserted" on each exceedance, consistent with the spec text.

No concrete defects found.

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

Subject: 022de40...1b4e846, diff digest b6714281157064c2084897ba85b6df0861201cb4aecb42031a74a188125f0a0d, 1 call(s). An AI comment is not an approval.

Base automatically changed from impl/061-inc4 to main November 5, 2026 00:38
@bartekus
bartekus merged commit 7855bb1 into main Nov 5, 2026
3 checks passed
@bartekus
bartekus deleted the impl/061-inc5 branch November 5, 2026 00:38
bartekus added a commit that referenced this pull request Nov 5, 2026
Spec 061 (host-scored repeat sets, A-77), increment 6 of 6: mutation
seeds, declared verification and closure.

Stacked on #495 (increment 5).

- `crates/rustev-eval/mutation/seeds.py`: the seven acceptance seeds
under `spec 061` (joins `OWN_RUNS`): mixed provenance accepted, an
unknown latency skipped, unknown cost counted as zero, failed cases
included in latency, stable cohorts compared for host sets,
`observation: "host"` treated as historical, a duplicate `host.run`
accepted. `tests/host_run.rs` adds the unknown-cost case.
- Spec 061: the `verify:cli` block, `extends` edges on `Makefile` and
`scripts/acceptance/` (001, additive), the increment 6 record and
`implementation: complete`.
- `Makefile`: 061 in `VERIFIED_SPECS`. `scripts/acceptance/verify.py`:
061 in `cli-backends` beside 029 and 041.
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

AI review (no-findings)

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

host_sets.rs — schema_of: The read-one-extra-byte pattern (saturating_add(1)) followed by the > REPLAY_V1.max_bytes guard is correct. parse_bounded is called only on bytes that passed the length check.

host_sets.rs — provenance_of: schemas.extend(schema_of(s, p)?) correctly handles Option<String> via extend, silently skipping absent files. one_provenance then checks all collected schema strings for consistency.

host_sets.rs — ImportFiles::read: The views and per-scorer scores files use std::path::Path::new(&path).exists() before s.doc(). This bypasses the Reads abstraction for the existence check (actual read still goes through s.doc), and introduces a minor TOCTOU pattern. In a CLI context against a local filesystem this is benign, and the read itself is bounded, so no concrete defect.

host_sets.rs — baseline: Checks repeat.json and run-0.cases.json for provenance before proceeding. Consistent with spec 3.6.2 (I-1) requirement that baseline record check its first run-0.cases.json.

host_sets.rs — reproducibility: Uses base.repeat (from the baseline's import output) rather than run.repeat for the reproducibility call. This is intentional — the band parameters are defined relative to the baseline configuration. The tampered-baseline path is correctly refused before any comparison.

host_sets.rs — select: Silently falls through to the Rustev path when directories fails; documented by comment, and the Rustev path will produce the same error. The absence check (s.absent) happens before bound_baseline, so a tampered baseline is refused before any file is written — confirmed by the test at the tampered-baseline branch. Output is written for exit codes 0, 11, and 12; "nothing written" is only promised for invalid_input, consistent with spec text.

repeat.rs — compare dispatch: The let-chain if p.spec.path == ["eval", "reproducibility"] && let Some(r) = ... correctly guards the host-reproducibility path so eval diff is unaffected.

repeat.rs — select and baseline dispatch: Both dispatch before constructing Reads, returning early on host inputs, leaving the Rustev path's bytes unchanged.

Golden files: The assertion: "host-asserted" on stdout outputs and assertion: "host" in recorded documents is consistent with spec intent. Each exceedance in not-reproducible.stdout carries "assertion":"host-asserted" as required. Exit codes (0 / 11 / 12 / 13) match the existing spec 029 codes.

Spec text: The Increment 5 paragraph correctly summarises the implementation, including the mixed-provenance table, the eval diff refusal, and the distinction between refused reassembly (reproducibility) and library-delegated unknown (select).

No concrete defect found.

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

Subject: 5feed59...e270d75, diff digest b6714281157064c2084897ba85b6df0861201cb4aecb42031a74a188125f0a0d, 1 call(s). An AI comment is not an approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

statecraft:stacked-ci Run the full CI matrix on a stacked pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant