Skip to content

impl(067): the Node binding's filesystem host for liveRun (increment 2b, part 1) - #556

Merged
bartekus merged 3 commits into
mainfrom
impl/067-inc2b-fs
Nov 7, 2026
Merged

bartekus merged 3 commits into
mainfrom
impl/067-inc2b-fs

Conversation

@bartekus

@bartekus bartekus commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Spec 067 (approved), increment 2b part 1: 3.4.2 ("out is a directory path the binding writes directly ... Inputs may be paths ... under the filesystem host"). Increment 2b is split in two to stay under the review size; part 2 adds engine.liveRun, which calls this host.

Summary

  • integrations/rustev-node/src/live_fs.rs: a rustev_surface::host::Host over real paths for engine.liveRun, mirroring the CLI's Reads (crates/rustev-cli/src/io.rs), which the binding cannot depend on:
    • bounded reads (document limit plus one byte), a 256 MiB per-run read budget classified apart from file failures (ReadFail::Budget);
    • list in byte order (at most max names), entry_kind without following links, ensure_absent, never-overwriting all-or-none publication (temporary file, fsync, hard link, rollback);
    • the replay Store resolver (64 lowercase hex references only, regular files only, one byte past the maximum so oversized items are classed, never truncated);
    • publish_live_outputs, the repeat outputs eval live publishes at the end of an evaluated_live run (identical files accepted on resume, conflicting ones refused).
  • No new dependency: a non-regular input is refused by its metadata before and after opening. The CLI's O_NONBLOCK open also closes a FIFO/device swapped in between; that residual race is documented in the module header.
  • lib.rs: the module is #[allow(dead_code)] until part 2 calls it (as increment 1b did for live.rs).
  • Spec 067 Implementation record: an "Increment 2b, part 1" paragraph; implementation stays pending.

Evidence

cargo test -p rustev-node (new: filesystem_reads_are_bounded_and_classify_links_without_following, store_resolves_regular_items_by_reference_only), cargo clippy -p rustev-node --all-targets -D warnings, cargo fmt --check, make gate: pass.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the three changed files for bugs, security issues, and correctness.


integrations/rustev-node/src/live_fs.rs

publish_live_outputs — directories never created before writing (medium correctness)

The function builds file paths like out/<name>/adapter.json for each report:

let mut files: Vec<_> = reports
    .keys()
    .map(|name| (join(&join(out, name), "adapter.json"), bytes.clone()))
    .collect();

It then calls:

publish_outputs(&pending, &[], |temp, path| std::fs::hard_link(temp, path))

The dirs argument is &[]. publish_outputs creates the temp file at out/<name>/.rustev-repeat-<pid>-<n>.tmp using OpenOptions::create_new(true). If out/<name>/ does not exist this open fails immediately with NotFound, before any file is written — the entire call errors out. The write_all_in host method accepts a dirs slice precisely to handle this, but publish_live_outputs bypasses it. The subdirectories out/<name>/ for each report key must be passed as dirs, or created before the publish_outputs call.


integrations/rustev-node/src/live_fs.rs

list — pop_last discards the lexicographically largest entry when over max (low, potential correctness note)

names.insert(name);
if names.len() > max {
    names.pop_last();
}

The spec says "list in byte order." This keeps the lexicographically smallest max names rather than the first max encountered, which is consistent with a stable ordered subset. However, the CLI's behaviour against which this mirrors should produce the same set; if the CLI returns names in a different stable order this would diverge. No governance rule is contradicted by the evidence supplied, so this is noted but not a blocking finding.


specs/067-node-live-repeat-runs/spec.md

Increment 2b description accurately describes what live_fs.rs delivers and explicitly states "No acceptance item is claimed." No contradiction with governance documents.


