Skip to content

feat(trackers,electron): Electron Power, Display and window trackers (TR9, part 2) - #91

Merged
krassx merged 2 commits into
mainfrom
feat/electron-power-display-app-trackers
Oct 20, 2026
Merged

krassx merged 2 commits into
mainfrom
feat/electron-power-display-app-trackers

Conversation

@krassx

@krassx krassx commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Three DOMAIN trackers in @bugsee/trackers/electron (Electron injected structurally, no electron/DOM dep), per-object singletons over a shared per-stage lazy attach/release base: ElectronPowerTracker (powerMonitor), ElectronDisplayTracker (screen), ElectronApplicationTracker (app + BrowserWindow).
  • events.system: power_suspend|resume|lock|unlock|ac|battery; display_added|removed|metrics_changed; window_focus|blur|show|hide ({windowId?}); renderer_unresponsive|responsive ({webContentsId?}, on webContents ONLY, never double-recorded).
  • Trace electron_displays = {displays:[{id,width,height,scale_factor?,rotation?,internal?,refresh_rate_hz?}]} (held step trace; displays stays reserved until the Android-shaped list is confirmed against the viewer).
  • launchMain gains optional powerMonitor, screen, BrowserWindow; each tracker is built through its registry accessor, skipped on repeat launches, absent object = domain off. Mux and producers are lazy: nothing attached with captureSystemEvents:false, all released on client.stop().
  • Not mapped (stated): thermal-state-change/speed-limit-change.

Test plan

  • Tracker unit tests + per-entity mutator loop (0 survivors after strengthening)
  • Mux/producer unit tests, launch-level accessor spies, real-launch integration tests (window created after launch, hang recorded once, option off, stop releases, repeat launch, throwing getters)
  • pnpm ci:local passes (coverage gate included)
  • Real Electron run (unverified: event firing per OS, Display shape, re-emit timing)

🤖 Generated with Claude Code

…(TR9, part 2)

Adds ElectronPowerTracker, ElectronDisplayTracker and ElectronApplicationTracker
(@bugsee/trackers/electron, Electron injected structurally) over a shared per-stage
lazy listener base. @bugsee/electron forwards them through the lazy events mux
(power_*, display_*, window_*, renderer_(un)responsive) and adds the electron_displays
trace; launchMain takes optional powerMonitor, screen and BrowserWindow.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@claude

claude Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Claude finished @krassx's task in 51s —— View job


Review of PR #91: Electron Power, Display and window trackers (TR9, part 2)

I read the PR diff in full, plus InterceptorBase, the emitter and the tracker registry it builds on. I did not run the test suite, lint or typecheck, and nothing was checked against a real Electron. The PR's own test plan lists the real-Electron run as unchecked.

No inline comments: I found no defects that I could back with a concrete failure scenario.

What I checked and found sound

  • Attach and release (stage-tracker.ts)
    • bindAll is all-or-nothing, and a source that cannot be removed is never attached to.
    • The live flag keeps a listener whose removal failed from emitting after stop().
    • The shared reporter indirection survives relaunch, and a throwing or rejecting reporter is absorbed.
  • Application tracker
    • The hang pair is bound on webContents only, so a hang is not recorded twice through the window re-emit.
    • Destroyed objects are never bound, are forgotten on closed/destroyed without touching the dead object, and are skipped at release.
    • Windows that already exist at arm time and windows created later are both covered, and each object is bound once per stage.
    • rebind releases and re-arms the stages only when BrowserWindow actually changed.
  • Event payload mapping matches Electron's signatures: display-added(event, display), display-metrics-changed(event, display, changedMetrics) and browser-window-created(event, window).
  • Mux and producers
    • The mux builds its unsubscribe list incrementally, so a throw part-way through onActivate still releases what was subscribed.
    • DisplaysProducer subscribes before the baseline read, so no change can fall between the two.
  • launchMain
    • Trackers are built only on the first launch, through the registry accessors, so a repeat call does not rebind the live launch's trackers.
    • The app overloads and the LaunchMainOptions additions are consistent with the existing child-process-gone handling.

Observations (non-blocking, not defects)

  1. 'destroyed' on webContents is unconfirmed. application-tracker.ts:100 forgets a webContents on its destroyed event. If the Electron version in use does not emit it, tracked keeps references to destroyed objects until the stage is released. That would only matter for an app that opens and closes many windows or webviews over a long uptime, so it needs a check in the real-Electron run. Cleaning up at emit time would avoid it, for example dropping an object when its isDestroyed() is true.
  2. A held electron_displays trace can go stale. display-tracker.ts:118 returns undefined for an empty or unreadable list, so DisplaysProducer never publishes it. If the last display is removed (headless or remote-session edge case), the trace keeps showing the previous list. That follows the "absence is never zero" rule, but you may want it documented next to the trace spec.

