Subtractive scratchpad · NVIDIA/hyperflare-inference #79

Raw Markdown for agents: https://autobot.eidonix.com/p/d1152dec-a8d6-41d4-ac65-02ecd48b2f8e.md

#1 [high] Should fix: directory-publication preflight is a second, redundant mechanism (~200 lines)

PR #79 adds, besides the blob hard-link fallback, a whole "preflight directory publication" mechanism. It is redundant with checks already at every call site and is not needed by #54's chosen fix (issue #54 "Possible changes" lists the fallback or a preflight as alternatives; the PR does both).

What it adds:

Why nothing is lost:

  1. Every call site already checks the destination immediately before, so the preflight's own symlink_metadata(destination) check is a duplicate: helios/src/core/cache.rs:2351-2357 (export_entry) and 3118-3124 (commit_standalone) test fs::symlink_metadata(destination).is_ok() first; heliopause/src/export/core.rs:686-700 already has two path.exists() checks before the added preflight at 708-710.
  2. The unsupported-rename verdict the probe produces is exactly what rename_noreplace itself returns at the same place: cache.rs:2371 and 3143 both call rename_noreplace(&staging, destination).map_err(failure) after the staging tree is built. The probe cannot remove that error, it only moves it earlier.
  3. The probe is not free: it creates a .flare-rename-probe-<32 hex> directory in the user's output parent (cache.rs:3652-3665) and creates that parent (fs::create_dir_all(parent)) from a function documented as "reserves nothing" (cache.rs:3621-3622). model_core.py calls it before capture, core.rs:709 calls it again in publish_payload, and export_entry/commit_standalone call it a third time — three probe directories per directory export on the happy path.
  4. It also duplicates RNG/unique-name machinery that exists: helios/src/core/cache.rs:2991 token() and helios/src/core/conversion.rs:2462-2481 staging_token/unique_staging.

Smaller version: delete preflight_directory_publication, preflight_directory_publication_with, the export_preflight_directory pyfunction and its registration, the 4 call sites, the 3 cache.rs tests, the conversion.rs call, model_core.py:41-42 and tests/preparation/test_directory_preflight.py, and revert export_capture in binding.rs to main's inline shape (which also deletes capture_with_owners and its test). Lines saved: ~87 (cache.rs fn) + 68 (cache.rs tests) + 68 (new test file) + ~30 (binding refactor) + 48 (binding test) + ~10 (call sites/py binding) ≈ 300 added lines of the +468, leaving only the archive.rs fallback.

#2 [high] Should fix: archive.rs fallback tests prove the same two things twice (~60 lines)

heliopause/src/export/archive.rs:471-486 adds install_blob_after_rename_error (16 lines, #[cfg(any(target_os = "linux", test))]) and 432-453 calls it from install_blob. The behaviour needed is 6 lines and can live in install_blob itself:

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 still fails with EEXIST,
    // which BlobStore::commit (heliopause/src/export/blob.rs:204-211) treats as reuse.
    std::fs::hard_link(temporary, destination)?;
}

Tests added in archive.rs:608-728 = ~95 lines. Two pairs prove the same thing:

Lines saved: ~52 of the ~95 test lines, plus ~10 by inlining the helper (the helper exists mainly so tests can inject an error; keeping it is acceptable if a reviewer prefers the seam — then save only the duplicate tests).

#4 [high] Should fix: the retained fallback does not cover #54's actual default-export path

PR title says "fix(heliopause): fall back when no-replace rename is unsupported. Fixes #54." but #54 is about ignition export with the package cache on mergerfs, and reviewer original-el8 (2026-10-26) explains the export then hits other rename_noreplace sites with no fallback:

Verified: rename_noreplace (helios/src/core/cache.rs:3712-3732) still returns the raw EINVAL, and nothing wraps it. So the PR does not fix #54's default export path: the blob commit now succeeds, and the export fails one step later ("Commit core", core.rs:938) with the very same Invalid argument (os error 22). The description should say "partially fixes"; either the same 6-line fallback applies at publish_staged_directory/export_entry (directories cannot hard-link, so a documented fs::rename after the existing existence check is the fallback), or the title/claim shrinks to the blob path.

This is not an additional-feature request: it is the stated purpose of the PR being unmet, and it means the one retained piece (the fallback) is in the wrong place relative to #54.

