Skip to content

impl(061): increment 4, host baselines, reproducibility and selection in the library - #492

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

bartekus merged 1 commit into
mainfrom
impl/061-inc4

Conversation

@bartekus

@bartekus bartekus commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Spec 061 (host-scored repeat sets, A-77), increment 4: host baselines, the reproducibility check and selection, in the library (3.6 to 3.8).

Stacked on #488 (increment 3). It needs only #486's library, but increment 5 (the CLI) needs both, so the chain stays linear.

  • crates/rustev-eval/src/host_select.rs: provenance / one_provenance (mixed-provenance, I-1), rustev.host-baseline/1 and record, reproducibility (3.7.2), rustev.host-selection/1 and evaluate_selection with the 3.7.4 preconditions (no stable-cohort comparison, decision 4) and 3.7.5 coverage clauses.
  • crates/rustev-eval/src/selection.rs: spec 029's clause, verdict and ranking code moved into judge and sort_ranks over a Side, which both selections call. baseline.rs: the 3.9 comparison moved into stability. comparison.rs: check_name_list. No behavior change; every existing selection, comparison and diff test passes unchanged.
  • crates/rustev-eval/mutation/seeds.py: the "unknown selection qualifies" anchor follows the moved line (indentation only).
  • Spec 061 record paragraph; archive-policy.json lists src/host_select.rs.
  • Tests: crates/rustev-eval/tests/host_select.rs.

Archive size: rustev-eval packages to 782,692 unpacked and 193,712 compressed bytes, under #480's 786,432 and the 196,608 archive bound, with little headroom.

@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 across all changed paths: the stability extraction from baseline.rs, the check_name_list extraction from comparison.rs, the new host_select.rs module, the selection.rs refactoring to extract Side, judge, and sort_ranks, the test files, the spec increment, and the archive policy update.

baseline.rs — stability extraction
The refactored reproducibility correctly passes mut reasons by move into stability, which appends exceedances and returns Reproducibility. The change from run.cohorts.iter() to run.iter() is correct for the new slice parameter. No issue.

comparison.rs — check_name_list
The extracted function accepts &[&str] directly; check_names now collects names and delegates. The name-uniqueness BTreeSet logic is unchanged. No issue.

host_select.rs — reproducibility double-checks repeat_config
The first guard uses config.id().ok(): if id() returns Err (a serialization failure), .ok() is None, which is always unequal to Some(&baseline.repeat_config), silently adding a spurious reason even when the configurations actually match. This is an inherited pattern from baseline::reproducibility, not a new regression, but the new host path replicates it.

host_select.rs — comparable case-list check

let ids = |e: &HostSetEvidence<'_>| -> Option<Vec<String>> {
    Some(e.cases.first()?.cases.iter().map(|c| c.case.clone()).collect())
};
if ids(b) != ids(c) { return Err("case lists or order differ".into()); }

