Simplicity scratchpad · NVIDIA/hyperflare-inference #79

Raw Markdown for agents: https://autobot.eidonix.com/p/c9f71a8c-b9a4-4722-9289-f7556540c741.md

#1 [high] should fix: EINVAL/ENOTSUP vs ENOSYS: two definitions of "no-replace unsupported"

archive.rs:477-480 (blob fallback) treats only EINVAL and ENOTSUP as "renameat2 unsupported": error.raw_os_error().is_some_and(|code| code == libc::EINVAL || code == libc::ENOTSUP). cache.rs:3685-3696 (new directory preflight) treats EINVAL, ENOTSUP and ENOSYS as unsupported (matches!(error.raw_os_error(), Some(libc::EINVAL | libc::ENOTSUP | libc::ENOSYS))).

Why it matters: the same filesystem property now has two independent definitions in the tree, and they disagree. On a host where renameat2 itself is unavailable (old kernel, or a seccomp profile that filters it, which is the very class of restriction issue #54 comes from — mergerfs returns EINVAL) the preflight reports "filesystem does not support atomic no-replace directory publication" while the blob install in the same export still returns a bare ENOSYS and aborts. Fix: one shared predicate, e.g. fn noreplace_unsupported(error: &io::Error) -> bool in helios core (next to rename_noreplace) used by both, and include ENOSYS in both. Smaller version of the diff: delete the duplicated == EINVAL || == ENOTSUP literal at archive.rs:479 and call the shared helper.

#3 [high] should fix: same preflight runs up to three times per export; python bootstrap + pyfunction deletable

Simplification: the preflight is now called from four places, three of them immediately after an existence check of the same destination, and one of those is inside a Python-level path that also probes.

Call sites added by the PR:

  1. helios/src/core/cache.rs:2358 export_entry — right after cache.rs:2351 if fs::symlink_metadata(destination).is_ok() { return Err("already exists") }.
  2. helios/src/core/cache.rs:3125 commit_standalone — right after cache.rs:3118 the same symlink_metadata check.
  3. helios/src/core/conversion.rs:245 unpack_selected — right after conversion.rs:289… actually before the if output.exists() check at conversion.rs:289-291; the preflight duplicates that check (cache.rs:3641-3650 does symlink_metadata again and returns its own "destination exists" error).
  4. heliopause/src/export/core.rs:708 publish_payload — after the two existing path.exists() checks at core.rs:686-700 (payload export destination already exists, checked twice already in that function).
  5. heliopause/src/export/binding.rs:34 export_capture — before capture, for the !request.sources path; publish_payload at binding.rs:64 does it again in the same call for the same request.path.
  6. ignition/preparation/model_core.py:41-42 export_preflight_directory — before capture; the export then reaches (5) and then (4).

So a single ignition export of a directory core runs the probe up to three times in sequence (Python preflight → export_capture → publish_payload), each one creating and removing a probe directory in the destination parent. That is the "parallel paths / redundant checks" pattern the contribution rules call out (AGENTS.md:170-175 "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement"; and charter "Look for the smallest footprint in shared code, or a way to solve it without new code at all.").

Smaller version: keep the probe in exactly one place — the earliest point that the export reaches before capture. export_capture (binding.rs:34) already covers every non-sources capture, including the ignition path, because model_core.py always goes through export_model/RuntimeCore.write → export_capture. The Python bootstrap in model_core.py:41-42 and its 68-line test file (tests/preparation/test_directory_preflight.py) can then be deleted, as can the export_preflight_directory pyfunction and its registration (binding.rs:120-124, 128). For unpack_selected, the preflight also duplicates the output.exists() check at conversion.rs:289 and can be dropped, since rename_noreplace at conversion.rs:324 already returns AlreadyExists, mapped to destination exists at :325-327.

#8 [high] Research summary

Reviewed PR #79 through the simplicity lens (what can be deleted) against the charter, AGENTS.md and docs/design-review.md. Six findings recorded in the scratchpad; none are blocking, four should fix.

  1. should fix — heliopause/src/export/archive.rs:477-480 vs helios/src/core/cache.rs:3685-3696: the PR writes the "no-replace rename is unsupported" predicate twice and the two copies disagree — the blob fallback accepts only EINVAL/ENOTSUP, the new preflight also accepts ENOSYS. One shared predicate (next to rename_noreplace) deletes the duplicate and makes the blob path honour the same set.

  2. should fix — one ignition export of a directory core runs the probe three times: ignition/preparation/model_core.py:41-42 → heliopause/src/export/binding.rs:34 → heliopause/src/export/core.rs:708. Smallest footprint is one probe at export_capture; the Python bootstrap, the export_preflight_directory pyfunction and its registration, and the whole 68-line tests/preparation/test_directory_preflight.py then go away. The check added at helios/src/core/conversion.rs:245 also duplicates unpack_selected's own output.exists() guard at :289 and the AlreadyExists mapping at :324-327.

  3. should fix — helios/src/core/cache.rs:3653-3665: the probe reinvents unique naming with ring::SystemRandom and a retry loop, although token() (cache.rs:2991) is used by both neighbouring publication paths. ~12 lines and an untestable error arm deletable; the name needs no unpredictability.

  4. should fix — archive.rs:616-661: the 0o555 staging test does not prove its stated premise (as root, which the container builds use, the chmod is unenforced), and two other 20-line tests both only pass a single Err through an 8-line helper. One error test plus the existing destination/temporary assertions suffice.

  5. should fix — binding.rs:97-118: capture_with_owners is a 22-line generic helper extracted only to be testable, and its sole test (binding.rs:1046-1091) passes Cell/AtomicBool stubs, so helper and test only prove each other's control flow. The old inline OwnerLease shape would be ~4 lines.

  6. nit — inside the preflight: the destination existence check duplicates every caller's identical check with a different message, the Ok(())-replaced-target branch and its Unsupported arm are unreachable on any conforming filesystem, and the three-arm (result, cleanup) match reduces to result.and(cleanup). Also commit_standalone (cache.rs:3117-3126) moves synchronize(&self.directory) after the new checks with no test or stated reason.

I did not review rename-fallback atomicity/concurrency guarantees (that is the filesystem-correctness lens, where original-el8 has already commented), and I could not run the Rust tests.

#9 [high] Review scope, rule citations and caveats for the D-lens report

Scope of this review (lens D, simplicity): read all 7 changed files in context — heliopause/src/export/{archive,binding,core}.rs, helios/src/core/{cache,conversion}.rs, ignition/preparation/model_core.py, tests/preparation/test_directory_preflight.py — plus callers: heliopause/src/export/{blob,conversion,transfer}.rs, helios/src/core/export.rs:735-760, ignition/preparation/{core_file,core_snapshot,runtime_core,host_ranks}.py. Findings are in scratchpad entries 1-7.

Rule citations to use in the report:

Caveat to state honestly in the report:

#2 [medium] should fix: preflight probe uses ring RNG where token() already exists (12 lines deletable)

cache.rs:3638/3653-3665 (new preflight probe) draws a probe name from ring's SystemRandom with a random retry loop, while the same module already has a cheap unique-name helper used by both directory publications that sit right next to the probe:

Why it matters (simplicity lens): the probe name does not need to be unguessable — nothing security-relevant depends on it, it is created with create_new semantics (DirBuilder::create fails with EEXIST) and it lives in the same parent directory as the caller-named staging directory. Randomising it buys nothing over the existing pid+counter token, costs a ring::rand dependency edge and 12 lines of hex formatting, and adds an error path (could not generate publication probe name) that has no test and cannot practically occur. Fix: let probe = parent.join(format!(".flare-rename-probe-{}", token())); fs::DirBuilder::new().mode(0o700).create(&probe) and drop the loop/SystemRandom block. If the EEXIST retry matters for the token form, the surrounding TRANSACTION counter plus pid already makes collisions exclusive to a single process, so the retry can go too.

#4 [medium] should fix: archive.rs temporary-cleanup test relies on unenforced 0o555; two error tests overlap

archive.rs:616-661 test unsupported_noreplace_rename_leaves_temporary_cleanup_to_the_caller — this is the heaviest test in the PR (chmod 0o555 on the staging directory, restore, then assert the temporary still exists, then call remove_temporary). What it actually proves beyond unsupported_noreplace_rename_installs_blob_with_a_hard_link (archive.rs:612-633, which already asserts destination and temporary both exist and both read payload) is only that install_blob_after_rename_error does not call unlink — which is visible in the 4-line body, and which the 0o555 chmod does not test reliably: the test runs as root in most CI containers (the repository builds via containers, docs/container.md), where write permission on a directory is not enforced, so the chmod is a no-op and the test's stated premise ("unlinking also needs write permission... Publication must not unlink") is not exercised. That makes it a test that does not prove its behaviour, which AGENTS.md:176-181 rejects ("Tests must exercise the affected behavior or contract").

Also perf/lens: other_rename_errors_are_preserved_without_installing_the_blob (archive.rs:682-702) and unsupported_noreplace_rename_preserves_hard_link_errors (archive.rs:708-…) are both pure pass-through of a single Err, 20 lines each, for a 8-line function; one error-preservation test would carry both.

Fix: delete the 0o555 test (the caller's cleanup is already covered end-to-end by blob.rs:216-224 and by the first test's temporary-still-present assertion), and merge the two error-preservation tests into one.

#5 [medium] should fix: binding.rs capture_with_owners helper + its stub test test only themselves

binding.rs:97-118 — capture_with_owners is a new generic helper extracted from the old inline code, and capture at binding.rs:33-86 was converted from a closure passed to py.detach into a let capture = || { ... } closure ending in a bare result (note the leftover let result = ...; result at binding.rs:37/84-85 — the final result binding is now redundant; result was already the tail expression of the and_then chain, so lines 46-84 could end ... }) and drop the let result = name).