#6 [high] Blocking: line accounting and total subtraction

Counting from pr_files: +468/−22 across 7 files.

Smallest version that fixes the stated bug (blob commit on mergerfs): heliopause/src/export/archive.rs only — the ~6-line in-place fallback plus the one EEXIST test. That is about +30/−1 instead of +468/−22.

Subtraction total if all findings are applied: ~450 of the 468 added lines; of that, ~245 lines are the preflight mechanism (+87 cache.rs fn, +68 cache.rs tests, +68 python test file, ~30 binding refactor incl. test, ~10 call sites), ~52 are duplicate fallback tests, ~48 are capture_with_owners + its test, and ~10 are the inlined helper/probe duplication.

Severity: blocking and not merely "should fix" — the PR's own claim ("Fixes #54") is not met (finding 4), and roughly 95 % of the diff serves a mechanism that duplicates checks already present at every call site while the actual bug's path stays broken.

#7 [high] Research summary

Reviewed PR #79 (+468/−22, 7 files) against the subtraction lens, the charter and AGENTS.md/design-review.md (not opened). Six findings recorded in the scratchpad, ranked by lines saved.

The core conclusion: the ~6-line hard-link fallback in heliopause/src/export/archive.rs is the whole fix, and everything else in the diff should go. The PR adds a full "preflight directory publication" mechanism — a 87-line probe in helios/src/core/cache.rs plus 68 lines of Rust tests, a new 68-line Python test file, a pyfunction, and four call sites (Python model_core.py, binding.rs, core.rs, cache.rs export_entry/commit_standalone) — that duplicates destination checks already made immediately before each call and produces no verdict rename_noreplace does not already produce at the same place; it also creates and removes a probe directory in the user's output parent up to three times per export. Reverting export_capture to main's inline shape also deletes capture_with_owners and its test, which exist only for their own test.

Separately, verified that the PR does not fix #54 as claimed: rename_noreplace at cache.rs:2371 (export_entry), 3143 (commit_standalone), export.rs:742 and conversion.rs:324 are untouched, so the default directory export still fails with EINVAL one step later at "Commit core" — matching original-el8's review. That makes the change both too big and aimed at only part of its stated bug.

Estimated total subtraction ≈ 450 of the 468 added lines, leaving ~+30/−1 in archive.rs.

#8 [high] Blocking: consolidated ranked findings list for the final report

