diff --git a/apps/host/server/monitor.mjs b/apps/host/server/monitor.mjs index c861d9b9..810704a6 100644 --- a/apps/host/server/monitor.mjs +++ b/apps/host/server/monitor.mjs @@ -4,7 +4,7 @@ import { detect, cachedHardware } from './hardware.mjs'; import { readGpuTelemetry, gpuMemoryTotals } from './device-probes.mjs'; import { createSystemSampler } from './system-telemetry.mjs'; import { sensorPace, WATCH_MS } from './sensor-pace.mjs'; -import { readTemperatures } from './temperature-telemetry.mjs'; +import { readTemperatures, stopTemperatures } from './temperature-telemetry.mjs'; import { addEnergy, energyWh } from './energy-meter.mjs'; import { state as servingState } from './serving.mjs'; import { originalDashboard } from './monitor-dashboard.mjs'; @@ -127,11 +127,14 @@ function tick() { if(!sensorsPending&&Date.now()-sensorsAt>=pace.intervalMs){ sensorsPending=true;sensorsAt=Date.now(); const hardware=cachedHardware()??hwCache; - void Promise.all([readGpuTelemetry(hardware?.gpus??[],{transfer:pace.transfer}),sampleSystem(hardware?.processors??[]),(process.env.STRATA_REAL_ENGINE==='1'?readTemperatures():Promise.resolve(temperatures)).catch(()=>({cpuTempC:null,ssdTempC:null}))]) + void Promise.all([readGpuTelemetry(hardware?.gpus??[],{transfer:pace.transfer}),sampleSystem(hardware?.processors??[]),(process.env.STRATA_REAL_ENGINE==='1'&&Date.now()({cpuTempC:null,ssdTempC:null}))]) .then(([readings,system,temps])=>{state.hardware.gpus=readings;systemReading=system;temperatures=temps;}) .catch(()=>{state.hardware.gpus=[];systemReading=null;}) .finally(()=>{sensorsPending=false;}); } + /* #4661: the drive-temperature reader asks every physical drive for its temperature. Only while the Monitor is looked at, never from the first second of the app + (on some PCs the storage queries stall the whole system); it ends a couple of minutes after the Monitor was last seen. */ + if(Date.now()>watchedUntil+120000)stopTemperatures(); addEnergy(hardwareSnapshot().powerW,Date.now()); const hw = state.hardware; const busy = state.phase === 'generating' || state.phase === 'reading' || state.phase === 'thinking'; diff --git a/apps/host/server/temperature-telemetry.mjs b/apps/host/server/temperature-telemetry.mjs index 0417dc04..73d2c343 100644 --- a/apps/host/server/temperature-telemetry.mjs +++ b/apps/host/server/temperature-telemetry.mjs @@ -122,3 +122,8 @@ export async function readTemperatures({ platform = process.platform, now = Date } return { cpuTempC: null, ssdTempC: null }; } + +/** Ends the Windows drive-temperature loop (the Monitor has not been open for a while); the next read starts it again. */ +export function stopTemperatures() { + if (windowsReader) { windowsReader.stop(); windowsReader = null; } +} diff --git a/apps/host/tests/sensor-pace.test.mjs b/apps/host/tests/sensor-pace.test.mjs index 46d99f37..0d6da3a0 100644 --- a/apps/host/tests/sensor-pace.test.mjs +++ b/apps/host/tests/sensor-pace.test.mjs @@ -47,3 +47,14 @@ test('the monitor uses the pace, the Monitor screen asks while it is open, and / const screen = await readFile(new URL('../src/screens/Monitor.tsx', import.meta.url), 'utf8'); assert.match(screen, /api\.get\('\/api\/monitor'\)/); }); + +test('the drive-temperature reader starts only while the Monitor is watched and ends after it is gone (#4661)', async () => { + const monitor = await readFile(new URL('../server/monitor.mjs', import.meta.url), 'utf8'); + assert.match(monitor, /STRATA_REAL_ENGINE==='1'&&Date\.now\(\)