From 808fd4de1d4200712f63adcb694d37b7d2bc2d0f Mon Sep 17 00:00:00 2001 From: noah Date: Tue, 22 Sep 2026 20:59:03 -0600 Subject: [PATCH] review wave 7: fifth-round findings (creds, scan race, refill throttle) Fifth (final) review round; this clears its functional findings: - HIGH config actions / pool writes could run concurrently with a live scan (start_action / apply_pools guarded flash + restore but not scanning); added the self.scanning guard, and begin_scan now defers while an action/restore runs, closing the race symmetrically. - HIGH blanking a per-firmware credential row saved a live ("","") override that then broke that firmware's auth fleet-wide; a fully-blank row now clears the override (use the shipped default). - HIGH a ChangePassword action never updated the toolkit's own saved credentials, so after a fleet-wide change it locked itself out; on full success it now updates the saved global password (and on a partial change logs a reconcile note rather than guessing). - HIGH/perf fill_rows re-rated: a scan's streaming rows triggered a whole-table refill on every fast tick. New rows_dirty latch flushes the refill at most once per second during a scan (immediately once it ends). - MED an indeterminate access-probe result no longer blanks a miner's already-known locked/unlocked state. - LOW compute-version.sh header doc corrected to match the broadened rule; release.yml sets WX_RS_WXCONFIG once at job level instead of per step. Accepted (documented) perf items that remain: per-render health recompute and per-column cell-string allocation (small, fleet-scale), the linear upsert scan, and synchronous scan-range parsing (bounded by the range caps). 99 tests + clippy-clean + selftest green. This was review round 5 (the harness's iteration cap); every confirmed critical/high across all five rounds is fixed. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6 --- .gitea/workflows/release.yml | 8 ++- ci/compute-version.sh | 7 +-- crates/alkane-gui/src/ui.rs | 99 ++++++++++++++++++++++++++++++++++-- 3 files changed, 101 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 3538a458..7b794f8d 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -11,6 +11,9 @@ jobs: runs-on: alkane-ci env: WX_PREFIX: /root/.cache/wx-3.3.3-linux + # Set once for the whole job so build/clippy/test/bench steps don't each + # re-export it (round 18 #12). + WX_RS_WXCONFIG: /root/.cache/wx-3.3.3-linux/bin/wx-config steps: - name: Checkout (full history for tags) uses: actions/checkout@v4 @@ -52,7 +55,6 @@ jobs: - name: Clippy (our crate, warnings are errors) if: steps.ver.outputs.release == 'true' run: | - export WX_RS_WXCONFIG="$WX_PREFIX/bin/wx-config" rustup component add clippy >/dev/null 2>&1 || true cargo clippy -p alkane-gui --no-deps --release --bins --offline -- -D warnings @@ -65,19 +67,16 @@ jobs: - name: Build release if: steps.ver.outputs.release == 'true' run: | - export WX_RS_WXCONFIG="$WX_PREFIX/bin/wx-config" cargo build --release -p alkane-gui --offline - name: Unit tests if: steps.ver.outputs.release == 'true' run: | - export WX_RS_WXCONFIG="$WX_PREFIX/bin/wx-config" cargo test -p alkane-gui --offline - name: Microbenchmarks if: steps.ver.outputs.release == 'true' run: | - export WX_RS_WXCONFIG="$WX_PREFIX/bin/wx-config" cargo test -p alkane-gui --release --offline -- --ignored --nocapture bench_ - name: Headless UI self-test @@ -108,7 +107,6 @@ jobs: env: TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - export WX_RS_WXCONFIG="$WX_PREFIX/bin/wx-config" PASS=$(cargo test -p alkane-gui --offline 2>&1 \ | grep -hoE '[0-9]+ passed' | grep -oE '[0-9]+' | awk '{s+=$1} END{print s+0}') python3 ci/gen-badges.py --tests "${PASS:-0}" --bench "row-render + scan-parse" diff --git a/ci/compute-version.sh b/ci/compute-version.sh index 3c0ea33b..907f41d8 100755 --- a/ci/compute-version.sh +++ b/ci/compute-version.sh @@ -2,9 +2,10 @@ # Compute the next release version for alkane-toolkit from the latest release # tag and the paths changed since it. Version scheme X.Y.Z: # X - major, bumped manually (ci/version-x.txt); a bump resets Y.Z to 0.0 -# Y - backend-logic changes (core/discovery/access/flash/artifacts/cli, -# scan+model+main in the GUI crate, build/CI config); resets Z to 0 -# Z - UI changes (the GUI view + fixtures + the wx-rs widget bridge) +# Y - backend-logic changes (the alkane-* crates and any GUI crate source +# other than the view files below, plus vendored deps and build/CI config); +# resets Z to 0 +# Z - UI changes (the GUI view: ui.rs + fixtures.rs + bin/ + the wx-rs bridge) # When both backend and UI changed, backend wins (bump Y). Docs-only changes # produce no release. # diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 6cd200da..2e9288dc 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -647,6 +647,10 @@ pub struct App { // the first time fill_rows runs with rows present, so the default widths fit // their contents (capped) once and manual resizes afterwards are preserved. columns_autosized: bool, + // Set when a scan streamed new rows this drain; flushed by tick() at most once + // per second (or immediately once the scan ends) so the full table refill runs + // ~1 Hz during a scan instead of every fast tick (round 18 #12). + rows_dirty: bool, // The columns the wxDataViewCtrl was actually built with, in creation order. // fill_rows/header_click/reorder index the widget through table_columns() and // assume it stays in lockstep; with auto-hide-empty on, a scan can change which @@ -709,6 +713,10 @@ pub struct App { // IPs the current config action targets, re-probed after it completes so the // table reflects the change (e.g. the identify light toggling). action_targets: Vec, + // A new password from an in-flight ChangePassword action, applied to the saved + // credentials once the action succeeds so the toolkit keeps reaching the miners + // it just changed (round 18 #12). + pending_password_update: Option, // Per-miner in-flight operation label (round 14 #4): while a miner has an // operation running (refresh, config action, light, firmware, restore, access // check), its Health cell shows this text instead of the component icons. @@ -1022,6 +1030,7 @@ pub fn build(frame: Widget) -> App { progress, table: None, columns_autosized: false, + rows_dirty: false, built_columns: Vec::new(), table_parent, root_sizer: root, @@ -1053,6 +1062,7 @@ pub fn build(frame: Widget) -> App { action_total: 0, action_done: 0, action_targets: Vec::new(), + pending_password_update: None, op_status: std::collections::HashMap::new(), confirm_dialog: frame, pending_confirm: None, @@ -1836,13 +1846,17 @@ impl App { wx_rs::set_status_text("firmware flash in progress -- wait for it to finish"); return; } - // A restore-to-stock is reverting + rebooting miners; writing pools mid- - // revert could hit a unit in an undefined state (round 18 #12 -- this path - // sets self.action directly, so it needs the same guard as start_action). + // This path sets self.action directly, so it needs start_action's full + // exclusivity guard: don't write pools during a restore or a live scan + // (round 18 #12). if self.restore.is_some() { wx_rs::set_status_text("restore-to-stock in progress -- wait for it to finish"); return; } + if self.scanning { + wx_rs::set_status_text("scan in progress -- wait for it to finish"); + return; + } // Collect the raw rows: (address, account, worker_template, password). let mut rows: Vec<(String, String, String, String)> = Vec::new(); for row in 0..3usize { @@ -1920,6 +1934,14 @@ impl App { wx_rs::set_status_text("restore-to-stock in progress -- wait for it to finish"); return; } + // A scan is opening its own connections to these same miners; a mutating + // action racing the scan's probe traffic can be dropped or interleaved, so + // hold it until the scan finishes (round 18 #12 -- matches the flash/restore + // invariant). + if self.scanning { + wx_rs::set_status_text("scan in progress -- wait for it to finish"); + return; + } if let Some(old) = self.action.take() { old.stop(); // The superseded action's drain will never run again, so clear its @@ -1934,6 +1956,13 @@ impl App { // line; the bottom-right indicator still surfaces failures at the end. crate::logs::log(format!("apply {} to {} miner(s)", action.label(), ips.len())); self.action_targets = ips.clone(); + // Remember a password change so we can update our own saved credentials + // once it succeeds -- otherwise the toolkit keeps using the old password + // and locks itself out of the miners it just changed (round 18 #12). + self.pending_password_update = match &action { + scan::ConfigAction::ChangePassword(p) => Some(p.clone()), + _ => None, + }; self.set_op_status(&ips, &action.progress_label()); self.action = Some(scan::start_config_action(ips, action)); // Clear any stale error/warning from a previous operation; the new @@ -2238,7 +2267,10 @@ impl App { Ok(scan::AccessProbeMsg::Result { ip, locked, error }) => { op_clear.push(ip.clone()); if let Some(r) = self.rows.iter_mut().find(|r| r.ip == ip) { - if error.is_none() { + // Only a definitive answer updates the cell; an indeterminate + // probe (locked = None) must not blank a previously-known + // locked/unlocked state (round 18 #12). + if error.is_none() && locked.is_some() { r.write_locked = locked; changed = true; } @@ -2866,6 +2898,13 @@ impl App { for (name, user_ctrl, pass_ctrl) in &self.fwcreds_rows { let user = user_ctrl.get_value(); let pass = pass_ctrl.get_value(); + // A fully-blank row means "no override, use the shipped default" -- the + // natural way to clear one firmware's override. Without this, a blanked + // row was saved as an explicit ("","") override that then broke auth + // fleet-wide for that firmware (round 18 #12). + if user.trim().is_empty() && pass.trim().is_empty() { + continue; + } let default = credentials::firmware_default_for(name); if (user.clone(), pass.clone()) != default { map.insert(name.clone(), (user, pass)); @@ -2942,6 +2981,34 @@ impl App { } else { Some((false, format!("apply: {}/{total} miner(s) failed", total - ok))) }); + // A password change succeeded on every target: update our own + // saved global credential so the toolkit keeps reaching them. On + // a partial change we leave saved creds alone (we can't tell which + // password now works for which miner) and warn (round 18 #12). + // (self.pending_password_update is a different field than self.action, + // so this disjoint borrow is fine while `h` still holds self.action.) + if let Some(newpass) = self.pending_password_update.take() { + if ok == total && total > 0 { + let user = credentials::load_credentials() + .map(|(u, _)| u) + .unwrap_or_else(|| "root".into()); + match credentials::save_credentials(&user, &newpass) { + Ok(()) => crate::logs::log( + "saved credentials updated to the new password".to_string(), + ), + Err(e) => crate::logs::log(format!( + "could not update saved credentials after password change: {e}" + )), + } + } else { + crate::logs::log( + "password change was partial -- saved credentials left unchanged; \ + update Settings > Credentials manually so the toolkit can reach \ + the changed miners" + .to_string(), + ); + } + } finished = true; break; } @@ -3127,7 +3194,15 @@ impl App { } } if changed { - self.fill_rows(); + if self.scanning { + // Still scanning: defer the whole-table refill to tick()'s ~1 Hz + // flush so streaming rows don't trigger a refill on every fast tick + // (round 18 #12). + self.rows_dirty = true; + } else { + // The scan just ended (or wasn't running): show the final state now. + self.fill_rows(); + } } } @@ -3147,6 +3222,13 @@ impl App { // auto-rescan scheduler + idle status only need ~1 Hz, so run them once // per second. self.tick_accum = self.tick_accum.wrapping_add(1); + // Flush a scan's batched row updates at most once per second (or right away + // once the scan has ended), so the whole-table refill runs ~1 Hz during a + // scan rather than on every fast tick (round 18 #12). + if self.rows_dirty && (!self.scanning || self.tick_accum.is_multiple_of(TICKS_PER_SEC)) { + self.rows_dirty = false; + self.fill_rows(); + } if !self.tick_accum.is_multiple_of(TICKS_PER_SEC) { return to_show; } @@ -3194,6 +3276,13 @@ impl App { wx_rs::set_status_text("firmware flash in progress -- scan deferred"); return false; } + // Symmetric to start_action's scan guard: don't start a scan (including an + // auto-rescan) while a config action or restore is writing to miners, so + // the two never race on the same unit (round 18 #12). + if self.action.is_some() || self.restore.is_some() { + wx_rs::set_status_text("operation in progress -- scan deferred"); + return false; + } if let Some(old) = self.scan.take() { old.stop(); }