Skip to content

impl(033): increment 3, check evaluation and actionable outcomes - #122

Merged
bartekus merged 1 commit into
mainfrom
impl/033-eval
Oct 20, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/033-eval

Conversation

@bartekus

@bartekus bartekus commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Spec 033, increment 3 of 5: check evaluation and actionable outcomes (3.3 to 3.7). Stacked on #121. Judgment 2 needs an action on every outcome and notice, so evaluation and actions land together (plan revised in the record).

  • Checks run after input validation, before any step, in declaration order: relaxed, not_evaluated (unresolved/absent subject), unevaluable (unresolved read or fault; the subject becomes unresolved with the reason), passed, failed{class, consequence}.
  • Consequences: drop_field (absent for every reader, entry kept in evidence with dropped{check}), relax (later checks of the group), downgrade_grade (lowers, never raises), continue_with_notice; each emits its notice. First failing terminal check decides: refused lists every refusing check; abstain/escalate that check's; no step, no semantic request, no policy; derivation and lineage from the deciding reads.
  • provenance_within: an input's accepted entry's class, or every class of a plan 3 step value's provenance set.
  • Policy reports the deciding site; propagate_with carries its remediation/address; needs_input its fields and question ids.
  • rustev.judgment/2: unresolved{reason, action}; refused with one action per refusing check and their combined party; needs_input with byte-identical templates, rustev.continuation/1 digest and a caller-addressed provide_fields action; every notice carries an action. Causes per 3.5.6, overrides per 3.5.3, remediations per 3.6 (declared params evaluated; none when one reads an unresolved input), transience per 3.6.4 with the bound backend's determinism. Backend origin is upstream until increment 4 wires the runtime's.
  • Evidence 2: every check record, each dropped input.
  • Tests: actionability_eval.rs (section 5 rows 1, 2, 10, 11, 12, 16, 20, 22, 23 and more).

Review round 1 (2 findings, both fixed): a subject that is resolved but has no used entry records its check as not_evaluated instead of skipping it; the continuation's canonical bytes are taken with an explicit expectation rather than a silent empty default. Rebased on #121.
Local: full cargo test --workspace passed at the previous head (existing goldens unchanged).

Review round 2 (3 findings): (1) a version 1 input keeps its accepted classes in observed because only a version 2 definition declares actionability, the sole reader; the code says so; (2) the notice match is exhaustive: uncalibrated_threshold and fallback are capability{step} with provide_capability (3.5.4 table), and the check kinds, which never appear among the policy notices, keep their own causes; (3) the continuation digest covers exactly the question ids the outcome carries, computed after filtering (the compiler already refuses undeclared ids, 3.7.1).

Review round 3 (1 finding, answered in code): 3.5.2 defines accepted{classes} as the declared classes, and an input cause carries one class; with several entries of different classes and none used, the cause lists the declared classes, which bound every class the field could have had. conflict lists each entry's observed class itself (3.5.6). The code says so.

Review round 4 (2 findings): (1) fixed: a continuation digest that did not parse would be a defect, so it is an expect (like the canonical bytes beside it), never a placeholder; (2) only inputs can be unresolved in a check's test: the compiler refuses step reads (types) and now and literals always resolve; the code says so.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff carefully across actionable.rs, compile.rs, evaluate.rs, policy.rs, the new test file, and the spec update.

Finding 1 — Silent wrong continuation when record_canonical_bytes fails

In evaluate.rs, actionable_outcome(), Outcome::NeedsInput arm:

let bytes = rustev_contract::canonical::record_canonical_bytes(&json!({...}))
    .unwrap_or_default();           // ← silent fallback to []
let digest = rustev_contract::canonical::tagged_digest(
    rustev_contract::actionability::CONTINUATION_TAG,
    &bytes,
);
if let Ok(d) = serde_json::from_value(json!(digest)) {
    n.continuation = d;             // ← skipped silently if parse fails
}

If record_canonical_bytes ever returns Err (e.g. for a non-finite decimal in the snapshot), bytes is empty and the digest is computed over zero bytes — a wrong continuation is emitted with no error. The second if let Ok(...) also silently leaves the zeroed placeholder. Since the continuation digest is the verifiable binding between evaluation and a follow-up request, a wrong value here breaks integrity without any observable failure path. The function should propagate the error, or at minimum log it rather than swallowing it.

Finding 2 — Silent skip of a failing check when input_evidence is not Resolved

In evaluate.rs, run_checks():

