From cf94b52add4f09559101db9caba22c6ab6990e22 Mon Sep 17 00:00:00 2001 From: netrunner <299844489+plotarmordev@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:50:35 +0800 Subject: [PATCH 1/7] feat(store): support macOS evidence I/O with F_FULLFSYNC flushes Open evidence inputs with POSIX O_NOFOLLOW|O_NONBLOCK on every UNIX platform instead of Linux only, and route every file and directory sync through sync_to_disk, which issues F_FULLFSYNC on macOS where fsync only reaches the buffer cache. Widen the libc target dependency to cfg(unix). --- Cargo.toml | 5 ++-- src/store.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7d2d4ea..90074a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ reqwest = { version = "0.13", default-features = false, features = ["rustls"] } # Current-thread runtime, deadlines, Unix signal latch and select!. tokio = { version = "1", default-features = false, features = ["rt", "net", "time", "signal", "macros"] } -[target.'cfg(target_os = "linux")'.dependencies] -# Architecture-correct O_NOFOLLOW/O_NONBLOCK constants for evidence opens. +[target.'cfg(unix)'.dependencies] +# Platform constants for evidence opens (O_NOFOLLOW/O_NONBLOCK), flock +# ownership, and macOS F_FULLFSYNC flushes. libc = { version = "0.2", default-features = false } diff --git a/src/store.rs b/src/store.rs index 227fcea..656dc25 100644 --- a/src/store.rs +++ b/src/store.rs @@ -11,12 +11,12 @@ fn io_error(operation: &str, path: &Path, error: std::io::Error) -> String { } pub(crate) fn read(path: &Path, cap: usize) -> Result> { - #[cfg(not(target_os = "linux"))] + #[cfg(not(unix))] { let _ = (path, cap); - Err("evidence file handling is supported on Linux only".into()) + Err("evidence file handling requires a UNIX platform".into()) } - #[cfg(target_os = "linux")] + #[cfg(unix)] { use std::io::Read; use std::os::unix::fs::OpenOptionsExt; @@ -27,7 +27,7 @@ pub(crate) fn read(path: &Path, cap: usize) -> Result> { path.display() )); } - // Linux O_NOFOLLOW | O_NONBLOCK: reject symlinks, do not hang if a FIFO + // POSIX O_NOFOLLOW | O_NONBLOCK: reject symlinks, do not hang if a FIFO // is substituted between metadata and open. Parent races are not a sandbox. let file = OpenOptions::new() .read(true) @@ -50,6 +50,23 @@ pub(crate) fn read(path: &Path, cap: usize) -> Result> { } } +/// Flush one open file or directory to stable storage. On macOS `fsync` only +/// reaches the buffer cache, so `F_FULLFSYNC` is required for the durability +/// every evidence write promises. +pub(crate) fn sync_to_disk(file: &File) -> std::io::Result<()> { + #[cfg(target_os = "macos")] + { + use std::os::fd::AsRawFd; + // SAFETY: the descriptor remains owned until after this call. + if unsafe { libc::fcntl(file.as_raw_fd(), libc::F_FULLFSYNC) } == -1 { + return Err(std::io::Error::last_os_error()); + } + Ok(()) + } + #[cfg(not(target_os = "macos"))] + file.sync_all() +} + fn directory(path: &Path) -> Result<()> { let metadata = fs::symlink_metadata(path).map_err(|e| io_error("inspect directory", path, e))?; @@ -65,7 +82,7 @@ fn exists(path: &Path) -> bool { pub(crate) fn sync_directory(path: &Path) -> Result<()> { File::open(path) - .and_then(|f| f.sync_all()) + .and_then(|f| sync_to_disk(&f)) .map_err(|e| io_error("sync directory", path, e)) } @@ -114,7 +131,7 @@ pub(crate) fn write_new(path: &Path, bytes: &[u8]) -> Result<()> { let mut file = open_new(path)?; file.write_all(bytes) .and_then(|_| file.flush()) - .and_then(|_| file.sync_all()) + .and_then(|_| sync_to_disk(&file)) .map_err(|e| io_error("write/sync", path, e)) } @@ -1273,7 +1290,7 @@ pub(crate) mod tests { } } - #[cfg(target_os = "linux")] + #[cfg(unix)] fn tool_fixture(call: &str) -> (Pack, Vec, Plan) { let pack_bytes = serde_json::to_vec(&serde_json::json!({ "version":5, "label":"synthetic", "worlds":["w"], "groups":["g"], @@ -1311,7 +1328,7 @@ pub(crate) mod tests { provenance: Provenance { grill: "fixture".into(), lockfile: String::new(), - os: "linux".into(), + os: std::env::consts::OS.into(), arch: "fixture".into(), started_unix_ms: 0, pid: 0, @@ -1321,8 +1338,8 @@ pub(crate) mod tests { (pack, inputs, plan) } - // Replays evidence through store::read, which is Linux-only like tests/offline.rs. - #[cfg(target_os = "linux")] + // Replays evidence through store::read, which is UNIX-only like tests/offline.rs. + #[cfg(unix)] #[test] fn followup_rejects_call_artifact_without_raw_body_replay() { let call = @@ -1403,4 +1420,31 @@ pub(crate) mod tests { } } } + + #[cfg(unix)] + #[test] + fn full_sync_flushes_open_files_and_directories() { + static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); + let dir = loop { + let path = std::env::temp_dir().join(format!( + "grill-sync-{}-{}", + std::process::id(), + NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + )); + match fs::create_dir(&path) { + Ok(()) => break path, + Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue, + Err(error) => panic!("fixture directory: {error}"), + } + }; + let mut file = open_new(&dir.join("synced")).unwrap(); + file.write_all(b"synced").unwrap(); + // The platform flush (F_FULLFSYNC on macOS, fsync elsewhere) must accept + // both the open file and its directory. + sync_to_disk(&file).unwrap(); + sync_directory(&dir).unwrap(); + drop(file); + assert_eq!(fs::read(dir.join("synced")).unwrap(), b"synced"); + fs::remove_dir_all(&dir).unwrap(); + } } From 5cb135dd041d7cdd52406a7dd7d7f308801d1f71 Mon Sep 17 00:00:00 2001 From: netrunner <299844489+plotarmordev@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:50:36 +0800 Subject: [PATCH 2/7] feat(lifecycle): hold run ownership and admission locks on macOS flock, O_DIRECTORY and O_NOFOLLOW behave the same on macOS, so the ownership and admission locks now build for every UNIX platform; only other platforms fail closed. The non-Linux fail-closed unit test becomes an exclusivity test that runs on macOS too. --- src/lifecycle.rs | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/lifecycle.rs b/src/lifecycle.rs index dcdae6b..67db5f1 100644 --- a/src/lifecycle.rs +++ b/src/lifecycle.rs @@ -1,22 +1,22 @@ -//! Cooperative admission control and immutable continuation sessions (Linux local filesystems). +//! Cooperative admission control and immutable continuation sessions (Linux and macOS local filesystems). use crate::contract::*; use crate::store::{self, AttemptState, Loaded}; use crate::{identity, record}; use serde::{Deserialize, Serialize}; -#[cfg(target_os = "linux")] +#[cfg(unix)] use std::fs::{File, OpenOptions}; -#[cfg(target_os = "linux")] +#[cfg(unix)] use std::os::fd::AsRawFd; -#[cfg(target_os = "linux")] +#[cfg(unix)] use std::os::unix::fs::OpenOptionsExt; use std::path::{Path, PathBuf}; const SESSION_CAP: usize = CASE_CAP + 1; const META_CAP: usize = 8192; -#[cfg(target_os = "linux")] +#[cfg(unix)] pub(crate) struct Lock(File); -#[cfg(target_os = "linux")] +#[cfg(unix)] impl Lock { pub fn run(root: &Path) -> Result { let file = OpenOptions::new() @@ -55,7 +55,7 @@ impl Lock { Ok(Self(file)) } } -#[cfg(target_os = "linux")] +#[cfg(unix)] impl Drop for Lock { fn drop(&mut self) { // SAFETY: the descriptor remains owned until after this call. @@ -65,21 +65,21 @@ impl Drop for Lock { } } -/// Ownership and admission rely on Linux `flock` semantics; elsewhere every +/// Ownership and admission rely on POSIX `flock` semantics; elsewhere every /// lifecycle operation fails closed instead of running without a lock. -#[cfg(not(target_os = "linux"))] +#[cfg(not(unix))] pub(crate) enum Lock {} -#[cfg(not(target_os = "linux"))] +#[cfg(not(unix))] impl Lock { pub fn run(root: &Path) -> Result { let _ = root; - Err("run ownership locking is supported on Linux only".into()) + Err("run ownership locking requires a UNIX platform".into()) } fn gate(root: &Path) -> Result { Self::run(root) } } -#[cfg(not(target_os = "linux"))] +#[cfg(not(unix))] impl Drop for Lock { fn drop(&mut self) { match *self {} @@ -535,17 +535,15 @@ mod tests { assert_eq!(prefix(&attempts).unwrap(), 1); } - #[cfg(not(target_os = "linux"))] + #[cfg(unix)] #[test] - fn pause_fails_closed_without_linux_locking() { + fn run_ownership_lock_is_exclusive_while_held() { let root = std::env::temp_dir().join(format!("grill-lock-{}", std::process::id())); - std::fs::create_dir_all(root.join("lifecycle")).unwrap(); - std::fs::write(root.join("lifecycle/admission.lock"), b"").unwrap(); - let result = pause(&root); + std::fs::create_dir_all(&root).unwrap(); + let owner = Lock::run(&root).unwrap(); + assert!(Lock::run(&root).is_err()); + drop(owner); + assert!(Lock::run(&root).is_ok()); std::fs::remove_dir_all(&root).unwrap(); - assert_eq!( - result.unwrap_err(), - "run ownership locking is supported on Linux only" - ); } } From 2a7c470616acdd4510935b6e6847887b1a5fa1bd Mon Sep 17 00:00:00 2001 From: netrunner <299844489+plotarmordev@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:50:36 +0800 Subject: [PATCH 3/7] feat(run): latch SIGINT and sync body evidence on macOS sigaction with SA_RESTART is POSIX, so the interrupt latch builds on every UNIX platform, and the captured body is flushed through the store's platform sync (F_FULLFSYNC on macOS). --- src/run.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/run.rs b/src/run.rs index bb34498..c8de695 100644 --- a/src/run.rs +++ b/src/run.rs @@ -24,7 +24,7 @@ fn interrupted() -> bool { INTERRUPTED.load(Ordering::SeqCst) } -#[cfg(target_os = "linux")] +#[cfg(unix)] fn latch_interrupt() -> Result<()> { extern "C" fn on_interrupt(_: libc::c_int) { INTERRUPTED.store(true, Ordering::SeqCst); @@ -43,9 +43,9 @@ fn latch_interrupt() -> Result<()> { Ok(()) } -#[cfg(not(target_os = "linux"))] +#[cfg(not(unix))] fn latch_interrupt() -> Result<()> { - Err("the runner's interrupt latch is supported on Linux only".into()) + Err("the runner's interrupt latch requires a UNIX platform".into()) } #[derive(Clone, Copy, clap::ValueEnum)] @@ -430,7 +430,7 @@ impl Capture { .into_inner() .map_err(|e| format!("flush body evidence: {}", e.error()))?; file.flush() - .and_then(|_| file.sync_all()) + .and_then(|_| store::sync_to_disk(&file)) .map_err(|e| format!("sync body evidence: {e}"))?; Ok((self.bytes, self.hash.finish(), self.truncated)) } From cd7d242f8f8251866fa77b2fc6bb052ad247b16d Mon Sep 17 00:00:00 2001 From: netrunner <299844489+plotarmordev@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:50:36 +0800 Subject: [PATCH 4/7] test: run offline and runner suites on macOS and reject FIFO packs The suites were compiled for Linux only because store::read was; they now run on every UNIX platform, proving run/inspect/regrade, SIGINT and pause/resume exclusivity on macOS. Add FIFO pack rejection next to the symlink case. --- tests/offline.rs | 14 +++++++++++++- tests/runner.rs | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/offline.rs b/tests/offline.rs index 98aec0a..95973ed 100644 --- a/tests/offline.rs +++ b/tests/offline.rs @@ -1,4 +1,4 @@ -#![cfg(target_os = "linux")] +#![cfg(unix)] use serde::Deserialize; use std::fs; use std::path::{Path, PathBuf}; @@ -295,6 +295,18 @@ fn forged_or_missing_evidence_and_unsafe_inputs_are_rejected() { .status .success() ); + success( + &Command::new("mkfifo") + .arg(s.path("pack-fifo")) + .output() + .unwrap(), + ); + assert!( + !grade(&s.path("pack-fifo"), &a, &s.path("fifo-view")) + .status + .success() + ); + assert!(!s.path("fifo-view").exists()); } #[test] diff --git a/tests/runner.rs b/tests/runner.rs index 8f9b211..a50aa87 100755 --- a/tests/runner.rs +++ b/tests/runner.rs @@ -1,4 +1,4 @@ -#![cfg(target_os = "linux")] +#![cfg(unix)] // Regressions against an independent counted loopback HTTP fixture. Every // scenario proves dispatch counts and persisted evidence through the real CLI; // nothing here contacts a model service. From 8bf7e7933017eb085467a0f81f30c6fecdabc711 Mon Sep 17 00:00:00 2001 From: netrunner <299844489+plotarmordev@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:50:36 +0800 Subject: [PATCH 5/7] docs: state macOS support for quality storage, locks and latch PROJECT.md's storage paragraph now records the F_FULLFSYNC flushes behind every macOS sync and the flock paragraph drops its Linux-only framing; CONTRIBUTING.md says the quality CLI runs on Apple Silicon macOS with its test suites. --- CONTRIBUTING.md | 13 +++++++------ docs/PROJECT.md | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a4f40e4..5e15377 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ For upcoming releases, reviewed staged archives and the documented source fallba work before publication. The quality CLI remains a separate source-built work in progress. -The Grill is a Rust CLI for Linux. Build and check the workspace with: +The Grill is a Rust CLI for Linux and macOS (Apple Silicon). Build and check the workspace with: ```sh cargo build --workspace --locked @@ -27,11 +27,12 @@ cargo clippy -p grill-perf --locked --all-targets -- -D warnings ``` Native `/proc`/cgroup/NVML resource capture and external-program microbench -capture remain Linux-only, as do the quality CLI's evidence storage, run -ownership locks and interrupt latch; on macOS those paths fail closed and their -tests are compiled for Linux only. The full workspace check list above also -builds and passes on Apple Silicon macOS. Its media adapter fixture runs -`python3` from `PATH`, which must be Python 3.12 (the macOS system 3.9 lacks +capture remain Linux-only. The quality CLI's evidence storage, run ownership +locks and interrupt latch run on Linux and macOS: storage flushes use +`F_FULLFSYNC` on macOS, and the offline and runner test suites are compiled +for all UNIX targets. The full workspace check list above also builds and +passes on Apple Silicon macOS. Its media adapter fixture runs `python3` from +`PATH`, which must be Python 3.12 (the macOS system 3.9 lacks `importlib.metadata.entry_points` selection). macOS changes must not weaken those Linux contracts. diff --git a/docs/PROJECT.md b/docs/PROJECT.md index e0301a1..21b12c0 100644 --- a/docs/PROJECT.md +++ b/docs/PROJECT.md @@ -117,7 +117,7 @@ A successful new view directory contains fixed names `pack.json` (exact input by `View = {version, claim, identities, cases}` where `claim` is `"submitted-artifacts-not-verified-execution"` and `cases` is an ordered CaseGrade array. `CaseGrade = {case_id, input, artifact, evidence, outcome}`: `input` is the per-case input digest; `artifact` is a digest or null; `evidence` and `outcome` have the values above. Receipt IDs are not trusted: comparison requalifies the pack, validates the submission, recomputes all identities, artifacts and outcomes, and requires exact typed equality. A missing/malformed required file, hash mismatch or forged grade fails verification. A fully rewritten internally consistent submission/view remains submitted evidence, not forgery-proof execution. -Storage currently supports Linux local filesystems with ordinary file and parent-directory sync. Inputs, required snapshot entries and the final view directory must be nonsymlink regular files/directories as appropriate. The parent of `--out` must already exist and must itself be a nonsymlink directory. Required file opens use libc's architecture-specific `O_NOFOLLOW | O_NONBLOCK` constants to reject final-component symlinks and avoid hanging on FIFO substitution; opened files are then checked for regular-file type. Ancestor traversal is not a sandbox against concurrent parent replacement or a hostile filesystem. +Storage currently supports Linux and macOS local filesystems. On Linux, files and directories use ordinary `fsync` sync; on macOS every file and directory sync goes through `F_FULLFSYNC`, because `fsync` there only reaches the buffer cache and does not force the data to disk. Inputs, required snapshot entries and the final view directory must be nonsymlink regular files/directories as appropriate. The parent of `--out` must already exist and must itself be a nonsymlink directory. Required file opens use libc's architecture-specific `O_NOFOLLOW | O_NONBLOCK` constants to reject final-component symlinks and avoid hanging on FIFO substitution; opened files are then checked for regular-file type. Ancestor traversal is not a sandbox against concurrent parent replacement or a hostile filesystem. Publication exclusively creates a fresh directory (0700), synchronizes its parent, exclusively creates and syncs snapshots (0600), then syncs their directory before creating and syncing `.view.json.pending`. A no-clobber hard link publishes `view.json`; the staging link is removed and the view directory and parent are synced. Existing destinations are always refused. Failures leave the owned partial directory for inspection and never recursively delete it or unrelated data; final-sync failure may leave a visible receipt despite a nonzero exit. Absent `view.json` means no authoritative grading view. Extra unreferenced files are never read or promoted. There is no overwrite/resume/repair or power-loss/hostile-race/cross-platform durability guarantee. Move/copy all three required files together for relocation. @@ -316,7 +316,7 @@ Execution state is independent of attempt exhaustion. A final-attempt interrupti `grill resume RUN` accepts no changed endpoint, model, pack, protocol, or credential-variable selector. It re-admits the saved pack and plan, verifies request/response/terminal/artifact lineage and every historical session snapshot, and requires a contiguous terminal prefix followed only by never-started cases. Completed, failed, and interrupted terminal attempts are consumed, never retried. Reserved-but-unsettled attempts, unfinished sessions, changed evidence, foreign attempt names, and unsupported lifecycle versions fail closed. An unfinished session is refused even if its last attempt appears settled: no operator-accounting or repair switch is provided for native evidence. Original v1 runs without lifecycle sidecars remain inspectable and regradeable, but are not implicitly adopted for continuation. -Linux `flock` ownership is held on the original run directory descriptor for the whole collector/resumer lifetime. Kernel lock release on process exit avoids PID-reuse ownership guesses and stale lock-file deletion. A separate permanent `lifecycle/admission.lock` serializes short admission/control operations; there is no daemon, polling loop, retry scheduler, or signal sent by `pause`. Advisory locking coordinates these collectors, not a hostile writer replacing directory ancestors or bypassing the protocol. +`flock` ownership (Linux and macOS) is held on the original run directory descriptor for the whole collector/resumer lifetime. Kernel lock release on process exit avoids PID-reuse ownership guesses and stale lock-file deletion. A separate permanent `lifecycle/admission.lock` serializes short admission/control operations; there is no daemon, polling loop, retry scheduler, or signal sent by `pause`. Advisory locking coordinates these collectors, not a hostile writer replacing directory ancestors or bypassing the protocol. New runs add `lifecycle/NNNNNN/start.json`, optional `pause.request` (the session-start digest), `view.json`, and `end.json`. Session starts bind version 1, the original plan digest, previous session-end digest, first attempt, time, PID, binary version and compiled lockfile digest. End receipts bind the start digest, next attempt, state, and exact session-view digest. Each session view preserves the full fixed denominator and is independently checked against the corresponding immutable evidence prefix. Files are no-clobber publications with directory synchronization; credentials never enter these records. The fixed ceiling is 1025 sessions, including the first; the advisory byte bound includes all session metadata and view ceilings. No timing continuity or warmed-client equivalence is claimed across sessions. From 72857b7a2df1c6c5dc186613ecebd5f6a43520b4 Mon Sep 17 00:00:00 2001 From: netrunner <299844489+plotarmordev@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:15:04 +0800 Subject: [PATCH 6/7] refactor(store): rely on std sync_all for the macOS F_FULLFSYNC flush Rust's File::sync_all already issues fcntl(F_FULLFSYNC) with EINTR retry on Apple targets, so the manual helper added an unsafe block and lost the retry for nothing. Restore direct sync_all calls, drop the helper and its test (it could not observe which syscall ran), attribute the macOS flush to std in the docs, and call flock what it is: BSD, not POSIX. --- CONTRIBUTING.md | 5 +++-- Cargo.toml | 4 ++-- docs/PROJECT.md | 2 +- src/lifecycle.rs | 2 +- src/run.rs | 2 +- src/store.rs | 48 ++---------------------------------------------- 6 files changed, 10 insertions(+), 53 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5e15377..1fc3cdb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,8 +28,9 @@ cargo clippy -p grill-perf --locked --all-targets -- -D warnings Native `/proc`/cgroup/NVML resource capture and external-program microbench capture remain Linux-only. The quality CLI's evidence storage, run ownership -locks and interrupt latch run on Linux and macOS: storage flushes use -`F_FULLFSYNC` on macOS, and the offline and runner test suites are compiled +locks and interrupt latch run on Linux and macOS: on Apple platforms the +evidence flushes come from std `sync_all`, which issues `F_FULLFSYNC`, and +the offline and runner test suites are compiled for all UNIX targets. The full workspace check list above also builds and passes on Apple Silicon macOS. Its media adapter fixture runs `python3` from `PATH`, which must be Python 3.12 (the macOS system 3.9 lacks diff --git a/Cargo.toml b/Cargo.toml index 90074a9..e7a81b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,6 @@ reqwest = { version = "0.13", default-features = false, features = ["rustls"] } tokio = { version = "1", default-features = false, features = ["rt", "net", "time", "signal", "macros"] } [target.'cfg(unix)'.dependencies] -# Platform constants for evidence opens (O_NOFOLLOW/O_NONBLOCK), flock -# ownership, and macOS F_FULLFSYNC flushes. +# Platform constants for evidence opens (O_NOFOLLOW/O_NONBLOCK) and flock +# ownership. libc = { version = "0.2", default-features = false } diff --git a/docs/PROJECT.md b/docs/PROJECT.md index 21b12c0..8edb178 100644 --- a/docs/PROJECT.md +++ b/docs/PROJECT.md @@ -117,7 +117,7 @@ A successful new view directory contains fixed names `pack.json` (exact input by `View = {version, claim, identities, cases}` where `claim` is `"submitted-artifacts-not-verified-execution"` and `cases` is an ordered CaseGrade array. `CaseGrade = {case_id, input, artifact, evidence, outcome}`: `input` is the per-case input digest; `artifact` is a digest or null; `evidence` and `outcome` have the values above. Receipt IDs are not trusted: comparison requalifies the pack, validates the submission, recomputes all identities, artifacts and outcomes, and requires exact typed equality. A missing/malformed required file, hash mismatch or forged grade fails verification. A fully rewritten internally consistent submission/view remains submitted evidence, not forgery-proof execution. -Storage currently supports Linux and macOS local filesystems. On Linux, files and directories use ordinary `fsync` sync; on macOS every file and directory sync goes through `F_FULLFSYNC`, because `fsync` there only reaches the buffer cache and does not force the data to disk. Inputs, required snapshot entries and the final view directory must be nonsymlink regular files/directories as appropriate. The parent of `--out` must already exist and must itself be a nonsymlink directory. Required file opens use libc's architecture-specific `O_NOFOLLOW | O_NONBLOCK` constants to reject final-component symlinks and avoid hanging on FIFO substitution; opened files are then checked for regular-file type. Ancestor traversal is not a sandbox against concurrent parent replacement or a hostile filesystem. +Storage currently supports Linux and macOS local filesystems. Every file and directory sync goes through std `sync_all`, which issues `F_FULLFSYNC` on Apple platforms — plain `fsync` there only reaches the buffer cache and does not force data to disk. Inputs, required snapshot entries and the final view directory must be nonsymlink regular files/directories as appropriate. The parent of `--out` must already exist and must itself be a nonsymlink directory. Required file opens use libc's architecture-specific `O_NOFOLLOW | O_NONBLOCK` constants to reject final-component symlinks and avoid hanging on FIFO substitution; opened files are then checked for regular-file type. Ancestor traversal is not a sandbox against concurrent parent replacement or a hostile filesystem. Publication exclusively creates a fresh directory (0700), synchronizes its parent, exclusively creates and syncs snapshots (0600), then syncs their directory before creating and syncing `.view.json.pending`. A no-clobber hard link publishes `view.json`; the staging link is removed and the view directory and parent are synced. Existing destinations are always refused. Failures leave the owned partial directory for inspection and never recursively delete it or unrelated data; final-sync failure may leave a visible receipt despite a nonzero exit. Absent `view.json` means no authoritative grading view. Extra unreferenced files are never read or promoted. There is no overwrite/resume/repair or power-loss/hostile-race/cross-platform durability guarantee. Move/copy all three required files together for relocation. diff --git a/src/lifecycle.rs b/src/lifecycle.rs index 67db5f1..51dbeec 100644 --- a/src/lifecycle.rs +++ b/src/lifecycle.rs @@ -65,7 +65,7 @@ impl Drop for Lock { } } -/// Ownership and admission rely on POSIX `flock` semantics; elsewhere every +/// Ownership and admission rely on BSD `flock` semantics; elsewhere every /// lifecycle operation fails closed instead of running without a lock. #[cfg(not(unix))] pub(crate) enum Lock {} diff --git a/src/run.rs b/src/run.rs index c8de695..d5f50f2 100644 --- a/src/run.rs +++ b/src/run.rs @@ -430,7 +430,7 @@ impl Capture { .into_inner() .map_err(|e| format!("flush body evidence: {}", e.error()))?; file.flush() - .and_then(|_| store::sync_to_disk(&file)) + .and_then(|_| file.sync_all()) .map_err(|e| format!("sync body evidence: {e}"))?; Ok((self.bytes, self.hash.finish(), self.truncated)) } diff --git a/src/store.rs b/src/store.rs index 656dc25..ce4e104 100644 --- a/src/store.rs +++ b/src/store.rs @@ -50,23 +50,6 @@ pub(crate) fn read(path: &Path, cap: usize) -> Result> { } } -/// Flush one open file or directory to stable storage. On macOS `fsync` only -/// reaches the buffer cache, so `F_FULLFSYNC` is required for the durability -/// every evidence write promises. -pub(crate) fn sync_to_disk(file: &File) -> std::io::Result<()> { - #[cfg(target_os = "macos")] - { - use std::os::fd::AsRawFd; - // SAFETY: the descriptor remains owned until after this call. - if unsafe { libc::fcntl(file.as_raw_fd(), libc::F_FULLFSYNC) } == -1 { - return Err(std::io::Error::last_os_error()); - } - Ok(()) - } - #[cfg(not(target_os = "macos"))] - file.sync_all() -} - fn directory(path: &Path) -> Result<()> { let metadata = fs::symlink_metadata(path).map_err(|e| io_error("inspect directory", path, e))?; @@ -82,7 +65,7 @@ fn exists(path: &Path) -> bool { pub(crate) fn sync_directory(path: &Path) -> Result<()> { File::open(path) - .and_then(|f| sync_to_disk(&f)) + .and_then(|f| f.sync_all()) .map_err(|e| io_error("sync directory", path, e)) } @@ -131,7 +114,7 @@ pub(crate) fn write_new(path: &Path, bytes: &[u8]) -> Result<()> { let mut file = open_new(path)?; file.write_all(bytes) .and_then(|_| file.flush()) - .and_then(|_| sync_to_disk(&file)) + .and_then(|_| file.sync_all()) .map_err(|e| io_error("write/sync", path, e)) } @@ -1420,31 +1403,4 @@ pub(crate) mod tests { } } } - - #[cfg(unix)] - #[test] - fn full_sync_flushes_open_files_and_directories() { - static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); - let dir = loop { - let path = std::env::temp_dir().join(format!( - "grill-sync-{}-{}", - std::process::id(), - NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed) - )); - match fs::create_dir(&path) { - Ok(()) => break path, - Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue, - Err(error) => panic!("fixture directory: {error}"), - } - }; - let mut file = open_new(&dir.join("synced")).unwrap(); - file.write_all(b"synced").unwrap(); - // The platform flush (F_FULLFSYNC on macOS, fsync elsewhere) must accept - // both the open file and its directory. - sync_to_disk(&file).unwrap(); - sync_directory(&dir).unwrap(); - drop(file); - assert_eq!(fs::read(dir.join("synced")).unwrap(), b"synced"); - fs::remove_dir_all(&dir).unwrap(); - } } From 40baede1e675e5da6e96f2e25fe3591fb3ba2c29 Mon Sep 17 00:00:00 2001 From: netrunner <299844489+plotarmordev@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:10:06 +0800 Subject: [PATCH 7/7] fix(release): renew reviewed root manifest digest in notice ledger libc moved from cfg(target_os = "linux") to cfg(unix): same crate and version already covered by Cargo.lock and THIRD-PARTY-NOTICES.txt (union over all release targets), so only the manifest_sha256 pin was stale. --- licenses/NOTICE-INPUTS.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/licenses/NOTICE-INPUTS.json b/licenses/NOTICE-INPUTS.json index dcc56ba..07ee67a 100644 --- a/licenses/NOTICE-INPUTS.json +++ b/licenses/NOTICE-INPUTS.json @@ -1,7 +1,7 @@ { "cargo_lock_sha256": "98e8e77d419daffad29e3fcbb7dd6f5b137d5daa02076451d9791db212976543", "manifest_sha256": { - "Cargo.toml": "d42fce6074b77852935ba2d9b82ea4f419f619a27c0aa8a815fb7bcb50c55a5d", + "Cargo.toml": "4db39089363e587d1694caaf0ca9fe2450a46ab64cf32c84d7c9f08692d84e55", "crates/grill-perf/Cargo.toml": "10efcb4bf626a6bef07acf0bdbd7e508105e15f958e28cd7a000b6b734d82e14", "crates/grill-sse/Cargo.toml": "5f6d34630cd32f54aae216f1b5996886e4865343a3d1421e4053ba9c21ccabb1" },