Summary

  1. Overall risk: Low. The change is additive and opt-in per injected Electron object, and nothing attaches when captureSystemEvents is off.
  2. Merge recommendation: Approve and merge once the real-Electron run is done. The unchecked item covers per-OS event firing, the Display shape and re-emit timing.
  3. Most important items: the real-Electron verification, including the webContents destroyed behaviour from observation 1.
  4. Positives:
    • A clean extraction of the shared ElectronStageTracker base with reportTo deduplicated.
    • Careful handling of hostile or destroyed Electron objects and throwing getters.
    • No *.user stream writes, and no ids read beyond numeric ids (no titles or URLs).
    • Thorough unit and integration coverage, including the single-record hang case and the stop-releases case.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7c8d070d-dd33-4a5c-842c-ccff0cd59976
📥 Commits

Reviewing files that changed from the base of the PR and between a40e0f5 and ccb5928.

📒 Files selected for processing: 19
  • .changeset/electron-power-display-app-trackers.md
  • docs/PROGRESS.md
  • packages/bugsee/src/option-directions.test.ts
  • packages/bugsee/src/relaunch-options.test.ts
  • packages/electron/README.md
  • packages/electron/src/launch-main.test.ts
  • packages/electron/src/launch-main.ts
  • packages/electron/src/system-events.test.ts
  • packages/electron/src/system-events.ts
  • packages/electron/src/system-telemetry.integration.test.ts
  • packages/electron/src/system-traces.ts
  • packages/trackers/src/electron/application-tracker.test.ts
  • packages/trackers/src/electron/display-tracker.test.ts
  • packages/trackers/src/electron/display-tracker.ts
  • packages/trackers/src/electron/index.ts
  • packages/trackers/src/electron/power-tracker.test.ts
  • packages/trackers/src/electron/power-tracker.ts
  • packages/trackers/src/electron/stage-tracker.test.ts
  • packages/trackers/src/electron/stage-tracker.ts
🚧 Files skipped from review as they are similar to previous changes: 4
  • .changeset/electron-power-display-app-trackers.md
  • packages/electron/README.md
  • packages/trackers/src/electron/index.ts
  • packages/electron/src/system-traces.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

📝 Summary

Summary by CodeRabbit

  • New Features

    • Added Electron telemetry for power events, display changes, window focus and visibility, and renderer responsiveness.
    • Added display-list traces with screen dimensions and metadata.
    • Added optional integrations for power monitoring, display detection, and browser windows.
    • Added automatic listener management, cleanup, duplicate-event prevention, and support for newly created windows.
    • Added fail-closed handling for invalid window-event capture settings.
  • Documentation

    • Expanded Electron tracker and telemetry documentation, including configuration, lifecycle, privacy, and supported data.

The change adds Electron power, display, and application trackers. launchMain accepts injected Electron sources and connects available trackers to system-event forwarding and display tracing. Trackers attach listeners while observed and release them during cleanup. The change also adds tests and documentation for event mapping, display snapshots, launch lifecycle, and relaunch option handling.

Sequence Diagram(s)

sequenceDiagram
  participant ElectronPowerTracker
  participant ElectronSystemEventsSource
  participant SystemEventSource
  ElectronSystemEventsSource->>ElectronPowerTracker: subscribe to power events
  ElectronPowerTracker->>ElectronSystemEventsSource: emit power event
  ElectronSystemEventsSource->>SystemEventSource: forward mapped system event
Loading

Priority: ➖ Normal

Change: Feature

Merge Risk: ⚪ Minimal · up to ccb59

No actionable issue remains from this review; the change is ready for normal merge checks.

Security architecture risk: 🔵 Low · up to ccb59

New telemetry broadens collection within an Electron application, but the inspected paths limit payloads to selected metadata and enforce capture controls. No new privilege or identity-boundary bypass was established. Host-specific listener behavior and real Electron compatibility remain incompletely verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The added application collector has application-wide scope within the injected app: it discovers existing windows and later-created windows or webContents, rather than selecting a tenant or individual renderer. Renderer activity can influence responsiveness telemetry, but the inspected callbacks translate it into event names and numeric identifiers rather than executing renderer-supplied commands.

Trust Boundaries and Controls

  • observed — The existing shared option definitions normalize malformed captureSystemEvents and captureSystemTraces values to false. Electron additionally normalizes captureWindowEvents fail-closed before constructing its application tracker.
  • observed — Disabling system events does not disable display traces: the display trace producer retains its own three display-change listeners while traces remain enabled. The inspected integration test explicitly distinguishes these controls and expects no domain listeners when both capture options are false.

Resilience and Maintainability Implications

  • observed — Normal collection ownership is subscription-based. The multiplexer releases its subscriptions, and stage wrappers are made inactive before host listener removal. The inspected integration test asserts that stop releases the new power, display, window, and renderer listeners; tests were read, not executed in this review.

