Conventions scratchpad · NVIDIA/hyperflare-inference #79

Raw Markdown for agents: https://autobot.eidonix.com/p/49d3aef0-2e40-40ff-bdd1-b4c4b7799af4.md

#1 [high] Should fix: two copies of the "no-replace rename unsupported" predicate with different errno sets

PR 79 introduces the same decision twice, with different answers:

ENOSYS is the errno renameat2 returns on a kernel without the syscall/flag. Both paths use it (helio pause via the glibc libc::renameat2 wrapper, helios via libc::syscall(SYS_renameat2) at cache.rs:3718). So on such a kernel the directory export now reports a clean "does not support atomic no-replace directory publication" (cache.rs:3689-3692) while the blob install on the same export still fails with a raw ENOSYS (archive.rs:485).

Repository precedent for this exact decision is selene/src/disk.rs:1100-1104, which treats EOPNOTSUPP | ENOSYS as "feature unavailable" (on Linux EOPNOTSUPP == ENOTSUP) and re-raises everything else. Neither new site follows it exactly.

Fix: one shared predicate (heliopause already depends on helios-core, heliopause/Cargo.toml:23) used by both sites, whose errno set matches or deliberately documents the reason for the difference. At minimum add ENOSYS to archive.rs so the file path and directory path agree.

Note: hard-link fallback for a file is valid, so no design problem with the fallback itself; the finding is the divergence.

#2 [high] Should fix: publication helper publish_staged_directory still has neither preflight nor fallback

The repository already has a single shared "publish a staged directory atomically without replacing" helper: publish_staged_directory at helios/src/core/export.rs:735-749, documented at 730-734 as "Shared by the cache entry export and by exports without a configured cache, so both have identical durability and no-replacement semantics"; it calls crate::core::cache::rename_noreplace(staging, destination) at export.rs:742.

PR 79 does not touch that helper. Instead it adds the preflight at three separate call sites:

Consequence: the established shared publication path stays unguarded, so heliopause/src/export/core.rs:1070 (publish_staged_directory(&core_directory, path)) still hits a bare rename_noreplace on an unsupported filesystem. That is the same class of gap the reviewer raised in the PR conversation ("partially fixes #54"), and it exists because the check was added per call site rather than in the one helper the codebase already centralised this through.