{"head": "0369bbb78037c6a262a025d93ed2fc64fe3fb804", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/live_fs.rs", "line": 338, "severity": "medium", "category": "correctness", "summary": "publish_live_outputs passes empty dirs to publish_outputs while targeting paths under out/<name>/adapter.json; the subdirectories out/<name>/ are never created, so the temp-file open fails with NotFound on any first-time publication."}]}

Subject: a52d38b...0369bbb, diff digest 4eaa08baf947ec545e2501b84f2e39b13236f8719fe7f22e528c8786b7ef6c2b, 1 call(s). An AI comment is not an approval.

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

bartekus commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Review note: the finding on publish_live_outputs (live_fs.rs:338) is a false positive. The function runs only after rustev_live::run ended evaluated_live, and by then the engine has already published each candidate's repeat outputs under out/<name>/: crates/rustev-live/src/reports.rs publish creates every missing parent (std::fs::create_dir(parent) before the rename, lines ~350-356). adapter.json is added beside those files, so out/<name>/ always exists and dirs is empty by design. This is the CLI's own code (crates/rustev-cli/src/repeat.rs publish_live_outputs, which also passes &[]), and the part 2 node test full runs reserve before dispatch ... asserts out/a/adapter.json exists after a first-time run.

@bartekus
bartekus added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (findings)

Review of live_fs.rs and spec 067 increment 2b, part 1

Code analysis

publish_live_outputs — budget exhaustion on resume

publish_live_outputs (around line 300) constructs a fresh Reads::default() — a 256 MiB read budget — to check whether previously written adapter files are identical to what it would write now. Each matched file deducts its full byte count from that budget:

let reads = Reads::default();
...
for (path, bytes) in files {
    match reads.read_classified(&path, bytes.len().saturating_add(1)) {
        Ok(Some(existing)) if existing == bytes => {}   // bytes.len() debited
        Ok(None) => pending.push((path, bytes)),

For N repeat runs, the total bytes debited is N × adapter_bytes + comparison_md. Once the total exceeds MAX_TOTAL_BYTES (268 435 456 bytes), read_classified returns ReadFail::Budget, which the error arm maps to Done::io(command, ...) — identical to a real conflict. A directory with many runs and a sizable adapter serialization (e.g., 2 000 runs × 200 KB = 400 MiB) triggers this on a valid resume with no actual conflict.

rollback_outputs — remove_dir_all instead of remove_dir

The rollback first removes every placed and temporary file, then removes directories with remove_dir_all. At that point the directories this function created should be empty. Using remove_dir_all silently deletes any files a concurrent writer placed in those directories between creation and rollback, rather than failing visibly. remove_dir would refuse a non-empty directory, surfacing the unexpected state instead.

Other items reviewed (no finding)

  • read_classified budget arithmetic: the remaining.saturating_add(1) probe-byte logic is correct.
  • is_reference hex-and-length guard prevents path traversal in Store::resolve; test covers ../escape. ✓
  • publish_outputs temp-naming with std::process::id() + atomic counter avoids collisions. ✓
  • hard_link as publisher enforces the never-overwrite invariant at the OS level. ✓
  • Spec text claims draft status and no acceptance item — consistent with governance rules. ✓
{"head": "b591df043c3a85b555185b0af197478b0bf00d24", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/live_fs.rs", "line": 305, "severity": "medium", "category": "correctness", "summary": "publish_live_outputs checks existing adapter files against a single 256 MiB Reads::default() budget; when len(reports) × adapter_bytes exceeds that limit the budget is exhausted and the function returns a spurious budget error, blocking valid resumption even when no conflict exists."}, {"path": "integrations/rustev-node/src/live_fs.rs", "line": 272, "severity": "low", "category": "correctness", "summary": "rollback_outputs calls remove_dir_all on newly created directories rather than remove_dir, so concurrent writes to those directories during the rollback window are silently deleted instead of causing a detectable non-empty-directory error."}]}

Subject: e8f6653...b591df0, diff digest 32c185545481428b3fd58651d47cf46c29593119561294a57b7d38ca84da68c9, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 7, 2026 22:11 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (findings)

Looking at the three changed files: integrations/rustev-node/src/live_fs.rs (new), integrations/rustev-node/src/lib.rs (adds mod live_fs), and specs/067-node-live-repeat-runs/spec.md (increment 2b description). I'll review the core logic carefully.

rollback_outputs uses remove_dir_all on created directories (live_fs.rs, ~line 265)

for dir in created.iter().rev() {
    report(std::path::Path::new(dir), std::fs::remove_dir_all(dir));
}

created holds directories that this function just created with std::fs::create_dir. On rollback, the placed files inside them are already removed (the preceding loop), so these dirs should be empty. Using remove_dir_all instead of remove_dir silently destroys any content written by a concurrent process between create_dir and rollback. remove_dir would fail loudly in that case, surfacing the race; remove_dir_all swallows it. The function is pub(crate) and write_all_in on the Host impl forwards dirs directly here, so this affects any caller that passes non-empty directories. The residual race is documented for reads but not for the write-side rollback's destructiveness.

Budget accounting in read_classified when remaining = 0 (live_fs.rs, ~line 73)

When remaining = 0: take = max.min(0usize.saturating_add(1)) = max.min(1) = 1 (assuming max >= 1). One byte is read; bytes.len() = 1 > 0 = remaining triggers ReadFail::Budget. Correct. For a zero-byte file, bytes.len() = 0, not greater than 0, succeeds with Ok(Some([])), remaining stays 0. This edge case is fine.

Store::resolve size semantics are consistent with caller contract — the test comment "One byte past the maximum, never truncated to it" and assert!(matches!(store.resolve(&reference, 3), Resolution::Bytes(b) if b == b"abcd")) correctly reflects the design: 4 bytes returned for max_bytes=3 signals oversized to the caller, matching read_classified's same +1 convention.

Path traversal in Store is correctly blocked — is_reference requires exactly 64 lowercase hex chars; "../escape" (length 9) and anything with / or . is immediately Inaccessible. The unix symlink test confirms symlink_metadata correctly refuses links.

Spec text matches implementation — the increment 2b description accurately describes the file's contents, the #[allow(dead_code)] guard, the documented swap race, the test coverage, and the absence of an acceptance claim.

{"head": "0e7af03bb334bc08863ed431665438030e005fcf", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/live_fs.rs", "line": 265, "severity": "medium", "category": "correctness", "summary": "rollback_outputs uses remove_dir_all on directories this function created, silently destroying any content written concurrently by another process between create_dir and rollback; remove_dir would surface that race rather than swallowing it."}]}

Subject: e8f6653...0e7af03, diff digest 33fc90d19230f7c584b4c6c3138a55cf5c6ba4642864e187f9ca321c6326bd48, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 7, 2026 22:17 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the three changed files for correctness, security, and consistency with governance and spec claims.

integrations/rustev-node/src/live_fs.rs

Reads::read_classified — per-file "+1 byte" is missing

The module-level doc comment (lines 1–9) states:

each file is read up to its document's limit plus one byte, so an oversized file reaches the parser and is refused by the document's own bound

The spec increment note added in specs/067-node-live-repeat-runs/spec.md repeats this:

with the CLI's per-file bound plus one byte

But the actual take calculation at line 76 is:

let take = max.min(remaining.saturating_add(1));

When remaining >= max (the typical case — a 256 MiB budget is fresh when the first few files are read), this evaluates to min(max, remaining+1) = max. Only max bytes are read, not max+1. A file with exactly max+1 bytes is silently truncated; the document parser receives max bytes and cannot distinguish it from a legitimately sized document.

The companion Store::resolve correctly implements the "+1" behavior:

.take((max_bytes as u64).saturating_add(1))

The fix for read_classified is to add 1 to max before the min:

let take = max.saturating_add(1).min(remaining.saturating_add(1));

This is the only substantive defect found. Path-traversal in Store is correctly blocked by the 64-char hex validation; the rollback logic is sound; the list truncation and symlink classification are correct.

The spec edit itself is a progress note on an existing draft spec, claims no acceptance item, and does not alter ownership or lifecycle status — no ratification or authority concerns.

{"head": "05756b81aa031958829448fcc40d1d80510ec963", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/live_fs.rs", "line": 76, "severity": "medium", "category": "correctness", "summary": "take = max.min(remaining.saturating_add(1)) reads exactly max bytes (not max+1) when remaining >= max, so an oversized file is silently truncated to the per-file limit and the document parser cannot detect it; the module doc, spec text, and the sibling Store::resolve all require max+1 bytes to be read."}]}

Subject: e8f6653...05756b8, diff digest ca29e92b3e6e268a6ea84112d6f325549192f2d4cc61a776578df28632857dc8, 1 call(s). An AI comment is not an approval.

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

bartekus commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Review note: the finding on live_fs.rs:76 is a false positive. read_classified(label, max) takes the maximum to read, and the plus-one byte is added by its callers: rustev_surface::host::Host::read(label, limit) calls read_bounded(label, limit.saturating_add(1)) (crates/rustev-surface/src/host.rs), and the surface's loaders pass DOC.max_bytes + 1 explicitly (for example inputs.read_classified(path, SNAPSHOT_V1.max_bytes + 1) in crates/rustev-surface/src/live.rs). An oversized document therefore reaches its parser with limit + 1 bytes and is refused by its own bound. This is the same contract as the CLI's Reads::read_classified (crates/rustev-cli/src/io.rs) that every CLI command uses; the unit test filesystem_reads_are_bounded_... pins it (read_classified(file, 3) returns abc). Store::resolve(reference, max_bytes) differs because the Resolver contract passes the item limit itself.

@bartekus
bartekus added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 7, 2026
@bartekus
bartekus added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 181941b Nov 7, 2026
25 of 26 checks passed
@bartekus
bartekus deleted the impl/067-inc2b-fs branch November 7, 2026 23:50

This branch was previously deployed

1 inactive deployment
statecraft-review-exception — 05756b81 Deployed Nov 7, 2026 by bartekus via review-exception #3744
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