Subtractive scratchpad · NVIDIA/hyperflare-inference #79

Raw Markdown for agents: https://autobot.eidonix.com/p/df4de591-7da5-4362-9a34-e50fa4ec481e.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.

#11 [high] Blocking: whole directory-publication preflight is redundant (~244 lines)

Head 41f1c76. Verified with search_code (preflight_directory_publication / export_preflight_directory) and read_file.

Where it lives (all added by this PR):

Why nothing is lost (verified in code):

  1. Every call site already checks the destination immediately before: cache.rs:2797-2803 (export_entry), :3671-3677 (commit_standalone), core.rs:618-620 and :627-632 (publish_payload, second check is main's), conversion.rs:364-366 (destination exists: {output}). The probe's own AlreadyExists arm (cache.rs:4194-4200) is a third/duplicate check with a different message ("destination exists" vs the established "directory export preflight: …" wrapper at conversion.rs:316-317).
  2. The verdict duplicates what the real call returns: cache.rs:2817 and :3696 call rename_noreplace (cache.rs:4265-4285) right where the tree is published; on mergerfs the same EINVAL surfaces there. Nothing at 4265 wraps it, so the probe only moves the failure earlier, after the expensive capture.
  3. It reimplements existing helpers: token() (cache.rs:3537-3543) already makes unique staging names, unique_staging/staging_token (conversion.rs:2603-2623) already do the ring-random hex name, TempDirectory (conversion.rs:2595-2601) already handles cleanup.
  4. It is not free, despite its doc ("this probe reserves nothing", cache.rs:4175): fs::create_dir_all(parent) at :4205 creates the user's output parent and :4206-4218 creates and removes a .flare-rename-probe-<32 hex> tree.
  5. Redundancy in one export: model_core.py:42 → later publish_payload (core.rs:640-642) → root.export_entry (core.rs:934 → cache.rs:2804) all probe the same destination; 2-3 probes per export.

Smaller version: delete all of the above; keep no preflight.

Lines saved: ~244 (87 + 70 + 68 + 10 call/pyfunction lines + 2 model_core.py + 4 binding closure).

#12 [high] Should fix: capture_with_owners + its test exist only for the preflight test (~69 lines)

Head 41f1c76. search_code capture_with_owners → definition heliopause/src/export/binding.rs:97-118, single call :89, test :1474-1520. Nothing else uses it.

Main's export_capture (read at main binding.rs:14-100) has the same capture → drain → release ordering inline, with OwnerLease created before py.detach and take_after_drain after. The PR version at binding.rs:33-95 is the same body wrapped in two closures plus the generic.

Smaller version: restore main's inline body; the preflight call at binding.rs:34-36 goes with the preflight (see the blocking note).

Lines saved: ~69 added lines (22 helper + 47 test); reverting also restores the 20 lines the PR removed, so binding.rs returns to its main size.

#13 [high] Should fix: archive.rs fallback tests duplicate each other (~63 lines)

Head 41f1c76. heliopause/src/export/archive.rs:438-555 = five tests, ~118 lines, for a 15-line branch (:298-313).

Duplicate pairs (verified by reading both bodies):

Also heliopause/src/export/archive.rs:298-313 install_blob_after_rename_error is called from production at :275 only; it exists so the tests can inject an errno. Inlining into install_blob (:259-297) is ~10 lines shorter and keeps the same behaviour.

Total: ~63 lines saved (32 + 21 + 10).

#14 [high] Should fix: the fallback still misses every directory publisher (~1 claim, 0 lines)

Head 41f1c76. The retained fallback is only heliopause/src/export/archive.rs:275-279 + :298-313 (blob install). The directory publishers remain bare rename_noreplace:

No wrapper exists at these sites (search_code rename_noreplace). Independently reported by original-el8 in the PR thread (2026-10-26). The PR adds preflights in front of three of them instead of fixing them, so on mergerfs the export now fails at "Commit core"/"Publish core directory" with the same EINVAL — only later and after capture.

Issue #54's "Possible changes" lists the fallback and a preflight as alternatives; the PR ships both.

Smaller version: say "Partially fixes #54", or add the same 6-line fallback in publish_staged_directory (fs::rename after the existence check) and drop the preflights — either way the diff shrinks.

#16 [high] Blocking: corrected line accounting (~378 of 468 removable)

Head 41f1c76, pr_files: +468/−22 across 7 files. Corrected accounting (an earlier note over-counted; these numbers do not double count):

File (added/removed) Removable What
helios/src/core/cache.rs (+163/−1) 159 preflight fn 87 + 3 tests 70 + 2 call sites
tests/preparation/test_directory_preflight.py (+68) 68 whole new file
heliopause/src/export/binding.rs (+91/−20) 71 capture_with_owners 22 + its test 47 + preflight call 4, less restoring the 20 removed lines
heliopause/src/export/archive.rs (+139/−1) 63 2 duplicate tests 53 + helper inlined 10
heliopause/src/export/core.rs (+3) 3 preflight call
helios/src/core/conversion.rs (+2) 2 preflight call
ignition/preparation/model_core.py (+2) 2 preflight call
cache.rs synchronize reorder (+1/−1) 2 revert
Total ~378 of 468

What remains after all cuts: archive.rs 76 added lines (the 6-line hard-link branch, the EEXIST test and one errno test); that is the honest size of the fix, roughly +80/−1 in one file. The "+30" in the previous report assumed a single test.

Severity: blocking. ~80 % of the diff is a second mechanism (preflight) that duplicates checks at every call site (cache.rs:2797-2803, :3671-3677; core.rs:618-620, :627-632; conversion.rs:364-366) and cannot change the outcome, while the publishers that actually fail (#54) — cache.rs:2817, :3696, export.rs:742, conversion.rs:436, edit.rs:250 — are left bare.

#17 [high] Research summary

Verdict: should not be merged at this size — the ~6-line hard-link fallback is the fix; about 80 % of the diff is a second mechanism that changes no outcome.

The change at head 41f1c76: +468 / −22 across 7 files (archive.rs, binding.rs, core.rs, cache.rs, conversion.rs, model_core.py, and a new 68-line Python test file). Five new Rust tests plus one new Python test file for one branch.

Could remove: about 378 of the 468 added lines, in four places, leaving ~80 lines in heliopause/src/export/archive.rs (the branch, the EEXIST test, one errno test).

Left behind: cache.rs:2817 (export_entry), :3696 (commit_standalone), helios/src/core/export.rs:742 (publish_staged_directory), conversion.rs:436 and edit.rs:250 (not opened) are still bare rename_noreplace with no fallback, so on mergerfs the default directory export still fails with EINVAL one step later (Issue #54; also reported by original-el8 in the thread). "Fixes #54" should be "partially fixes" unless the 6-line fallback reaches those sites — which would also let the preflight go entirely.

Judged against AGENTS.md:188-199 ("Reject unsupported abstractions and churn", "Require focused, meaningful validation"). Details and line numbers are in scratchpad notes 11-16, which supersede notes 1-8; the previous report (#10) over-counted, and its "~+30/−1" estimate assumed only one retained test.

#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.

#15 [medium] Nit: commit_standalone synchronize reorder is unsolicited churn (~1 line)

Head 41f1c76. helios/src/core/cache.rs:3670-3679 commit_standalone now checks the destination, runs the preflight and then synchronizes; main (main cache.rs:3669-3677) synchronizes first and then checks. Verified by reading both.

With the preflight deleted the reorder has no purpose and is unsolicited churn (AGENTS.md:188-193, "Reject unsupported abstractions and churn"). Reverting restores main exactly.

Lines saved: 1 added / 1 removed pair (net +1 in the diff).

#18 [medium] Detail: the Python preflight test asserts call order and the absence of its own subject

Head 41f1c76, file read in full (68 lines).

Whole file goes with the preflight (see the blocking note). Nothing needs a replacement: the destination-not-replaced guarantee is already covered by helios/src/core/cache.rs:5497-5530 exported_entries_never_replace_existing_output and helios/src/core/export.rs:1917/1946.

#19 [medium] Rules cited, verification limits, and what was not run

Rules (read directly):

Verified by reading at head 41f1c76: every claim in notes 11-16 — preflight call sites and their pre-existing destination checks (cache.rs:2797-2803, :3671-3677; core.rs:618-620, :627-632; conversion.rs:364-366), rename_noreplace callers with no wrapper (cache.rs:2817, :3696; export.rs:742; conversion.rs:436; edit.rs:250), capture_with_owners single caller, the duplicate test bodies, main's commit_standalone order (main cache.rs:3669-3677), BlobStore::commit treating AlreadyExists as reuse (blob.rs:204-211), the preflight creating the parent (cache.rs:4205), existing helpers token() (cache.rs:3537-3543), unique_staging/staging_token (conversion.rs:2603-2623), TempDirectory (conversion.rs:2595-2601), and pre-existing coverage of no-replacement (cache.rs:5497-5530, export.rs:1917/1946).

Not run: no cargo build/cargo test and no pytest (macOS review host; the PR itself says the Heliopause Cargo tests do not compile there because unchanged Helios code uses Linux-only APIs). mergerfs was unavailable, so the EINVAL behaviour rests on issue #54's strace and the PR's own unit tests. No filesystem-level reproduction of the probe's side effects. Say so in the report.