The helper exists only to be testable, and the only test (binding.rs:1046-1091, preflight_failure_drains_without_capturing_and_retains_owners_on_failed_drain) passes closures that are Cell/AtomicBool stubs — it does not exercise OwnerLease, capture_rank, drain_context, or any preflight. What the test proves is the control flow of capture_with_owners itself, i.e. the helper tests the helper. That is the "mocks that bypass the behavior cannot establish runtime correctness" case in AGENTS.md:176-181.

Also the preflight is placed inside capture, so its failure path runs the drain — meaning a preflight rejection still drains the CUDA context even though nothing was captured. That is a behaviour question for another lens, but from the simplicity lens it is worth noting that the old code shape (preflight in the closure) would have been 4 lines rather than a 22-line generic helper plus a 34-line test.

Smaller version: inline the preflight at binding.rs:33-36, keep the original let mut lease = OwnerLease(Some(owners)); / drop(lease.take_after_drain()) shape, and delete capture_with_owners plus its stub test (binding.rs:1046-1091). If the owner-retention-on-failed-drain invariant genuinely needs a test, it belongs against a real drain, not against closures.

Additionally: the extraction changes the error type for the drain failure from PyRuntimeError (raised at binding.rs:93 for every error now) — verify the Python callers that distinguished RuntimeError from ValueError still behave; test_runtime_core.py:76 tests export_capture errors.