Fix: perform the preflight inside publish_staged_directory (and/or inside rename_noreplace's callers via one wrapper) and let the three new sites rely on it, so every staged-directory publication is covered once. This also removes three duplicated four-line blocks.

#6 [high] Should fix: the new directory preflight runs three times per export instead of once at the authoritative layer

The same "can this destination be published" check now runs up to three times in one directory export:

  1. ignition/preparation/model_core.py:41-42 — new Python call flare_heliopause.export_preflight_directory(str(path)), before capture.
  2. heliopause/src/export/binding.rs:33-36 — new in-native preflight inside export_capture (!request.sources && !request.path.as_os_str().is_empty()).
  3. heliopause/src/export/core.rs:708-710 — new preflight in publish_payload for !cache_only && form == "directory".

Steps 2 and 3 both run inside the same export_capture call (binding.rs:35 then binding.rs:64 → publish_payload), so one export probes the filesystem twice, and the Python caller makes it three. Each probe creates and removes a .flare-rename-probe-* directory plus two child directories in the destination parent (helios/src/core/cache.rs:3666-3684), so this is 3 × 3 directory creations and removals per export.

Existing precedent for the "check once, early" pattern is ignition/preparation/core_file.py:72-80 (_export_native) and core_snapshot.py:53-54 etc., which do a single Path(...).exists() guard in Python before calling native; the native side then owns the atomic no-replace rename as the authoritative check. The PR does the opposite: it adds the guard at every layer.

Fix (conventions lens): keep one authoritative probe. The cheapest place that covers all native paths is publish_payload/publish_staged_directory; the Python and binding-level probes are then redundant. If the intent is to fail before GPU capture (the rationale asserted at binding.rs:33-36 and tested at tests/preparation/test_directory_preflight.py:11-42), say so in a comment on the single surviving probe rather than probing repeatedly.

Note the probe is also not free of side effects on a read-only parent: fs::create_dir_all(parent) at cache.rs:3652 will fail if the parent does not exist and cannot be created, which the later publish_payload would also report — harmless but again duplicated behaviour.

#11 [high] Research summary

Reviewed PR 79 (fix(heliopause): fall back when no-replace rename is unsupported) through the conventions-and-duplication lens. All seven changed files were read in context against AGENTS.md, docs/design-review.md, the repo-prose skill and docs/core-format-design.md, and callers were followed where behaviour changed. Ten notes are in the scratchpad.

Three should-fix findings: (1) the "no-replace rename unsupported" predicate is written twice with different errno sets — archive.rs accepts EINVAL|ENOTSUP while the new cache.rs preflight also accepts ENOSYS, so the blob path and directory path disagree on kernels without renameat2, whereas the repo's existing precedent at selene/src/disk.rs:1100-1104 treats EOPNOTSUPP|ENOSYS uniformly; (2) the repository's shared staged-directory publisher publish_staged_directory (helios/src/core/export.rs:735-749, documented as shared by cache and non-cache exports) was not touched, so the preflight was instead pasted at three call sites and the helper's own caller at heliopause/src/export/core.rs:1070 remains unguarded; (3) the new directory preflight executes three times per export (Python model_core.py:41, binding.rs:33, publish_payload core.rs:708), each probe creating and removing three directories, where existing convention is one guard in Python before the single authoritative native check.

Also recorded: the new test file is the only file under tests/preparation/ without the SPDX header; the probe's name generation and cleanup re-implement conversion.rs staging_token/unique_staging and TempDirectory; the new export_preflight_directory binding flattens AlreadyExists into RuntimeError while the Python side uses FileExistsError; the novel cfg(any(target_os = "linux", test)) gate leaves dead code off Linux; capture_with_owners was extracted from one of three identical lease/drain blocks; and the changed publication contract is not reflected in docs/core-format-design.md, which AGENTS.md requires for architectural behaviour. A final note records candidates I checked and cleared so they are not re-derived. No blocking findings: the blob fallback itself matches the repo's hard-link-plus-AlreadyExists precedent.

#12 [high] PR 79 review context: state, and what the rules allowed

PR under review: https://github.com/NVIDIA/hyperflare-inference/pull/79 — "fix(heliopause): fall back when no-replace rename is unsupported", fixes #54. Head 06b9011, base main, 7 files, +468/−22, labels area:caching/area:packaging/bug/model:gemma4/priority:P2/triage:review, "changes requested" by yatesdr, no CI checks on head. Author efegokemir (association NONE, one other open PR #147).

Scope of the diff for the report: heliopause/src/export/{archive.rs +139/−1, binding.rs +91/−20, core.rs +3}; helios/src/core/{cache.rs +163/−1, conversion.rs +2}; ignition/preparation/model_core.py +2; tests/preparation/test_directory_preflight.py +68 (new). The last two are not mentioned in the PR description.

Prior conversation on the PR (original-el8, 2026-10-26) already argues the blob fallback does not fully fix #54 because the directory export reaches a second no-replace rename (helios/src/package/cache.rs:2377/3559 in main, i.e. helios/src/core/cache.rs:2371/3143 here) and suggests a preflight or directory-specific fallback, and asks that "Fixes #54" become "Partially fixes". A second comment (2026-11-13) re-checks mergeability only and explicitly says filesystem correctness is not approved. My finding #2 and #6 are the conventions-lens counterpart of that concern: the preflight exists but was added at three call sites instead of in the shared publisher, so coverage and single-ownership both suffer.

Rules applied, and how they land:

Nothing in the diff reads as an instruction to me; the PR text, reviewer comments and repo docs were treated as material to review only. No injection attempt found.

#13 [high] Verified specifics for each finding (line-level evidence)

Anchor lines re-verified at head 06b9011.

F1 errno divergence. heliopause/src/export/archive.rs:477-480 error.raw_os_error().is_some_and(|code| code == libc::EINVAL || code == libc::ENOTSUP). helios/src/core/cache.rs:3685-3696 closure wrapping result; line 3687 matches!(error.raw_os_error(), Some(libc::EINVAL | libc::ENOTSUP | libc::ENOSYS)). Both call sites reach the same syscall: archive.rs:438-446 uses glibc libc::renameat2(... RENAME_NOREPLACE); cache.rs:3712-3732 rename_noreplace uses libc::syscall(libc::SYS_renameat2, …). Precedent: selene/src/disk.rs:1100-1104 match error.raw_os_error() { Some(libc::EOPNOTSUPP | libc::ENOSYS) => Ok(()), _ => Err(error) }. heliopause already depends on helios-core (heliopause/Cargo.toml:23) so one shared predicate is available.

F2 shared publisher bypassed. helios/src/core/export.rs:730-749; doc comment at 730-734 says "Shared by the cache entry export and by exports without a configured cache, so both have identical durability and no-replacement semantics"; line 742 calls rename_noreplace. Untouched by the diff. Its caller heliopause/src/export/core.rs:1070 publish_staged_directory(&core_directory, path)?. New preflight call sites: cache.rs:2358 (in Root::export_entry, doc 2344-2349), cache.rs:3125 (in Staging::commit_standalone, doc 3112-3116), conversion.rs:245-246 (in unpack_selected). Other unguarded rename_noreplace users remain: cache.rs:2371 (same function, after the preflight), conversion.rs:324, conversion/edit.rs:250, export.rs:742.

F3 missing SPDX. tests/preparation/test_directory_preflight.py:1 is the module docstring; no header. Compare tests/preparation/test_native_publication.py:1-3 and every other file matched under tests/preparation/.

F4 probe helpers. cache.rs:3653-3665 manual unique-name loop (SystemRandom, 16 bytes hex, .flare-rename-probe-{name}, DirBuilder::new().mode(0o700)), unbounded loop on AlreadyExists at 3661-3663. Existing: conversion.rs:2462-2482 staging_token()/unique_staging(); cache.rs:2991-2997 token(); archive.rs:412-431 temporary() with bounded 0..100 create_new loop. Cleanup: cache.rs:3684-3707 manual match (result, cleanup) composing a compound error, vs the RAII TempDirectory guard at conversion.rs:2454-2460.

F5 Python error mapping. binding.rs:120-124 .map_err(|error| PyRuntimeError::new_err(error.to_string())). Python convention: core_snapshot.py:53-54, 66-67, 78-79, 89-90, 109-110 and core_file.py:77-78 raise FileExistsError; tests assert it at test_native_publication.py:55, test_core_protection.py:805, tests/cli/test_production_signing.py:40. The new test matches on message text instead: test_directory_preflight.py:66 pytest.raises(RuntimeError, match="destination exists").

F6 triple probing. model_core.py:41-42 (Python, before capture); binding.rs:33-36 (inside export_capture, condition !request.sources && !request.path.as_os_str().is_empty()); core.rs:708-710 (inside publish_payload, condition !cache_only && form == "directory"). binding.rs:64 calls publish_payload from within the same capture closure, so 2 and 3 both run per export. Each probe creates .flare-rename-probe-* + source + target (cache.rs:3659-3670) and removes them (3684). Existing single-guard precedent: core_file.py:72-80 _export_native.

F7 cfg form. archive.rs:471 #[cfg(any(target_os = "linux", test))]; sole caller at 448 is inside #[cfg(target_os = "linux")]. Search for that cfg pattern across the repo returned only this line; established forms are #[cfg(any(test, feature = "test-tools"))] (helios/src/frontend/mod.rs:101, helios/src/runtime_core/mod.rs:40) and paired #[cfg(target_os="linux")]/#[cfg(not(...))] (cache.rs:3711-3743, selene/src/disk.rs:1093-1110).

F8 docs. docs/core-format-design.md:692-704 (payload install, hardlink, standalone export) and 710-711 ("Publication includes the file and directory synchronization needed for crash-safe visibility") vs the behaviour changes listed in that note. Also relevant: cache.rs:3117-3126 reordered synchronize to run after the existence check and preflight inside commit_standalone (the diff removes the original synchronize(&self.directory)? first line and re-adds it after the preflight).

F9 lease/drain duplication. New helper binding.rs:97-118 capture_with_owners; identical inline sequence remains at binding.rs:1250-1270 (export_reset_peer_storage, message "collective reset CUDA drain failed; preparation owners retained") and a shorter copy at transfer.rs:1221-1227. New test relies on the preserved message text: binding.rs:1048-1093.

#3 [medium] Should fix: new Python test file lacks the SPDX header every other file in the directory has

tests/preparation/test_directory_preflight.py (new, +68) begins at line 1 with """Standalone directory exports reject unsupported publication before capture.""" and has no license header.

Every other file in tests/preparation/ carries the two-line header, e.g. tests/preparation/test_native_publication.py:1-3:

# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 2026 Flare community contributors
# SPDX-License-Identifier: Apache-2.0

(I checked all 89 files matched by that pattern under tests/preparation/; the new file is the only one without it.) The Rust files the PR touches keep theirs (heliopause/src/export/archive.rs:1-4, helios/src/core/cache.rs:1-4).

Fix: add the two-line SPDX header above the module docstring, matching the neighbour files.

#4 [medium] Nit: probe naming and cleanup duplicate existing helpers in the same crate

The probe in helios/src/core/cache.rs:3634-3708 builds its unique probe name by hand (ring SystemRandom, hex-encoding 16 bytes, .flare-rename-probe-{name}, loop on AlreadyExists) at lines 3653-3665, and creates the directory with DirBuilder::mode(0o700).

Two established precedents it ignores:

  1. helios/src/core/conversion.rs:2462-2482 — staging_token() + unique_staging() are exactly this ("random token + parent.join(name)") and live in the same crate; helios/src/core/cache.rs:2991 token() is the other existing generator. A third generator is now needed only for this probe.
  2. heliopause/src/export/archive.rs:412-431 — temporary() uses OpenOptions::create_new(true) in a bounded 100-iteration loop for uniqueness, the repository's pattern for collision-safe temporary names; the probe instead retries an unbounded loop on AlreadyExists (line 3661-3663).

Also, the probe creates a directory named .flare-rename-probe-* in the user's destination parent and leaves it only if remove_dir_all succeeds. helios/src/core/cache.rs:3684-3707 composes a compound error when cleanup fails. That composition duplicates the existing TempDirectory-style RAII guard (helios/src/core/conversion.rs:2454-2460) which the same crate already uses to guarantee cleanup; using a guard would remove the manual match (result, cleanup) at 3697-3707.

Severity: nit/should-fix depending on maintainer taste; I record it as a nit on duplication because the behaviour is correct.

#8 [medium] Should fix: changed filesystem publication contract is not reflected in docs/core-format-design.md

The repository keeps user-visible filesystem behaviour in the design docs, not only in code:

PR 79 changes that contract in three ways and documents none of it:

  1. Blob installation no longer always uses renameat2(RENAME_NOREPLACE); on EINVAL/ENOTSUP it publishes with hard_link and leaves the temporary for BlobStore::commit (heliopause/src/export/archive.rs:471-486, comment "BlobStore::commit owns temporary cleanup after publication").
  2. Directory export now refuses a filesystem without atomic no-replace directory publication, before preparation, with the message at helios/src/core/cache.rs:3689-3692.
  3. Staging::commit_standalone reordered synchronize after the existence check and preflight (helios/src/core/cache.rs:3117-3126) — behaviour the doc at core-format-design.md:710-711 ("Publication includes the file and directory synchronization needed for crash-safe visibility") describes generically.

AGENTS.md:47-55 requires architectural behaviour to be specified in the docs and defects/unrun checks in docs/TODO.txt; it also says "Documentation changes do not require GPU tests" (docs/design-review.md:155-156), so this is cheap to add.

Severity: should fix — the design doc now understates what the export guarantees on mergerfs-like filesystems, which is precisely the case #54 is about. Add a paragraph to docs/core-format-design.md around line 692-704 stating: blob publication falls back to a hard link when the filesystem refuses RENAME_NOREPLACE; directory publication requires RENAME_NOREPLACE and is refused up front otherwise; and record the unrun mergerfs reproduction in docs/TODO.txt as AGENTS.md:52-55 directs.

#5 [low] Nit: new Python binding flattens AlreadyExists/Unsupported into RuntimeError, unlike Python-side FileExistsError convention

Heliopause already delivers std::io::Error to Python as an exception whose class encodes the errno — blob.rs/archive.rs rely on downcast_ref::<std::io::Error>() and ErrorKind inside Rust (e.g. heliopause/src/export/blob.rs:204-211 distinguishes AlreadyExists; heliopause/src/export/archive.rs:481 relies on hard_link returning AlreadyExists).

The new binding export_preflight_directory at heliopause/src/export/binding.rs:120-124 does .map_err(|error| PyRuntimeError::new_err(error.to_string())), flattening every error into RuntimeError with a string. The CLI/sort side of the repo distinguishes this condition with FileExistsError: ignition/preparation/core_snapshot.py:54,66,78,90,109 and ignition/preparation/core_file.py:78 raise/inspect FileExistsError for "destination exists", and the tests assert it (tests/preparation/test_native_publication.py:55, tests/cli/test_production_signing.py:40, tests/preparation/test_core_protection.py:805).

So the new Python surface is the only publication entry point that cannot report "already exists" as FileExistsError; the new test at tests/preparation/test_directory_preflight.py:55-68 has to match on the message "destination exists" instead of the exception type. The sibling function in the same file, export_capture (binding.rs:93), also uses PyRuntimeError, so this is consistent with that one — but conflict with the Python-side convention above.

Severity: nit. Fix if the maintainer wants the probe to be distinguishable: map ErrorKind::AlreadyExists to PyFileExistsError and ErrorKind::Unsupported to PyNotImplementedError/PyOSError, keeping RuntimeError for the rest.

#7 [low] Nit: cfg(any(target_os = "linux", test)) is a new cfg form and leaves dead code off Linux

heliopause/src/export/archive.rs:471 gates the new helper with #[cfg(any(target_os = "linux", test))]. Its only caller (archive.rs:448) sits inside #[cfg(target_os = "linux")]. Consequences:

Severity: nit. Fix: gate the helper #[cfg(target_os = "linux")] and put a #[cfg(all(test, target_os = "linux"))] on the tests that call it — or, if non-Linux unit coverage is wanted, follow the crate's existing alternates pattern (a #[cfg(not(target_os="linux"))] version returning the input error).

#9 [low] Nit: owner-lease/drain extraction is applied to one of three identical copies

PR 79 extracts the "owner lease + drain" sequence into capture_with_owners (heliopause/src/export/binding.rs:97-118) and rewires only export_capture to it. The identical sequence still exists inline a few hundred lines below at export_reset_peer_storage, heliopause/src/export/binding.rs:1250-1270:

let mut lease = OwnerLease(Some(owners));
let (result, drain) = ...;
if drain.is_ok() { drop(lease.take_after_drain()); }
if let Err(error) = drain { let primary = ...; return Err(PyRuntimeError::new_err(format!("{primary}collective reset CUDA drain failed; preparation owners retained: {error}"))); }

That is the same logic and the same message shape as the new helper's "…export CUDA drain failed; preparation owners retained: {error}". A third, shorter copy is heliopause/src/export/transfer.rs:1221-1227. So the extraction removes one of three copies rather than converging them; capture_with_owners is also generic over the capture closure, which the reset path could use.

Additionally the helper changes the returned error type: the old code produced PyRuntimeError, the helper produces super::invalid(...) which the caller maps to PyRuntimeError at binding.rs:93 — equivalent for callers, but note that the drain-failure string is now built from super::Result instead of Box<dyn Error + Send + Sync>; the messages stay identical, which the new test relies on (binding.rs:1048-1093).

Severity: nit. Fix: pass the drain-failure prefix (or the context) in and reuse the helper at binding.rs:1250 and transfer.rs:1221, completing the consolidation the PR starts.

#10 [low] Checked and cleared: candidate duplicates that are actually consistent with precedent

Checked for duplication that turned out NOT to be a finding, so other reviewers need not re-derive it:

Prose: PR title/description follow AGENTS.md:67-107 four-part order (why / what / claimed result / evidence) and disclose the macOS compile failure and the missing mergerfs reproduction, per repo-prose SKILL.md:35-37. One wording issue: the description says "Fixes #54" while the change leaves the directory path on unsupported filesystems refused rather than fixed — but that is a scope/claim issue covered by the shared-helper finding (entry 2), so I did not record it separately.