Repository navigation
Conversation
…on from it usockets records, per JavaScript thread, when its loop waits in the poll and for how long, how many events each poll returns, and how many iterations the loop has run. Only the thread writes these; other threads read them with atomic loads. A hook, unset unless the N|Solid agent runs, is called at the start of each outermost tick. perf_hooks uses them: nodeTiming.loopStart and nodeTiming.idleTime are the loop's, and eventLoopUtilization() is Node's (v26.3.0), where it returned zeros before. On the same script it now reads within a few percent of Node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
…d GC metrics, crash exits Phase 2 of the agent: a Bun process can be diagnosed from the N|Solid Console. - Event loop and GC metrics, per thread, as N|Solid defines them: loopIdleTime, loopIterations, loopIterWithEvents, eventsProcessed, eventsWaiting, providerDelay, processingDelay, loopUtilization, loopIdlePercent, loopAvgTasks, loopEstimatedLag, res5s to res15m, and gcCount, gcForcedCount, gcFullCount, gcMajorCount and gcDurUs (wall time of each collection; median and 99th percentile of the last 1,000). - The `profile` command: a CPU profile of any thread, started and stopped through JSC's shell-timeout trap, so a thread busy in JS answers at once. Gaps between samples are filled with (idle) where the loop waited, (garbage collector) where it collected, and (program) elsewhere. A profile running when the process exits is sent, and the exit names it. - The `snapshot` command: a heap snapshot in V8's format from our own builder on JSC's HeapAnalyzer interface. With redaction, which the Console always asks for, string nodes are named "(redacted)". It is written in 1 MiB chunks, and refused with N|Solid's 1005 when it would take more than half of the memory left (measured at about 240 bytes per heap cell). - Blocked loops: a 100 ms watchdog sends loop_blocked past blockedLoopThreshold with the thread's stack (source-mapped, 100 frames), then loop_unblocked with the iteration's length. A thread blocked outside JavaScript gets its event with an empty stack after 1 s, where N|Solid sends none. - nsolid.profile(), profileEnd(), snapshot(), enableAssets() and disableAssets() with N|Solid's signatures and status codes; heapProfile and heapSampling answer 404. - Crash exits: a segfault, abort or panic sends ExportExit with the signal, the crash's reason and its trace string, through the signal reporter. - Info carries the runtime and the commands and settings the agent supports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
…re the crash hook on Unix only The release build crashed (a null address) taking the snapshot in the redaction test, which the debug build passes. The builder asked JSC for a constructor name of every object, through each one's property lookup. Bun's own V8 builder does that only for plain objects with a realm; other objects, and closures compiled ahead of time, are named after their class. The builder now does the same, and skips edges JSC reports with no target or no name. Bun__NSolid__recordCrash is only called on Unix: declared everywhere, it was dead code on Windows, which mordant checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
…ntil the snapshot is written The collector hands the analyzer a property's or a variable's name that is only sure to live through the call. The snapshot is written after the collection, while allocations sweep the heap, and a name whose last holder was swept could be gone by then. Each edge now holds its name, as JSC's own V8 snapshot builder does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
edsadr
force-pushed
the
claude/nsolid-p2-diagnose
branch
from
December 4, 2026 14:57
64fee75 to
c61d906
Compare
edsadr
force-pushed
the
claude/nsolid-p2-diagnose
branch
from
December 4, 2026 15:09
c61d906 to
17aa8ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2 of nsolid-bun, the third PR of the stack:
main)Phase 2 makes a Bun process diagnosable from the N|Solid Console: CPU profiles and heap snapshots on demand for any thread, GC and event-loop metrics, and blocked-loop events with the stack that blocked. The Console-side Phase 2 work is in the Console repository, in a draft pull request of its own.
Phase 2 items
perf_hooks.eventLoopUtilization()profilecommand, through JSC's VM trap, with(idle),(program)and(garbage collector)samplessnapshotcommand: our own V8-format builder, redacted, chunked, with a memory guardnsolidmodule, part 2:profile,profileEnd,snapshot, the asset togglesInfoBodycarries the runtime and the agent's capabilitiesRebased on 2026-12-04 onto
mainat 6cab274, which brings in oven-sh/bun at 39b4945. The commit SHAs in this description are the rebased ones. What the rebase changed here: upstream movedus_loop_run_bun_tickintoloop.c, around oneus_internal_loop_waitfor epoll, kqueue and IOCP, so the loop timing moved there with it; and WebKit'sStringhas noutf8()now, so the snapshot writer callsmakeUTF8CString.What does this PR do?
Loop timing and
eventLoopUtilization(commit 124cf10)perf_hooks:nodeTiming.loopStartandnodeTiming.idleTimeare the loop's, andeventLoopUtilization()is Node's (v26.3.0). Before, it returned zeros. On the same script it now reads within a few percent of Node.The agent's Phase 2 (commit 94348a2)
loopIdleTime,loopIterations,loopIterWithEvents,eventsProcessed,eventsWaiting,providerDelay,processingDelay,loopUtilization,loopIdlePercent,loopAvgTasks,loopEstimatedLag,res5stores15m;gcCount,gcForcedCount,gcFullCount,gcMajorCount, andgcDurUs(median and 99th percentile of the last 1,000 collections).gcDurUsis each collection's wall time, from JSC's start to its end (decision P2-5), not the pause N|Solid measures.(idle)where the loop waited,(garbage collector)where it collected,(program)elsewhere. A mostly idle process shows mostly(idle).--cpu-profholds the profiler), 410 no such thread, 1003 failure.NSolidHeapSnapshot.cpp, on JSC's publicHeapAnalyzerinterface. It writes V8's format with V8's node types,snapshotfirst andstringslast, as the Console's scanner requires.(redacted), as N|Solid's are. Regexp sources are left out too.NSOLID_DISABLE_SNAPSHOTS), 409, 410, 1005.blockedLoopThresholdms (default 200,NSOLID_BLOCKED_LOOP_THRESHOLD, reconfigure).ExportBlockedLoopcarries the thread's stack, taken through the VM trap: script frames only, up to 100, 1-based and source-mapped asError.stackis.ExportUnblockedLoopfollows when the loop iterates again, with that iteration's length. One pair per episode.nsolidmodule, part 2 (layer 5):profile(timeout = 600000, cb),profileEnd(cb),snapshot(cb),enableAssets(),disableAssets(), with N|Solid's signatures, messages and status codes. The agent sends the assets with metadatareason: "Agent API".heapProfileandheapSamplinganswer 404.start()and the asset toggles now updatensolid.configat once.bun_coreonce only one thread is left reporting.ExportExitwith the signal (SIGSEGV,SIGABRT, ...) and the error, and acknowledges. The wait is 6 s at most.runtime(bun, its version,jsc, the agent's version) andcapabilities(the commands and settings the agent supports), the proposed fields 18 and 19.Fixes from CI (commits 7457466 and 17aa8ad)
How did you verify your code works?
bun bd test test/js/bun/nsolid/nsolid-agent.test.ts: all 42 tests pass on the debug build, with the whole file running concurrently (37 s). The 15 new ones cover:--cpu-prof, and the exit;profile,profileEndandsnapshot, with and without an agent;bun bd test test/js/node/perf_hooks/perf_hooks.test.ts: the neweventLoopUtilizationtest passes. "net entries are instanceof PerformanceEntry" fails here because this container has no IPv6; it is unrelated.Driven with
-e:eventLoopUtilizationreads idle 233 ms, active 108 ms on a script where Node reads 249 ms and 101 ms.The bun-types test passes, except the bindgen check, which needs WebKit's code generators that this container doesn't have.
Against a local N|Solid Console, with this debug binary and the Console's Bun end-to-end suite: all 10 tests pass. The Console:
(idle)labeled as JavaScriptCore's;loop_blockedrule grouped by agent, whose profile diagnostic completes and is linked from the alert;The first run had one failure, a race in the Console's test (it read the alert before the diagnostic was added to it). Fixed there.
64fee75, before the rebase: the snapshot tests pass on the debug build. The release crash is not reproduced locally (a release build does not fit this machine), so this PR's Linux x64 check is what confirms it.
Not done here:
After the rebase: every check passes at 17aa8ad, and
bun bd test test/js/bun/nsolid/nsolid-agent.test.tspasses on the debug build.Generated by Claude Code