Ranked by lines saved. Severity prefixes as the report must use them (note 1's title lacked one; its severity is Blocking, folded into item 1 below).

  1. BLOCKING (~245 lines) — delete the whole directory-publication preflight mechanism. helios/src/core/cache.rs:3621-3708 (fn + helper), :3948-4017 (3 tests), helios/src/core/conversion.rs:245-246, tests/preparation/test_directory_preflight.py (all 68 lines), heliopause/src/export/binding.rs:33-36 + 120-128, heliopause/src/export/core.rs:708-710, ignition/preparation/model_core.py:41-42. Nothing replaces it: every call site already checks the destination (cache.rs:2351-2357, 3118-3124; core.rs:686-700) and rename_noreplace (cache.rs:3712) already returns the unsupported verdict at cache.rs:2371/3143. Running it 3x per export and creating/removing .flare-rename-probe-* in the user's output parent is cost, not guarantee. Smallest version: no preflight at all.

  2. SHOULD FIX (~52 lines) — duplicate fallback tests in heliopause/src/export/archive.rs:608-728. Drop unsupported_noreplace_rename_leaves_temporary_cleanup_to_the_caller (630-661, same assertions as 611-629 plus a 0o555 test of unchanged remove_temporary), and merge other_rename_errors_are_preserved_without_installing_the_blob (685-706) with unsupported_noreplace_rename_preserves_hard_link_errors (707-728). Keep unsupported_noreplace_rename_does_not_replace_an_existing_blob (662-684) — it is the EEXIST guarantee.

  3. SHOULD FIX (~48 lines) — heliopause/src/export/binding.rs:97-118 capture_with_owners + test 1046-1091. One caller, exists for the test; revert export_capture to main's inline shape (main binding.rs:32-102), which preserves the same capture→drain→release ordering.

  4. SHOULD FIX (~10 lines, and the claim itself) — the retained fallback does not fix #54: cache.rs:2371 (export_entry), :3143 (commit_standalone), export.rs:742, conversion.rs:324 are still bare rename_noreplace. Either apply the same 6-line fallback there (directories: fs::rename after the existing existence check) or change "Fixes #54" to partial.

  5. NIT (~10 lines + 1 behavioural change) — inline install_blob_after_rename_error (archive.rs:471-486, called only from 448) into install_blob as the 6-line matches!(raw_os_error, Some(EINVAL | ENOTSUP)) branch; and revert the unrelated synchronize(&self.directory) reordering in commit_standalone (cache.rs:3117-3126) — it has no purpose once the preflight is gone and is churn under AGENTS.md:170-175.

Total ≈ 450 of the 468 added lines; the smallest correct change for the stated blob bug is ~+30/−1 in archive.rs alone.

#3 [medium] Nit: commit_standalone reorders synchronize for no reason (churn)

helios/src/core/cache.rs:3117-3151 commit_standalone (changed by this PR at 3117-3125):

Before (main):

pub fn commit_standalone(mut self, destination: &Path) -> Result<()> {
    synchronize(&self.directory)?;
    if fs::symlink_metadata(destination).is_ok() { ...existing... }
    ...

After: the PR adds preflight_directory_publication(destination).map_err(failure)?; at 3125 and moves synchronize(&self.directory)? after it. Reordering synchronize is unrelated cleanup for this PR (AGENTS.md:170-175 "Reject unsupported abstractions and churn": unrelated refactoring must directly support the requested behaviour). Revert it: with the preflight deleted the reorder has no purpose, since the destination check at 3118-3124 already precedes the sync in either order.

Also note: commit_standalone has no distinction from export_entry for this fix — both end in rename_noreplace and both are reachable from publish_payload-adjacent code (conversion.rs:346, core.rs:990). Neither is covered by the PR's fallback, so neither is fixed by it; only the error moves earlier.

Lines saved: 1 net in cache.rs, but it removes an unrelated behavioural change (a long synchronize of the staged tree now runs after an extra probe directory create/remove).

#5 [medium] Should fix: one export runs the probe three times; capture_with_owners has one caller

Independent of whether the preflight mechanism stays, the PR wires it in four times for one export:

  1. ignition/preparation/model_core.py:41-42 (Python, before capture)
  2. heliopause/src/export/binding.rs:33-36 (inside capture, per rank)
  3. heliopause/src/export/core.rs:708-710 (publish_payload)
  4. helios/src/core/cache.rs:2358 (export_entry) and 3125 (commit_standalone) plus helios/src/core/conversion.rs:245 (unpack_selected).

For one ignition export (model_core path) the probe runs at 1, then again at 3, then again at 4 — three create/rename/remove cycles of a .flare-rename-probe-* directory in the output parent, plus fs::create_dir_all(parent). One call site is enough for the stated purpose ("fail before capture"), and it is the earliest one; the other three are the subtraction. This also shows the check does not belong in three shared layers at once.

binding.rs:97-118 capture_with_owners + its test at 1046-1091 (~48 lines): the generic helper exists only to let the new test inject a failing capture closure. Nothing else calls it (search_code capture_with_owners → 2 hits: definition and the one call). Reverting export_capture to main's inline shape (main binding.rs:32-102) removes the closure pair, the generic, and the test, and loses no behaviour: main's ordering (capture, drain, then release owners only if drain succeeded) is preserved by the new code verbatim.

#9 [medium] Rules cited and verification checklist for the report

Rules cited (judge against these, not preference):

Verified in code: every call site's preceding destination check; rename_noreplace callers and their lack of fallback; that capture_with_owners has exactly one caller; that preflight_directory_publication has 4 production call sites plus tests; that fs::create_dir_all(parent) runs inside the "reserves nothing" probe; that blob.rs:204-211 treats EEXIST as reuse (so the hard-link fallback's EEXIST behaviour is needed and already correct).

Not verified / caveats to state honestly: no Rust build or test run was performed (macOS host, Linux-only paths, per the PR's own note); mergerfs was not available, so the EINVAL claim rests on issue #54's strace and the PR's unit tests. The probe-count-per-export claim follows call order model_core.py:42 → core.rs:709 → cache.rs:2358 for the single-host directory export; the multi-host path (host_ranks.py) reaches core.rs:709 and cache.rs:2358 instead.