Hardening Proposals

  • proposed — Make stage attachment explicitly re-entrancy-safe and exercise synchronous callbacks during registration, including unsubscribe and resubscribe before attachment returns. This would strengthen cleanup ownership for alternate structural emitters; it is not a verified production capture-control bypass.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.17% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 20 files. (3 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: adding Electron power, display, and window trackers to the trackers and Electron packages.
Description check Passed The description directly explains the new Electron domain trackers, launch integration, event and trace behavior, tests, and known verification limits.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 54.17% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 20 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

…play id -1, add captureWindowEvents (#91 review)

Guards every host property read (Electron's real screen throws before app ready),
isolates each mux subscription so stop() always releases, documents the held
electron_displays caveat and platform-dependent power events.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@claude

claude Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Claude finished @krassx's task in 29s —— View job


Re-review of PR #91 after ccb5928e (the "#91 review" fix commit)

I read the new commit's diff for launch-main.ts, system-events.ts, system-traces.ts, and the display, power, stage and index tracker files. I did not run tests, lint or typecheck, because pnpm isn't available in this runner. I did not run anything against a real Electron either.

No new findings, so I posted no inline comments.

What the new commit changes, and what I checked

  • isReleasable / bindAll (stage-tracker.ts)
    • Property reads on the injected source are now guarded, and a throwing read is reported and answers false.
    • isReleasable is no longer a type guard. It now returns a plain boolean, and its only use here is inside bindAll.
    • every stops at the first failing binding, so the report fires at most once per attach.
  • attachStage is wrapped in a try/catch that reports. A hostile host object can no longer fail a subscriber or the launch, and the stage is retried on the next listener change or rebind.
  • current() in the display and power trackers now does the typeof … !== 'function' read inside the try block. The undefined and non-array/non-boolean fallbacks are unchanged.
  • mapDisplay drops id === -1 and keeps -10. The -1 check runs before the size check, which is fine. A display with no id returns undefined through the existing path.
  • ElectronSystemEventsSource.#sub
    • Each subscription is isolated. #offs is reset at the start of onActivate, so onActivate cannot throw.
    • One throwing on(...) no longer strands the inner node source's handlers or the other subscriptions.
    • This also removes the old assumption that onActivate throws part-way and still gets unwound.
  • captureWindowEvents (launch-main.ts)
    • It defaults to ON and is fail-closed through the existing resolveFailClosedBoolean. A non-boolean value turns it off and is reported.
    • It is destructured out, so it is not forwarded into nodeOptions or the relaunch option set.
    • The application tracker is skipped when it is off. app is still used for the process tracker, so app_metrics and child_process_gone are unaffected.
    • The non-boolean report is made before the repeat check. On a repeat launch it can still report, which is harmless.
    • The relaunch comment now lists all the Electron traces and events that stop after a relaunch. That matches the code.
  • Held electron_displays caveat and power-event platform notes are documentation only. They address observation 2 and the platform-dependence point from the earlier review.

Carried over from the earlier review (still open, non-blocking)

  1. 'destroyed' on webContents. application-tracker.ts forgets a webContents on 'destroyed'. This still needs a check in a real Electron run.
  2. CodeRabbit's low-severity note. Callbacks for closed or destroyed objects are not disarmed separately from native listener removal. I could not build a concrete failing scenario. Normal Electron teardown drops those objects.
  3. The real-Electron box in the test plan is still unchecked. That run covers per-OS event firing, the Display shape, and re-emit timing. I'd keep that as the merge condition.

Summary

  1. Overall risk: Low. The change is additive, and each domain is off unless its Electron object is injected. The new guards make failure modes quieter, not new.
  2. Merge recommendation: Approve and merge once the real-Electron smoke run is done. CI should confirm lint, typecheck and coverage, since I did not run them.
  3. Most important items: there are no code defects to fix. The remaining work is the real-Electron verification, including webContents 'destroyed'.
  4. Positives:
    • The fixes correctly handle Electron's behavior of throwing on property reads before app ready.
    • onActivate can no longer throw.
    • captureWindowEvents follows the repo's fail-closed boolean convention.
    • The commit added tests alongside each change (display, power, stage, application, launch and integration).
      · Branch: feat/electron-power-display-app-trackers

@krassx
krassx merged commit 9b05e36 into main Oct 20, 2026
krassx added a commit that referenced this pull request Oct 20, 2026
…o and Electron trackers merged)

Update §14.5/§15.5 to origin/main 9b05e36: TR8 (#87, #88) and TR9 (#90, #91) as built, owner decision on private-mode opt-out, captureUserIdle opt-in pending confirmation, unverified-Electron list, and the remaining plan.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
krassx added a commit that referenced this pull request Oct 29, 2026
…o and Electron trackers merged)

Update §14.5/§15.5 to origin/main 9b05e36: TR8 (#87, #88) and TR9 (#90, #91) as built, owner decision on private-mode opt-out, captureUserIdle opt-in pending confirmation, unverified-Electron list, and the remaining plan.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant