Skip to content

impl(043): enforce A-75's USD 10 testing cap - #476

Merged
bartekus merged 1 commit into
mainfrom
impl/a75-enforce
Nov 3, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/a75-enforce

Conversation

@bartekus

@bartekus bartekus commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Enforces owner decision A-75 (2026-11-03): R-29's testing cap rises from USD 5 to USD 10 in total. The production cap (USD 25 per month) is unchanged. The A-75 decision row is in #473; this change cites it.

What changed

  • rustev_live::journal: TESTING_CAP_UNITS is now 10,000,000,000 nano-USD; the old value is kept as SUPERSEDED_TESTING_CAP_UNITS.
  • Header migration: SpendJournal::open accepts a testing journal whose header names the superseded cap. It replays every line first, then, under the lock, writes a sibling file holding the new header followed by every later byte unchanged, fsyncs it, renames it over the journal (keeping its permissions) and fsyncs the directory. Entries, sequence numbers and unsettled reservations are untouched. Every other header mismatch is still refused, and a journal refused for a later line is left unchanged.
  • Resume: a checkpoint that binds the superseded testing header digest (SpendJournal::superseded_testing_header_digest()) resumes and is rewritten with the current digest, so a run stopped by the USD 5 cap can complete (043 3.10.5).
  • Specs: 043 3.5.4, the new 3.5.6, 3.10.2, Decision 12 and an Implementation record paragraph; normative cap text in 012 (summary, R-2, 3.8), 022, 030 and 039 now states USD 10 and cites A-75. Historical record paragraphs are unchanged. Derived shards are refreshed.
  • Tests: new journal migration, refusal and digest tests; a resume test; literal cap values in rustev-live and rustev-cli tests now track the constant.
  • Docs: rustev-jev PRODUCTION.md and smoke example, rustev-bedrock README.

Checks

  • make gate: pass
  • make code (build, test, clippy -D warnings, fmt, boundaries): pass
  • cargo test -p rustev-live -p rustev-jev -p rustev-bedrock --all-features, cargo test -p rustev-cli --test eval_live: pass
  • spec-spine verify 043, 012, 001, 022, 030, 039: pass
  • scripts/check-authored-content.sh: pass

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (findings)

Looking at the PR, which raises the testing spend cap from USD 5 to USD 10 and adds journal header migration logic (A-75).

Finding 1 — Numbered list out of order in spec 043

In specs/043-live-re-execution-at-scale/spec.md, the diff inserts the new item as 6. **Header migration (A-75).** immediately after item 4. **Budget.**, which appears before the existing 5. **One writer.**. The rendered document lists items 4, 6, 5 — item 6 precedes item 5. This is a concrete ordering defect in the spec's numbered list.

Finding 2 — Lock released before migrate_header is called

In crates/rustev-live/src/journal.rs, the migration block explicitly drop(file) (releasing the exclusive lock on the old journal) before calling migrate_header:

drop(file);
file = migrate_header(&path, &bytes).map_err(io)?;

Yet migrate_header's own docstring states "The caller holds the lock." This is self-contradictory. Between drop(file) and the atomic rename inside migrate_header, another opener can acquire the exclusive lock on the old inode (still reachable at path until the rename lands), see the superseded header, and attempt its own migration. If that second opener reaches migrate_header and renames its own .migrate file over path after the first process already renamed a correctly migrated file there, the first process's migrated file is silently replaced by a second migrated copy. Conversely, if the second opener completes and is still writing when the first process's rename arrives, the second opener's lock is held on the now-detached old inode and it will write entries to the wrong (unlinked) file. The one-writer invariant is supposed to prevent this, but it is enforced by the lock — which is deliberately dropped here before the critical section completes.

{"head": "cbfda17de066e2a0c056f4be8b22ee7447d26341", "verdict": "findings", "findings": [{"path": "specs/043-live-re-execution-at-scale/spec.md", "line": 352, "summary": "New item numbered 6 is inserted before existing item 5, producing the out-of-order sequence 4 → 6 → 5 in the rendered numbered list."}, {"path": "crates/rustev-live/src/journal.rs", "line": 519, "summary": "`drop(file)` releases the exclusive lock before `migrate_header` is called, contradicting that function's own \"The caller holds the lock\" contract and opening a race window where a concurrent opener can acquire the lock and attempt a second migration between the drop and the atomic rename."}]}

Subject: cf3ae8d...cbfda17, diff digest ed41f8e3e1399cb33296dd30f59e45beb6dc2c70aba762cc81a6090bf9261dc2, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 3, 2026 18:48 — with GitHub Actions Inactive
Raise TESTING_CAP_UNITS to 10,000,000,000 nano-USD and migrate a testing
journal header that names the superseded USD 5 cap: after the replay, under
the lock, the header is replaced through an fsynced sibling file and rename,
entries and sequence numbers unchanged. Every other header mismatch is still
refused. A checkpoint bound to the superseded header digest resumes and is
rebound to the current one. Specs 043, 012, 022, 030 and 039 state the new
cap and cite A-75.
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR, which raises the testing budget cap from USD 5 to USD 10 (A-75) and adds atomic journal header migration.

Code correctness:

The migration logic in journal.rs is structurally sound. The superseded header is correctly constructed from ..header.clone() (which carries kind=Testing), so a production journal whose cap happens to equal SUPERSEDED_TESTING_CAP_UNITS cannot trigger migration — confirmed by the other_header_mismatches_are_refused_unchanged test cases.

The refactoring from let mut lines = text.lines().enumerate(); lines.next() to text.lines().next() + text.lines().enumerate().skip(1) is semantically equivalent: in both cases the loop body sees i starting at 1, so line: i + 1 in error reporting correctly names the second line as line 2.

The drop(file); file = migrate_header(...) sequence is correct: the old handle is closed before the sibling temp file is renamed over it, the lock file is a separate inode and survives the rename, and migrate_header returns the new handle already positioned at EOF.

The checkpoint fallback in run.rs (e.subject == "checkpoint-mismatch") correctly retries with the superseded digest only, propagating the original error if that also fails.

Atomicity and crash safety:

migrate_header implements write-sibling / fsync / rename / dir-fsync, which satisfies the module's crash-safety requirements on POSIX filesystems. A crash leaves either the old file or the new one; a torn migration retries at the next open because the old header is still present.

Spec/code consistency:

All changed spec files (012, 022, 030, 039, 043) and the doc strings reference A-75 consistently. Section 3.5.6 and 3.10.2 in spec 043 match what the code does. The eval_live.rs golden string update from headroom=5000000000 to headroom=10000000000 is correct given zero spend against the new cap.

No concrete defects found.

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

Subject: cf3ae8d...0b9f37f, diff digest 6e3ca83873e26870293bdc9473e2104899ab65aae80c9bf8ea1410978f486bbd, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 2f7b8e6 Nov 3, 2026
27 checks passed
@bartekus
bartekus deleted the impl/a75-enforce branch November 3, 2026 20:11
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