Conventions report · NVIDIA/hyperflare-inference #178

Raw Markdown for agents: https://autobot.eidonix.com/p/58fc1bc7-a60f-4414-8523-36e75c9a4fe2.md

Review of PR #178 — "Keep the default Windows Ctrl-C termination while loading"

Lens: conventions and duplication. Head reviewed: 43c6ea78, 2 files, +9/−8 (flare-cli/src/main.rs +7/−6, docs/windows.md +2/−2). Base main; labels area:api, bug, priority:P2, triage:review; yatesdr requested changes 2026-11-18.

Key findings

Nits

Nit 1 — the new registration stays inline in main.rs rather than in flare/src/windows.rs

flare-cli/src/main.rs:704-710. The CLI's native Windows console operations live in flare/src/windows.rs, whose doc comment is "Native Windows console and per-user trust-store operations" (flare/src/windows.rs:6); it already imports System::{… Console::*, …} (:21) and hosts named, io::Result-returning functions (terminal_columns() at :160-166, trust_path() :34, file_identity() :169). CLI modules reach it as crate::windows::… through use flare::windows; at flare-cli/src/main.rs:36-37 (cf. cache_commands.rs:139 (not opened), trust.rs:268 (not opened)). The new block keeps the raw windows_sys::Win32::System::Console::SetConsoleCtrlHandler call at the call site, unlike every other console operation in the CLI. Why it matters: the "where does Windows syscall code live" rule is broken by the one construct this PR introduces, so the next console call has two precedents to copy from. Fix: a pub fn install_ctrl_handler() -> io::Result<()> (wrapping SetConsoleCtrlHandler(Some(stop_console), 1)) in flare/src/windows.rs, called from serve_local. No manifest change: Win32_System_Console is already enabled for both crates (flare-cli/Cargo.toml:49, flare/Cargo.toml:59) and windows.rs already imports Console::*. Honesty note: the departure predates the PR — the same inline call sat at main.rs:187-192 on main — and AGENTS.md:188-193 rejects churn-only refactors, so this is worth doing only because the line is already moving.

Nit 2 — a second, unscoped Windows console-handler policy; no second-Ctrl-C escalation

flare-cli/src/main.rs:704-710 (plus the existing handler at :737-746). The repository already has a Windows console-control-handler abstraction this block re-implements by hand: heliopause/src/processes_windows.rs — handler exit_cli with the same event filter (:16-19), install-once guard and last_os_error() on failure in CliSignals::new() (:32-43), and RAII deregistration in Drop (:46-51). The PR's block reproduces only the middle third: no install-once, no scope, no removal. Nothing relates the two policies. It is not reused because it cannot be: heliopause is a cdylib (heliopause/Cargo.toml:9-11) and no crate depends on it, and its policy (ExitProcess(130) at :26) is the opposite of this PR's drain-first intent. So the correct action is not "reuse it" — it is to note that two policies now coexist, and that a third copy would be the point to extract a shared handler. Substantive consequence (verified): after registration stop_console returns 1 for Ctrl-C/Ctrl-Break for the rest of the process, so default termination stays suppressed during session.close() and shutdown (:718-731) too. A second Ctrl-C only re-stores an already-set atomic and cannot escalate past a stuck drain; both heliopause (ExitProcess(130)) and the pre-PR flare behaviour could be forced to exit. The tree does escalate on repeat Ctrl-C where it owns the protocol: flare-cli/src/orbit/controller.rs:70 (catch_interrupts, with a SAFETY: note: "the handler only stores to an atomic") and the printed escalation at :1579/:1585 ("Ctrl-C again stops every rank now" / "…leaves without waiting"). Cheap fix if wanted: if STOP.swap(true, Ordering::Relaxed) { return 0 } inside the match, so a second event chains to the default handler and terminates. Otherwise leave as-is and accept one event per process.

Nit 3 — the new unsafe block has no // SAFETY: line

flare-cli/src/main.rs:705-710. Every other unsafe block in main.rs is prefaced by a SAFETY: justification: :287 ("The trusted core owners remain live until every rank drains."), :551 ("The core owner and the transport stay live until rank zero confirms drain…"), :599 ("This executable loads a trusted core and retains its resources until the native server confirms every replay stream has drained."). The marker is used elsewhere too (orbit/controller.rs:70, flare-cli/src/environment.rs:10, flare/src/windows.rs:176). The new block carries only an ordering note (":706"), which explains when the handler is installed, not why calling stop_console as a console control handler is sound. Fix: add // SAFETY: stop_console only stores to a process-wide atomic, so it is safe as a console control handler; above the call and keep the ordering note (it is the one non-obvious local fact and reads as a one-line note, not the design restatement that the previous head carried — consistent with AGENTS.md:188-193 on comment expansion).

Checked and clean in this lens

  1. Single registration site, no leftovers: the old run()-level block is deleted (:187 now falls straight from the multi-host rejection at :178-186 to let bind), and --stage-only's early return (:269-275) is covered by there being no handler at all during loading.
  2. No duplicated stop machinery: STOP (:51) keeps one writer per platform (stop :53-55, stop_console :737-746) and unchanged readers (:656, :674, :715, :729) with the same Ordering::Relaxed. The PR adds no flag, loop or state machine.
  3. The new Windows block mirrors its Unix sibling in the same function (unix :699-703, windows :704-710, both after loaded.start() at :696), and the == 0 → Err check matches the old code and heliopause/src/processes_windows.rs:38-41. Failing after loaded.start() is safe because LoadedSession::start wraps the owner in DrainGuard and ServingSession::drop calls close() (helios/src/server/session.rs:57, :104-108, :125-133).
  4. Docs: docs/windows.md:141-142 states the new contract in the one place the Windows contract is stated; the general statements elsewhere (AGENTS.md:279, docs/model-preparation.md:472) describe a serving Flare and stay true.
  5. No test precedent broken: the only Windows console test is flare-cli/tests/cli.rs:56-75 (windows_rejects_multi_host_options_before_loading), about rejection ordering; there is no GenerateConsoleCtrlEvent anywhere in the tree.
  6. No reusable handler helper in flare/helios: helios/src/server/dashboard.rs:1049-1083 InputMode guards console mode (SetConsoleMode) and deliberately keeps ENABLE_PROCESSED_INPUT (:1068) so Ctrl-C arrives as a control event — which requires the handler this PR installs.

Open questions / not settled

Retired from an earlier run

An earlier head (85fb08c7) edited flare/src/main.rs (not opened), a path removed on main in fa158284; that blocking "file no longer exists" finding is retired — the PR now edits flare-cli/src/main.rs, main's live path. Likewise the earlier "should fix: duplicates heliopause's handler" is downgraded to Nit 2 above, because CliSignals is a cdylib with the opposite exit policy and cannot be reused here.