Skip to content

impl(067): live runs bind the journal identity: checkpoint digest, journal member, --require-existing-journal, new_journal (increment 1a, run binding) - #550

Merged
bartekus merged 3 commits into
mainfrom
impl/067-inc1a
Nov 8, 2026
Merged

bartekus merged 3 commits into
mainfrom
impl/067-inc1a

Conversation

@bartekus

@bartekus bartekus commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Spec 067 increment 1a, run binding (the journal half is #551; this pull request is stacked on #551's branch and is retargeted to main once #551 merges). The AI review of the earlier, unsplit head timed out on size.

  • rustev-live run (src/run.rs, src/documents.rs): RunOptions gains journal_path, require_existing_journal and journal_clock (breaking library change, allowed at the 0.6.0 position, 067 3.9.4). prepare reads the header through JournalOpening before any output exists, binds the digest of the actual header in the checkpoint (043 3.10.1), refuses a missing journal with journal-missing when the switch is set (3.4.6), and refuses a resume whose journal is missing or replaced (checkpoint-mismatch); the superseded-cap exception (043 3.10.2) is computed from the actual header. PreparedRun::open_journal opens exactly the checked journal; execute refuses a journal whose header digest is not the bound one. rustev.live-run/1 and RunOutcome gain journal { id, created_at_ms, created } (3.4.5); old reports without it still parse.
  • CLI (crates/rustev-cli): rustev eval live --require-existing-journal (switch, usage text added); stdout gains new_journal when the run created the journal; journal creation time comes from --now-ms (the testing period is total, so accounting is unchanged).
  • Callers: live tests and support, the crash suite (open_journal), rustev-bedrock's live_run example, and the live conformance runner (tools/rustev-conformance/src/live.rs, test(067): live conformance cases and their Rust runner (increment 3, part 1) #557), which now prepares with the journal path and SetClock(now_ms) and opens through PreparedRun::open_journal.

Goldens: the live conformance outputs are re-blessed with the suite's mechanism (RUSTEV_BLESS=1 cargo test -p rustev-conformance --test live, then --test manifest); a structural comparison of every expected/live/*/out/*.json against the base shows only /journal (new member), /bindings/journal_header_digest and /identities/journal_header_digest changed, and each journal.jsonl changes only its header line (the id now derives from the case's run id instead of standalone); cases/ changes are sha256 pins. Otherwise the only moved expectation is eval live's inline stdout line in crates/rustev-cli/tests/eval_live.rs ( new_journal); no golden file, plan golden or PlanId changes.

Spec: 067 3.4.5, 3.4.6, 3.10.1, 3.10.3. The implementation record paragraph and the extends edge for integrations/rustev-bedrock/ are held for the increment 4 closure pull request.

Spec-Drift-Waiver: spec 067 (approved, A-86) already extends crates/rustev-live/ and crates/rustev-cli/ for 3.4.5 and 3.4.6; the Bedrock example change only follows the changed RunOptions. Under the 0.6.0 orchestrator rule of 2026-11-07 22:05, 067 implementation record paragraphs and edges land together in the increment 4 closure pull request, because parallel record edits collided on .statecraft/derived and ejected each other from the merge queue. Covered by the owner's 0.6.0 preapproval of 2026-11-07.

Tests

crates/rustev-live/tests/run.rs: first/second/fresh/legacy runs (this_run/earlier/legacy, spend before, ids), replaced journal on resume checkpoint-mismatch before lock or output changes, the switch on missing (no journal, lock or out dir) and existing journals, a journal changed between prepare and open refused, superseded-cap checkpoints still resume, old reports round-trip. crates/rustev-cli/tests/eval_live.rs: the same through the CLI, including help text and new_journal.

Local, on top of #551: cargo test -p rustev-conformance --locked (full), cargo clippy -p rustev-conformance --all-targets -- -D warnings; earlier, on top of #551 and current main: cargo test -p rustev-live -p rustev-live-crash -p rustev-cli -p rustev-surface --locked, cargo build -p rustev-bedrock --examples --locked, cargo clippy --workspace --all-targets --locked -- -D warnings, cargo fmt --all --check, make gate; earlier head also cargo test -p rustev-jev -p rustev-bedrock.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (findings)

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

with_cap – unchecked slice access

Inside the depth == 1 && "cap" branch (crates/rustev-live/src/journal.rs, with_cap function):

