fix: three defects around offline CPUs and a blocked UI thread - #38
Merged
Conversation
get_system_monitor was a non-async #[tauri::command], which tauri runs inline on the IPC thread. It sleeps 200ms between the two /proc/stat samples it has to diff, and shells out to df and ps aux. The Monitor view polls every 2s, so the UI was hard-blocked for at least 200ms out of every 2000 -- a visible ~10% duty cycle of dropped frames while that view was open. spawn_blocking moves the whole collection off, subprocesses included. set_cpu_governor counted cpuN directories and emitted one bare redirect per index under set -e. That count includes CPUs that are present but OFFLINE, whose cpufreq/ directory the kernel removes, and it assumes contiguous numbering. Offlining a core aborted the script partway, so earlier cores were already changed while the UI reported failure. Now globs at execution time and only errors when nothing applied at all. parse_cpu_snapshot parsed each core id to check it was numeric and then discarded it, letting the Vec index stand in. /proc/stat omits offline CPUs, so past a gap every core was labelled one too low and read its frequency from the wrong CPU -- the offline one, showing 0 MHz. The id is now carried, and the two snapshots are matched by id rather than position so a CPU going offline between them cannot diff one core against another. The governor tests are verified against the genuine original implementation, not a paraphrase: restoring it fails all four. An earlier mutation that only re-added 'set -e' passed, because bash suppresses errexit inside an if condition -- the original's bare redirects were what made it fire. 104 tests.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
thinkutils | 6a72077 | Jul 20 2026, 03:14 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three independent runtime defects found while auditing the backend. All three are invisible in normal operation on a machine with every core online.
1. The Monitor view blocks the UI thread ~10% of the time
get_system_monitorwas a non-async#[tauri::command]. Tauri's default isExecutionContext::Blocking, so the body runs inline on the IPC thread — not on the async runtime.That body sleeps 200ms between the two
/proc/statsamples it has to diff, and additionally shells out todfandps auxsynchronously.monitor.jspolls every 2s.So for as long as the Monitor view is open, the main thread is hard-blocked for ≥200ms out of every 2000ms — a visible duty cycle of dropped frames in scrolling, hover states, and window dragging.
spawn_blockingmoves the whole collection off, subprocesses included, rather than just converting the sleep.2. Setting the CPU governor fails wholesale if any CPU is offline
The old script counted
cpuNdirectories, then emitted a bare redirect per index0..countunderset -e. Two bad assumptions: the count includes CPUs that are present but offline — whosecpufreq/directory the kernel removes — and the numbering is assumed contiguous.Disable SMT (
echo 0 > .../cpu5/online) and the redirect forcpu5fails with ENOENT,set -eaborts, pkexec returns non-zero — after cpu0–cpu4 were already changed. Mixed governors, and a UI saying the operation failed.Now globs at execution time (as root, so it sees whatever is online at that moment) and treats only a total failure as an error.
3. Per-core stats are shifted past an offline CPU
parse_cpu_snapshotparsed each core id purely to check it was numeric, then discarded it and let the caller'senumerate()index stand in./proc/statomits offline CPUs entirely. With cpu5 offline the file lists cpu0–4, cpu6, cpu7 — so vector index 5 is really cpu6. Every core past the gap was labelled one too low and read its frequency from the wrong CPU. Index 5 pointed at the offline cpu5, which has no cpufreq directory: 0 MHz.The id is now carried through, and the two snapshots are matched by id rather than by position, so a CPU going offline between the two 200ms-apart reads can't diff one core's counters against another's.
Verification
104 tests, clippy clean.
The governor tests are checked against the genuine original implementation rather than a paraphrase — restoring it fails all four:
Worth recording: an earlier mutation that only re-added
set -epassed, because bash suppresses errexit inside anifcondition. The original's bare redirects were what made it fire — so the weaker mutation proved nothing, and the test needed the real thing to be trustworthy.