Skip to content

fix(inspector): defer full garbage collection for local sessions - #95

Merged
steipete merged 6 commits into
mainfrom
claude/w116-inspector-heap-gc
Oct 3, 2026
Merged

steipete merged 6 commits into
mainfrom
claude/w116-inspector-heap-gc

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown

Problem

In-process node:inspector sessions reject HeapProfiler.collectGarbage, so applications cannot request a full collection from a main-thread or local-worker session. Posting with a callback before connecting also reports the connection error asynchronously, unlike Node.

Change

Implement HeapProfiler.enable, disable, and deferred full collectGarbage. A native event-loop task performs Bun's synchronous full collection after the posting JavaScript job unwinds, then resolves the request. This boundary also lets WeakRef targets lose the current-job keep-alive before collection. Successful callbacks receive (null, {}); disconnected pending requests receive Node's ERR_INSPECTOR_CLOSED on the next tick. Posting before connection throws synchronously for both overloads.

A worker session created with connect() collects that worker's VM. Collection through connectToMainThread() remains explicitly unsupported, avoiding a misleading successful collection of the worker heap. Heap allocation sampling remains unsupported: it requires a real JavaScript allocation sampler in JSC.

Validation

Built and tested on Linux x64 (release, no LTO). Node 24.21.0 is the callback/error oracle. The unpatched current-main build fails all seven new regression checks; two existing connection checks pass. The patched inspector-profiler file passes 52/52 tests, and the surrounding inspector suite passes 76/76. Tests cover callback timing, actual WeakRef collection with a strongly reachable control, local workers, promise sessions, and disconnect/reconnect behavior.

Measured test costs: inspector-profiler build-and-test command 0.765 seconds; surrounding inspector build-and-test command 1.016 seconds. Builtin TypeScript check passes in 4.421 seconds. Baseline build 195.994 seconds; first successful candidate build 200.900 seconds; subsequent type-only repair build 6.123 seconds. Scoped P2 branch review is clean. Repeated application-consumer qualification is tracked separately; this PR does not claim allocation-sampling support.

Upstream

Related: oven-sh#34719 provides broad inspector/CDP routing, including generic main-thread heap collection through the existing adapter. Its worker fallback and native scheduling boundary do not cover this change. This focused implementation is not a port of that PR. Upstream proposal: oven-sh#44549, covering deferred collection and local-worker sessions.

@steipete
steipete merged commit c999d9c into main Oct 3, 2026
7 checks passed
@steipete
steipete deleted the claude/w116-inspector-heap-gc branch October 3, 2026 15:57
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