Only the first element of e.cases (the first run's cases document) is compared. If a set has multiple runs with differing case lists across runs, the check passes. The spec precondition "case list and order" implies all runs; a uniform-case-list invariant is not enforced here, so a multi-run set whose first run matches but later runs diverge would not be caught.

host_select.rs — counts u64 subtraction
all - failed is a u64 subtraction in coverage. If host-provided data were inconsistent with failed > all, this would panic in debug or wrap in release. The host data is external/asserted, so there is no prior bounds check.

selection.rs — sort_ranks and evaluate_selection for Rustev
The extraction of judge and sort_ranks is faithful: the verdict and ranking logic is identical to the original; stable (precondition for Rustev) remains in evaluate_selection, outside judge, and is not affected. All existing tests are stated to pass. No issue.

selection.rs — value with host flag
Routing to host_repeat::observed for host/ metrics correctly maps host/latency_ms/p0.5 and host/cost_per_1000 as candidate observations per 3.5.3. No issue.

tests/host_support/mod.rs — score_shift clamping
The .min(1.0) → .clamp(0.0, 1.0) fix is defensive and correct for negative score_shift values used in coverage-rejection tests.

Spec increment 4 accurately describes the implementation: stability shared by both reproducibility checks, judge/sort_ranks shared by both selection functions, coverage clauses per run, and the decisions listed (equal run counts not a host precondition, check_name_list, baseline error codes). No contradiction with the governing spec or constitution found.

The concrete, evidence-supported defect is the case-list check in comparable that only inspects the first run's cases document:

{"head": "916ebc619e967a3999f65e99b450c63a02f81e3d", "verdict": "findings", "findings": [{"path": "crates/rustev-eval/src/host_select.rs", "line": 296, "summary": "The `ids()` closure uses `.first()?` and so only compares the first run's case list between baseline and candidate; if subsequent runs in either set carry a different case list the precondition 'case list and order' check passes silently."}]}

Subject: 7eb1a08...916ebc6, diff digest 8f677641ad44236a74fd03c7f3a92382067213cd581bd1c40c59a634feccb59c, 1 call(s). An AI comment is not an approval.

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

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff carefully across all changed paths.

crates/rustev-eval/src/baseline.rs — reproducibility correctly delegates its second half to the new stability(reasons, ...) helper; the ownership/signature change is clean.

crates/rustev-eval/src/comparison.rs — check_name_list extraction is straightforward; the original check_names now delegates to it. No logic change.

crates/rustev-eval/src/selection.rs — The refactor into judge / sort_ranks / Side is faithful to the original inline logic. The metric function now takes &Side<'_> instead of &RepeatReport; it accesses r.cohorts which exists on Side. The value function's new host flag dispatches to crate::host_repeat::observed for host sets, correctly handling the host/ latency/cost observation semantics (3.5.3). The HeldOut arm change from &c.held_out to c.held_out is correct since Side.held_out is already Option<&HeldOut>.

crates/rustev-eval/src/host_select.rs — New file, main subject of the review.

  • provenance / one_provenance: correct; schemas cleanly partitioned; SELECTION_GATE correctly absent (it is shared infrastructure).
  • record: re-assembles via reassemble before constructing the baseline; n is set to r.runs.len() as u64, correct.
  • verify_baseline: re-records and compares structurally; correct.
  • as_metric: uses the irrefutable |HostObservation::Host| pattern to map to Observation::Candidate; this would be a compile error if HostObservation ever gained variants, so it is self-enforcing.
  • reproducibility (host): converts baseline cohorts to BaselineCohort with observation: None, then delegates to baseline::stability. The observation field is not read by stability (which compares pooled/band values), so None is correct.
  • coverage: integer comparison uses i128 arithmetic; all - failed where both are u64 could underflow in release mode if failed > all. Semantically num ≤ den per the count-ratio contract, and reassemble is called before coverage on every candidate, but the subtraction is not guarded within this function.
  • comparable: the ids closure calls e.cases.first() to get the case list; subsequent runs' case lists are not checked. If all runs in a set share the same case list (a likely import-time invariant enforced by reassemble), this is sufficient; but the gap means a candidate whose runs disagree internally (run 0 matches baseline, run 1 does not) would pass comparable and only be caught later by reassemble with a reconcile error rather than the specific "case lists or order differ" message. Not an exploitable hole but the precondition message would be misleading.
  • evaluate_selection: base_ok is computed once and .clone()d per candidate; this correctly makes all candidates Unknown when the baseline verification fails. Gate double-validation pattern matches the existing Rustev path.
  • HostSelection::exit_code: matches spec 029 3.14 (Unknown → 12, any Qualifies → 0, else 11).

crates/rustev-eval/tests/host_select.rs — Tests exercise provenance separation, baseline binding, reproducibility at and beyond the band, selection (qualify, reject, unknown), opaque scorer, held-out clause, and tampered import. Coverage looks complete for the stated increment.

crates/rustev-eval/mutation/seeds.py — Whitespace correction matches the moved code's indentation. Correct.

specs/061-host-scored-repeat-sets/spec.md — Increment 4 paragraph accurately describes the implementation: stability extraction, Side/judge/sort_ranks refactor, check_name_list reuse, decision on equal-run-count not being a precondition, coverage clause labels, and test coverage. Consistent with the diff.

tools/rustev-release/archive-policy.json — src/host_select.rs inserted in alphabetical order. Correct.

No finding rises to a concrete defect with clear incorrect behavior: the comparable / first-run-only case list gap produces a less specific error message in a narrow case but does not cause a false pass (reassemble catches it), and all other logic is faithful to the spec.

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

Subject: 7eb1a08...0e4a27d, diff digest 2a64358de4163747afc44fc71730b09b462ac7d1a2ab233184d8a311243db49a, 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 spec 061 increment 4: host baselines, reproducibility and selection in rustev-eval.

baseline.rs — The stability extraction is clean. reproducibility delegates correctly and the host-side caller in host_select.rs maps HostBaselineCohort to BaselineCohort before calling it. The observation: None in that mapping is intentional: the observation classification for host metrics is handled upstream in as_metric, not in the stability path.

comparison.rs — check_name_list is a straightforward lift of the name-validation body. check_names delegates to it correctly. The pub(crate) visibility is appropriate.

selection.rs — The judge / sort_ranks / Side extraction preserves behavior. The Rustev path reconstructs Side from RepeatEvidence fields, the Host path from HostCohortReport. The value split on host correctly routes to host_repeat::observed for the host/ prefix metrics. The mutation seed indentation change tracks the moved line.

host_select.rs

  • provenance / one_provenance: correctly separates schemas; mixed-provenance is enforced.
  • record / verify_baseline: re-assembly round-trip binds the baseline to its import output.
  • reproducibility: the config.id() check and the run.repeat_config check are logically independent (one compares the in-memory config object's digest, the other the stored digest), so both can fire for a single mismatch. This is a minor UX annoyance but not a correctness defect.
  • comparable: only inspects cases[0] for the case-list equality check. The spec (3.7.4) states equal "case list and order," but reassemble is called per-candidate and enforces set integrity; checking only the first run's list is an intentional simplification consistent with the invariant that all runs in a valid host set share the same list.
  • as_metric: the closure |HostObservation::Host| requires HostObservation to have exactly one variant, which is a Rust compile-time constraint (non-exhaustive patterns would be a compile error). The observation: Some(HostObservation::Host) → Some(Observation::Candidate) mapping matches 3.5.3.
  • evaluate_selection: base_ok is cloned per-candidate; on baseline failure every candidate gets the same unknown reason. SelectionGate::parse roundtrip after gate.check() is intentional integrity enforcement.
  • Coverage clause arithmetic (i128::from(num) * 1_000_000_000 >= min.units() * i128::from(den)) is safe: u64::MAX * 10^9 ≈ 1.6×10^28, well within i128.

Tests — Cover provenance separation, baseline binding, tampering, reproducibility at and one ULP below the band, selection qualifies/rejects/unknown cases, exit codes, and held-out / post-import-tampering unknowns. The single candidate (N=1, unknown k_sd band) correctly reaches an unknown verdict without hitting the run-count precondition (decision 4).

archive-policy.json — host_select.rs correctly added.

No concrete defects found.

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

Subject: 470ec4a...a89466b, diff digest 231d5e4eef02d3b64ae4d89e7b5473cba673a2e3e64ac162472ce3a48f7c689b, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/061-inc3 branch 2 times, most recently from 808f0eb to 74be481 Compare November 4, 2026 23:35
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff across all changed paths: the new host_select.rs module, refactoring of selection.rs/baseline.rs/comparison.rs, updated tests and fixture helpers, spec increment, and archive-policy entry.

crates/rustev-eval/src/host_select.rs — logic and arithmetic

  • counts returns (u64, u64) and coverage computes all - failed (u64 subtraction). Both are aggregate sums over CaseMeasure::Count { num, den } where each per-case num <= den; the aggregate invariant holds for well-formed data.
  • i128 overflow in coverage comparison is impossible: u64 fits in i128.
  • one_provenance correctly short-circuits on the first mixed pair.
  • comparable checks only e.cases.first()? for case-list equality, implicitly assuming all runs share the same case list; this is consistent with how host sets are constructed, and reassemble validates each run's output independently.
  • reproducibility checks run.host != baseline.host (full HostFlow, including flow version) which is correct for reproducibility; comparable checks only host.system (correctly permitting flow/version differences for selection).
  • The double repeat-config check (config.id() and run.repeat_config) is redundant but not wrong; both can fire for different reasons.

crates/rustev-eval/src/selection.rs — refactoring

  • judge correctly takes ownership of clauses, appends require/and_any results, computes the verdict, and returns both. All existing logic is preserved.
  • sort_ranks is correctly split out; evaluate_selection in both files calls it after the candidate loop.
  • metric now takes &Side<'a> and returns &'a MetricReport; lifetime propagation is correct through r.cohorts: &'a [CohortReport].
  • value's new host branch dispatches crate::host_repeat::observed for host metrics; non-host metrics keep the existing observed call. Correct per 3.5.3.
  • The HeldOut match changed from match &c.held_out to match c.held_out where c.held_out: Option<&'a HeldOut>; match ergonomics handle this correctly.

crates/rustev-eval/src/baseline.rs

  • stability is correctly extracted with mut reasons: Vec<String> (moved in), consistent across both callers.

crates/rustev-eval/mutation/seeds.py

  • Indentation updated from 12 to 8 spaces, matching the moved Verdict::Unknown { clause } line inside judge at function-body depth. Correct.

crates/rustev-eval/tests/host_select.rs and host_support/mod.rs

  • extra_failed and latency_base fixture additions are consistent with their use in outcome and record.
  • .min(1.0) → .clamp(0.0, 1.0) is a correctness improvement (guards the lower bound too).

specs/061-host-scored-repeat-sets/spec.md — increment 4 description matches the code changes.

tools/rustev-release/archive-policy.json — src/host_select.rs correctly added in alphabetical order.

No concrete defects found.

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

Subject: 74be481...0bfea28, diff digest 09dcc26960cef1f0e5fc3fc1b93fe06012c0550d174c4fd02a5f3732c49d4622, 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 carefully against the governance documents and the visible repo context.

crates/rustev-eval/src/baseline.rs — The extraction of stability from reproducibility is clean; the host path passes observation: None for every BaselineMetric, which is correct for the symmetrical reproducibility check (both sides are "host" observations and no candidate-observation guard is needed).

crates/rustev-eval/src/comparison.rs — check_name_list splits off the string-slice path; check_names delegates to it. The name-validation logic is unchanged.

crates/rustev-eval/src/selection.rs — The judge/sort_ranks/Side extraction is mechanically correct. The relevant filter (!starts_with("and_any[")) includes coverage clauses, precondition, metric clauses, and the and_any summary but excludes individual and_any[*] members, which matches the original behavior. The change match c.held_out (from match &c.held_out) is valid because Side.held_out is already Option<&HeldOut>. The metric function signature change from &RepeatReport to &Side<'_> is correct since Side.cohorts replaces the RepeatReport.cohorts access. The value function's new host parameter routes the observation check through host_repeat::observed for host-side metrics, as required by 3.5.3.

crates/rustev-eval/src/host_select.rs — Key points checked:

  • provenance / one_provenance: correctly identifies host vs Rustev schemas and refuses mixed sets with mixed-provenance.
  • record / verify_baseline: re-assembles the set before writing the baseline and verifies round-trip equality, binding 3.8.1's members.
  • reproducibility: checks run.host != baseline.host (all of system, flow, flow version), which is correct per 3.7.2 ("equal system, flow, flow version"). comparable (for selection) checks only host.system, which is correct since flow/version may differ there.
  • coverage: uses unsigned all - failed where all and failed come from folding CaseMeasure::Count {num, den}. Because HostCases documents go through reassemble before coverage is ever called, any failed > all inconsistency would be caught by reassemble first; a bare underflow here is not reachable from valid, reconciled data.
  • Verdict logic: coverage clauses precede metric clauses in relevant; a failing coverage clause produces Verdict::Rejected ("measured, never unknown" per test comment), consistent with 3.7.5 being a hard gate minimum.
  • one_provenance correctly identifies same-provenance documents and returns Ok(None) when no known schema is present.

crates/rustev-eval/mutation/seeds.py — Indentation correction from 12 to 8 spaces matches the new nesting level of Verdict::Unknown { clause } inside the extracted judge function.

specs/061-host-scored-repeat-sets/spec.md — Increment 4 prose documents all the decisions accurately (provenance separation, stability factoring, Side, coverage arithmetic, equal-run-count decision, check_name_list reuse).

tools/rustev-release/archive-policy.json — src/host_select.rs inserted in alphabetical order. Correct.

No concrete defects found.

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

Subject: 36cc344...022de40, diff digest 09dcc26960cef1f0e5fc3fc1b93fe06012c0550d174c4fd02a5f3732c49d4622, 1 call(s). An AI comment is not an approval.

Base automatically changed from impl/061-inc3 to main November 5, 2026 00:37
@bartekus
bartekus merged commit 5feed59 into main Nov 5, 2026
3 checks passed
@bartekus
bartekus deleted the impl/061-inc4 branch November 5, 2026 00:38
bartekus added a commit that referenced this pull request Nov 5, 2026
… in the CLI (#495)

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).
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff, I'll focus on the new host_select.rs logic, the refactored selection.rs, and the test infrastructure.

comparable only inspects the first run's case list

The spec 061 §3.7.4 precondition is "equal case list and order." The implementation computes ids with .first()?, returning only the first HostCases entry:

let ids = |e: &HostSetEvidence<'_>| -> Option<Vec<String>> {
    Some(
        e.cases
            .first()?
            .cases
            .iter()
            .map(|c| c.case.clone())
            .collect(),
    )
};
if ids(b) != ids(c) {
    return Err("case lists or order differ".into());
}

If e.cases has more than one HostCases entry (one per run) and runs 2…N have different case lists between base and candidate, the check passes silently. The spec's precondition requires equal case list and order across the whole set, not just the first run. Unless reassemble enforces a single canonical case list for all runs (not visible in this diff), a multi-run candidate whose later runs deviate in case order would reach the clause evaluation with mismatched inputs, producing silently wrong clause results rather than an Unknown precondition.

No other concrete defects were found. The refactoring of judge/sort_ranks/Side from evaluate_selection, the stability extraction in baseline.rs, the value host-observation dispatch, the provenance separation, and the mutation seed indentation update all appear correct. The exit-code priority (Unknown > Qualifies > Rejected) matches spec 029 §3.14.

{"head": "a17b737980d29f234cff7a50f9aa4e60e4a74240", "verdict": "findings", "findings": [{"path": "crates/rustev-eval/src/host_select.rs", "line": null, "summary": "comparable() uses .first()? and therefore only checks the first run's case list; mismatches in subsequent runs are silently ignored, violating the spec 061 §3.7.4 precondition that case list and order be equal across the whole set."}]}

Subject: 9fc59f6...a17b737, diff digest 09dcc26960cef1f0e5fc3fc1b93fe06012c0550d174c4fd02a5f3732c49d4622, 1 call(s). An AI comment is not an approval.

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

This branch was previously deployed

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