// status() just returned Ok for c.subject:
let class = match self.input_evidence.get(&c.subject) {
    Some(InputStatus::Resolved { provenance, .. }) => *provenance,
    _ => continue,   // ← silent skip
};

After self.status(…) returns Ok, the check failed its predicate but input_evidence is absent or holds a non-Resolved variant. The continue skips the check entirely — no Failed record is pushed, no notice is emitted, no refusal is registered — effectively treating a failing check as if it had passed. For a refuse consequence this would mean a non-compliant input reaches the policy unchallenged. Even if the invariant between inputs_status and input_evidence holds in practice, a debug assertion or an explicit error record would make the assumption explicit rather than silently correct.

{"head": "6b113ef152904f2bb9757de72c31987c9a5da419", "verdict": "findings", "findings": [{"path": "crates/rustev-core/src/evaluate.rs", "line": null, "summary": "In actionable_outcome() NeedsInput arm, record_canonical_bytes(...).unwrap_or_default() silently replaces a serialization failure with empty bytes, producing a wrong continuation digest with no error surfaced."}, {"path": "crates/rustev-core/src/evaluate.rs", "line": null, "summary": "In run_checks(), after status() returns Ok for the check subject, `_ => continue` silently skips a failing check (emitting no record, notice, or refusal) when input_evidence does not hold Resolved for that subject."}]}

Subject: 8222ce9...6b113ef, diff digest 264d9d89a461f2a7fc90428e1cd48596aeeb8a5bd3757845aac92be6ee91f38d, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 20, 2026 07:34 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/033-compile branch 2 times, most recently from 9b9e848 to c080c64 Compare October 20, 2026 07:46
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the implementation of spec 033 increment 3 (checks, consequences, provenance_within, actionable outcomes).

actionable.rs

reason_fields() (line ~1218): split('/').next() always returns Some, so .unwrap_or(f) is unreachable. Cosmetic only.

evaluate.rs — observed map for v1 inputs

Lines ~387–407: for v1 inputs the observed map is populated with all accepted classes before validate_input() runs. Unlike v2 inputs, observed is never narrowed to the single resolved provenance after validation. Downstream input_cause() then sees multiple classes and emits Accepted rather than Observed causes, giving the wrong party computation. In practice actionability requires definition/2, which always sets v2 = true, so the v1 branch is unreachable — but the inconsistency is latent.

evaluate.rs — actionable_notices catch-all arm

Lines ~2028–2039:

_ => (
    vec![Cause::Capability { name: name.clone() }],
    Remediation::with("provide_capability", ...),
),

Every pre-existing Notice whose kind is not Truncation is classified as a capability cause with provide_capability. If NoticeKind carries any variant that is not capability-related (e.g. a future or existing variant for grading, data quality, etc.), that notice would receive a wrong cause and remediation in every judgment/2 document. The correctness of this depends entirely on the full NoticeKind enum, which is not shown.

evaluate.rs — NeedsInput question filtering vs. continuation digest

