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
- Nothing blocking and nothing should-fix. The change is small, lands in exactly one place, and does not duplicate the stop machinery. Three nits are recorded below, all style/convention departures rather than defects.
- The port target is correct: the registration was removed from
run()(diff atflare-cli/src/main.rs:184-192) and added once inserve_local(flare-cli/src/main.rs:704-710), immediately afterloaded.start()(:696) and beside the Unix sibling (:699-703). Windows can only reachServer::startviaserve_local(run()rejects multi-host on Windows at:178-186;serve()delegates at:596-598), so the single-site requirement is met andserve()'s Unix install (:647-651) is never on the Windows path. - The premise holds in the code:
STOP(:51) is read before serving only by Unix-only code paths, so pre-PR Windows Ctrl-C during loading was swallowed. - The docs change is correct and additive, not duplicative:
docs/windows.md:141-142is the same paragraph at the same length.
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
- Single registration site, no leftovers: the old
run()-level block is deleted (:187now falls straight from the multi-host rejection at:178-186tolet bind), and--stage-only's early return (:269-275) is covered by there being no handler at all during loading. - 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 sameOrdering::Relaxed. The PR adds no flag, loop or state machine. - The new Windows block mirrors its Unix sibling in the same function (unix
:699-703, windows:704-710, both afterloaded.start()at:696), and the== 0 → Errcheck matches the old code andheliopause/src/processes_windows.rs:38-41. Failing afterloaded.start()is safe becauseLoadedSession::startwraps the owner inDrainGuardandServingSession::dropcallsclose()(helios/src/server/session.rs:57,:104-108,:125-133). - Docs:
docs/windows.md:141-142states 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. - 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 noGenerateConsoleCtrlEventanywhere in the tree. - No reusable handler helper in flare/helios:
helios/src/server/dashboard.rs:1049-1083InputModeguards console mode (SetConsoleMode) and deliberately keepsENABLE_PROCESSED_INPUT(:1068) so Ctrl-C arrives as a control event — which requires the handler this PR installs.
Open questions / not settled
- Whether the Windows build compiles and live Ctrl-C behaves as described. There are no CI checks on 43c6ea78 and no Windows toolchain here;
.github/workflows/native-serving.yml:45(not opened)/:73builds and tests flare-cli on windows-2022 for every pull request, so a CI run settles compilation, and only a liveflare run COREsession settles the behaviour. This is a validation gap, not a conventions finding; it corresponds to yatesdr's request item 2, which the author acknowledged as unrun in the 2026-11-28 comment (AGENTS.md:194-199 requires exactly such an acknowledgment, which is present).
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.