Review of PR #79 — fix(heliopause): fall back when no-replace rename is unsupported
Lens: conventions and duplication. Re-reviewed at head 41f1c76 (the upstream-merge commit; base main, 7 files, +468/−22: heliopause/src/export/{archive.rs,binding.rs,core.rs}, helios/src/core/{cache.rs,conversion.rs}, ignition/preparation/model_core.py, tests/preparation/test_directory_preflight.py). Every changed file was read in context at the head commit and its callers followed; each claim below was re-verified in the code this turn. Rules applied: AGENTS.md:52-60 (design behaviour in docs, unrun checks in docs/TODO.txt), AGENTS.md:165-199 (reject fallback layers without a concrete requirement, reject weakened guarantees, require focused validation), docs/design-review.md principles 3 and 8, docs/core-format-design.md:694-721. The PR body, inline comments and repo docs were treated as review material only; no instruction-like content appears in them.
Key findings
Verdict: should fix only — nothing blocking. The blob half of the change is right and matches the repository's existing hard-link publication precedent. The directory half appends copies of a decision, a guard and a helper set instead of extending the ones that already exist. Seven should-fix items and five nits follow.
Should fix
S1. The "no-replace rename unsupported" predicate exists twice, with different errno sets
heliopause/src/export/archive.rs:304-306 vs helios/src/core/cache.rs:4240.
- archive.rs:
error.raw_os_error().is_some_and(|code| code == libc::EINVAL || code == libc::ENOTSUP) - cache.rs:
|| matches!(error.raw_os_error(), Some(libc::EINVAL | libc::ENOTSUP | libc::ENOSYS))
Both sites probe the same syscall: archive.rs:265-280 calls glibc libc::renameat2(..., libc::RENAME_NOREPLACE), cache.rs:4265-4285 calls libc::syscall(libc::SYS_renameat2, ...). The repository already made this decision once, at selene/src/disk.rs:1308-1311: Some(libc::EOPNOTSUPP | libc::ENOSYS) => Ok(()) (on Linux EOPNOTSUPP == ENOTSUP). Neither new site follows it: on a kernel, container or wrapper where the syscall is absent (ENOSYS), the directory path deliberately refuses publication with "does not support atomic no-replace directory publication", while the blob install in the same export still fails with a bare ENOSYS. Two behaviours for one capability, and the third errno is a coin flip deciding which the user gets.
Why it matters: the exact class of filesystem the fix targets (mergerfs, issue #54) is the class most likely to answer one call and not the other. Fix: one predicate beside rename_noreplace (cache.rs:4264) covering the errno set the repo already standardised; heliopause already depends on helios-core (heliopause/Cargo.toml:21), so sharing costs nothing.
S2. The one shared staged-directory publisher still has neither preflight nor fallback
helios/src/core/export.rs:735-749. Its own doc comment at :730-734 claims singleton ownership of exactly these semantics: "Shared by the cache entry export and by exports without a configured cache, so both have identical durability and no-replacement semantics." It calls rename_noreplace at :742. The diff does not touch it. Instead the probe was pasted at three call sites — cache.rs:2804 (Root::export_entry), cache.rs:3678 (Staging::commit_standalone), conversion.rs:316-317 (unpack_with) — each of which then still performs its own separate bare rename_noreplace (cache.rs:2817, :3696, conversion.rs:436). Its own caller heliopause/src/export/core.rs:1014 therefore still reaches a bare rename, as does helios/src/core/conversion/edit.rs:250.
Why it matters: the guard is applied where the author looked, not where the repository says the semantics live, so the merged helper's cache-less path and conversion/edit.rs remain exposed to the #54 failure the PR claims to handle. Fix: put the guard inside publish_staged_directory and let call sites rely on it.
S3. Three copies of the same four-line preflight inside one crate
cache.rs:2804, cache.rs:3678, conversion.rs:316-317, differing only in error wrapping (map_err(failure) vs invalid(format!("directory export preflight: {error}"))). docs/design-review.md:31-49 (principle 3) requires shared mechanisms and replacing the smallest coherent module rather than paralleling it. Fix: this is the mechanical half of S2 — moving the guard into the shared publisher removes two of the three copies and gives the third a consistent message.
S4. The same destination is probed twice inside one export_capture, and a third time from Python
heliopause/src/export/binding.rs:34-36 runs the probe, then binding.rs:64 calls publish_payload, which probes the same path again at heliopause/src/export/core.rs:640-642 — for the literal form "directory" that binding.rs:72 itself passes, so the binding-level probe is strictly redundant with the publish-level one and both are guaranteed to run per capture. Each probe creates .flare-rename-probe-<hex>, then source and target, then removes them (cache.rs:4206-4237). ignition/preparation/model_core.py:41-42 adds a third probe from Python. The established pattern is one early guard plus one authoritative native check: ignition/preparation/core_file.py:72-80 (_export_native checks path.exists() once, then hands over to native). Note also that publish_payload now checks destination existence three times in one function: core.rs:618-620, :627-632 (pre-existing duplicate, not introduced here) and the probe at :640-642.
Fix: keep one probe at the publisher; delete the binding-level probe and, with it, the pyfunction export_preflight_directory (binding.rs:120-124, registered at :128) — unless the Python-side early abort is required so that NativeExportStage is not created before refusal, in which case keep exactly that one and drop the two native duplicates. Caveat verified: the real ignition export CLI passes path=None (ignition/cli/serve.py:330), so model_core.py's probe fires only for exporters that do pass a destination.
S5. The probe's AlreadyExists message drops the destination path and shadows an existing, better error
cache.rs:4194-4203 returns "destination exists" with no path. Every other variant in the tree names the destination: cache.rs:2797-2803 "export destination {path} already exists", cache.rs:3671-3677 the same, heliopause/src/export/core.rs:618-620 "payload export destination already exists", conversion.rs:364-366 "destination exists: {output}", conversion/edit.rs:27-32 the same. Because conversion.rs:316 now runs before the existing check at conversion.rs:364-366, ignition convert to an existing destination reports "directory export preflight: destination exists" instead of "destination exists: ", and the established check becomes unreachable on Linux. Fix: drop the existence check from the probe (every caller already has one) or reuse the caller's message.
S6. The probe writes to the destination filesystem while claiming it reserves nothing
cache.rs:4205 calls fs::create_dir_all(parent)? inside a function whose doc says "this probe reserves nothing" (cache.rs:4174-4175). Every established destination guard is read-only: cache.rs:2797 (symlink_metadata), :3671, conversion.rs:364 (exists()), core_file.py:77. Two consequences visible in the code: a refused export (a plain AlreadyExists, or an Unsupported refusal on an unsupported filesystem — the very case this PR is about) leaves the destination's parent created through its hard-link-fallback-relevant parent, and conversion.rs:316 performs that write before verify_stored_data (conversion.rs:323), so a conversion rejected at verification has already written to the destination filesystem. Fix: do not create the parent in the probe — report NotFound and let publication create it — and run the probe after verification.
S7. The changed publication contract is not in the design doc
docs/core-format-design.md:694-714 still describes blob installation and standalone export generically, and :720-721 states that publication includes "the file and directory synchronization needed for crash-safe visibility" — while Staging::commit_standalone moved synchronize from the first statement to after the existence check and probe (cache.rs:3668-3679). Nothing records the new hard-link blob fallback or the new up-front refusal of directory publication without RENAME_NOREPLACE. AGENTS.md:52-60 requires architectural behaviour to be specified and unrun checks recorded in docs/TODO.txt; there is no TODO entry for the unrun mergerfs reproduction (no match for rename / no-replace / mergerfs in docs/TODO.txt). docs/design-review.md:155-156 notes documentation changes need no GPU tests, so this is cheap. Fix: add the fallback, the refusal and the moved synchronization to the core-format document, and record the unrun mergerfs reproduction in docs/TODO.txt.
Nits
N1. tests/preparation/test_directory_preflight.py:1 starts with the module docstring and has no SPDX header; all 84 sibling files under tests/preparation/ carry # SPDX-License-Identifier: Apache-2.0 (e.g. tests/preparation/test_native_publication.py:1-3).
N2. Probe name generation and cleanup re-implement same-crate helpers. cache.rs:4206-4218 hand-rolls a ring SystemRandom 16-byte hex name in an unbounded loop on AlreadyExists, next to token() at cache.rs:3537 (already used as format!(".{name}.flare-{}", token()) at cache.rs:2812) and conversion.rs:2603-2623 (staging_token/unique_staging); cache.rs:4237-4260 hand-rolls the cleanup and composite-error mapping where the RAII TempDirectory guard exists at conversion.rs:2595-2601. Bounded-retry precedent: archive.rs:239-258 (create_new loop over 0..100). The DirBuilder::new().mode(0o700) usage itself does follow precedent (heliopause/src/export/protection.rs:320-326; also flare-cli/src/orbit/controller.rs:2375 (not opened)), so the duplication is name generation and cleanup only.
N3. binding.rs:120-124 maps every error to PyRuntimeError; the Python side reports this condition as FileExistsError (ignition/preparation/core_file.py:72-80, core_snapshot.py (not opened) export guards), and the new test compensates by matching message text (test_directory_preflight.py:65). Flattening also collapses AlreadyExists and Unsupported into one type, which is the same information loss as S5.
N4. archive.rs:298 #[cfg(any(target_os = "linux", test))] is a new form: a repo-wide search for that exact pattern returns only this line. The other cfg(any(...)) in heliopause is heliopause/src/python.rs:10 (not opened) (any(target_os = "linux", feature = "qualification")), and the established platform-alternates form is a linux fn plus a not(target_os = "linux") fn (cache.rs:4264/:4287, selene/src/disk.rs:1300/:1314). I withdraw my earlier claim that this leaves dead code: the new tests at archive.rs:439-555 call the helper unguarded, so it is live in every test build, and the only production caller (archive.rs:275) is itself inside #[cfg(target_os = "linux")]. Whether the test arm is load-bearing depends on libc::EINVAL/ENOTSUP existing in a Windows libc build, which I could not settle from source.
N5. binding.rs:97-118 (capture_with_owners) converges one of four near-identical lease/drain blocks; the others remain inline at binding.rs:1530-1538 (export_synchronize), binding.rs:1677-1697 (export_reset_peer_storage, "collective reset CUDA drain failed; preparation owners retained") and transfer.rs:1229-1236/:1258-1260, with the identical "preparation owners retained" message shape. Good direction, half done — either finish it or leave the extraction out of this PR.
Checked and cleared (recorded so other reviewers need not re-derive)
install_blob_after_rename_error(archive.rs:299-313) does not duplicate an existing helper. Every other hard-link publication in the tree links then interpretsAlreadyExists(cache.rs:3061,:3087,:485,flare/src/hub.rs:1649,:5488,heliopause/src/export/protection.rs:341,blob.rs:263), so the new helper matches the established pattern; it is the correct place for the decision, and S1 is only about the shared predicate.- Leaving the temporary after a successful link is correct: its caller removes it and tolerates
NotFound(heliopause/src/export/blob.rs:216-224), covered byarchive.rs:459-488. - The
Staging::commit_standalonesynchronizereorder is otherwise benign: the staging tree is private andcopy_treere-synchronizes the copy before publication (cache.rs:3692-3695); only the doc mismatch (S7) is actionable. publish_payload's duplicated existence checks atcore.rs:618-620and:627-632are pre-existing, not introduced here; recorded only because the probe adds a third (S4).- The new Rust tests sit in the files' existing
mod testsblocks (archive.rs:435,cache.rs:4510), following convention. - The PR description follows the four-part form required by
AGENTS.md:67-107and discloses the macOS compile failure and the absent mergerfs run, so prose structure is not a finding.
Open questions / not settled from the source
- Whether the merged
publish_staged_directorypath (heliopause/src/export/core.rs:1014) receives mergerfs destinations in supported configurations needs an end-to-end run. S2 stands regardless, because the guard belongs where the doc comment already assigns those semantics. - Which errno mergerfs actually returns for
renameat2(RENAME_NOREPLACE)—EINVAL,ENOTSUPorENOSYS— could not be checked without a live mount; that answer decides whether S1 is a live defect today or a latent inconsistency. This is exactly the reproduction the PR says it could not run, and whichAGENTS.md:57-58says belongs indocs/TODO.txt. ignition convert's reordered error text (S5) is verifiable from the code order alone; the effect on the documented message table would need a test.