Review of PR #79 — fix(heliopause): fall back when no-replace rename is unsupported
Lens: conventions and duplication. Reviewed at head 06b9011 (base main, 7 files, +468/−22). All seven changed files read in context, callers followed, every claim below re-verified in the code at the head commit. Rules applied: AGENTS.md (esp. 44-60 and 165-180), docs/design-review.md, docs/core-format-design.md. No instruction-like content was found in the PR text or comments; the description follows the required four-part order and does disclose the macOS compile failure and the absent mergerfs run, so the prose is not a finding.
Key findings
The blob fix itself is sound and matches the repository's existing hard-link publication precedent (AGENTS.md:170-175 forbids speculative fallback layers, but #54 is a concrete requirement, so the fallback is earned). What departs from precedent is the directory half of the change:
- The "filesystem refuses RENAME_NOREPLACE" decision is now written twice, with different errno sets, and neither copy matches the repository's existing such decision at
selene/src/disk.rs:1100-1104. - The one shared staged-directory publisher the codebase already centralises publication through —
publish_staged_directory— is left untouched, so the check was duplicated at three call sites and its own caller stays unguarded. - The new preflight executes up to three times per single export, where the established pattern is one early guard plus one authoritative native check.
No blocking issues: behaviour is correct in the covered paths, and nothing regresses.
Should fix
S1. The "no-replace rename unsupported" predicate is duplicated with divergent errno sets
heliopause/src/export/archive.rs:477-480 and helios/src/core/cache.rs:3686-3688
The PR decides the same question twice:
// heliopause/src/export/archive.rs:477-480
if error.raw_os_error()
.is_some_and(|code| code == libc::EINVAL || code == libc::ENOTSUP)
{ std::fs::hard_link(temporary, destination)?; ... }
// helios/src/core/cache.rs:3686-3688
if error.kind() == io::ErrorKind::Unsupported
|| matches!(error.raw_os_error(), Some(libc::EINVAL | libc::ENOTSUP | libc::ENOSYS))
Both sites are probing the same syscall: archive.rs:438-446 calls the glibc libc::renameat2(..., RENAME_NOREPLACE) wrapper, cache.rs:3712-3732 (rename_noreplace) calls libc::syscall(libc::SYS_renameat2, ...).
Why it matters: ENOSYS is exactly what a kernel without the syscall returns. On such a kernel the directory export now reports a clean, deliberate error (cache.rs:3689-3692, "filesystem at … does not support atomic no-replace directory publication") while the blob install in the same export still fails with the raw ENOSYS (archive.rs:485). The two halves of one export disagree about whether the filesystem is unsupported.
The repository already made this decision once, selene/src/disk.rs:1100-1104:
let error = io::Error::last_os_error();
match error.raw_os_error() {
Some(libc::EOPNOTSUPP | libc::ENOSYS) => Ok(()),
_ => Err(error),
}
(on Linux EOPNOTSUPP == ENOTSUP). Neither new site follows it exactly.
Fix: one shared predicate — heliopause already depends on helios-core (heliopause/Cargo.toml:23), so helios_core::core::cache can export it — used by both sites, with the errno set matching selene/src/disk.rs:1100-1104 or documenting why file and directory differ. At minimum add ENOSYS to the archive.rs set.
S2. The shared publisher publish_staged_directory still has neither preflight nor fallback
helios/src/core/export.rs:730-749
The repository has exactly one shared "publish a staged directory atomically, never replacing" helper, and its own doc comment claims singleton ownership of the semantics (export.rs:730-734):
Shared by the cache entry export and by exports without a configured cache, so both have identical durability and no-replacement semantics.
It calls crate::core::cache::rename_noreplace(staging, destination) at export.rs:742 and the diff does not touch it. Instead the new preflight is added at three separate call sites:
helios/src/core/cache.rs:2358(Root::export_entry)helios/src/core/cache.rs:3125(Staging::commit_standalone)helios/src/core/conversion.rs:245(unpack_selected)
Consequence: the documented shared publication path stays unguarded, so the caller at heliopause/src/export/core.rs:1070 (publish_staged_directory(&core_directory, path)?) still reaches a bare rename_noreplace on an unsupported filesystem. This is the conventions-lens form of the concern already raised on the PR (comment of 2026-10-26: the directory path reaches a second no-replace rename; "Fixes #54" → "Partially fixes"): the gap survives because the guard went to the call sites rather than to the one helper the codebase already centralised this through.
Fix: run the preflight (or a directory fallback/refusal) inside publish_staged_directory, and let the three new call sites rely on it. That covers every staged-directory publication once and removes three duplicated four-line blocks.
S3. Three copies of the same four-line preflight in one crate
helios/src/core/cache.rs:2358, helios/src/core/cache.rs:3125, helios/src/core/conversion.rs:245
Same body each time, differing only in the error wrapper:
// cache.rs:2358 and cache.rs:3125
preflight_directory_publication(destination).map_err(failure)?;
// conversion.rs:245-246
crate::core::cache::preflight_directory_publication(output)
.map_err(|error| invalid(format!("directory export preflight: {error}")))?;
docs/design-review.md requires preservation/reuse of shared mechanisms rather than parallel copies. conversion.rs is the same crate, so this is not a layering necessity but copy-paste. This finding is the mechanical half of S2; fixing S2 by moving the guard into publish_staged_directory removes two of the three outright. (Note Root::export_entry at cache.rs:2350-2378 still performs its own bare rename_noreplace at 2371 after the new preflight at 2358 — the guard and the rename it guards are separated by the whole staging build, which is why the single shared publisher is the right home.)
S4. The new directory preflight runs three times per export instead of once at the authoritative layer
ignition/preparation/model_core.py:41-42, heliopause/src/export/binding.rs:33-36, heliopause/src/export/core.rs:708-710
One directory export now probes the destination up to three times:
model_core.py:41-42—flare_heliopause.export_preflight_directory(str(path))before capture.binding.rs:33-36— insideexport_capture, when!request.sources && !request.path.as_os_str().is_empty().core.rs:708-710— insidepublish_payload, when!cache_only && form == "directory".
Steps 2 and 3 run inside the same export_capture invocation (binding.rs:35, then binding.rs:64 → publish_payload), so even without the Python caller the destination is probed twice. Each probe creates a .flare-rename-probe-* directory plus source/target children and removes them (helios/src/core/cache.rs:3653-3684) — three create/remove cycles per export, on the user's destination filesystem.
The established pattern is the opposite: one early guard in Python, then the single authoritative native check. See ignition/preparation/core_file.py:72-80 (_export_native) and ignition/preparation/core_snapshot.py:53-54, 66-67, 78-79 — a Path(...).exists() guard before the native call, after which the atomic no-replace rename is the authoritative check.
Fix: keep one authoritative probe. The cheapest placement that covers all native paths is publish_payload / publish_staged_directory (S2). If the intent is to fail before GPU capture — the stated rationale at binding.rs:33-36, tested at tests/preparation/test_directory_preflight.py:11-42 — then keep exactly one early probe and delete the later ones, with a comment saying the later check is intentionally absent because the early probe does not reserve anything (cache.rs:3621-3622 already says "this probe reserves nothing"). One note for the survivor: fs::create_dir_all(parent) at cache.rs:3652 makes the probe create the destination parent as a side effect, which publish_payload would otherwise do at core.rs:711.
S5. The changed filesystem publication contract is not reflected in the design doc
docs/core-format-design.md:692-704, :710-711
AGENTS.md:47-55 requires architectural behaviour to be specified in the docs, with unresolved defects and unrun checks recorded in docs/TODO.txt. docs/design-review.md:155-156 notes documentation changes need no GPU tests, so this is cheap.
The PR changes three documented behaviours and updates none:
- Blob install no longer always uses
renameat2(RENAME_NOREPLACE); on EINVAL/ENOTSUP it publishes viahard_linkand leaves the temporary forBlobStore::commit(archive.rs:471-486, comment at 482). - Directory export now refuses a filesystem without atomic no-replace directory publication, up front (
cache.rs:3688-3693). Staging::commit_standalonemovedsynchronizeto after the existence check and preflight (cache.rs:3117-3126), where the doc atcore-format-design.md:710-711describes synchronization generically as part of publication.
The doc currently says only (core-format-design.md:697-698) "an unavailable hardlink must not result in a partially published entry" and does not state which fallbacks are allowed or that directory publication requires RENAME_NOREPLACE. Since #54 is precisely about mergerfs-like filesystems, the design doc now understates what export guarantees there.
Fix: a short paragraph near core-format-design.md:692-704 stating the blob hard-link fallback and the up-front refusal of directory publication without RENAME_NOREPLACE; record the unrun mergerfs reproduction in docs/TODO.txt as AGENTS.md:52-55 directs.
Nits
N1. New test file is the only one under tests/preparation/ without the SPDX header
tests/preparation/test_directory_preflight.py:1
Line 1 is the module docstring; there is no license header. Every other file in the directory — e.g. tests/preparation/test_native_publication.py:1-3, test_module_images.py:3 (not opened), payload_fixture.py:2 (not opened) — carries the three-line header (SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES..., ... Flare community contributors, SPDX-License-Identifier: Apache-2.0). The Rust files this PR touches keep theirs (heliopause/src/export/archive.rs:1-4, helios/src/core/cache.rs:1-4). Fix: add the header above the docstring.
N2. Probe name generation and cleanup re-implement helpers that already exist in the same crate
helios/src/core/cache.rs:3653-3707
The probe rolls its own unique-name loop at 3653-3665 (ring SystemRandom, 16 bytes hex, .flare-rename-probe-{name}, unbounded loop on AlreadyExists) and its own compound-error cleanup at 3697-3707. Precedents it ignores:
helios/src/core/conversion.rs:2462-2482—staging_token()+unique_staging(), the same "random token joined to parent" pattern, in the same crate;helios/src/core/cache.rs:2991(token()) is the other existing generator.heliopause/src/export/archive.rs:412-431—temporary()usesOpenOptions::create_new(true)inside a bounded0..100loop, the repository's collision-safe temporary-name pattern; the probe loops unbounded instead.helios/src/core/conversion.rs:2454-2460— the RAIITempDirectoryguard the crate uses to guarantee cleanup, which would replace the manualmatch (result, cleanup)at3697-3707.
Behaviour is correct; this is duplication only.
N3. The new binding flattens AlreadyExists/Unsupported into RuntimeError, unlike the Python-side convention
heliopause/src/export/binding.rs:120-124
.map_err(|error| PyRuntimeError::new_err(error.to_string())) collapses every failure into a string. The Python side of this repository reports "destination exists" as FileExistsError: ignition/preparation/core_snapshot.py:54, 66-67, 78-79, 89-90, 109-110 and core_file.py:77-78 raise or inspect it, and tests assert the type (tests/preparation/test_native_publication.py:55, tests/preparation/test_core_protection.py:805, tests/cli/test_production_signing.py:40). Because the new binding cannot, the new test has to match on message text (tests/preparation/test_directory_preflight.py:66, match="destination exists"). Sibling export_capture also returns PyRuntimeError (binding.rs:93), so the new function is internally consistent — the divergence is with the Python-side contract. Fix if the maintainer wants it distinguishable: map ErrorKind::AlreadyExists → PyFileExistsError, Unsupported → PyOSError/PyNotImplementedError, keep RuntimeError otherwise.
N4. #[cfg(any(target_os = "linux", test))] is a new cfg form and leaves dead code off Linux
heliopause/src/export/archive.rs:471
The sole caller (archive.rs:448) is inside #[cfg(target_os = "linux")], so on macOS/Windows test builds the new helper is compiled (its body uses libc::EINVAL/libc::ENOTSUP, available because libc is an unconditional dependency) and never called — dead code in exactly those builds, currently masked by the unrelated Helios compile failure the PR notes.
No other #[cfg(any(target_os = "linux", test))] exists in the repository (search returned only this line). Established forms: #[cfg(any(test, feature = "test-tools"))] (helios/src/frontend/mod.rs:101 (not opened), helios/src/runtime_core/mod.rs:40 (not opened)) and paired #[cfg(target_os = "linux")] / #[cfg(not(target_os = "linux"))] alternates (helios/src/core/cache.rs:3711-3743, selene/src/disk.rs:1093-1110). Fix: gate the helper #[cfg(target_os = "linux")] and its tests #[cfg(all(test, target_os = "linux"))], or follow the alternates pattern.
N5. The lease/drain extraction converges one of three identical copies
heliopause/src/export/binding.rs:97-118
capture_with_owners is extracted and wired into export_capture only. The identical sequence with the identical message shape remains inline at heliopause/src/export/binding.rs:1250-1270 (export_reset_peer_storage: OwnerLease(Some(owners)), drain, take_after_drain, "{primary}collective reset CUDA drain failed; preparation owners retained: {error}"), with a shorter third copy at heliopause/src/export/transfer.rs:1221-1227 (not opened). Since the helper is generic over the capture closure, both could use it. Fix: parameterise the drain-failure prefix and migrate the remaining two call sites, completing the consolidation the PR starts. The messages stay identical today, which matters because the new test asserts on them (binding.rs:1048-1093).
Checked and cleared (recorded so they are not re-derived)
install_blob_after_rename_error(archive.rs:471-486) has no existing equivalent to reuse; the repo's other hard-link publications (helios/src/core/cache.rs:2583, 2608, 3030,flare/src/hub.rs:1228, 3718) all callfs::hard_linkand interpretAlreadyExists— the new helper matches precedent rather than duplicating it.- Deliberately not removing the temporary after a successful link is correct: the caller
heliopause/src/export/blob.rs:216-224removes it and toleratesNotFound; covered byarchive.rs:632-661. - The new test's module-faking technique (
monkeypatch.setitem(sys.modules, "flare_heliopause", SimpleNamespace(...))) matchestests/preparation/test_module_images.py:41(not opened),test_graph_bundle.py:59(not opened),tests/cli/test_serve.py:87-92(not opened). - New Rust tests live in the pre-existing
mod testsblocks (archive.rs:608,cache.rs:3940), matching those files' convention. - PR title/description follow the four-part order and disclose the unrun checks; the only wording issue ("Fixes #54" for a change that refuses rather than fixes the directory path) is a scope claim covered by S2.
Open questions / what could not be settled from the code
- Whether the merged
publish_staged_directorypath (heliopause/src/export/core.rs:1070) can actually receive a mergerfs destination in the supported configurations is not determinable from the source; only an end-to-end mergerfs run (unavailable to the author and to me) would settle whether it is a live defect or only an inconsistency. S2 stands either way, since the guard belongs where the semantics are documented. - Whether maintainers consider
ENOSYSgenuinely reachable forrenameat2(RENAME_NOREPLACE)on any kernel they support — pre-3.15 kernels, or container runtimes filtering the syscall — determines whether S1 is a live correctness bug or only a consistency fix.selene/src/disk.rs:1102suggests the project already assumes it is reachable. tests/preparation/test_directory_preflight.pyasserts the Python-level probe stops the export before capture; I could not run it or any Helios/Heliopause cargo test in this environment, so all findings are source-verified only.