Commit Graph
5 Commits
Author SHA1 Message Date
paulandClaude Opus 5.5 eb771656fb Privilege split 6/11: the app reads and drives the hardware through the service
- kurgan/hw/client.py: HardwareClient polls the service's state once a second
  on its own thread, reconnecting (and greeting again) whenever the pipe
  breaks, and sends the app's chase clock with each poll. Profile and RAM
  lighting changes are sent at once: bad values are ValueError before anything
  is sent; an unreachable or refusing service is HardwareUnavailable. A state
  that stops arriving (5 s) or a service loop that stops publishing (15 s)
  counts as unavailable. PipeTransport for the real pipe, LocalTransport (same
  encoding and checks, no pipe) for --demo and tests.
- Telemetry: the CPU package temperature and power (CpuSensors(package=...))
  and the Commander PRO RPMs for the power model (SystemPower(fans=...)) come
  from the service; the app opens neither PawnIO nor the Commander PRO.
  "hardware service" is its own health source, and while it's down the
  missing CPU temperature isn't reported a second time.
- The fan UI, profile buttons and fan history come from the service's state;
  the RAM lighting zone goes through it (LightingService(ram=...)), and the
  case fan and GPU zones stay local. The alert monitor balloons "Hardware
  service unavailable"; the header shows a hardware service pill instead of
  the admin-rights one (and warns if the app itself runs elevated); the tray
  lines read the service's fans. POSTs answer 503 while it's unavailable.
- Removed --gpu-fan-ports, --no-gpu-fan-control and --rgb-memory-*: the
  service owns those now.
- settings.json: cooling and lighting.memory are legacy. Old files keep them
  (still validated), nothing reads them, and defaults no longer add them.
- --demo runs the real HardwareService in-process on the demo fakes, with its
  settings in demo-hw-settings.json, through the same client.
- --preview reads the CPU temperature and fan power from the service too.
- Tests: 13 for the client (including a real pipe end to end); the alert,
  lighting, settings and web tests follow the new shapes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 19:41:51 +13:00
paulandClaude Opus 5.5 7190db733f Privilege split 4/11: the kurgan.hw service process
- kurgan/hw/service.py, HardwareService: one loop a second reads the CPU
  package (PawnIO MSR: temperature and power) and the GPU (NVML), runs the
  fan curves, and publishes a state snapshot. It never depends on a client:
  the pipe side takes no lock the loop needs, every sensor read is guarded
  (a fault is a missing temperature, so those fans fail safe), and a bug in
  the loop fails the fans safe and retries. On exit the case fans are left at
  100% and the top fans go back to the BIOS curve.
- Without saved ports it only reads the Commander PRO's RPMs (for the app's
  power estimate). With an invalid hw-settings.json it holds every connected
  PWM fan at 100% (CommanderPro.full_speed) and says why in its state,
  instead of refusing to start and leaving the fans at their last duty.
- State carries the app's cooling snapshot unchanged (profile, groups, top,
  note, row) plus the CPU temperature and power, GPU temperature, the
  Commander PRO RPMs and the RAM lighting. NaN never reaches the pipe.
- RAM lighting runs in the service; its chase follows the app's clock
  (SyncedChase, fed by ram_chase) so it stays in step with the other chases.
- kurgan/hw/settings.py: %ProgramData%\Kurgan\hw-settings.json, the cooling
  and RAM lighting sections, as strict as settings.json (validate_cooling is
  shared). The folder is created SYSTEM/Administrators full, Users read.
- kurgan/hw/main.py: serve() wires the loop, the RAM lighting and the pipe
  (the fans run whatever happens to the pipe); `python -m kurgan.hw` runs it
  in a console. The pipe user comes from HKLM\...\Services\KurganHw\
  Parameters\UserSid; the OpenRGB check reads that user's %APPDATA%.
- control.py: CaseFanControl.step() (one guarded pass) and shutdown()
  replace run(); CpuTemperature also keeps the latest reading, the package
  power and why it has none. The fan CLI saves to hw-settings.json.
- sensors.py: the Commander PRO mutex is Global\KurganCommanderPro, so a
  console tool in the user's session sees the service's claim.
- The app still uses the old worker; it is rewired in step 6.
- Tests: 16 new or rewritten (202 pass), including the loop with no client
  and a stuck client that can't stop fan control.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 19:28:32 +13:00
paul 9036c6e734 Stop presenting stale data as live, and back off broken devices
- readings.py: PowerReadings.total now sums the known parts (None only when
  nothing is known), with a complete property saying whether it under-counts;
  the snapshot exposes it as partial and the web UI marks it with a tilde.
- display/service.py: telemetry older than 15 s is drawn as -- instead of
  re-rendering frozen readings as if they were current.
- sensors.py: Commander PRO last-known RPMs expire after 10 s instead of
  feeding the power model forever (empty list = unknown); a runtime MSR
  failure backs off 15 s instead of re-opening PawnIO every second; GPU NVML
  reconnects back off 10 s instead of nvmlInit() every second, and the
  sample-buffer timestamp resets on a driver-reset reconnect.
- control.py: CpuTemperature read failures back off 15 s instead of churning
  the MSR handle every poll.
2026-12-05 16:54:01 +13:00
paul d637d46777 Fail safe, not dead: bound the HID cancel wait, isolate sensor failures, keep the fan worker alive
- hid.py: after a timed-out HID operation, wait at most 1 s for the driver to
  finish the cancelled IRP; if it does not, mark the channel broken so the
  caller's reconnect path closes it instead of blocking forever on a wedged
  device. Keep abandoned OVERLAPPED/buffer references alive until close so a
  late IRP completion cannot write into reused memory. Check CreateEventW.
- telemetry/service.py: read each source (CPU, GPU, system power, GPU memory)
  independently; a failing source now costs only its own readings instead of
  the whole sample, logged at most once a minute per source.
- sensors.py: the Commander PRO iCUE ownership check runs inside a guard; if
  ownership cannot be established the device is released rather than risking
  swapped replies (and the failure no longer escapes into the sample).
- cooling/control.py: an unexpected exception no longer ends fan control for
  the life of the process; fail safe, log at most once a minute, retry with a
  fresh sensor object after 5 s. failsafe() no longer raises, and control
  errors back off 5 s instead of re-opening the device every second.
2026-12-05 16:47:16 +13:00
paul f631386618 The Kurgan 1.0.0: one process for the LCD, fans, lighting, local LLM servers and the web UI 2026-12-05 16:20:49 +13:00