Review of PR #178 — "Keep the default Windows Ctrl-C termination while loading"
Lens: conventions and duplication. Read: the diff ([result 6]), the changed function at the PR head (flare/src/main.rs:560-652) and on main (flare-cli/src/main.rs:178-196, :690-716), heliopause/src/processes_windows.rs in full, flare/src/windows.rs:1-26, the repo's own rules (AGENTS.md:48-66, docs/design-review.md:10-26), and docs/windows.md:135-148.
Key findings
- Blocking: the file this PR edits does not exist on the base branch.
flare/src/main.rswas moved toflare-cli/src/main.rsby fa158284 ("Add a native Windows desktop backed by the shared Flare library", 2026-11-09) after this PR branched at 902c88e. On main the registration is still at the old pre-download position, so the change is inert and the defect it fixes still reproduces. This is the substance of yatesdr's first requested change (2026-11-18). - Should fix: the inline
SetConsoleCtrlHandlerre-implementsheliopause/src/processes_windows.rs, the workspace's existing scoped Windows console-handler mechanism (install-once flag, RAII deregistration, escalation toExitProcess). Its natural home isflare/src/windows.rs, which every otherwindows_sysconsole call in the CLI already routes through. - Nits (3): FFI stays inline in
main.rswith no// SAFETY:comment although every otherunsafeblock inflare/srchas one; Windows and Unix registration now follow opposite contracts (checked/pre-start vs unchecked/post-start) in the same function whiledocs/windows.md:141-142still claims Ctrl-C always drains; the two added comment lines re-argue the design instead of documenting the local fact, and the handler has no second-Ctrl-C escalation, unlike both its predecessors. - Verified clean: no duplicate stop-flag machinery (one
STOPatomic, one writer moved), and the PR's factual premise holds — the only pre-serving reader ofSTOP,distribution::root, is#[cfg(unix)], so nothing on the Windows path observes it during download/loading.
Blocking
B1. The changed file no longer exists on main; the change is inert and the bug still reproduces — flare/src/main.rs (whole PR)
- At the PR head,
flare/src/main.rsexists. Atmainit does not:list_fileswith patternflare/src/main.rsat refmainreturns "No files match" ([result 12]); the binary isflare-cli/src/main.rs([result 11]).flare/src/now holds the library modules (application.rs(not opened),cache_support.rs(not opened), …,windows.rs). The move came in fa158284 (2026-11-09), i.e. after this PR's branch point 902c88e. - On main, the exact block the PR removes is still present at the old position, immediately after the Windows multi-host rejection and before
load_core:flare-cli/src/main.rs:187-192→
([result 5])#[cfg(windows)] unsafe { if windows_sys::Win32::System::Console::SetConsoleCtrlHandler(Some(stop_console), 1) == 0 { return Err(std::io::Error::last_os_error().into()); } } - Windows serving on main runs through
serve_local(flare-cli/src/main.rs:692-734):LoadedSession::newat:698, phase "Start server" at:701,loaded.start()at:702, the#[cfg(unix)]signal install at:705-709, dashboard at:711, the serving loop at:714([result 9]). There is no#[cfg(windows)]counterpart anywhere inserve_local. - Why it matters: the branch main merges cannot compile this hunk (the path is gone), and once rebased the described defect still stands — the handler is registered before package download and model loading, and nothing on the Windows path reads
STOPin that window, so Ctrl-C is swallowed exactly as the PR says. GitHub's textual-merge status is a poor guide here: original-el8 reported a clean merge against 5fd4070d (2026-11-13), but the path was deleted five days earlier, so this is a semantic conflict regardless of textual cleanliness. - Fix: rebase onto main, delete
flare-cli/src/main.rs:187-192, and register immediately beforeloaded.start()(flare-cli/src/main.rs:702) insideserve_local. Note the multi-hostservepath (flare-cli/src/main.rs:592-689, unix handler at:653-657) needs no Windows counterpart on main: Windows rejects multi-host earlier (:178-186) and the cluster transport is unix-gated.
Should fix
S1. Duplicates the existing scoped console-handler mechanism in heliopause — PR head flare/src/main.rs:576-581 (main: flare-cli/src/main.rs:187-192)
heliopause/src/processes_windows.rs is already the repository's Windows console-control-handler abstraction, and it is the closest precedent by a wide margin ([result 4]):
:6—//! Scoped console termination for the model preparation CLI.:14—static CLI_SIGNALS: AtomicBoolinstall-once flag.:16-27—unsafe extern "system" fn exit_cli(event: u32)matchingCTRL_C_EVENT | CTRL_BREAK_EVENTand returning 0 otherwise — structurally the same shape asstop_console(flare/src/main.rs:643-652).:29-44—pub struct CliSignals::new() -> io::Result<Self>:SetConsoleCtrlHandler(Some(exit_cli), 1), thenio::Error::last_os_error()on failure, with the flag rolled back.:46-51—impl Dropderegistering withSetConsoleCtrlHandler(Some(exit_cli), 0)and clearing the flag.
The PR hand-rolls the same mechanism inline: windows_sys::Win32::System::Console::SetConsoleCtrlHandler(Some(stop_console), 1) plus last_os_error() mapping at the call site (PR head flare/src/main.rs:576-581; on main flare-cli/src/main.rs:187-192 [results 5, 6]), with no scoped owner, no install-once guard, no deregistration.
Why it matters:
- It leaves two divergent, unrelated Ctrl-C policies in one workspace: heliopause force-exits via
ExitProcess(130)(:26), flare setsSTOP. Nothing in the tree relates or documents the difference. - The PR's own justification is a lifetime/ordering property ("A registration failure must return before replay starts",
:575; and on the pre-replay drain, see the// SAFETY:atflare/src/main.rs:246asserting the package owner stays live until every rank drains). The install-once/Dropshape is precisely how this repository makes a handler's lifetime explicit; the inline form encodes the property in statement position only. - The handler is never removed, so after
servereturns a registered handler keeps storing into astatic— harmless for the one-shotflarebinary, but that is exactly why the heliopause version is scoped.
Project rules: AGENTS.md:52-57 — "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement. Unsolicited formatting, renaming, comment expansion, annotation sweeps, and file rearrangements are not contributions by themselves. Refactoring must directly support the requested behavior…" ([result 8]). A second Ctrl-C mechanism is a second extension point for behaviour the workspace already has a mechanism for. (docs/design-review.md:15-20 is about keeping native Helios specialization small rather than about cross-crate duplication, so it is a weak cite here — AGENTS.md is the governing rule.)
Fix: add e.g. pub fn install_ctrl_handler() -> io::Result<()> (or a CtrlHandler guard mirroring CliSignals) to flare/src/windows.rs, whose doc comment at :6 is literally "Native Windows console and per-user trust-store operations" ([result 13]), and call it at the ordering point the PR wants. If cross-crate code sharing is deliberately unwanted, state that in the PR rather than duplicating silently.
Nits
N1. Native console FFI stays inline in main.rs, and the new unsafe block has no // SAFETY: comment — PR head flare/src/main.rs:574-581
The repository convention is that CLI-facing windows_sys console/OS calls live in the platform module, never in main.rs:
flare/src/windows.rs:6(doc) and:17-23(use windows_sys::Win32::{… System::{… Console::*, …}}), withterminal_columns()at:160-166.- Callers route through
crate::windows::…:flare/src/download_cache.rs:1033 (not opened),1055;flare/src/hub.rs:1253(not opened);flare/src/trust.rs:163 (not opened),235,250,257,274,649;flare/src/environment.rs:56(pub use crate::windows::home_directory); on mainflare-cli/src/cache_commands.rs:139(not opened),flare-cli/src/trust.rs:268(not opened). main.rsis the only place wherewindows_sysis called inline, and only at the two spots this PR touches (this block and the handler's localuseatflare/src/main.rs:645).
Second half: every other unsafe block in flare/src carries a // SAFETY: line — environment.rs:15,29,47; hardware.rs:39 (not opened),53; hub.rs:647 (not opened),664; inspect.rs:129 (not opened); main.rs:246,504,549; orbit/agent.rs:251 (not opened),1609; orbit/banner.rs:149 (not opened); orbit/controller.rs:70; orbit/gpu.rs:66 (not opened),70,90,276; cluster.rs:81 (not opened); trust.rs:653 (not opened). The new block's two comment lines explain why the ordering is right, not why the call is sound ([result 6]).
Fix: move the call into flare/src/windows.rs (folds into S1) and add // SAFETY: noting the handler only stores to an atomic and is handler-safe — the same justification already used for the sibling pattern at flare/src/orbit/controller.rs:66-74 ("the handler only stores to an atomic, which is async-signal-safe", [result 15]).
N2. Windows and Unix registration now follow opposite contracts in one function, and the Windows doc still claims Ctrl-C always drains — PR head flare/src/main.rs:572-581 vs :605-609; docs/windows.md:141-142
Unix in the same function (unchanged): installed after Server::start succeeds and after the phase closes (:601-604), unconditionally, return value ignored (:605-609). Windows (new): installed before Server::start, while the "Start server" phase is still open (:572), checked, returning Err on failure (:576-581) ([result 10]).
Two consequences worth a reviewer's attention in this lens:
- The PR description says download/loading keep "the default console termination, as on Unix before its handlers are installed" — but the Unix analogue it cites is installed after
Server::startreturns, so the Windows position is strictly earlier than the precedent it invokes. The placement is defensible on the failure path, but the two halves of the same concept now read differently with no note tying them together. - The
Errpath at:579dropstransport/owner(and on mainLoadedSession) with no drain confirmation, while the file's// SAFETY:at:246asserts owners stay live until every rank drains. The comment should say which guarantee holds on that path, or the failure should be handled explicitly (as theServer::starterror arm at:593-599does withstd::mem::forgetwhen!error.drained). docs/windows.md:141-142(main) still reads "Ctrl-C and Ctrl-Break drain native work before releasing CUDA resources" ([result 7]) — no longer true for the loading window under this PR. This is also yatesdr's requested change 3 (2026-11-18).
Exit-code note for completeness: a Ctrl-C during Server::start sets STOP, so the unexpected-stop check at :632 passes and the process exits 0, matching Unix's normal exit; a Ctrl-C before Server::start now dies by the default console action with STATUS_CONTROL_C_EXIT, unlike a Unix signal death. That asymmetry is inherent to the design, but it belongs in the doc.
Fix: align the comment with the chosen contract, say what holds on the Err path, and update docs/windows.md:141-142 to state that Ctrl-C before the server starts ends the process.
N3. The added comment re-argues the design rather than documenting the local fact; the handler has no second-Ctrl-C escalation — PR head flare/src/main.rs:574-575
Style: the two added lines —
// Loading keeps the default Ctrl-C termination because nothing observes STOP before serving.
// A registration failure must return before replay starts.
— restate the PR description inside the code, and they sit above let context_tokens (:573) rather than on the unsafe block they describe (:576-581), unlike every sibling // SAFETY: comment in this file (:246, :504, :549), which sit directly on their blocks. AGENTS.md:52-57 explicitly pushes back on "comment expansion", and AGENTS.md:61-63 puts the problem/behaviour rationale in the PR description and commit message ("Keep each PR focused … and describe its problem, resulting behavior, validation, and material limitations"). Operational notes in this file are one line (e.g. "// Allow the terminal multiplexer to finish restoring the main screen.", :616; "// The proxy stops before the package releases the region it posts from.", :636). Recommend collapsing to one // SAFETY:/note line.
Substance (verified, and the one claim a later maintainer would rely on): "nothing observes STOP before serving" is true of STOP, but it is not the whole story of what the handler does. stop_console returns 1 for CTRL_C_EVENT|CTRL_BREAK_EVENT (flare/src/main.rs:646-648), and a nonzero return means "handled", so the default termination is suppressed for the rest of the process lifetime after registration, not only while the loop is spinning. The correctness argument is therefore "the window between registration and the loop is short", not "STOP is always observed". The window is not short in one place: server.close() at :619 runs after the loop exits, so a second Ctrl-C during a stuck drain returns 1, re-sets an already-set flag, and cannot escalate. Both predecessors can escalate — the current behaviour (default termination, so a second Ctrl-C kills the process) and heliopause's shipped handler (heliopause/src/processes_windows.rs:25-26, ExitProcess(130)). The repository deliberately escalates on the second Ctrl-C where it owns the protocol: flare/src/orbit/controller.rs:1569-1591 counts interrupts and prints "Ctrl-C again stops every rank now" / "…leaves without waiting", returning after the third ([result 16]). Meanwhile docs/windows.md:141-142 tells Windows users Ctrl-C is the supported way to stop.
Fix: reduce the comment to one line stating the local fact plus the // SAFETY: justification, and consider allowing a second Ctrl-C to force-exit past a stuck drain (or state in the doc that it cannot).
Verified clean (no finding)
- No duplicate stop-flag machinery.
STOPis the file's single stop signal: writerstop(unix), writerstop_console(windows,flare/src/main.rs:643-652), readers at the serving loop (:614), the unexpected-stop check (:632),distribution.rs:192-194, andlaunch.rs:176. The PR only moves one existing writer and adds no second flag or loop.Ordering::Relaxedmatches the existing writer/reader pair. - The PR's factual premise holds.
STOPbefore the serving loop is read only bydistribution::root, and that module is#[cfg(unix)](flare/src/main.rs:17); Windows setsmembership = None, so nothing on the Windows path observesSTOPduring download/loading. Pre-PR registration therefore did swallow Ctrl-C with no observer, as claimed. - Nothing in Helios to duplicate. No
SetConsoleCtrlHandlerinhelios/src; the dashboard keepsENABLE_PROCESSED_INPUTso Ctrl-C follows normal shutdown, and the PR correctly registers before the dashboard starts (:576-581before:611). - No test convention broken by omission. Existing Windows coverage is
flare-cli/tests/cli.rs:56-75(windows_rejects_multi_host_options_before_loading), which asserts multi-host rejection ordering, not Ctrl-C; there is noGenerateConsoleCtrlEventprecedent anywhere in the tree, so the absence of a console-ctrl test matches repo practice. The unrun check is declared in the PR description, satisfyingAGENTS.md:58-63.
Open questions / what could not be settled from the code
- Is the Windows branch compiled? No Windows toolchain or GPU was available per the PR description, and CI on head
85fb08creports no checks. The#[cfg(windows)]arm is therefore uncompiled — yatesdr's requested change 2 asks forcargo check --manifest-path flare-cli/Cargo.toml (not opened) --target x86_64-pc-windows-msvcplus a liveflare run CORECtrl-C session. Only a build/run settles this; nothing in the source can. - Should the two Ctrl-C policies be unified? Whether
flareshould reuse heliopause'sCliSignalscontract (deregistration,ExitProcessescalation) or intentionally keep itsSTOP-based, drain-first contract is a maintainer decision; the code cannot answer it. My finding is that the duplication is unreported and unrationalized either way. - Process not re-litigated: DCO/Signed-off-by and the design acknowledgment (yatesdr item 4 —
CONTRIBUTING.mdrequiresSigned-off-by, absent on 85fb08c7) is process, not code conventions.