PR #79 — fix(heliopause): fall back when no-replace rename is unsupported (lens D: simplicity)
Key findings
Verdict: should-fix issues only — no blocking defect. Six findings, two of them nits.
- should fix — The PR adds a second mechanism (a Linux directory-publication preflight) beside the scoped blob fallback, and it probes the same destination twice per directory export: once from Python (
ignition/preparation/model_core.py:41-42) and again insidepublish_payload(heliopause/src/export/core.rs:708-710; for non-sourcescaptures the pair isbinding.rs:34+core.rs:709). One probe in one place removes theexport_preflight_directorypyfunction (binding.rs:120-124) and a whole Python bootstrap step. - should fix — "no-replace rename unsupported" now has two definitions in the tree that disagree:
heliopause/src/export/archive.rs:477-480acceptsEINVAL/ENOTSUP,helios/src/core/cache.rs:3687also acceptsENOSYS. One shared predicate next torename_noreplacedeletes the duplicate and makes the blob path honour the same set. - should fix — the probe reinvents unique naming with
ring::SystemRandomand a retry loop (cache.rs:3653-3665) althoughtoken()(cache.rs:2991) is used by both neighbouring publication paths; ~12 lines and an error arm that cannot be tested. - should fix —
archive.rstests: the 0o555 staging test does not prove its stated premise when run as root, and two 20-line tests both only pass anErrthrough an 8-line helper. - should fix —
binding.rs:97-118: a 22-line generic helper extracted only to host a stub test that proves nothing about owners, drain or preflight. - nit — leftovers inside the preflight and an unexplained reorder in
commit_standalone.
Rule basis used throughout: charter, "How We Work": "Look for the smallest footprint in shared code, or a way to solve it without new code at all."; AGENTS.md:170-175 (reject unsupported abstractions: "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement"); AGENTS.md:176-181 ("Tests must exercise the affected behavior or contract; source-text checks and mocks that bypass the behavior cannot establish runtime correctness"); docs/design-review.md principle 15 (reject scope expansion).
should fix
1. The preflight runs twice per directory export; the Python bootstrap and its pyfunction are deletable
Files: ignition/preparation/model_core.py:41-42, heliopause/src/export/core.rs:708-710, heliopause/src/export/binding.rs:33-36 and 120-124.
# ignition/preparation/model_core.py:41-42
if not cache_only and form == 'directory':
flare_heliopause.export_preflight_directory(str(path))
// heliopause/src/export/core.rs:708-710
if !cache_only && form == "directory" {
helios_core::core::cache::preflight_directory_publication(path)?;
}
// heliopause/src/export/binding.rs:33-36
let capture = || {
if !request.sources && !request.path.as_os_str().is_empty() {
helios_core::core::cache::preflight_directory_publication(&request.path)?;
}
export_core exports ranks with sources=True (model_core.py:51-52), so binding.rs:34 is skipped on that path, and the directory publication happens later through combine → export_combine → publish_payload, which probes the same path again at core.rs:709. Two probes per ignition export. For a non-sources capture (e.g. runtime_core.write(..., sources=False), ignition/preparation/runtime_core.py:109) export_capture probes at binding.rs:35 and then publish_payload probes the identical destination at core.rs:709 inside the same call.
Why it matters: each probe is create_dir + 2×create_dir + renameat2 + remove_dir_all in the destination parent (cache.rs:3652-3684) — not free on the FUSE/mergerfs filesystem that issue #54 is about, and it is duplicated knowledge of the destination's properties with no single owner. The charter asks for "the smallest footprint in shared code", and AGENTS.md:170-175 rejects added layers without a concrete requirement; the Python hook is exactly such a layer.
Fix (smaller version): keep one probe, at the point the export first knows its destination. Since the purpose is to fail before capture burns GPU work, the earliest caller is the natural owner: have export_preflight_directory called from export_capture unconditionally for directory destinations (drop the !request.sources guard) and delete the probe from publish_payload, or keep the guard and delete the Python bootstrap instead. Either way one of the two hooks goes. If the Python bootstrap is the one kept, binding.rs:120-124 (export_preflight_directory), its registration at binding.rs:128, and most of tests/preparation/test_directory_preflight.py become deletable — the third test there (:55-68) only re-tests preflight_directory_publication, already covered by the Rust test at cache.rs:3950-3967.
Related, same pattern: helios/src/core/conversion.rs:245-246 probes output at the top of unpack_selected, which then re-checks output.exists() at :289-291 and maps AlreadyExists from rename_noreplace at :324-330. The probe here adds a third statement of the same precondition; dropping it loses no behaviour because rename_noreplace already refuses to replace and reports it.
2. Two disagreeing definitions of "no-replace rename is unsupported"
Files: heliopause/src/export/archive.rs:477-480 vs helios/src/core/cache.rs:3685-3696.
// archive.rs
if error.raw_os_error().is_some_and(|code| code == libc::EINVAL || code == libc::ENOTSUP)
// cache.rs:3687
|| matches!(error.raw_os_error(), Some(libc::EINVAL | libc::ENOTSUP | libc::ENOSYS))
Why it matters: the same filesystem/kernel property now has two independent encodings that differ by ENOSYS. Where renameat2 itself is unavailable (old kernel, or a seccomp profile filtering the syscall — the class of restriction #54 comes from, mergerfs returning EINVAL), the preflight would report "filesystem does not support atomic no-replace directory publication" while the blob install in the same export still aborts on a bare ENOSYS. The next person changing the accepted set must find both sites.
Fix: one predicate beside rename_noreplace (cache.rs:3710-3712), e.g. pub(crate) fn noreplace_unsupported(error: &io::Error) -> bool accepting EINVAL | ENOTSUP | ENOSYS, called from archive.rs:477 (deleting the inline literal) and from cache.rs:3687.
3. The probe reinvents unique naming with ring::SystemRandom
File: helios/src/core/cache.rs:3653-3665.
let probe = loop {
let mut random = [0u8; 16];
SystemRandom::new()
.fill(&mut random)
.map_err(|_| io::Error::other("could not generate publication probe name"))?;
let name: String = random.iter().map(|byte| format!("{byte:02x}")).collect();
let probe = parent.join(format!(".flare-rename-probe-{name}"));
match fs::DirBuilder::new().mode(0o700).create(&probe) {
Ok(()) => break probe,
Err(error) if error.kind() == io::ErrorKind::AlreadyExists => continue,
Err(error) => return Err(error),
}
};
The same module already owns a unique-name helper, used by the two publication paths sitting immediately next to this probe:
cache.rs:2991-2997—fn token() -> String { format!("{}-{:x}", std::process::id(), TRANSACTION.fetch_add(1, Ordering::Relaxed)) }cache.rs:2366(.{name}.flare-{token()}inexport_entry) andcache.rs:3133(commit_standalone).
Why it matters: nothing security-relevant depends on the probe name being unguessable — it is an empty directory created with create_new semantics in the very parent the caller names in its own staging path, and it exists for microseconds. Unpredictability buys nothing; the ring::rand use adds a dependency edge, 12 lines of hex formatting, a loop, and an error arm (could not generate publication probe name) that has no test and practically cannot fire. AGENTS.md:170-175 again.
Fix:
let probe = parent.join(format!(".flare-rename-probe-{}", token()));
fs::DirBuilder::new().mode(0o700).create(&probe)?;
The pid+counter token is unique per process and the probe is removed in the same call, so the EEXIST retry loop is unnecessary.
4. archive.rs tests: one proves nothing, two overlap
File: heliopause/src/export/archive.rs:630-661, 686-706, 708-728.
unsupported_noreplace_rename_leaves_temporary_cleanup_to_the_caller (:632-661) chmods the staging directory to 0o555 and comments "Linking needs only search permission on the source directory, but unlinking also needs write permission. Publication must not unlink." But directory write permission is not enforced for root, which is how the container builds documented in docs/container.md (not opened) run, so the chmod is a no-op there and the premise is not exercised. What the test actually asserts beyond the preceding test (:611-629, which already checks destination and temporary both exist and both read payload) is only that install_blob_after_rename_error (archive.rs:471-486) does not call unlink — visible in its 4-line body.
Caveat stated honestly: if the suite runs unprivileged the chmod does bite; either way the test is redundant with :611-629's "temporary still present" assertion, and end-to-end cleanup by the caller is covered where it belongs (the BlobStore::commit path, referenced by the comment at archive.rs:482).
The two error tests — other_rename_errors_are_preserved_without_installing_the_blob (:685-706) and unsupported_noreplace_rename_preserves_hard_link_errors (:707-728) — each take ~20 lines to assert that a single Err came back unchanged through an 8-line function.
Fix: delete the 0o555 test; merge the two error tests into one parameterised test over [PermissionDenied, EINVAL, ENOTSUP] asserting the error kind and that destination was not created. Keeps :611-629 and :662-684 (existing destination → EEXIST), which are the two that prove the contract.
5. capture_with_owners exists only to be tested by a stub of itself
File: heliopause/src/export/binding.rs:97-118 and 1046-1093.
The PR extracts a 22-line generic helper:
fn capture_with_owners<O, T>(
owners: O,
capture: impl FnOnce() -> super::Result<T>,
drain: impl FnOnce() -> super::Result<()>,
) -> super::Result<T> { ... }
Its only test (:1047-1093) passes Cell/AtomicBool closures and a Result it constructs itself (:1065-1066); it never touches OwnerLease, capture_rank, drain_context or the preflight. It asserts the control flow of the helper — helper and test only prove each other (AGENTS.md:176-181). The old shape (let mut lease = OwnerLease(Some(owners)); … drop(lease.take_after_drain()) inline in the py.detach closure) was shorter than the helper plus its test.
Also in the same refactor: line 37 let result = match recorder_lock {...} and line 85's bare result are now redundant — the and_then chain at :46-84 is already the tail expression, so :37 can drop let result = and :85 disappears.
Fix: inline the drain/lease handling back into capture (4 lines), delete capture_with_owners and the 47-line stub test, and drop the redundant result binding. If the "owners retained on failed drain" invariant genuinely needs a test, it belongs against a real drain_context failure, which the current test does not provide either way.
nits
6. Cuts inside the preflight body
File: helios/src/core/cache.rs:3623-3708.
:3641-3650re-checkssymlink_metadata(destination)and returnsAlreadyExists "destination exists", although every caller checked immediately before with a different message:cache.rs:2351-2356and:3118-3123("export destination … already exists"),conversion.rs:289-291,core.rs:686-700. Same condition, two vocabularies (the Python test attests/preparation/test_directory_preflight.py:65matches one of them). Keep one check and one message.:3674-3679(Ok(())from the first rename → "no-replace rename replaced an existing directory") and the matchingUnsupportedarm at:3686describe a filesystem that ignoresRENAME_NOREPLACE, which is not a real case: a successful rename is simply the success of the second probe at:3682. Dropping the branch removes 5 lines and an arm.:3697-3707: the three-arm(result, cleanup)match reduces toresult.and(cleanup)if the "probe could not be removed" detail is not wanted, or to two lines mapping the error.:3623-3631: the#[cfg(not(target_os = "linux"))] { let _ = destination; Ok(()) }body exists only because the Linux arm is areturn; a#[cfg]-split body expression is shorter.
7. commit_standalone reorders synchronize with no stated reason
File: helios/src/core/cache.rs:3117-3126. synchronize(&self.directory)? used to be the first statement of the function; it now sits after the new existence check and preflight (:3126). The effect (an existing destination no longer synchronises the staged tree first) is harmless, but nothing in the diff or a test explains why it moved. If it is not needed for the fallback, restoring it as the first line keeps the change to one added statement. Separately, commit_standalone and export_entry (:2350-2378) are now near-identical (existence check, preflight, parent/name derivation, .{name}.flare-{token()} staging, rename_noreplace, cleanup, syncdir); consolidating them is optional and is pre-existing duplication, not introduced here.
Notes on scope and process
- The PR description describes a heliopause blob fix, but the diff also adds a Helios preflight, a new pyfunction, an ignition bootstrap step and a new Python test file (the orientation packet flags
tests/preparationandignition/preparationas "not mentioned"). The simplicity consequence is the one reported as finding 1: the change is now two mechanisms where one was scoped. The description gap itself belongs to the prose lens (AGENTS.md:67-135, four-part PR description). - I read all seven changed files in context plus their callers (
heliopause/src/export/{blob,core}.rs,helios/src/core/export.rs,ignition/preparation/{core_file,runtime_core,model_core}.py) at head06b9011. - Open question, not verified:
export_capturenow maps every error toPyRuntimeErroratbinding.rs:93(previously thePyValueErrorpaths at:24and:29short-circuited before the detach). Whether Python callers distinguish those types is testable by runningtests/preparation/test_runtime_core.py(not opened); I ran no tests. - Out of lens, deliberately not assessed: the fallback's atomicity/
EEXISTsemantics under concurrency, which another reviewer has already commented on, and the macOS/Linux build matrix (the PR notes the Heliopause Cargo test does not compile on macOS). - The single unverified premise in finding 4 is whether the test suite runs as root; the finding is stated with both outcomes, and its recommendation (drop the test as redundant with
:611-629) holds either way.