Review fixes: demo fans, record averages and restarts, combined alerts, quiet sensors

- demo.py: FakeBoard grows rpms(). The top fans' stall check (b2da221) called
  it, so under --demo every poll raised AttributeError and the case fans sat
  in CONTROL ERROR at 100%.
- control.py: TopFanCurve.update hands the headers back to the BIOS on any
  failure, a bug included, instead of letting it escape into the case fans'
  loop (unexpected errors are logged with a traceback once). The worker's
  catch-all now fails the top fans safe as well as the case fans, as the
  device-error path already did. The snapshot gives None for a channel whose
  tach has never turned, and the UI says "no tach reading" (and "Channel",
  not "Port") rather than showing SYS_FAN1's unwired tach as a dead fan.
- record.py: an hour's average is over the samples that carried the metric,
  not all of them: a GPU that dropped out for half an hour no longer halves
  its recorded power. Lines carry the count as a fourth number; the reader
  weights by it, and treats three-number lines as before.
- record.py: the hour in progress is checkpointed to records-current.json
  every minute and on close and resumed at start, so a hard stop (schtasks
  /End, the documented restart) loses at most a minute instead of the hour;
  a checkpoint from an earlier hour is written out at start. A failing write
  no longer stops recording for the run: it is logged at most once an hour
  and finished hours wait in memory (up to 48) until the disk works.
- app.py: alerts that start together share one balloon (Windows shows one at
  a time, so each notify() replaced the last), shortened to fit 255
  characters; a problem that clears and comes back balloons again only after
  10 minutes.
- telemetry/service.py: health also counts a source that returns no
  temperature three reads running. GpuSensors and CpuSensors don't raise
  when their device is lost, so a lost GPU driver used to show as healthy.
- hid.py: buffers of IRPs the driver never finished cancelling are kept for
  the life of the process; freeing them with their channel could still let a
  late completion write into reused memory.
- Tests: 13 new (160 pass). README updated to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
paulandClaude Opus 5.5 committed 2026-12-05 18:31:11 +13:00
1 parent 8cc1e9223f
commit b983528183
12 files changed
+394 -73

No files matched your search

+36 -2
View File
@@ -88,11 +88,42 @@ def alert_states(fans, ai, telemetry) -> dict[str, str]:
return states
ALERT_REPEAT_SECONDS = 600.0 # a problem that clears and comes back balloons again only after this
def new_alerts(known: dict[str, str], states: dict[str, str]) -> list[tuple[str, str]]:
"""(key, message) for alerts that are new since the last look; recovered ones stay quiet."""
return [(key, states[key]) for key in sorted(states.keys() - known.keys())]
def due_alerts(new: list[tuple[str, str]], alerted: dict[str, float], now: float) -> list[tuple[str, str]]:
"""The new alerts not already ballooned in the last ALERT_REPEAT_SECONDS; records them in
`alerted` (key -> when). A flapping problem balloons once, not every time it comes back."""
due = [(key, message) for key, message in new if now - alerted.get(key, -1e18) >= ALERT_REPEAT_SECONDS]
alerted.update((key, now) for key, _ in due)
return due
def balloon(messages: list[str]) -> tuple[str, str]:
"""One balloon (title, text) for all of them: Windows shows one balloon at a time, so a
second notify() would only replace the first. The text holds up to 255 characters."""
if len(messages) == 1:
return APP_NAME, messages[0]
lines: list[str] = []
for i, message in enumerate(messages):
rest = len(messages) - i - 1
tail = f"\n...and {rest} more" if rest else ""
if len("\n".join(lines + [message])) + len(tail) > 255:
if not lines: # the first one alone is too long: shorten it
lines.append(message[:255 - len(tail) - 3] + "...")
lines.append(tail.lstrip("\n"))
else: # the previous round made sure this note fits
lines.append(f"...and {rest + 1} more")
break
lines.append(message)
return f"{APP_NAME}: {len(messages)} problems", "\n".join(filter(None, lines))
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
from kurgan.cooling.control import parse_ports
@@ -283,6 +314,7 @@ class Kurgan:
"""Balloon tips for things starting to go wrong. The first look is the baseline: what
is already wrong at startup sits in the tray menu and the UI, it doesn't need a balloon."""
known: dict[str, str] | None = None
alerted: dict[str, float] = {} # key -> when it last ballooned
while not stop.wait(ALERT_SECONDS):
if self.tray is None:
continue # no icon, no balloons -- and no baseline burnt before the icon exists
@@ -294,9 +326,11 @@ class Kurgan:
if known is None:
known = states
continue
for _, message in new_alerts(known, states):
due = due_alerts(new_alerts(known, states), alerted, time.monotonic())
for _, message in due:
log.warning("Alert: %s", message)
self.tray.notify(APP_NAME, message, warning=True)
if due:
self.tray.notify(*balloon([message for _, message in due]), warning=True)
known = states
def _start_tray(self) -> None: