Skip to content

feat(node,trackers): event_loop_utilization in percent; gc as a system event (C15, C16) - #100

Merged
krassx merged 6 commits into
mainfrom
feat/elu-percent-gc-event
Oct 21, 2026
Merged

krassx merged 6 commits into
mainfrom
feat/elu-percent-gc-event

Conversation

@krassx

@krassx krassx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • C16: event_loop_utilization is now PERCENT 0-100, one decimal (round(x*1000)/10), like cpu_usage_process. createGuardedElu converts perf_hooks' fraction; the tracker utilization stage payload is { utilizationPercent }; omit-never-zero is unchanged (Bun/Deno still omit on idle+active both 0). Breaking value change (beta).
  • C15: gc_count / gc_pause_ms / gc_pause_max_ms traces are retired. GC is the gc events.system event, params {count, pauseMs, maxPauseMs}, one per 1 s interval with at least one collection, nothing for a quiet interval. Node and Electron main only; Bun/Deno keep measuresGc:false (blind observer) and never emit it.
  • The node events source (createNodeSystemEventsSource(proc, { processTracker, onError }), wired in launch()) subscribes to the shared tracker's gc stage lazily (first event subscriber), releases on stop, attaches nothing with captureSystemEvents:false. The tracker still owns the single observer and arms it only while a gc listener exists, so there is no second observer.
  • Electron main composes the node source: verified through the mux that gc passes through once, untouched, with no extra subscription.
  • Tracker tweak needed by this: a stage the runtime cannot answer (gated off, NOOP) no longer keeps the shared sampling timer alive. Otherwise Bun/Deno would run an idle 1 s timer for the gc event they can never emit.
  • Behaviour note: the events source now arms the tracker's shared timer, so captureSystemTraces:false alone no longer means timer-free (needs captureSystemEvents:false too).

Test plan

  • Test-first; mutator loop run on every changed entity (percent math/rounding, stage mapping, producer, gc handler guards/params/name, lazy attach/release, error paths, launch wiring, timer rule); all killed, one equivalent line simplified.
  • pnpm ci:local green (lint, typecheck, cycles, per-package coverage gate, harness unit).
  • New tests: system-events (lazy, count>0 only, params, real-tracker e2e, Bun/Deno gate, error paths), launch (default launch records gc, captureSystemEvents:false never arms the observer, stop releases), electron mux pass-through, trace-producers (no gc traces, no observer), guarded ELU percent/rounding.

🤖 Generated with Claude Code

…m event (C15, C16)

C16: event_loop_utilization goes on the wire as percent 0-100 (one decimal); the tracker utilization stage payload is { utilizationPercent }.
C15: the gc_count/gc_pause_ms/gc_pause_max_ms traces are retired; the node events source emits a gc event {count, pauseMs, maxPauseMs} per interval with GC activity, lazily subscribed to the shared ProcessTracker gc stage. The tracker no longer keeps its sampling timer alive for a stage the runtime cannot answer.

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

claude Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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


Review of PR #100 (C15 / C16: ELU in percent, gc as a system event)

