Subtraction review — PR #79, "fix(heliopause): fall back when no-replace rename is unsupported"
Key findings
- Blocking: the entire "directory publication preflight" mechanism (~245 of the 468 added lines) serves no purpose and should be deleted.
preflight_directory_publication(helios/src/core/cache.rs:3621-3708) plus its helper, three cache.rs tests (3948-4017), a 68-line Rust-new Python test file (tests/preparation/test_directory_preflight.py), a#[pyfunction](export_preflight_directory, heliopause/src/export/binding.rs:120-124), and four call sites (ignition/preparation/model_core.py:41-42, binding.rs:33-36, heliopause/src/export/core.rs:708-710, cache.rs:2358 and :3125, conversion.rs:245-246) duplicate a destination check every caller already makes and produce a verdictrename_noreplacealready returns at the same place. It also creates and removes a.flare-rename-probe-*directory in the user's output parent up to three times per export. - Should fix: ~52 lines of the new archive.rs tests prove the same two things twice (archive.rs:608-728), and the retained fallback helper (archive.rs:471-486) exists only as a test seam and can be inlined into
install_blob. - Should fix: ~48 lines —
capture_with_owners(binding.rs:97-118) has one caller, its own test; revertingexport_captureto main's inline shape deletes the generic, the closure pair and the test with no behaviour change. - Should fix: the one retained piece is in the wrong place relative to its stated bug.
rename_noreplaceat cache.rs:2371 (export_entry), :3143 (commit_standalone), helios/src/core/export.rs:742 (publish_staged_directory), conversion.rs:324 and edit.rs:250 (not opened) are untouched, so #54's default directory export still fails with EINVAL one step later — independently confirmed by original-el8 (PR comment, 2026-10-26). - Net: the smallest change that fixes the stated blob bug is
heliopause/src/export/archive.rsalone, about +30/−1 instead of +468/−22. Total removable: ~450 lines in 5 places.
Judged against the project's own rules: AGENTS.md:170-175 ("Reject unsupported abstractions and churn" — no fallback layers, extension points or speculative compatibility without a concrete requirement; refactoring must directly support the requested behaviour) and AGENTS.md:176-181 ("Require focused, meaningful validation" — tests must exercise the affected behaviour; a PR must be focused on one coherent outcome and describe its problem, behaviour, validation and limitations). Issue #54's "Possible changes" lists the fallback or a preflight as alternatives; the PR ships both.
Findings, ranked by lines saved
1. Blocking — delete the whole directory-publication preflight mechanism (~245 lines)
What goes
| Location | Lines | What it is |
|---|---|---|
| helios/src/core/cache.rs:3621-3708 | ~87 | preflight_directory_publication + preflight_directory_publication_with |
| helios/src/core/cache.rs:3948-4017 | ~68 | 3 tests for the probe |
| tests/preparation/test_directory_preflight.py | 68 | new Python test file for the probe |
| heliopause/src/export/binding.rs:33-36, 120-124, 127-128 | ~10 | call inside capture, the export_preflight_directory pyfunction, its registration |
| heliopause/src/export/core.rs:708-710 | 3 | call in publish_payload |
| helios/src/core/cache.rs:2358, 3125 | 2 | calls in export_entry and commit_standalone |
| helios/src/core/conversion.rs:245-246 | 2 | call in unpack_selected |
| ignition/preparation/model_core.py:41-42 | 2 | call before capture |
What replaces it: nothing.
Why nothing is lost
- Every call site already checks the destination immediately before.
export_entry(cache.rs:2351-2357) andcommit_standalone(cache.rs:3118-3124) both return "export destination already exists" fromfs::symlink_metadata(destination).is_ok()before the added preflight at 2358/3125.publish_payloadalready has twopath.exists()guards (heliopause/src/export/core.rs:686-688 and 695-700) before the added call at 708-710. So the probe's ownsymlink_metadatacheck (cache.rs:3641-3650) is a third copy of a check made twice in the same function. - The probe's verdict is exactly what the real call returns.
rename_noreplace(cache.rs:3712-3732) is invoked at cache.rs:2371 and :3143 immediately after the staging tree is built; on mergerfs it returns the same EINVAL the probe reports. The probe cannot remove that error — it only moves it earlier, after the expensive part of the export has already run. - It duplicates machinery that exists.
fs::create_dir_all(parent)+ a random unique name is already done bytoken()(cache.rs:2991) andstaging_token/unique_staging(conversion.rs:2462-2481); the probe reimplements it withring::SystemRandomand a hand-rolled hex loop (cache.rs:3653-3665). - It is not free. Despite its own doc comment — "this probe reserves nothing" (cache.rs:3622) — it calls
fs::create_dir_all(parent)on the user's output parent (cache.rs:3652), creates and removes a.flare-rename-probe-<32 hex>directory, and creates two sub-directories inside it (cache.rs:3666-3682). For oneignition exporton the model_core path it runs three times: model_core.py:42 → core.rs:709 → cache.rs:2358.
Smaller version: delete all of the above and revert export_capture in binding.rs to main's inline shape (main binding.rs:32-102). That also removes capture_with_owners (finding 3).
Lines saved: ~245 added lines.
2. Should fix — the archive.rs fallback tests prove the same two things twice (~52 lines)
Where: heliopause/src/export/archive.rs:608-728 — five tests, ~95 lines, for a three-line branch.
Duplicates to drop
unsupported_noreplace_rename_installs_blob_with_a_hard_link(611-629) andunsupported_noreplace_rename_leaves_temporary_cleanup_to_the_caller(630-661) assert the same two facts for both EINVAL and ENOTSUP: the destination holds the bytes, and the temporary still exists (611-629: lines 626-627; 630-661: lines 654, 656). The second test's only extra content is the0o555permission dance at 642-653, which proves something aboutremove_temporary(487-490) — an unchanged, already-existing function — not about the fallback. Drop it: ~31 lines.other_rename_errors_are_preserved_without_installing_the_blob(685-706) andunsupported_noreplace_rename_preserves_hard_link_errors(707-728) both prove "an error is returned and the destination is not created" (704/726 use!destination.exists()). One suffices: ~21 lines.
Keep: unsupported_noreplace_rename_does_not_replace_an_existing_blob (662-684) — this is the EEXIST guarantee the fallback must preserve, and BlobStore::commit (heliopause/src/export/blob.rs:204-211) relies on it to treat an existing blob as reuse.
Lines saved: ~52.
3. Should fix — capture_with_owners exists only for its own test (~48 lines)
Where: heliopause/src/export/binding.rs:97-118 (generic helper, 22 lines) and its single test at 1046-1091 (~45 lines). search_code capture_with_owners returns exactly two hits: the definition (97) and the one call (89). Nothing else can use it.
Why nothing is lost: the helper takes owners, a capture closure and a drain closure, purely so the test can substitute a failing capture. Main's shape (main binding.rs:32-102) had the same capture → drain → release ordering inline in export_capture; the PR's version at 87-94 preserves it verbatim inside capture_with_owners.
Smaller version: inline it back and delete the generic plus its test.
Lines saved: ~48.
4. Should fix — the retained fallback does not cover #54's actual default export path (~10 lines, and the claim)
The title says "Fixes #54", but the diff touches only install_blob (archive.rs:432-470). The other no-replace renames are still bare:
- helios/src/core/cache.rs:2371 —
export_entry, reached on the default directory export from heliopause/src/export/core.rs:990. - helios/src/core/cache.rs:3143 —
commit_standalone. - helios/src/core/export.rs:742 —
publish_staged_directory, used at core.rs:1070 when no cache is configured. - helios/src/core/conversion.rs:324 —
unpack_selected; also helios/src/core/conversion/edit.rs:250 (not opened).
rename_noreplace (cache.rs:3712-3732) still returns the raw error and nothing wraps it. So on mergerfs the export now succeeds at "Commit blob" and fails one step later at "Commit core" with the same Invalid argument (os error 22). original-el8 reached the same conclusion in review (PR #79 comment, 2026-10-26), and suggested the directory fallback — fs::rename after the existing existence check and sync — or the preflight, not both.
This is not a request for a new feature: it is the stated purpose of the PR. Either apply the same 6-line fallback at publish_staged_directory/export_entry (which would let the preflight be deleted entirely, since it was added to compensate for exactly this gap), or change "Fixes #54" to "Partially fixes".
Lines saved: ~10 (the preflight call sites that exist only to compensate) plus the honesty of the claim.
5. Nit — inline the fallback helper, and revert the unrelated synchronize reorder (~11 lines)
a) archive.rs:471-486 + :448-453. install_blob_after_rename_error is called from exactly one place in production (install_blob, 448) and exists mainly so the tests can inject an error; the tests reach it directly at 619, 647, 670, 692, 714. If the tests are consolidated per finding 2, the seam is worth less than the call. The whole behaviour is six lines inside install_blob:
if unsafe {
libc::renameat2(libc::AT_FDCWD, source.as_ptr(), libc::AT_FDCWD,
target.as_ptr(), libc::RENAME_NOREPLACE)
} != 0
{
let error = std::io::Error::last_os_error();
if !matches!(error.raw_os_error(), Some(libc::EINVAL | libc::ENOTSUP)) {
return Err(error.into());
}
// Link preserves no-replace: an existing destination fails with EEXIST, which
// BlobStore::commit (blob.rs:204-211) treats as reuse.
std::fs::hard_link(temporary, destination)?;
}
About 10 lines saved (the #[cfg(any(target_os = "linux", test))] helper, its signature and its doc), and the fallback reads in the place where it happens. Keeping the helper is acceptable if a reviewer prefers the seam; the duplicate tests in finding 2 are the real saving.
b) helios/src/core/cache.rs:3117-3126. commit_standalone on main is:
pub fn commit_standalone(mut self, destination: &Path) -> Result<()> {
synchronize(&self.directory)?;
if fs::symlink_metadata(destination).is_ok() { ... }
(main cache.rs:3669-3677). The PR moves synchronize below the destination check and inserts the probe at 3125. With the probe deleted the reorder has no purpose — the existence check precedes the sync in either order — and it is unsolicited churn under AGENTS.md:170-175. Revert it.
Lines saved: 1 net in cache.rs; removes an unrelated behavioural change.
Line accounting
From pr_files: +468 / −22 over 7 files.
| File | Added | Removable |
|---|---|---|
| heliopause/src/export/archive.rs (+139/−1) | fallback ~16 + tests ~95 | ~52 (dup tests) + ~10 (inline helper) = ~62 |
| heliopause/src/export/binding.rs (+91/−20) | preflight call, pyfunction, capture_with_owners, test |
~48 (helper + test) + ~10 (preflight wiring) |
| heliopause/src/export/core.rs (+3) | preflight call | 3 |
| helios/src/core/cache.rs (+163/−1) | probe ~87 + tests ~68 + call sites | ~157 |
| helios/src/core/conversion.rs (+2) | preflight call | 2 |
| ignition/preparation/model_core.py (+2) | preflight call | 2 |
| tests/preparation/test_directory_preflight.py (+68) | new file | 68 |
| Total | +468/−22 | ~450 |
Smallest correct change for the stated blob bug: heliopause/src/export/archive.rs only, ~+30/−1 (the in-place branch plus the kept EEXIST test). If finding 4 is also addressed, add the same 6-line branch at publish_staged_directory/export_entry — still under 60 lines for the whole PR.
What I verified, and what I did not
Verified in code: that every preflight call site already performs the equivalent destination check (cache.rs:2351-2357, 3118-3124; core.rs:686-700); that rename_noreplace has five production callers and none has a fallback (search over helios/src); that capture_with_owners has exactly one caller; that preflight_directory_publication has five production call sites; that fs::create_dir_all(parent) runs inside the probe documented as reserving nothing (cache.rs:3622 vs 3652); that blob.rs:204-211 treats EEXIST as reuse, so the hard-link fallback's EEXIST behaviour is both needed and already correct; that main's commit_standalone synchronizes before the destination check (main cache.rs:3669-3677), so the PR's reorder is new.
Not verified: no Rust build or test run (macOS host; the PR itself notes the Heliopause Cargo test does not compile there because unchanged Helios code uses Linux-only APIs). mergerfs was not available, so the EINVAL claim rests on issue #54's strace evidence and on the PR's own unit tests. The "three probes per export" count follows the model_core single-host path (model_core.py:42 → core.rs:709 → cache.rs:2358); the multi-host path reaches only core.rs:709 and cache.rs:2358.
Open questions
- Does the author intend the preflight to be the #54 fix, in which case it needs to cover the remaining
rename_noreplacesites (finding 4) rather than sit in four places as a warning? Either answer makes the current diff smaller. - Is
capture_with_ownersintended for another caller in a follow-up? Nothing in the repo, the description or the review thread says so, and AGENTS.md:170-175 rejects speculative extension points; absent that, it goes.