Repository navigation
feat(trackers,electron): thermal_state and cpu_speed_limit traces from powerMonitor (C13) - #125
Conversation
…m powerMonitor (C13) The Power tracker gains thermalState and speedLimit stages; @bugsee/electron adds the two producers. The thermal_state wire form is a single table (thermal-state-wire.ts). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
Claude finished @krassx's task in 50s —— View job Review of PR #125 (C13 thermal_state / cpu_speed_limit traces)I read the whole diff and its surrounding code (the stage tracker's Overall risk: Low–Medium. The change is small, isolated and well covered. The one real risk is untested against actual Electron. Merge recommendation: Merge after the event-argument shape is either confirmed on a real macOS Electron or handled in both forms (P2 below). Findings
Checked and found fine
Positives
|
|
No actionable comments were generated in the recent review.
|
| const thermalOf = (detail: unknown): { state: ElectronThermalState } => ({ | ||
| state: normaliseThermal((detail as { state?: unknown } | null | undefined)?.state), | ||
| }); | ||
|
|
||
| const speedLimitOf = (detail: unknown): { limit: number } | undefined => { | ||
| const limit = (detail as { limit?: unknown } | null | undefined)?.limit; | ||
| // the range test also rejects NaN and the infinities (every comparison with them is false) | ||
| return typeof limit === 'number' && limit >= 0 && limit <= 100 | ||
| ? { limit: Math.round(limit) } | ||
| : undefined; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Severity: P2 Medium
Problem: thermalOf and speedLimitOf read detail.state / detail.limit from the first listener argument only. If real Electron passes the value directly (listener(state) or listener(limit)) instead of a details object, both normalisers fail silently.
Impact: Every thermal-state-change becomes {state: 'unknown'}, which the producer drops. Every speed-limit-change becomes undefined and is dropped. Only the one-off baseline read of thermal_state at start would ever be written, and cpu_speed_limit would never be written. There is no error and nothing is reported.
Scenario: I could not verify the event's argument shape. There is no Electron typings package in the repo, and the PR says this was not run against a real Electron. The unit tests and the integration test all emit {state} / {limit} objects, so they would pass either way. The existing Emitter.emit helper in the integration test passes {} as the first argument, so the repo's own helpers are not a reliable guide here.
Fix: Accept both shapes, so the code is right whichever one Electron uses:
const field = (detail: unknown, key: 'state' | 'limit'): unknown =>
typeof detail === 'object' && detail !== null ? (detail as Record<string, unknown>)[key] : detail;Use field(detail, 'state') in thermalOf and field(detail, 'limit') in speedLimitOf, and add tests that fire the bare primitive. Alternatively, confirm the shape on a real macOS Electron before merging.
There was a problem hiding this comment.
Fixed in f9686b9. thermalOf and speedLimitOf now read the value from a details object ({state} / {limit}) or from a bare first argument (listener('fair'), listener(80)), so they are right whichever form Electron uses; anything else still normalises to unknown / is dropped. Tests cover both shapes (object, bare, garbage, null, undefined) and the mutator loop on detailValue killed all four mutations. The real event shape is still unverified on a real Electron (stated in the PR body).
| class ThermalStateProducer extends TraceProducerBase { | ||
| readonly name = 'thermal_state'; | ||
| #off: (() => void) | undefined; | ||
| constructor(private readonly tracker: ElectronPowerTracker) { | ||
| super(); | ||
| } | ||
| #publish(state: Parameters<typeof thermalStateWire>[0]): void { | ||
| const wire = thermalStateWire(state); | ||
| if (wire !== undefined) this.emit('thermal_state', wire); | ||
| } | ||
| protected onStart(): void { | ||
| // subscribe FIRST (arming the listener), then the baseline read: no change can fall between the two | ||
| this.#off = this.tracker.on('thermalState', (e) => this.#publish(e.state)); | ||
| const current = this.tracker.current('thermalState'); | ||
| if (current !== undefined) this.#publish(current.state); | ||
| } | ||
| protected override onStop(): void { | ||
| this.#off?.(); | ||
| this.#off = undefined; |
There was a problem hiding this comment.
Severity: P3 Low
Problem: thermal_state writes nothing for unknown. A real transition from a known state to unknown, for example serious to unknown, therefore leaves the previous value (2) as the last sample.
Impact: The trace is "sampled, never held" by the spec, but a viewer that draws the last point of a series would show the device as still serious after the OS stopped reporting.
Scenario: The state goes serious, then a thermal-state-change with an unrecognised state arrives, which normaliseThermal turns into unknown. Nothing is written and no later sample corrects the series.
Fix: This is mostly a spec question, since "omit, never zero" is deliberate. If it is intended, add a one-line note to the producer comment that a transition to unknown leaves the prior value as the last sample. The bare-primitive concern on power-tracker.ts:63 matters more.
There was a problem hiding this comment.
Agreed it is intended (spec: sampled, never held, omit never zero). Documented in the producer comment in f9686b9: a transition from a known state to unknown leaves the previous value as the last sample. Left as is; flagging it for the owner alongside the #288 question.
…e the unknown-state gap (C13 review) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
Claude finished @krassx's task in 18s —— View job Re-review of PR #125 after f9686b9I re-read the new commit Earlier findings are addressed
Still open (not a code defect)
Summary
|
…SPEED_LIMIT #125 landed the two Electron power traces with literals; the broadened scan caught them. They are now registered (int, not held; cpu_speed_limit in percent) and out of NOT_YET. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
…registry (C17, C24) (#131) * test(protocol,instrumentation-tests): spec-conformance guard and a single system wire-name registry (C17, C24) - @bugsee/protocol: TraceName / EventName registry with TRACE_SPEC (type, unit, held) and EVENT_PARAMS; every trace/event producer (browser, node, electron, capture, host-owned trace lists in browser/webview/electron renderer) now references it. TraceProducerBase.emit takes a TraceName; the electron power_${state} concatenation is a lookup over registered events. - Vendored snapshot of the JavaScript platform spec's tables (with the bugsee/specs commit) at packages/protocol/spec; pnpm spec:refresh / spec:check read it from a specs checkout by git ref. - spec-drift test: registry vs snapshot (names, type, unit, held, params), NOT_YET list with reasons, held style of every emit call, and an AST scan that fails on a wire name spelled as a literal in producer code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) * fix(protocol): make the wire-name registry string enums so the WebView bundle inlines it A const object of ~90 names stays whole in the IIFE (every runtime's names, ~2 KB gzip) and pushed the bundle over its 64 KB budget. As string enums esbuild inlines every use and the registry disappears (191585 raw / 64310 gzip, identical to main); the type is stricter too. 🤖 Generated with [Claude Code](https://claude.com/claude-code) * fix(spec-snapshot): atomic snapshot write, one params list per event, declare typescript (review feedback) - refresh writes through a temporary file renamed over the snapshot - event params: drop the unread per-family copy; a key optional in any family is one optional key - instrumentation-tests declares its typescript devDependency 🤖 Generated with [Claude Code](https://claude.com/claude-code) * test(spec-drift): scan every product file, type event names, fix EVENT_PARAMS, fail-closed parser (review F1-F6) - F1: the scan covers every packages/*/src file but protocol (found by location, not by keyword); the disk-pressure capture probe is built from TraceName.CAPTURE; a reasoned NOT_A_WIRE_NAME list that fails when stale. - F2: flags + / join / shared-suffix template assembly, quoted names inside strings, computed TraceName[key], and every spec name (pending ones included). SystemEvent.name and the electron #send are typed EventName. - F3: EVENT_PARAMS expands "the same keys, plus ...", marks omitted / no-params-at-all / one-runtime keys optional; eventParamProblems() checks real emitted events in the browser, node and electron source tests. - F4: the parser throws on a renamed column, an inexact held cell, an unnamed or wildcard row, a typeless value, an unknown unit, a cell-count mismatch and families that disagree; indented tables are read. - F5: refresh --specs/--ref/--out need a value, the temp file is removed when the write fails. - F6: the spec tooling runs under a coverage gate; NOT_YET names the spec item and the tracking issue/PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) * test(spec-drift): merge main (#125) and register THERMAL_STATE / CPU_SPEED_LIMIT #125 landed the two Electron power traces with literals; the broadened scan caught them. They are now registered (int, not held; cpu_speed_limit in percent) and out of NOT_YET. 🤖 Generated with [Claude Code](https://claude.com/claude-code) * test(spec-drift): pin exemptions to exact strings, type TraceSink, key the turbo cache, fail-closed parser (review round 2) - NOT_A_WIRE_NAME entries list the exact strings and counts they excuse; an appended leak, an extra or a vanished occurrence fails. this.emit('stage') in packages/trackers/src is exempt structurally. - TraceSink.emit takes a TraceName (type test); PROGRESS states exactly what the compiler covers. - instrumentation-tests test:unit hashes packages/*/src, the snapshot and scripts/spec-snapshot. - parser: throws on a table under an unrecognised ### heading in an inventory, a numeric value followed by a bare unit word, and a held claim in the held-less Node table. - tests for quoted-name boundaries, '%' units, the same-keys reset; EXPECTED_EVENTS of the three system-events tests must cover every registered event. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
…, rounding test, comments) (#136) * docs(electron),test(trackers): thermal/cpu-speed-limit README, rounding boundary test, stale comments Follow-up to #125: README lists thermal_state/cpu_speed_limit and the details-object listener shape (no getCurrentCPUSpeedLimit in Electron); pin Math.round at 62.5/99.6/99.4 boundaries (floor/ceil mutants killed); relaunch comment lists the new traces; reword the subscribe-first comment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) * docs(electron): note the systemMetricsSampler exception for the power traces 🤖 Generated with [Claude Code](https://claude.com/claude-code)
What
Closes spec gap C13 (Electron thermal and low-power signals) for Electron main.
ElectronPowerTracker(@bugsee/trackers/electron, the one Power-domain tracker; no per-signal trackers) gains two stages next tosuspendResume/lockScreen/powerSource:thermalState(thermal-state-change, macOS) andspeedLimit(speed-limit-change, macOS and Windows), plus a livecurrent('thermalState')read ofgetCurrentThermalState(). The tracker only normalises: an unrecognised thermal state isunknown; a speed limit outside 0-100 or not a number is dropped (otherwise rounded to an integer).@bugsee/electronadds two producers to the Electron main trace set wheneverpowerMonitoris injected:thermal_state(live read at start, then every change;unknownwrites nothing) andcpu_speed_limit(event-fed only, so no initial value). Both are sampled, never held, per the spec's "Electron main traces" rows.power_suspend,power_resume,power_lock,power_unlock,power_ac,power_battery) already existed; there is no Electron low-power-mode API (the spec markslow_power_modeas not available for Electron), so nothing is added for it.thermal_state wire form: one table
packages/electron/src/thermal-state-wire.tsis the single place that decides the value. Today it is the spec's current form, the iOS int (nominal0,fair1,serious2,critical3;unknownomitted). Switching to Android's strings (normal,light,severe,critical) is an edit to that table only; its header comment says so.Open owner question (for the PR discussion)
thermal_statevalue form. iOS writes an int, Android writes a string, and the spec currently picks the iOS int. This PR implements that and keeps the mapping in one table so it can change in one place. Needs an owner decision if the mobile SDKs converge on strings.thermal_stateandcpu_speed_limitare not held, so a rolling capture window that starts after the last change will not contain athermal_statevalue (same trade-off the spec already makes for other event-driven traces). Flagging in case the owner prefers held for the thermal state.Tests
Test-first. Tracker unit tests, producer unit tests, wire-table tests, launch-level composition tests (power producers present with a
powerMonitoralone; absent under the legacysystemMetricsSampler) and a real-launch integration test that assertsthermal_state[1, 2, 3]andcpu_speed_limit[80, 100]in the uploadedtraces.system, and thatclient.stop()releases every listener. Existing listener-count tests were updated (6 to 8 power listeners with both streams on; 2 with events off).Mutator loop (restored from a saved copy each time, ~38 injected mutations across
power-tracker.ts,system-traces.ts,thermal-state-wire.ts,launch-main.ts): all killed after removing one redundantNumber.isFinitethat the range test already implied.pnpm ci:localpasses locally (lint, typecheck, cycles, per-package coverage, unit). e2e job not run.Not verified
Not run against a real Electron: the argument shape of the two events (implemented from the Electron docs: first argument is a
detailsobject withstate/limit) andgetCurrentThermalState()semantics on a real macOS machine.🤖 Generated with Claude Code