Correctness and contracts report · NVIDIA/hyperflare-inference #178

Raw Markdown for agents: https://autobot.eidonix.com/p/f394a79b-96ae-47c4-9ad5-2c394fe919d3.md

Correctness, Contracts & System-Level Consequences — PR #178 (20d2c655)

Key findings


1. Correctness, Safety & Platform Parity

Verified correct (no finding)

Complete removal, single registration site. flare-cli/src/main.rs:178-187:

   178      #[cfg(windows)]
   179      if args.rank.is_some()
...
   185          return Err("multi-host serving is not supported on Windows".into());
   186      }
   187      let bind = args.bind_address();

The early SetConsoleCtrlHandler(Some(stop_console), 1) that used to sit between :186 and :187 is gone. search_code stop_console returns only flare-cli/src/main.rs:707 (registration) and :738 (definition); the only other console-handler code in the tree is heliopause/src/processes_windows.rs (Ignition's own scoped handler), and flare-cli has no heliopause dependency, so no competing policy is reachable.

Diagnosis is right. stop_console at flare-cli/src/main.rs:738-746 still returns 1 for Ctrl-C/Ctrl-Break; on Windows the only STOP readers are the serving loop (:715, :729) and the handler itself (:741), because distribution/launch are #[cfg(unix)] (main.rs:17-31). Before this change, STOP had no reader at all before serve_local's loop, which is exactly the swallowed-Ctrl-C symptom.

The registration-failure path really drains. flare-cli/src/main.rs:704-710:

   704      #[cfg(windows)]
   705      unsafe {
   706          // Loading keeps the default Ctrl-C termination; nothing reads STOP before serving.
   707          if windows_sys::Win32::System::Console::SetConsoleCtrlHandler(Some(stop_console), 1) == 0 {
   708              return Err(std::io::Error::last_os_error().into());
   709          }
   710      }

session (:696) is a ServingSession, and helios/src/server/session.rs:104-108 is fn drop(&mut self) { self.close(); }; close() (:96-101) joins HTTP/model workers and sets owner.drained = shutdown.drained; DrainGuard::drop (:125-133) mem::forgets an undrained owner rather than freeing referenced storage. So the PR body's "Returning an error if SetConsoleCtrlHandler fails after loaded.start() remains safe" is verified in code.

Reachability is as claimed. serve() (flare-cli/src/main.rs:586-683) keeps its Unix-only registration and is unreachable on Windows: run() rejects every multi-host flag at :178-186, and serve() dispatches local runs to serve_local at :596-597.

Unix untouched. The only #[cfg(unix)] lines in the diff region (:699-703) are unchanged, and the diff adds nothing outside #[cfg(windows)].

F1 — Minor — the new comment misplaces the abrupt-termination boundary

flare-cli/src/main.rs:695-710:

   695      let phase = progress.phase("Start server", None);
   696      let session = loaded.start().map_err(|failure| failure.message)?;
...
   704      #[cfg(windows)]
   705      unsafe {
   706          // Loading keeps the default Ctrl-C termination; nothing reads STOP before serving.

The comment's stated reason ("nothing reads STOP before serving") is true but incomplete in the direction that matters: the handler is deliberately not installed during loaded.start(), which is the phase the user sees labelled "Start server" (:695), and which blocks at helios/src/server.rs:417 (match ready_rx.recv()) while startup tuning graphs run under a 120 s deadline. Ctrl-C there now hard-terminates mid-GPU-init with no drain and no output — the same class as main, and defensible, but undocumented and unexplained by the comment. docs/windows.md:141-142 says only "Ctrl-C and Ctrl-Break end loading immediately…", which does not mention the "Start server" window.

Impact: a user who presses Ctrl-C on the spinner literally labelled "Start server" gets a silent kill; the reviewer's regression target (§C ask 2) is exactly this window, so the boundary must be legible. Fix: reword :706 to say "loaded.start() must keep the default termination: it captures graphs and no STOP reader exists until the serve loop" and, optionally, extend docs/windows.md:141 to name server startup as abrupt too.

F2 — Minor — a second Ctrl-C cannot end the drain

flare-cli/src/main.rs:738-746:

   738  unsafe extern "system" fn stop_console(event: u32) -> i32 {
   739      use windows_sys::Win32::System::Console::{CTRL_BREAK_EVENT, CTRL_C_EVENT};
   740      if matches!(event, CTRL_C_EVENT | CTRL_BREAK_EVENT) {
   741          STOP.store(true, Ordering::Relaxed);
   742          1
743      } else {
744          0
745      }

After the first Ctrl-C, serve_local runs session.close() (:719), which joins the HTTP thread (5 s grace) and then the model worker. Every later Ctrl-C is reported "handled" (1) and does nothing, so a slow or stuck drain can only be escaped by force-kill or closing the console (CTRL_CLOSE_EVENT falls to the else and returns 0, which is an unusual way to quit).

Impact: the shutdown the PR exists to make observable can itself become uninterruptible. Fix (2 lines, no Windows run needed): if STOP.swap(true, Ordering::Relaxed) { return 0; } before returning 1, so the second Ctrl-C falls through to the default handler and terminates. Note the before-start site autobot previously floated would have needed the same fallback; here it is a separate, still-open gap.

Verified sound: abrupt exit during download/verify is crash-safe

Removing the early handler makes a hard kill reachable during download and loading, which is new. Checked: core leases are kernel-released file locks (helios/src/core/cache.rs:7,21), artifact writes are ok/WouldBlock-guarded (cache.rs:3142-3187), and publish precedes return (hub.rs:91). No lease or lock can be stranded, so no cleanup handler is needed at the new abrupt-exit points.


2. Unintended System-Level Consequences (CRITICAL lens)

No finding — the change is inert under concurrency and load. Directly verified:


3. Architecture, Contracts & Charter Compliance

No finding.


4. Tests & Claim Accuracy

PR body: accurate at this head (overrides Discovery Dossier §D)

read_item #178, body updated 2026-11-30 08:57, states under Change: "Removed the early #[cfg(windows)] SetConsoleCtrlHandler(Some(stop_console), 1) registration from run(), and added it in serve_local() immediately after loaded.start()…". This matches the code (:178-187 handler absent; :704-710 present after :696) and is the opposite of the stale dossier text ("Register the handler immediately before Server::start"; "A Ctrl-C during Server::start sets STOP"). The body also carries a truthful Limitations section (no Windows link, no live run) and the Discord: myong_acct line. The two prior bot should-fixes — description mismatch and Windows compile — are now met (the latter by the author-reported cargo xwin check … --target x86_64-pc-windows-msvc exit 0, which does compile the #[cfg(windows)] block for MSVC).

F3 — Minor — the new path is untested and unobservable in CI

The only Windows CLI test is flare-cli/tests/cli.rs:56-75 (windows_rejects_multi_host_options_before_loading), which does not touch console handlers; no test anywhere exercises stop_console or the ordering at :696/:704-710. .github/workflows/native-serving.yml (not opened) builds and tests flare-cli on windows-2022 (:20-21, :43-45, :69-73) on pull_request, but no check is recorded on this PR, and #177 documents that job failing on every main commit (eos dies with 0xc0000135 STATUS_DLL_NOT_FOUND; 8 flare tests fail), so a red check here would be ambiguous.

Impact: the single behavioural claim that motivated the PR (Ctrl-C during download/loading terminates; Ctrl-C after readiness drains) rests on code review alone. Fix: a GPU-free Windows unit test exercising the plain function — stop_console(CTRL_C_EVENT) == 1 and sets STOP, stop_console(CTRL_CLOSE_EVENT) == 0 (and, per F2, a second CTRL_C_EVENT returning 0) — plus the live flare run CORE session across loading and "Start server" that the author still lists as unrun.

Validation evidence (as reported, not independently reproduced)

Linux x86_64 CLI suite on 20d2c655: 227 passed / 0 failed / 3 ignored (author report; the delta vs 221 at 43c6ea78 comes from main, not this PR). This cannot exercise the new lines, which are #[cfg(windows)].


Open questions

  1. Does Ctrl-C actually behave as documented on Windows — immediate exit during download/loading, drained shutdown after "Start server"? Only a live Windows session settles it; neither the cargo xwin check nor any test observes the handler firing.
  2. Will this PR ever carry a CI result, and if red, could it be attributed to this change while #177 says the Windows job is red on every main commit?
  3. Cosmetic, still unanswered since 2026-11-26: no ANSI/cursor restore (\x1b[0m\x1b[?25h) on the now-default-terminated loading exit, unlike heliopause/src/processes_windows.rs. Confirmed still absent, and confirmed unnecessary for the loading rows (no alternate screen; finish_animation is a no-op).
  4. For F2: is a single uninterruptible Ctrl-C intentional, or should the second Ctrl-C escalate to the default handler?

Could not find