let mut next = i;
while bytes[next].is_ascii_whitespace() { next += 1; }
if bytes[next] == b':' {
    next += 1;
    while bytes[next].is_ascii_whitespace() { next += 1; }

None of these accesses guards against next >= bytes.len(). The function is documented to operate only on validated headers (which always end with \n and are well-formed JSON), so the panic path is not reachable through any current caller, but the absence of bounds checks is a latent defect if the function is ever called on partially-read or truncated bytes.

Superseded-cap resume test broken by assert change

crates/rustev-live/tests/run.rs changes assert_eq! to assert_ne! for cp.bindings.journal_header_digest vs SpendJournal::testing_header_digest(). That assertion change is correct: a journal created by the new code carries journal_id and created_at_ms, so its digest differs from the legacy no-identity digest. However, the unchanged test body that follows immediately sets cp.bindings.journal_header_digest = SpendJournal::superseded_testing_header_digest(). superseded_testing_header_digest() is computed by header_digest(SUPERSEDED_TESTING_CAP_UNITS) with journal_id: None, created_at_ms: None, so it produces the legacy no-identity format. When prepare then attempts to resume, it tries the new journal's superseded_header_digest(), which calls with_cap(current_header_bytes(), SUPERSEDED_TESTING_CAP_UNITS) on a header that does contain journal_id and created_at_ms. The resulting digest therefore differs from the legacy superseded_testing_header_digest() installed in the checkpoint, so the migration branch returns the original checkpoint-mismatch error and the resume fails. The newly added test identity_checkpoint_accepts_only_the_same_header_with_superseded_cap handles this correctly by computing the digest from the actual journal bytes; the old test does not.

{"head": "d15f109f1838971b6801f2f8f55075997dc3db3a", "verdict": "findings", "findings": [{"path": "crates/rustev-live/tests/run.rs", "line": 2072, "severity": "medium", "category": "correctness", "summary": "Changing assert_eq! to assert_ne! is correct, but the unchanged test body then installs SpendJournal::superseded_testing_header_digest() (legacy no-identity format) in the checkpoint; a new-format journal's superseded_header_digest() includes journal_id and created_at_ms fields, so the digests cannot match and the migration resume path returns checkpoint-mismatch instead of succeeding."}, {"path": "crates/rustev-live/src/journal.rs", "line": null, "severity": "low", "category": "correctness", "summary": "The with_cap function accesses bytes[next] without a bounds check inside the depth==1 'cap'-key branch; unreachable on validated headers but would panic on a truncated or empty input."}]}

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

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

bartekus commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Review note: the medium finding on checkpoint_under_superseded_header_resumes_after_migration is a false positive. Before the resume, the test overwrites the journal with a hand-written legacy header ({"schema":"rustev-jev.spend-journal/1","budget":"testing","cap":5000000000}, no journal_id/created_at_ms) and opens it (dir.journal()), which migrates it to the current cap. prepare then reads that legacy header, so superseded_header_digest() = digest of the legacy header with cap 5000000000 = SpendJournal::superseded_testing_header_digest(), the value installed in the checkpoint; the resume takes the migration branch and the test asserts EvaluatedLive (it passes locally and in CI). The assert_ne! only covers the first, identity-carrying journal created by the first prepare. The low finding (bounds in with_cap) is fixed in 42e3d12: every read past the end yields a terminator and the string scan is clamped.

@bartekus

bartekus commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Split: the AI review timed out on size (20 min). The journal half (journal.rs and its tests) is now #551; this pull request is rebased onto main after #551 merges and then carries only the run binding, about 600 lines.

@bartekus
bartekus marked this pull request as draft November 7, 2026 20:43
@bartekus bartekus changed the title impl(067): journal identity, run report journal member and --require-existing-journal (increment 1a) impl(067): live runs bind the journal identity: checkpoint digest, journal member, --require-existing-journal, new_journal (increment 1a, run binding) Nov 7, 2026
@bartekus
bartekus changed the base branch from main to impl/067-inc1a-journal November 7, 2026 23:17
@bartekus
bartekus marked this pull request as ready for review November 7, 2026 23:18
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing this PR, which refactors journal opening from call sites into a two-phase JournalOpening model (prepare() → read-only header check, open_journal() → actual file creation/lock), and adds --require-existing-journal.

Key design properties I verified against the diff:

  1. Two-phase journal opening is read-only in phase 1. The tests require_existing_journal_refuses_without_creating_anything (eval_live.rs:703) and replaced_journal_is_refused_on_resume_without_modifying_evidence (eval_live.rs:722) both verify that on prepare()-phase failure no files are created or modified. This confirms JournalOpening::prepare() is purely read-only, making the try_exists() check in the resume path (run.rs around the checkpoint-mismatch/"resume journal is missing" block) effective.

  2. Header digest binding is correct. The journal_header_digest in CheckpointBindings is now set dynamically from the actual journal header (journal.header_digest()) instead of the static SpendJournal::testing_header_digest(). The assert_eq! → assert_ne! flip in checkpoint_under_superseded_header_resumes_after_migration (run.rs:2075) is consistent with this.

  3. Defense-in-depth check in execute(). The header digest re-check at the start of execute() (run.rs:510) guards against a SpendJournal from a different source being passed, verified by journal_changed_between_prepare_and_open_is_refused (run.rs:2227).

  4. Crash test reordering. rig() is now constructed before prepare() in run_to_end so its ReleaseClock can be passed into opts.journal_clock. Since JournalOpening::prepare() is read-only (no clock reads), the ReleaseClock initialization based on journal existence before prepare() is equivalent to the prior behavior where it was initialized after prepare().

  5. Backward compat for LiveRun.journal. The optional field with skip_serializing_if and serde(default) is correct; old_run_reports_round_trip_without_adding_journal (run.rs:2278) verifies existing records round-trip cleanly.

  6. BudgetKind::Testing is hardcoded in run.rs. This was also hardcoded in the old call sites, so it is not a regression.

No concrete defects found.

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

Subject: c2f6d47...bd720f7, diff digest bf1e68d7756b0ba5c902ce57f28065e7731dd6e3a1894bc4ecb8553c648f0711, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff, which refactors journal-opening from call sites into PreparedRun, adds --require-existing-journal, and exposes JournalIdentity in outputs.

Correctness of TOCTOU handling. JournalOpening::prepare() reads (or plans to create) the journal header before checkpoint preparation; open_journal() locks and writes it. The check inside execute() (journal.header_digest() != &self.checkpoint.bindings.journal_header_digest) catches a substitution between the two steps. The test journal_changed_between_prepare_and_open_is_refused explicitly covers this. The design is sound.

Resume path try_exists() ordering. After JournalOpening::prepare() succeeds, the resume branch adds a redundant try_exists() guard (run.rs ~line 354). This is safe but slightly redundant since prepare() already ingested the journal's absence and would have set ThisRun for a missing journal. The check prevents a confusing checkpoint-mismatch on a journal that was deleted between the two calls; failing safely.

Checkpoint digest migration. The legacy path (superseded_header_digest) handles old checkpoints written against the hardcoded testing header. The corresponding assert_ne! flip in the test is correct — the new code binds checkpoints to the actual journal header, so it should no longer equal testing_header_digest().

LiveRun.journal as Option / backward compat. skip_serializing_if = "Option::is_none" and the old_run_reports_round_trip_without_adding_journal test confirm round-trip compatibility with existing live-run documents.

Usage text omission. --host-cap-ms is defined in the args spec (args.rs line ~167) for the eval live command but is absent from the new usage line added for rustev eval live. The flag continues to work; only the documentation is incomplete.

Crash-test ReleaseClock.calls initialization timing. In crash.rs, calls is now computed before prepare() (which does not write the journal file) instead of before the old SpendJournal::open(). Since journal creation (writing the header) happens in open_journal(), the pre-prepare state is identical to what the old pre-open state was, so the synchronization is equivalent.

No other defects found in the supplied evidence.

{"head": "471b8cccd3a6f445012e9aa48ddd81ec74d40018", "verdict": "findings", "findings": [{"path": "crates/rustev-cli/src/args.rs", "line": 489, "severity": "low", "category": "other", "summary": "The new 'rustev eval live' usage line documents --run-deadline-ms but omits --host-cap-ms, which is defined in the args spec for this command and is a user-visible flag."}]}

Subject: 745dcc4...471b8cc, diff digest 4666f4fb80517a7e316f198ce285f6e32291c3824e0d3b5fb66ea9e2cbe05b7f, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception November 8, 2026 00:29 — with GitHub Actions Error
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff, which moves journal opening from call-site SpendJournal::open(...) calls into a two-phase JournalOpening::prepare() / PreparedRun::open_journal() pattern and adds --require-existing-journal and journal-identity tracking.

Key properties checked:

  1. TOCTOU between prepare and open (run.rs): JournalOpening::prepare() reads and binds the header digest into the checkpoint; open_journal() actually locks the file later. execute() re-checks journal.header_digest() != &self.checkpoint.bindings.journal_header_digest before any work starts. The test journal_changed_between_prepare_and_open_is_refused explicitly covers this window. The design is sound.

  2. Resume path missing-journal check (run.rs line ~354): The try_exists() guard fires inside if opts.resume after JournalOpening::prepare() has already run. Whether this code is reachable depends on whether JournalOpening::prepare() with require_existing_journal=false writes to disk—not visible in the diff. However, the replaced-journal test (resume_rejects_replacement_before_lock_or_output_changes) confirms that a replaced journal is caught by the header-digest mismatch path, and the bytes/checkpoint are left unmodified. No concrete misbehaviour is demonstrable from the supplied evidence.

  3. BudgetKind::Testing hardcoded in run.rs: Same as the removed call-sites; not a regression.

  4. Backwards compatibility of LiveRun.journal: Added with #[serde(default, skip_serializing_if = "Option::is_none")]; old_run_reports_round_trip_without_adding_journal verifies old documents round-trip without the field.

  5. Conformance fixture digests: The journal header now includes journal_id/created_at_ms, changing the journal_header_digest in every checkpoint. All affected fixtures are updated consistently. The live.journal-cap scenario correctly shows "created":"earlier" because it resumes from a pre-seeded journal.

  6. RunOptions manual Debug impl (run.rs): journal_clock (a dyn SpendClock trait object) is omitted via finish_non_exhaustive(); correct.

  7. checkpoint_under_superseded_header_resumes_after_migration assertion flip (run.rs line ~2072): Changed assert_eq! → assert_ne! to reflect that the new journal header format produces a digest different from SpendJournal::testing_header_digest(). Correct.

No concrete bugs, security issues, or rule contradictions supported by the supplied evidence.

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

Subject: 745dcc4...d10b7c4, diff digest 7a16b3fe55a4646683b9dacac9def8950a88993177169ae75ca8c74d26149bbc, 1 call(s). An AI comment is not an approval.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR, which moves journal opening into prepare() via a new JournalOpening type, adds journal identity tracking (JournalIdentity/JournalCreated), introduces --require-existing-journal, and propagates journal identity into LiveRun and RunOutcome.

Design integrity check:

The sequence in prepare() is: JournalOpening::prepare() reads/generates the journal header digest → digest is baked into CheckpointBindings → checkpoint is written → open_journal() is called by the caller, which re-verifies the digest on actual open → execute() has a redundant digest guard against externally-constructed journals. This chain is sound.

TOCTOU between prepare and open_journal: The header digest stored in JournalOpening is computed from the file as it existed during prepare, and open_journal re-verifies before granting write access. The test journal_changed_between_prepare_and_open_is_refused (run.rs:~2200) confirms this path. No lock file is left behind on mismatch. ✓

require_existing_journal ordering: JournalOpening::prepare() is the first call in prepare(), before any output directory or lock creation, so a JournalError::Missing leaves no side-effects. The test require_existing_journal_refuses_without_creating_anything (run.rs:~2228) verifies the directory stays empty. ✓

assert_ne! flip (run.rs:~2072): Old assertion verified the checkpoint digest equaled the static testing digest; new code stores the actual identity-bearing digest, so the assertion inversion is correct. ✓

LiveRun.journal as Option vs RunOutcome.journal non-optional: LiveRun uses Option for JSON backward-compatibility with pre-PR serialized runs; RunOutcome is in-memory only. The round-trip test old_run_reports_round_trip_without_adding_journal covers deserialization of legacy JSON. ✓

Conformance fixture consistency: live.full and live.probe-* now show journal_id: sha256:0335dadc... (new journal created at conformance time). live.journal-cap shows the older sha256:6e2964... because it starts from a pre-existing journal fixture with pre-committed spend — created: "earlier" is correct there. live.resume uses the same fresh journal as live.full and reports created: "earlier". All consistent. ✓

new_journal stdout token: Appended only for JournalCreated::ThisRun, not Earlier or Legacy. The legacy case deliberately omits it, consistent with the test legacy_journal_is_reported_without_rewriting_header. ✓

No concrete defects found.

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

Subject: c575145...b58cd99, diff digest 7a16b3fe55a4646683b9dacac9def8950a88993177169ae75ca8c74d26149bbc, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit 4c03500 Nov 8, 2026
26 checks passed
@bartekus
bartekus deleted the impl/067-inc1a branch November 8, 2026 02:33
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