From 7cd26aff56a5960179d75d12592e5bb051dc9a58 Mon Sep 17 00:00:00 2001 From: Noah <2+noah@noreply.gitea.bluefla.re> Date: Fri, 13 Nov 2026 11:22:00 -0600 Subject: [PATCH] fix(gui): address code-review findings on the install/scan changes - #1 Update must not rewrite the bootloader: start_install refuses a tier-3 (bootloader-writing) .afw when the dialog is an in-place Update, enforcing the "BOOT.bin is never written" guarantee. - #2 post-install verify could stick forever when auto-scan is off: tick() now re-probes awaiting boards on a fixed 10 s cadence until they answer as alkane or the give-up window expires. - #3 board-health no longer greys a genuinely-mining miner whose backend omits per-board active/working_chips: (None,None) reads green when the miner is hashing, grey only when idle (the bare S17 case). - #5 install docs/comments no longer describe the removed typed-FLASH step. - #6 the flash-plan checklist verifies against the install target board, so a file for another board surfaces as an error instead of a misleading plan. - #7 install board is taken from the selected row's board_family, not a fixed default (correct once more boards are supported). - #4 (verify on the UI thread) accepted: .afw bundles are ~7 MB, so the manifest read is a sub-100 ms hash, not a user-visible freeze. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i --- crates/alkane-gui/src/scan.rs | 35 ++++++++++++----- crates/alkane-gui/src/stock_ops.rs | 17 +++++++++ crates/alkane-gui/src/ui.rs | 61 ++++++++++++++++++++++++++---- docs/install.md | 10 ++--- 4 files changed, 101 insertions(+), 22 deletions(-) diff --git a/crates/alkane-gui/src/scan.rs b/crates/alkane-gui/src/scan.rs index 994ea2f5..fb690534 100644 --- a/crates/alkane-gui/src/scan.rs +++ b/crates/alkane-gui/src/scan.rs @@ -680,14 +680,28 @@ fn messages_to_faults( /// reads grey ("not detected") rather than green (issue #39: an S17 control board /// with no hashboards attached showed its boards green). A board that is present /// but idle or has zero working chips reads as a fault (red). -fn board_health(active: Option, working_chips: Option) -> crate::model::BoardHealth { +fn board_health( + active: Option, + working_chips: Option, + miner_active: bool, +) -> crate::model::BoardHealth { use crate::model::BoardHealth; match (active, working_chips) { (Some(true), _) => BoardHealth::Ok, (Some(false), _) => BoardHealth::Fault, (None, Some(c)) if c > 0 => BoardHealth::Ok, (None, Some(_)) => BoardHealth::Fault, - (None, None) => BoardHealth::Missing, + // No per-board evidence. If the miner shows overall activity (hashing), + // the board is clearly present and working -> green; only an idle miner + // with no board telemetry reads grey (issue #39: bare S17; review #3: do + // not grey a genuinely-mining miner whose backend omits per-board fields). + (None, None) => { + if miner_active { + BoardHealth::Ok + } else { + BoardHealth::Missing + } + } } } @@ -700,13 +714,16 @@ mod board_health_tests { fn no_activity_evidence_reads_grey_not_green() { // Issue #39: the firmware lists a board but reports no active flag and no // working-chip count -> not detected (grey), not green. - assert_eq!(board_health(None, None), BoardHealth::Missing); - // Positive evidence still greens. - assert_eq!(board_health(Some(true), None), BoardHealth::Ok); - assert_eq!(board_health(None, Some(63)), BoardHealth::Ok); + // Idle miner, no per-board evidence -> not detected (grey). + assert_eq!(board_health(None, None, false), BoardHealth::Missing); + // Mining miner, no per-board evidence -> still green (review #3). + assert_eq!(board_health(None, None, true), BoardHealth::Ok); + // Positive evidence still greens regardless of miner activity. + assert_eq!(board_health(Some(true), None, false), BoardHealth::Ok); + assert_eq!(board_health(None, Some(63), false), BoardHealth::Ok); // Present but idle / zero working chips -> fault (red). - assert_eq!(board_health(Some(false), Some(63)), BoardHealth::Fault); - assert_eq!(board_health(None, Some(0)), BoardHealth::Fault); + assert_eq!(board_health(Some(false), Some(63), false), BoardHealth::Fault); + assert_eq!(board_health(None, Some(0), false), BoardHealth::Fault); } } @@ -1225,7 +1242,7 @@ async fn to_row(miner: &dyn Miner) -> MinerRow { let mut board_status: Vec = data .hashboards .iter() - .map(|b| board_health(b.active, b.working_chips)) + .map(|b| board_health(b.active, b.working_chips, is_mining || hashrate_ths > 0.0)) .collect(); if let Some(exp) = data.expected_hashboards { while board_status.len() < exp as usize { diff --git a/crates/alkane-gui/src/stock_ops.rs b/crates/alkane-gui/src/stock_ops.rs index 9d6c4680..04a338e9 100644 --- a/crates/alkane-gui/src/stock_ops.rs +++ b/crates/alkane-gui/src/stock_ops.rs @@ -98,6 +98,7 @@ pub fn start_install( source: AfwSource, allow_unsigned: bool, password: Option, + is_update: bool, ) -> StockHandle { let (tx, rx) = channel(); let cancel = Arc::new(AtomicBool::new(false)); @@ -207,6 +208,22 @@ pub fn start_install( let _ = tx.send(StockMsg::Done); return; } + // An in-place Update must never rewrite the bootloader (review #1): + // refuse a tier-3 (bootloader-writing) bundle so the "BOOT.bin is + // never written" guarantee holds for an already-alkane board. + if is_update && verified.manifest.flash_plan().writes_uboot { + for ip in &ips { + let _ = tx.send(StockMsg::Result { + ip: ip.clone(), + ok: false, + detail: "update refused: this release reflashes the bootloader (tier 3); \ + pick a tier-1/2 release or use Install" + .to_string(), + }); + } + let _ = tx.send(StockMsg::Done); + return; + } // 3. Install onto each board via the network-only from-stock method. for ip in ips { diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index ab6b12b4..d9d46561 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -543,11 +543,14 @@ fn ascii_bar(pct: u8) -> String { /// it overwrites (U-Boot / Kernel / Userspace), from the bundle's own manifest. /// Shown in the install dialog when a file is picked so the operator sees exactly /// what the flash touches before starting. -fn afw_plan_text(path: &str) -> String { +fn afw_plan_text(path: &str, expect_board: &str) -> String { use alkane_artifacts::afw::{verify_afw, VerifyOptions}; + // Verify against the install target's board (review #6): a file for another + // board then surfaces as an error here instead of showing a plausible plan + // that start_install would later reject. let opts = VerifyOptions { allow_unsigned: true, - expect_board: None, + expect_board: Some(expect_board.to_string()), }; match verify_afw(std::path::Path::new(path), &opts) { Ok(v) => { @@ -910,6 +913,9 @@ pub struct App { // IPs of the install currently in flight, so a successful install can arm a // post-install alkane verification for exactly those boards. install_targets: HashSet, + // Ticks (1 s each) until the next post-install alkane re-probe, so boards are + // verified on a fixed cadence even when auto-scan is off (review #2). + verify_cooldown: u16, // After a successful install a board reboots into alkane; the next scan can // still catch it mid-reboot answering as stock. Each awaited IP maps to the // number of scan rounds left to confirm alkane before giving up; while an IP @@ -984,6 +990,11 @@ pub struct App { install_releases: Vec, install_ips: Vec, install_board: String, + // True when the open install dialog is an in-place Update (an already-alkane + // board) rather than a from-stock install: the worker then refuses a + // bootloader-writing (tier-3) bundle so "BOOT.bin is never written" holds + // (review #1). + install_is_update: bool, // A local .afw picked with the Browse button, used in place of a Gitea // release when set; the read-only label beside the button shows it. install_local_path: Option, @@ -1358,6 +1369,7 @@ pub fn build(frame: Widget) -> App { pending_password_update: None, op_status: std::collections::HashMap::new(), install_targets: HashSet::new(), + verify_cooldown: 0, installed_awaiting: HashMap::new(), confirm_dialog: frame, pending_confirm: None, @@ -1395,6 +1407,7 @@ pub fn build(frame: Widget) -> App { install_releases: Vec::new(), install_ips: Vec::new(), install_board: stock_ops::DEFAULT_BOARD.to_string(), + install_is_update: false, install_local_path: None, install_local_label: frame, install_plan_label: frame, @@ -2003,7 +2016,7 @@ impl App { // place); // - Uninstall: a board running Alkane OS (restored to stock). // A mixed stock/Alkane selection gets neither Install nor Update. The - // engine still gates on compatibility and a typed FLASH confirmation. + // engine still gates on compatibility. let supported = selected.iter().all(|r| alkane_detect::install_supported(r)); let all_alkane = selected.iter().all(|r| alkane_detect::is_alkane(r)); let none_alkane = selected.iter().all(|r| !alkane_detect::is_alkane(r)); @@ -2728,8 +2741,8 @@ impl App { /// Build the "Install alkane OS" dialog (or, with `update`, the "Update /// alkane OS" dialog for boards already running it): a scanned list of /// alkane-os releases to pick from, an optional board credential, the - /// allow-unsigned (bench) toggle, and a typed FLASH confirmation. The install - /// runs over the network via the toolkit's own compiled-in from-stock engine. + /// allow-unsigned (bench) toggle. The install runs over the network via the + /// toolkit's own compiled-in from-stock engine. /// Scan `owner/repo`'s releases and fill the install picker with the ones /// that carry an .afw compatible with the target board (newest first). Called /// when the dialog opens and from the Reload button. Requires @@ -2801,7 +2814,17 @@ impl App { wx_rs::set_status_text("select a board to install onto"); return None; } - let board = self.install_board.clone(); + // Target board family comes from the selected board(s), not a fixed + // default (review #7). Install/Update is only offered when every selected + // board is install-supported, so their board_family is consistent; fall + // back to the default only if none resolves. + let board = self + .selected_rows() + .into_iter() + .find_map(crate::alkane_detect::board_family) + .unwrap_or_else(|| stock_ops::DEFAULT_BOARD.to_string()); + self.install_board = board.clone(); + self.install_is_update = update; // Releases are scanned after the picker widget exists, from the repo in // the repo field (default blueflare/alkane-os); see @@ -3062,11 +3085,12 @@ impl App { source, allow_unsigned, password, + self.install_is_update, )); } /// Build the "Uninstall alkane OS (restore to stock)" dialog: the board's - /// alkane root credential and a typed FLASH confirmation. + /// alkane root credential and a genuine Bitmain firmware file. fn build_uninstall_dialog(&mut self) -> Option { if self.hardware_busy() { wx_rs::set_status_text("busy -- try again once the current operation finishes"); @@ -4618,6 +4642,25 @@ impl App { if self.showing_log { self.refresh_log_view(); } + // Keep verifying just-installed boards on a fixed cadence even when + // auto-scan is off (review #2): without this, a board could sit on + // "verifying alkane..." forever. Re-probes only when nothing else is in + // flight; each probe's Done decrements the give-up counter. + if self.installed_awaiting.is_empty() { + self.verify_cooldown = 0; + } else if self.scan.is_none() && self.refresh.is_none() && self.stock_op.is_none() { + if self.verify_cooldown == 0 { + let ips: Vec = self.installed_awaiting.keys().cloned().collect(); + self.start_refresh(ips.clone()); + for ip in ips { + self.op_status + .insert(ip, "installed; verifying alkane...".into()); + } + self.verify_cooldown = 10; + } else { + self.verify_cooldown -= 1; + } + } self.drain_action(); self.drain_refresh(); self.drain_access_probe(); @@ -6164,7 +6207,9 @@ impl App { .unwrap_or_else(|| path.clone()); self.install_local_label .set_label(&format!("Using local file: {name}")); - self.install_plan_label.set_label(&afw_plan_text(&path)); + let board = self.install_board.clone(); + self.install_plan_label + .set_label(&afw_plan_text(&path, &board)); self.install_local_path = Some(path); self.install_dialog.layout(); } else { diff --git a/docs/install.md b/docs/install.md index 3d001939..309957b6 100644 --- a/docs/install.md +++ b/docs/install.md @@ -142,15 +142,15 @@ selected board: for; today the Zynq-7010 Antminer S17/S17 Pro/T17) that is not running Alkane OS yet. Scans the alkane-os releases on Gitea, lets you pick one (newest first; pre-releases are marked), optionally takes a board password and an "allow - unsigned .afw (bench)" toggle, and - after you type FLASH to confirm - - downloads/verifies the `.afw` and installs it onto each selected board over the - network, via the same compiled-in engine the CLI uses. + unsigned .afw (bench)" toggle, then - when you click Install - downloads and + verifies the `.afw` and installs it onto each selected board over the network, + via the same compiled-in engine the CLI uses. - "Update alkane OS..." - for a supported board already running Alkane OS: the same release picker and confirmation; the board is updated in place (BOOT.bin is never written). - "Uninstall alkane OS (restore to stock)..." - for a board running Alkane OS: - takes the board's alkane root password, a genuine Bitmain firmware package and - a typed FLASH confirmation, then restores each selected board to genuine stock + takes the board's alkane root password and a genuine Bitmain firmware package, + then - when you click Restore - restores each selected board to genuine stock over the network. A stock board the scan identifies but cannot place on a supported control board