Review of PR #79 — fix(heliopause): fall back when no-replace rename is unsupported
Head 06b9011, base main, 7 files, +468/−22. Lens: correctness (callers, platforms, error paths, state changes). Governing rules: charter "Bring real evidence … Bug fixes need to address the root cause" (#397) and "PR descriptions: why / what / claimed result / evidence"; AGENTS.md contribution criteria ("Reject weakened guarantees … validation must exercise the affected behavior, not mocks"; "fallback layers … without a concrete requirement" — here issue #54 is the concrete requirement, so the fallback itself is in scope).
Key findings
- The blob fallback is correct and its earlier review nit is fixed; the second no-replace rename that @original-el8 flagged in #79 is covered for the export paths, but not for the core-edit path (
conversion/edit.rs:250) — the one remaining reachable instance of the #54 defect. - One new Python test (
test_directory_preflight.py:53-63) passes for the wrong reason and asserts nothing about its stated subject. - The
unpack_selectedpreflight is placed too early: it changes the established user-visible error for an existing destination and mutates the filesystem (creates the output parent) before the source core is verified.
Verified as correct
Blob install fallback — heliopause/src/export/archive.rs:432-470 (install_blob) now hands the renameat2 failure to install_blob_after_rename_error (:471-486). The helper links only on EINVAL/ENOTSUP (:477-480) and returns every other errno unchanged (:485), so unrelated rename failures keep their identity. std::fs::hard_link(temporary, destination) (:481) gives exactly the required semantics: it is atomic, it refuses to replace an existing entry with EEXIST, and temporary and destination are always in the same directory (blob.rs:177-178: self.root.join(&name) and archive::temporary(&self.root, "blob")), so there is no EXDEV exposure.
The caller is compatible: blob.rs:194-213 maps AlreadyExists from the install to verify_pinned (reuse of the existing blob) and returns any other error; blob.rs:216-224 performs the temporary cleanup and tolerates NotFound. The helper therefore returning Ok(()) without unlinking (:482-483) is right, and @original-el8's earlier nit ("remove_file(temporary)? after a successful link reports a false failure") is resolved in this head — the fallback no longer unlinks at all, and the added test at archive.rs:635-660 pins that by making the staging directory 0o555 so unlinking would fail. The destination-is-not-replaced test (:662-686) and the preserved-error test (:688-721) match the behaviour I read in the code.
Directory preflight — helios/src/core/cache.rs:3620-3701: on Linux it probes with the real rename_noreplace (:3625) on directories, which is the same operation and the same filesystem as the commit; it maps EINVAL/ENOTSUP/ENOSYS to ErrorKind::Unsupported with the parent path in the message (:3680-3695), and it distinguishes the "no-replace rename silently replaced the target" case (:3670-3674). Non-Linux returns Ok unchanged (:3627-3633), so macOS/Windows behaviour is untouched.
Coverage of the previously-flagged paths, checked one by one:
cache.rs:2358inRoot::export_entry— coversheliopause/src/export/core.rs:990(directory export with a cache).cache.rs:3125incommit_standalone(and thesynchronizeit now runs after the probe,:3126).conversion.rs:245inunpack_selected— coversrename_noreplaceatconversion.rs:324.heliopause/src/export/core.rs:708-710— covers thepublish_staged_directorycall at:1070.binding.rs:33-36— covers the non-sourcespayload capture beforecapture_rank, andignition/preparation/model_core.py:41-42runs the same probe before any rank capture, so the 20-minute preparation pass described in #54 is no longer wasted.
Owner lease restructure — binding.rs:97-118: capture_with_owners keeps OwnerLease alive across capture and drain, releases it only on a confirmed drain (:105), and lifetime.rs:14-21 still mem::forgets an unconfirmed lease, so the "never release resources still used by native work" guarantee is preserved. Capture and drain still run inside the same py.detach (:87-92), as before, so nothing new holds the GIL. The panic path (unwind through capture()) also retains owners, matching the pre-PR behaviour.
Should fix
1. helios/src/core/conversion/edit.rs:249-252 — the core-edit publication is still an uncovered no-replace rename.
edit synchronises its staging tree and then calls crate::core::cache::rename_noreplace(&staging, request.output) directly, with no preflight_directory_publication and no fallback. It is reachable in normal use through heliopause/src/export/conversion.rs:186 (export_payload_edit). On a mergerfs package cache/output this fails exactly as #54 describes, after the whole operation, and the message ("publish edited core: {e}" → Invalid argument (os error 22)) still does not name a cause. This is the same defect class the PR sets out to close; @original-el8's comment enumerated four paths and this is the one left. Fix: add the same one-line preflight (or a fallback) here as at conversion.rs:245, and add a case to test_directory_preflight.py or a Rust test that the destination is refused up front.
2. tests/preparation/test_directory_preflight.py:53-63 — the test cannot fail.
test_cache_only_and_packed_exports_do_not_probe_directory_publication installs an unexpected preflight that raises AssertionError, but it calls model_core.export_core(...) without an export_options(...) context, so _OPTIONS.get() is None and model_core.py:31-33 raises RuntimeError("export requires the configured core cache"). The test's pytest.raises(RuntimeError, match="configured core cache") matches that early error, so the assertion would pass even if model_core.py:41-42 probed unconditionally. This contradicts AGENTS.md ("validation that exercises the affected behavior, not mocks") and hides a real regression risk for cache-only exports, where path is None — note platform would str(None) the preflight argument if the guard were lost. Fix: wrap the call in export_options(tmp_path / "cache") as the first test does, and let the probe under test be the only thing that can raise.
3. helios/src/core/conversion.rs:245-246 — preflight before validation changes the error and touches the filesystem on the failure path.
The probe is placed immediately after the directory-form check and before payloads.verify() (:247-248) and before the existing-destination check at :289-291. Two consequences: (a) unpack/unpack_selected against an existing output now reports "directory export preflight: destination exists" instead of the established "destination exists: {output}", which is the message users and tests elsewhere rely on; (b) preflight_directory_publication_with calls fs::create_dir_all(parent) (cache.rs:3652), so an invalid or corrupt source core now creates the output parent directory before it is rejected — the code deliberately cleans up staging on error (:333-335) but not this. Fix: keep the output.exists() check ahead of the probe, and either run the probe after payloads.verify() or make it not create the parent.
Nits
binding.rs:33-36andheliopause/src/export/core.rs:708-710both probe, and both run for a single non-sources, directory-form capture, so each export creates and removes two.flare-rename-probe-*trees in the output parent. Harmless but redundant; one call site would do.- The probe name uses
ring'sSystemRandom(cache.rs:3654-3661) while the same module already has atoken()helper for staging names (cache.rs:2366,:3133); two random-name mechanisms now coexist. - The probe directory (
cache.rs:3657,0o700) is left behind if the process is killed or panic-aborts mid-probe; nothing sweeps it.commit's own failure messages already have this litter risk, so it is consistent, but worth a comment. preflight_directory_publicationreturnsOk(())on non-Linux (cache.rs:3627-3633), so callers cannot distinguish "supported" from "not checked". The doc comment says so, but the three call sites read as if a guarantee was made.install_blob_after_rename_erroris#[cfg(any(target_os = "linux", test))](archive.rs:471) while the Windows arm keeps the inline error path (:465-467) — fine, but it means the new helper's tests never exercise the Windows publication semantics they sit next to.- The PR description omits
tests/preparation/test_directory_preflight.pyandignition/preparation/model_core.py, and the preflight (the part that actually fixes #54's wasted preparation pass) is only implied by the title. Charter's four-part PR description rule wants those named, with the observed evidence.
Open questions / not settled by the code I could read
export_payload_combine(directory form) callsconversion::combinewithoutput = destinationand no preflight (heliopause/src/export/conversion.rs:162-172). Ifcombinepublishes throughcrate::core::export::publish_staged_directory(helios/src/core/export.rs:735-749, which callsrename_noreplacewith no preflight at:742), then TP-merge export is a second uncovered path of the same class. I could not confirmcombine's publication step within this review; a grep ofconversion::combine's body (helios/src/core/conversion.rs:2753) for its publish call would settle it.- Durability of the new hard-link publication:
blob.rs:191fsyncs the file before install, but I found no parent-directory sync on either therenameor thelinkpath, so the link gains nothing over the rename and loses nothing. If asyncdirhappens in the package-export caller, this is already covered — worth confirming rather than changing. - #54's second proposal (record the rename requirement beside the same-filesystem rule in
docs/multi-host.md:243(not opened)) is not done; the new error is explicit, but the documentation gap the issue names remains. - No live mergerfs reproduction was available (per the PR description), so the
EINVALmapping itself is verified by construction (raw errno comparison atarchive.rs:477-480;Unsupportedmapping atcache.rs:3680-3695) and by injected-error tests, not against the FUSE filesystem. That is the right shape of test, but the end-to-end claim in #54 rests on the two injected-error cases.
Note: my findings were produced in this final pass after the scratchpad retained only the PR-overview note; the three should-fix items and the six nits above were each re-verified in the files cited, but they are not separately written to the scratchpad.