Scope reviewed: I read all 14 changed files and the code around them: ProcessTracker (rebind, #sync, #syncTimer, #tick, #makeRun), createGcSource, processTrackerFor, the Bun, Deno and Electron launch composition, and launch.ts. I also grepped for leftover consumers of the old gc_* traces, the { utilization } payload and the 0..1 ELU unit. I did not run the test suite or CI locally. This is a read-only static review.

Findings

No P0–P2 findings. I tried to break these scenarios and could not:

  • Bun/Deno gate ordering. measuresGc:false binds into the shared tracker when createNodeSystemTraceProducers is built in bun/launch.ts and deno/launch.ts. That call sits in the object literal, so it runs even if the caller overrides systemTraceProducers via ...options. launch.ts then calls processTrackerFor({}, onError), and rebind merges seams without dropping any. So the events source cannot arm a blind observer on Bun or Deno. The new #syncTimer rule also means they don't run an idle 1 s timer.
  • Empty-seam rebind. processTrackerFor({}, onError) with no seams leaves changed === false, so it does not call #stopAll() or tear down armed stages. It only swaps the error reporter.
  • ELU rounding. Math.round(f*1000)/10 is correct at the boundaries (0.42 → 42, 0.0004 → 0, 1 → 100). A truthful idle 0 is still distinct from the omitted Bun/Deno case, which is gated on idle/active in eluUnavailable.
  • Other consumers of the changed names. No non-test code reads the { utilization } payload or the gc_* trace names. The remaining hits are historical docs and changesets.
  • Event-source lifecycle. The gc subscription is lazy and made in onActivate. Release goes through a guarded onDeactivate, and a throwing tracker doesn't cost the process-lifecycle events.

P3 (Low), unreleased changeset contradicts the new one.

  • Location: .changeset/node-gc-traces.md (not touched by this PR) vs .changeset/gc-event-and-elu-percent.md.
  • Problem: node-gc-traces.md is still pending. It announces gc_count, gc_pause_ms and gc_pause_max_ms in traces.system, and omit-unavailable-elu.md describes ELU in the old unit.
  • Impact: If these ship in the same release, the generated CHANGELOG announces traces and then lists them as retired in the same version. It also describes ELU as a fraction.
  • Scenario: Run changeset version with all three files present.
  • Fix: Either reword node-gc-traces.md to describe the final state (a gc event, not traces), or fold it into the new changeset. A one-line note in omit-unavailable-elu.md that the unit is now percent would also help.

Observation, not a defect. The PR body already notes that captureSystemTraces:false alone no longer means timer-free. This is a real behaviour change for anyone relying on that. It also affects Node by default: every Node process now runs the shared 1 s timer plus the GC observer as long as captureSystemEvents is on. That looks intended, but it is worth one sentence in the user-facing docs, not just PROGRESS.md.

Summary

  1. Overall risk: Low.
  2. Merge recommendation: Approve, with an optional fix for the changeset wording. I can't formally approve as a bot.
  3. Most important issue to fix: The P3 changeset inconsistency above. There is nothing blocking.
  4. Positives:
    • The tracker keeps the single GC observer, and the lazy attach and release lifecycle is clean.
    • The "absence is never zero" rule is preserved through the unit change.
    • The new timer rule closes the Bun/Deno idle-timer hole it would otherwise have opened.
    • Test coverage is thorough: real-tracker e2e, the Electron mux pass-through, error paths, and the launch wiring with captureSystemEvents:false.
      · branch feat/elu-percent-gc-event

@coderabbitai

coderabbitai Bot commented Oct 21, 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: 84df4a25-c2ac-4076-98e2-5d391818064b
📥 Commits

Reviewing files that changed from the base of the PR and between fcab248 and e4491da.

📒 Files selected for processing: 9
  • docs/PROGRESS.md
  • packages/bun/src/launch.test.ts
  • packages/bun/src/launch.ts
  • packages/deno/src/launch.test.ts
  • packages/node/src/trace-producers.test.ts
  • packages/node/src/trace-producers.ts
  • packages/trackers/README.md
  • packages/trackers/src/node/process-tracker.test.ts
  • packages/trackers/src/node/process-tracker.ts
🚧 Files skipped from review as they are similar to previous changes: 2
  • packages/trackers/README.md
  • packages/bun/src/launch.ts

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

📝 Summary

Summary by CodeRabbit

  • New Features

    • Event-loop utilization is reported as a 0–100 percentage, rounded to one decimal place.
    • Node and Electron report garbage-collection activity as gc system events with rounded pause durations.
  • Changes

    • Garbage-collection metrics are no longer included in system traces.
    • Bun and Deno do not report garbage-collection events or event-loop utilization.
    • Sampling timers run only when needed, reducing unnecessary background activity.

Event-loop utilization is now reported as a 0–100 percentage with one decimal place and uses the utilizationPercent payload field. GC metrics are removed from Node system traces and emitted as gc system events for intervals with collections. Node launches pass a shared process tracker to the system-event source. Electron forwards those events; Bun and Deno do not emit them.

Sequence Diagram(s)

sequenceDiagram
  participant NodeLaunch
  participant NodeSystemEventsSource
  participant ProcessTracker
  participant SystemEventListener
  NodeLaunch->>NodeSystemEventsSource: Pass the per-launch process tracker
  NodeSystemEventsSource->>ProcessTracker: Subscribe to GC data during activation
  ProcessTracker-->>NodeSystemEventsSource: Provide GC interval measurements
  NodeSystemEventsSource-->>SystemEventListener: Emit gc for intervals with positive counts
Loading

Priority: ➖ Normal

Change: Feature

Merge Risk: ⚪ Minimal · up to e4491

The telemetry changes are mergeable after normal checks; no actionable issue remains identified.

Security architecture risk: 🔵 Low · up to e4491

The change is bounded to process telemetry, with shared observer ownership and lazy cleanup limiting exposure. It intentionally changes metric contracts and capture-setting behavior; downstream compatibility remains unverified. No introduced security attack path was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The added GC path measures aggregate activity of the SDK's host process, including workloads sharing that process. Workload can influence counts and pauses, but the publisher fixes the event name and numeric fields; it does not derive an identity, command or destination from those measurements.

Trust Boundaries and Controls

  • observed — The existing system-event capture option controls the provider subscription. GC attachment occurs during source activation and is released during deactivation. Runtime gating remains in the tracker, where measuresGc:false leaves the default GC source absent.

Resilience and Maintainability Implications

  • observed — The unchanged default GC source contains observer-construction and observation failures, disconnects partially created observers, and ignores late deliveries from stopped observers. The new Node subscription and cleanup paths guard failures so GC handling does not prevent process-event cleanup.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 15 files. (2 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 summarizes the two main changes: percentage-based event-loop utilization and GC system events.
Description check Passed The description directly explains the implementation, behavior changes, integration details, and test coverage for the pull request.
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 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 15 files. (2 skipped: 2 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.

Also drops the stale second orientationToWire argument in browser/system-events (main's #97 and #98 disagreed on the signature, so main's browser typecheck/build failed).

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

claude Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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


Re-review of PR #100 (C15 / C16: ELU in percent, gc as a system event)

Scope: I read the full diff against origin/main (15 files) and the surrounding code: ProcessTracker (#sync, #syncTimer, #tick, #stopStage), createGuardedElu, the Bun, Deno and Node launch composition, and the Electron main producer wiring. I also grepped for remaining consumers of the old gc_* traces and the { utilization } payload. I did not run the test suite or CI. This is a static, read-only review. There are no commits since my previous review, so I'm not repeating its findings.

New findings

None at P0–P2. I tried to break these and could not:

  • Bun/Deno measuresGc:false gate. bun/launch.ts:22-30 and deno/launch.ts:29-35 build createNodeSystemTraceProducers({... measuresGc: false}) inside the options literal, unconditionally. That means the gate is bound into the shared tracker before launch.ts:997 calls processTrackerFor({}, onError). This holds even when the caller sets captureSystemTraces:false, because the producer set is still built. The gc event source can't arm a blind observer there.
  • #syncTimer change (process-tracker.ts:334-335). Armed stages that are all NOOP_RUN clear the timer. #tick still iterates #armed, but with no timer it never runs, so the change is safe. A stage that is actually armed keeps the timer.
  • Quiet GC interval. count > 0 gates the emit (system-events.ts:102), so a quiet interval writes nothing. The payload is a fresh copy from #tick, so subscribers can't mutate tracker state.
  • ELU rounding. Math.round(f*1000)/10 is correct at the boundaries, and the omit-never-zero discriminator (idle/active) is unchanged.
  • Other consumers. Non-test code outside trace-producers.ts has no remaining readers of the gc_* names or the { utilization } payload. The remaining hits are historical design docs and changesets.
  • browser/src/system-events.ts orientationToWire call sites. They match the one-argument signature at system-trace-values.ts:71.

Still open from my earlier review (unchanged)

  • P3, stale changesets. .changeset/node-gc-traces.md still announces gc_count/gc_pause_ms/gc_pause_max_ms in traces.system. .changeset/omit-unavailable-elu.md still describes ELU as utilization: 0..1. If these ship in one release, the CHANGELOG announces the traces and then retires them in the same version. Reword the first to describe a gc event, or fold it into gc-event-and-elu-percent.md, and add a one-line unit note to the second.
  • Docs, not a defect. captureSystemTraces:false alone no longer means timer-free, because the events source now arms the shared 1 s timer and the GC observer. The PR body says so, but only docs/PROGRESS.md records it. One sentence in the user-facing option docs (launch.ts captureSystemTraces / captureSystemEvents JSDoc) would help.

Nit (P3, style)

Several comment edits were appended to the end of existing lines. This leaves very long lines in system-events.ts:14, trace-producers.ts:12 and trace-producers.ts:159, plus the guarded-event-loop.ts header comment. Re-wrapping them would match the surrounding style.

Summary

  1. Overall risk: Low.
  2. Merge recommendation: Approve. I can't formally approve as a bot, and nothing here blocks a merge.
  3. Most important thing to fix: The stale changeset wording (node-gc-traces.md, omit-unavailable-elu.md).
  4. Positives:
    • The tracker still owns the single GC observer, and the lazy attach and release lifecycle is clean.
    • A throwing tracker subscription doesn't cost the process-lifecycle events.
    • The "absence is never zero" rule survives the unit change.
    • Test coverage is broad: a real-tracker e2e, the Electron mux pass-through, error paths, and the captureSystemEvents:false launch wiring.
      · branch feat/elu-percent-gc-event

Rewrite the changesets (unreleased: no breaking note, drop the stale gc-traces one), round gc pauses to 3 decimals, omit invalid injected ELU readings, document the shared timer, and close the test gaps for gated stages, Bun/Deno and launch onError wiring.

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

claude Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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


Re-review of PR #100 (C15 / C16: ELU in percent, gc as a system event)

Scope: I read the full diff against origin/main (18 files, 5 commits) and the surrounding code: ProcessTracker (#syncTimer, arm/stop paths, the utilization stage), createGuardedElu, NodeSystemEventsSource, the launch.ts wiring and the changesets. I did not run the test suite or CI, so this is a static read-only review. I did not push commits or modify any files.

New findings

None at P0–P3 beyond the nit below. I tried to break these and could not:

  • #syncTimer NOOP rule (process-tracker.ts:333-336). The timer now stays up only if some armed stage is not NOOP_RUN.
    • A real stage arming later still reaches #syncTimer from #sync (line 304), so the timer starts.
    • Gated stages on Bun/Deno no longer keep an idle 1 s timer alive.
    • If the scheduler throws, #stopAll() still cleans up the observer.
  • Utilization stage guard (process-tracker.ts:455-465). A non-finite or negative reader result is now omitted. Injected readers that answer percent can't leak NaN or negative values onto the wire, and omit-never-zero holds.
  • gc event source (system-events.ts:103-118).
    • The count>0 gate means a quiet interval emits nothing.
    • A throwing tracker.on is reported via reportGuarded and doesn't cost the lifecycle events.
    • Release in onDeactivate is guarded, so a throwing release doesn't skip the process.off calls that follow.
  • launch.ts wiring. processTrackerFor({}, onError) passes no seams, so it doesn't rebind or tear down armed stages. The Bun/Deno measuresGc:false gate is already bound when their producer set is built, even if the caller overrides systemTraceProducers.
  • ELU rounding. Math.round(f*1000)/10 is correct at the boundaries. The Bun/Deno omission still discriminates on idle/active, so a truthful idle 0 is still reported.

Earlier findings: status

  • Stale changesets (P3): fixed.
    • node-gc-traces.md is deleted.
    • gc-event-and-elu-percent.md now describes the final state.
    • omit-unavailable-elu.md still quotes raw perf_hooks output (utilization: 0.0019). That is a description of the runtime's raw reading and the omit rule, so it isn't contradictory now that the new changeset states the percent unit.
  • captureSystemTraces:false no longer timer-free (docs): fixed. The JSDoc on captureSystemTraces and captureSystemEvents in launch.ts:282-293 now says so, and so does the changeset.

Still open (nit, P3 style)

Comment edits were appended to the end of existing lines, which leaves lines over 140 characters:

  • packages/node/src/system-events.ts:14
  • packages/node/src/trace-producers.ts:12
  • packages/node/src/trace-producers.ts:159
  • packages/trackers/src/node/guarded-event-loop.ts:123

Re-wrap them to match the surrounding style. Non-blocking.

Summary

  1. Overall risk: Low.
  2. Merge recommendation: Approve. I can't formally approve as a bot, and nothing blocks the merge.
  3. Most important thing to fix: Nothing is blocking. The only open item is the optional comment re-wrapping above.
  4. Positives:
    • The tracker keeps the single GC observer, with lazy attach and release.
    • Absence is never reported as zero, and that survives the unit change.
    • The timer rule closes the idle-timer hole on Bun/Deno.
    • Tests cover a real-tracker e2e, the Electron mux pass-through, error paths and the captureSystemEvents:false launch wiring.
    • Both earlier review items were addressed promptly.
      · branch feat/elu-percent-gc-event

Eight trace producers remain (gc moved to events, available-memory folded into ram_system_free).

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

claude Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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


Re-review of PR #100 (C15 / C16: ELU in percent, gc as a system event)

Scope: The only commit since my last review is the merge of origin/main (#99, ram_system_free semantics) into this branch (e4491daf). I re-read the full diff against origin/main and, around it, ProcessTracker (#sync, #syncTimer, #stopStage, #tick, NOOP_RUN sites), NodeSystemEventsSource, createGuardedElu, the producer composition in trace-producers.ts and the launch.ts wiring. I also grepped for leftover consumers of gc_*, ram_system_available and the { utilization } payload. I did not run the test suite or CI. This is a static, read-only review, and I pushed no commits.

New findings

None at P0–P3. I tried to break these merge interactions and could not:

  • feat(node,trackers): ram_system_free means memory available to new work (C6); retire ram_system_available #99 and the #syncTimer NOOP rule. The merge added the system-memory and ram_system_free readers to process-tracker.ts. The run !== NOOP_RUN check still reads correctly against them. The only NOOP_RUN sources are the gated-off or absent readers (lines 480, 486, 548). Any real stage still keeps the timer, and a gated-only set clears it.
  • Producer count. The merge message says eight producers remain. trace-producers.ts matches: the GcProducer is gone, and gc is reachable only through the events source.
  • Leftover references. No non-test code reads gc_count, gc_pause_*, ram_system_available or { utilization }. The remaining hits in docs/PROGRESS.md are historical notes.
  • ELU unit. The producer emits utilizationPercent (trace-producers.ts:104). The stage guard drops NaN, infinite or negative injected readings. The idle/active omit rule for Bun/Deno is unchanged.

Earlier findings: status

  • Stale changesets: fixed in an earlier push, and unchanged by the merge.

  • captureSystemTraces:false no longer timer-free: documented in the launch.ts JSDoc and the changeset.

  • Still open, non-blocking nit (P3, style): comment edits were appended to existing lines. Three lines are still over 140 characters, and the merge did not change them:

    • packages/node/src/system-events.ts:14 (184 chars)
    • packages/node/src/trace-producers.ts:12 (202 chars)
    • packages/node/src/trace-producers.ts:150 (161 chars)

    The guarded-event-loop.ts header comment was re-wrapped. Re-wrapping these three to match the surrounding style would finish the clean-up.

Summary

  1. Overall risk: Low.
  2. Merge recommendation: Approve. I can't formally approve as a bot. Nothing blocks the merge.
  3. Most important thing to fix: Nothing is blocking. The only open item is the optional comment re-wrapping above.
  4. Positives:
    • The tracker still owns the single GC observer, with lazy attach and release.
    • Absence is never reported as zero, and that survives the unit change.
    • The timer rule closes the Bun/Deno idle-timer hole.
    • The merge with feat(node,trackers): ram_system_free means memory available to new work (C6); retire ram_system_available #99 is clean: the producer set and the tracker rule stayed consistent.
    • Tests cover a real-tracker e2e, the Electron mux pass-through, error paths and the captureSystemEvents:false launch wiring.
      · branch feat/elu-percent-gc-event

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