Lines ~2143–2152: ids captures question IDs from the placeholder before n.questions is overwritten with the filtered set. If a question ID from the rule/handler is absent from actionability.questions (compilation should prevent this but doesn't enforce it at runtime), it is silently dropped from the outcome while remaining in ids. The continuation digest would then cover a question ID not present in the outcome, breaking the reproducibility guarantee of 3.7.4.

policy.rs — provenance_within reads before get()

Lines ~168–175:

self.read(reference);
self.view.get(reference)?;
self.view.provenance(reference)?
    .iter()
    .all(|c| classes.contains(c))

provenance() also calls self.status() internally, so the status is checked twice; harmless but redundant. No bug.

evaluate.rs — Refused terminal with prior Abstain/Escalate

When terminal is already Abstain or Escalate, a later Refuse consequence still pushes to self.checks.refusals unconditionally, but since the terminal is not Refused those refusals are never surfaced. No observable effect, but the state is misleading.


{"head": "da5b8a5011533770af21e3ef03b68c85963df6ba", "verdict": "findings", "findings": [{"path": "crates/rustev-core/src/evaluate.rs", "line": 387, "summary": "For v1 inputs, the `observed` map is initialised to all accepted classes but never narrowed to the single resolved provenance after `validate_input()`, so `input_cause()` returns `Accepted` instead of `Observed` causes and computes the wrong party; unreachable today because actionability requires definition/2 (v2=true), but the latent inconsistency remains."}, {"path": "crates/rustev-core/src/evaluate.rs", "line": 2031, "summary": "The catch-all arm of `actionable_notices` assigns `Cause::Capability` and `provide_capability` remediation to every pre-existing non-Truncation notice kind; if any existing `NoticeKind` variant is not capability-related, every `judgment/2` document will carry a wrong cause and remediation for that notice."}, {"path": "crates/rustev-core/src/evaluate.rs", "line": 2143, "summary": "Question IDs absent from `actionability.questions` are silently dropped from `n.questions` but still included in `ids` used for the continuation digest, so the digest would cover question IDs not present in the outcome, violating the reproducibility guarantee of 3.7.4."}]}

Subject: c080c64...da5b8a5, diff digest c0e6063c1342d4726d96914efb2a34e3deb24ad57eda6f65b0d591afc65fa629, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff, which adds spec 033 increment 3: check evaluation, consequences, terminal outcomes, and actionable outcomes.

General structure looks sound. The check loop in run_checks handles relaxed, not-evaluated, unevaluable, and failing cases in the right order; terminal precedence is correctly enforced; deciding_reads accumulation for multiple refusals is correct; advance() is skipped on a terminal check; the policy is bypassed.

One actual bug — input_cause over-reports causes via decl.provenance:

In evaluate.rs, input_cause uses this fallback when observed holds ≠ 1 class:

_ => CauseProvenance::Accepted {
    classes: self.compiled.info.inputs.get(field)
        .map(|(_, d)| { let mut v = d.provenance.clone(); v.sort(); v })
        .unwrap_or_default(),
},

observed is populated from actual entries whose provenance matched the declaration. If a field has two accepted entries with different classes (say user-supplied and model-derived), observed holds [model-derived, user-supplied] — but the _ arm uses d.provenance (the full declared set) instead. Spec 3.5.2 says "every accepted entry's class when none was used", meaning the classes actually present in the snapshot, not all classes the input could theoretically accept. When decl.provenance is a strict superset of the observed subset, the cause lists classes for which no entry existed, fabricating a broader attribution than what the evidence supports.

The Some([]) sub-case (no entries at all) is harmless — there are no accepted entries to list — but the Some([a, b]) sub-case is the real conformance gap. No test covers it (every test uses single-entry snapshots).

Other observations (not bugs):

  • lower() correctly propagates the grade ceiling recursively and never raises; the combine direction is consistent with the rest of the grading model.
  • transient() matches spec 3.6.4 exactly.
  • provenance_within correctly returns true for an empty provenance set (vacuous all), matching the "an empty set is within" note in 3.4.7.
  • needs_input placeholder is correctly replaced in actionable_outcome; the continuation digest computation matches spec 3.7.4.
  • deciding_reads for terminal Refused accumulates reads from all refusing checks; Abstain/Escalate freeze reads at first occurrence — both correct.
  • The Abstained cause site routing (check: prefix detection in reason_causes) is correct for the reachable path where checks drive the abstain; a handler-propagated Abstained would misformat as rule:check_id but that path isn't reachable since the policy only runs when checks.terminal.is_none().
{"head": "717316efd298cc7a881987ff86f134970b040bae", "verdict": "findings", "findings": [{"path": "crates/rustev-core/src/evaluate.rs", "line": null, "summary": "input_cause's fallback arm uses decl.provenance (all declared accepted classes) instead of the actual observed subset when two or more entries with different provenance classes were present but none was selected, over-attributing causes to classes for which no snapshot entry existed, contrary to spec 3.5.2's 'every accepted entry's class when none was used'."}]}

Subject: 7a48144...717316e, diff digest 5d17bfa6968b7ac994c046a00f0b0dd8490f4cab976020eccd6c54a5da64a719, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 20, 2026 08:32 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at the diff, this is a substantial implementation of spec 033 increment 3 (checks, consequences, terminal outcomes, provenance_within, and actionable outcomes). The logic is generally well-structured. I found two issues worth calling out.


Issue 1 — Silent continuation placeholder corruption (evaluate.rs, actionable_outcome, NeedsInput arm)

let digest = rustev_contract::canonical::tagged_digest(
    rustev_contract::actionability::CONTINUATION_TAG,
    &bytes,
);
if let Ok(d) = serde_json::from_value(json!(digest)) {
    n.continuation = d;
}

If serde_json::from_value fails to parse the digest, the continuation silently stays as the all-zeros placeholder built in needs_input. A wrong continuation would make resumption impossible and would not be caught at runtime. The canonical-bytes step immediately above uses .expect("continuation inputs have canonical bytes"); the same pattern should be applied here. The failure mode is inconsistent and the diagnostic value of the placeholder is zero.


Issue 2 — run_checks only checks input: refs for unresolved resolution (evaluate.rs, run_checks)

let mut reads: Vec<String> = refs
    .iter()
    .filter(|r| r.starts_with("input:"))
    .map(|r| crate::expr::base_ref(r))
    .collect();
reads.sort();
reads.dedup();
let unresolved = reads.iter().find_map(|r| self.status(r).err());

Non-input: references in the test predicate (e.g. a stray step: ref, which has not yet been evaluated at check time) are excluded from reads and therefore from the unresolved probe. If one is present, unresolved is None, eval_predicate runs, it faults, and the subject ends up Unevaluable with an InvalidInput error whose fields name the subject rather than the offending ref. Compilation may already forbid step refs in check tests (not visible in this diff), but there is no guard here — a future edit to the compiler or definition format could introduce the mismatch silently.


{"head": "2a0fedde992a712e48c62ba5bdd13e48d710b8b8", "verdict": "findings", "findings": [{"path": "crates/rustev-core/src/evaluate.rs", "line": 2181, "summary": "Continuation digest parse failure is silently ignored, leaving the all-zeros placeholder in the NeedsInput outcome instead of surfacing an error."}, {"path": "crates/rustev-core/src/evaluate.rs", "line": 462, "summary": "run_checks filters reads to `input:` refs only, so non-input references in a check test bypass the unresolved probe and produce a misleading InvalidInput fault instead of a clean Unevaluable status."}]}

Subject: 7a48144...2a0fedd, diff digest bcf8aac867e9f4f6c549e3ccc61dbf251223ca0b680b16000aaf7ce6b48e4b3e, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 20, 2026 09:39 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff carefully: this PR implements spec 033 increment 3, adding evaluation of actionability checks and actionable outcomes to rustev-core.

actionable.rs additions

The new helpers (action, computed_remediation, transient, reason_fields) look correct. The transient function returns true when determinism is None, which is correct per spec 3.6.4 ("not bitwise" includes absent). reason_fields uses .split('/').next().unwrap_or(f) which is safe since split always yields at least one element.

compile.rs

The determinism map is populated in the semantic-step loop and threaded through to Info. The insert determinism.insert(s.id.clone(), backend.determinism) is placed before the calibration block and after backend is resolved — consistent with other step-level data.

evaluate.rs — run_checks

The check loop correctly handles: skip-if-relaxed, subject-unresolved → NotEvaluated, test-read-unresolved → Unevaluable (and immediately marks the subject unresolved so later checks see it missing), and all five consequence branches. DropField removes from input_values, present, metas, and sets inputs_status to Err(missing) while leaving input_evidence intact — consistent with "entry stays in evidence with dropped{check}". The deciding_reads accumulation logic is correct: Refuse extends it for every refusing check (all are listed), while Abstain/Escalate only set it once on first terminal. The terminal precedence is correct.

evaluate.rs — reason_action / actionable_outcome

The Refused placeholder { refusals: vec![], addressed_to: Party::None } is always replaced by actionable_outcome (which is only called when actionable is true, which is required for any terminal to exist). The NeedsInput continuation digest uses self.now as a Timestamp, matching the independent recomputation in the test using NOW: i64. The question-template substitution loop (filter_map → find(d.id == q.id)) is correct; the compiler guarantees no ids are missing.

policy.rs — ProvenanceWithin

The call self.view.get(reference)? precedes self.view.provenance(reference)?. The get() return value is unused — provenance() already calls self.status(&base)? so error propagation is handled twice. However, get() may additionally check policy_failures (for plan 3 step quality), making it non-redundant in that path. Either way there is no incorrect behaviour; the pattern is consistent with how Exact uses get().

policy.rs — needs_input placeholder

The sha256:000...000 (64 zeros) placeholder is a syntactically valid ContentDigest and is always overwritten before the judgment is returned.

No bugs, security issues, or spec inconsistencies found.

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

Subject: 7a48144...02e21fb, diff digest 6d12edff108f78cec0a31ba3b349833c934e306039af661d0e28d95c6f8597b8, 1 call(s). An AI comment is not an approval.

Base automatically changed from impl/033-compile to main October 20, 2026 11:53
@bartekus
bartekus enabled auto-merge (squash) October 20, 2026 12:08
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reading through the diff carefully, examining the logic for checks, consequences, terminal outcomes, action computation, and the policy changes.

actionable.rs additions — action(), computed_remediation(), transient(), reason_fields(): logic is consistent with the spec. The key_for nested function correctly maps "resolve_conflict" → "facts" and everything else → "fields". transient() correctly returns true for BackendUnavailable/DeadlineExceeded unconditionally, and true for InvalidBackendOutput unless the backend's determinism is Bitwise.

compile.rs — determinism is inserted inside the semantic-step loop, after backend is resolved, so only semantic steps get entries. Non-semantic steps get None in reason_action, making InvalidBackendOutput transient by default — a safe fallback.

evaluate.rs — run_checks(): Check ordering and consequence logic looks correct. DropField correctly removes the subject from inputs_status, input_values, present, and metas (but not observed, which is intentional — the cause needs the pre-drop observed class). The Refused terminal accumulates deciding_reads from every refusing check (not just the first), consistent with "refused lists every failing refusing check". Abstain/Escalate only the first check sets deciding_reads. The unevaluable case sets inputs_status to Err without removing input_values, but get() consults inputs_status first so the value is inaccessible.

evaluate.rs — actionable_outcome(): Outcome::Refused correctly reconstructs refusals from self.checks.refusals and re-derives addressed_to from their combined parties. Outcome::Unresolved (from Abstain terminal) correctly uses site = "check:{id}" so reason_causes produces Cause::Policy { site: "check:{id}" }. Outcome::NeedsInput continuation computation matches the spec (tagged digest over plan_id, snapshot_id, evaluation_time_ms, site, fields, question ids). Outcome::Escalate falls through to other => other — it carries no action, consistent with the spec enumerating only unresolved outcomes, refusals, and needs_input as action-carrying.

policy.rs — provenance_within: The self.view.get(reference)? call is redundant (since provenance() calls self.status() internally), but harmless. Returning Ok(false) for unmet references is consistent with how Present and comparisons treat unmet fields. [].iter().all(...) is true, correctly implementing "an empty set is within" for plan-3 steps with empty provenance sets.

policy.rs — needs_input and handler site tracking: decided() / done() correctly propagate site and handler to PolicyResult. PropagateWith and NeedsInput handlers both set site = Some("handler:{i}"), used for the continuation digest. The placeholder QuestionDecl values from needs_input() in policy are correctly replaced with actual templates in actionable_outcome().

No bugs, security issues, or spec inconsistencies found.

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

Subject: d2a8b42...cb0bdcd, diff digest 330f1432e3f7abb5dd21cacf48e4764f9ca58ac584719ab8e4853f5179e5ecd4, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus merged commit 4af0b63 into main Oct 20, 2026
12 of 14 checks passed
@bartekus
bartekus deleted the impl/033-eval branch October 20, 2026 13:40
bartekus added a commit that referenced this pull request Oct 20, 2026
Spec 033, increment 4 of 5: the runtime origin (3.9) and the CLI output
(3.11, amending 006). Stacked on #122.

- `RuntimeBuilder::host_backend` registers a host-implemented backend
(origin `host`); `backend` stays `upstream`, the default. Before
supplying a failure, the runtime notes the last attempt's backend to the
core (`Evaluation::note_failure`, `FailureContext`: origin and declared
determinism), which the `backend` cause and `invalid_backend_output`'s
transience use. Plans without `actionability` read neither; run records
keep their bytes. `rustev_core::transient` exposes 3.6.4's table.
- CLI: categories 16 and 17 named; `plan show` adds `caller_controlled`,
checks with each branch's classes, consequence and static party, groups,
remediations and question ids (other plans unchanged); `run` prints
`rustev.judgment/2` whole with top-level `addressed_to`/`transient`
(status `judged`, exit 0 for every outcome). The record file sink
accepts `rustev.run/3` so a plan 3 runs; capture of a plan 3 decision is
refused before any decision runs (spec 032 3.11 defers it to 036).
- Tests: core origin/transience (section 5 backend rows, full transience
table), runtime origin wiring, CLI goldens `refusal-16.json`,
`refusal-17.json`, `actionable.show.json`,
`actionable.run-{propose,refused,needs,unresolved}.json`. Existing CLI
goldens unchanged.

Review round 1 (2 findings): both comments made precise: `addressing`
lists each outcome (an unresolved or `needs_input` outcome's action, a
refusal's party with `false`, `null` for a proposal or an `escalate`,
which carries no action); the capture comment says the runtime refuses
capturing a plan 3 decision whatever the sink accepts, and `execute`
refuses the combination first.
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