Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,15 @@ jobs:
retention-days: 14

sanitizer:
runs-on: ubuntu-latest
# Pinned, never `-latest` (issue #74 ruling, same law as `valgrind`
# above): the leg's verdicts must be observed over a still environment.
# Its 2026-11-23 red was exactly an image-float class race -- the
# VCache identity key held a ctime whole-second stamp that a late
# hard_link could bump between two stats; the defect is now pinned
# out by law in src/rust/engine/tests/batch_v_cache.rs (late-link
# twin), and the image pin keeps the observation window from moving
# underneath it.
runs-on: ubuntu-24.04
# Hard gate: the 22 s/12 s archived legs (D1) died at target discovery.
timeout-minutes: 90
strategy:
Expand Down
20 changes: 11 additions & 9 deletions src/rust/engine/src/vcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! a fifty-case batch otherwise asks the kernel to decode and validate
//! byte-identical inputs fifty times. This module shares the decoded read
//! inside one batch process: cache identity is the FILE identity (device,
//! inode, byte length, and the kernel-reported mtime/ctime seconds --
//! inode, byte length, and the kernel-reported mtime second --
//! `std::os::unix`, no content hashing), and a hit hands back a clone of
//! the same `Rc`.
//!
Expand All @@ -16,12 +16,16 @@
//! CLI's reader is a thin delegate to it, so fault TEXT cannot drift;
//! * faults are fail-closed and never cached;
//! * any move of the bytes under a name (length, or the kernel's
//! mtime/ctime seconds, moved) forces a fresh decode. The same-inode,
//! same-length, same-clock-second rewrite is the one theoretical stale
//! window: unreachable under the serving law that case bytes are
//! written once and then read-only (campaign law, attested input
//! hashes), and every emitted byte is gated downstream by the P2
//! bit-identity family regardless;
//! mtime second, moved) forces a fresh decode. ctime is deliberately
//! not in the key: it also rises on byte-less metadata events such as
//! link(), so keying on it would buy no staleness protection a bytes
//! move does not already give (a bytes move moves mtime with it) and
//! would trade in spurious misses on the bridge's own late-linked
//! layout; the same-inode, same-length, same-clock-second rewrite is
//! the one theoretical stale window: unreachable under the serving law
//! that case bytes are written once and then read-only (campaign law,
//! attested input hashes), and every emitted byte is gated downstream
//! by the P2 bit-identity family regardless;
//! * two distinct files never fold together, even when their bytes are
//! equal (content hashing would fold them -- identity must not).

Expand Down Expand Up @@ -81,7 +85,6 @@ struct Key {
ino: u64,
len: u64,
mtime: i64,
ctime: i64,
}

/// The per-process V memo. One instance per batch (the batch entry builds
Expand Down Expand Up @@ -131,7 +134,6 @@ impl VCache {
ino: md.ino(),
len: md.len(),
mtime: md.mtime(),
ctime: md.ctime(),
};
if let Some(hit) = self.entries.get(&key) {
return Ok(hit.clone());
Expand Down
47 changes: 46 additions & 1 deletion src/rust/engine/tests/batch_v_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
//! sharing, the point of the exercise) with the naive-parse bytes
//! bit-for-bit (`assert_eq!` on the Vec);
//! 2. a hard-linked alias of that path shares the same Rc (that is the
//! bridge's layout, so it is the contract that must work);
//! bridge's layout, so it is the contract that must work) — including
//! an alias linked AFTER the base's first decode: POSIX `link()`
//! bumps the shared inode's ctime, and a ctime bump with untouched
//! bytes is not a move (law 4 keys on mtime), so the clock second the
//! link lands in must not cost the shared entry;
//! 3. a distinct file with equal bytes does NOT share (identity is the
//! key, not content hashing — no false aliasing across cases);
//! 4. any move of the bytes under a name (length or mtime moved) forces
Expand Down Expand Up @@ -178,6 +182,47 @@ fn hardlinked_aliases_decode_correctly_and_independently() {
}
}

#[cfg(unix)]
#[test]
fn a_hardlink_after_a_clock_tick_still_shares_the_decoding() {
// Law 2's timed face, and the sanitizer-leg race made deterministic:
// the bridge links case names after the base may already have been
// decoded, POSIX `link()` bumps the shared inode's ctime, and the key
// is a whole-second clock -- so when the link crosses a tick the two
// stats disagree on ctime while no byte ever moved. The sleep mirrors
// `bytes_moved_under_a_name_force_a_fresh_decode`: the crossing is
// forced, never flaked.
let t = Tmp::new("late-link");
let p = t.join("shared.csv");
write_grid(&p, M, N, 0);
let mut c = VCache::new();
let a = c.decode(&p, M, N, K).expect("decode base");
std::thread::sleep(std::time::Duration::from_millis(1_100)); // base stat first, tick second, link last
let alias = t.join("late.csv");
fs::hard_link(&p, &alias).expect("hard_link");
let got = c.decode(&alias, M, N, K).expect("decode late alias");
assert!(Rc::ptr_eq(&a, &got), "a link that crossed a clock tick is not a bytes move and must share the base decoding");
assert_eq!(*got, *a, "late alias bytes");
}

#[cfg(not(unix))]
#[test]
fn a_hardlink_after_a_clock_tick_decodes_fresh_and_correctly() {
// Fail-closed twin of `a_hardlink_after_a_clock_tick_still_shares_the_decoding`:
// there is no key to disagree about here, so every late alias is its
// own fresh read of the bytes on disk.
let t = Tmp::new("late-link");
let p = t.join("shared.csv");
write_grid(&p, M, N, 0);
let mut c = VCache::new();
let a = c.decode(&p, M, N, K).expect("decode base");
assert_eq!(*a, naive_read(&p, MN), "base bytes");
let alias = t.join("late.csv");
fs::hard_link(&p, &alias).expect("hard_link");
let got = c.decode(&alias, M, N, K).expect("decode late alias");
assert_eq!(*got, naive_read(&alias, MN), "the late alias must decode to the bytes on disk through its own fresh read");
}

#[test]
fn equal_bytes_under_different_names_do_not_share() {
// Keyed on file identity, never content: two distinct files holding
Expand Down
Loading