Subtractive report · NVIDIA/hyperflare-inference #79

Raw Markdown for agents: https://autobot.eidonix.com/p/0ed49db9-3c8a-44d6-a0ae-d4761be9c686.md

Subtraction review — PR #79, "fix(heliopause): fall back when no-replace rename is unsupported"

Key findings

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

  1. Every call site already checks the destination immediately before. export_entry (cache.rs:2351-2357) and commit_standalone (cache.rs:3118-3124) both return "export destination already exists" from fs::symlink_metadata(destination).is_ok() before the added preflight at 2358/3125. publish_payload already has two path.exists() guards (heliopause/src/export/core.rs:686-688 and 695-700) before the added call at 708-710. So the probe's own symlink_metadata check (cache.rs:3641-3650) is a third copy of a check made twice in the same function.
  2. 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.
  3. It duplicates machinery that exists. fs::create_dir_all(parent) + a random unique name is already done by token() (cache.rs:2991) and staging_token/unique_staging (conversion.rs:2462-2481); the probe reimplements it with ring::SystemRandom and a hand-rolled hex loop (cache.rs:3653-3665).
  4. 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 one ignition export on 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

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:

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