#6 [low] nit: preflight duplicates callers' existence check and has two near-duplicate error arms

Nit-level redundancies inside the new preflight function (helios/src/core/cache.rs:3623-3708):

  1. cache.rs:3641-3650 re-checks symlink_metadata(destination) and returns AlreadyExists "destination exists" — but every one of its callers already performed the identical check immediately before the call: cache.rs:2351, cache.rs:3118, conversion.rs:289, heliopause/src/export/core.rs:686-700 (twice). The check is needed for the publish_payload reachability and for zero-cost safety, but note that callers' messages differ ("export destination {} already exists" vs "destination exists"), so two different errors now describe the same condition for the same caller — see the test at tests/preparation/test_directory_preflight.py:65 matching "destination exists" while cache.rs:2352 says "export destination ... already exists". Pick one message and delete it from the callers rather than duplicating it.
  2. cache.rs:3686-3688: error.kind() == io::ErrorKind::Unsupported || matches!(raw_os_error …). The Unsupported arm exists only for the Ok(()) branch at cache.rs:3674-3679 (rename silently replaced the target). If that self-check is kept it needs its own branch; otherwise the whole Unsupported arm and the Ok(())-replaced branch (5 lines, unreachable on any filesystem that honours RENAME_NOREPLACE) can go: a rename that succeeds is simply the success of the second probe at cache.rs:3682.
  3. cache.rs:3697-3707 the (result, cleanup) match: (Ok(()), cleanup) => cleanup is just result.and(cleanup); the three-arm match can be two lines. Similarly preflight_directory_publication (cache.rs:3623-3631) needs the #[cfg(not(target_os = "linux"))] { let _ = destination; Ok(()) } shape only because the body is return-based; #[cfg] on a statement expression would be shorter.
  4. Docs comment at cache.rs:3621-3622 is fine and short. archive.rs:482 // BlobStore::commit owns temporary cleanup after publication. is a useful cross-reference — keep.

#7 [low] nit: commit_standalone moves synchronize after the check for no stated reason

Nit: helios/src/core/cache.rs:3117-3126 commit_standalone — the PR moved synchronize(&self.directory) (previously the first statement, cache.rs old line 3117) to after the new existence check and preflight (new cache.rs:3126). Behaviour that changed: a destination that already exists no longer synchronises the staged tree first — harmless, arguably better. But the preflight is now performed on destination before synchronize(&self.directory), so the reordering's stated purpose is unclear from the diff and there is no test distinguishing the orders. If the reorder is not needed for the fallback, restoring the original first-line synchronize(&self.directory)?; keeps the diff at one added line. (cache.rs:3117-3151 in the head file.)

Also: commit_standalone and export_entry are near-duplicates (both: existence check, preflight, parent/name derivation, staging path from parent, rename_noreplace, cleanup, syncdir). Now that both carry the same 4-line preflight block, the pair is a natural single helper — but that is pre-existing duplication, not introduced here; mention as optional.