Repository navigation
perf(diagnostics): avoid Gateway stalls when starting CPU profiles - #170932
Merged
steipete merged 2 commits intoOct 13, 2026
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Contributor
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
steipete
deleted the
steipete/perf-micro-cpuprofile-start-stall-20260919
branch
October 13, 2026 10:42
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 14, 2026
…penclaw#170932) * perf(diagnostics): reuse native CPU profiler for operator captures * fix(diagnostics): document native profile decoding invariant
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.
What Problem This Solves
Starting
diagnostics.cpuProfilestalls every Gateway user while a fresh inspector profiler scans V8's heap, even though the Gateway's stall flight recorder already has an active native sampler and code map.User Impact
On Node 26 with the stall flight recorder active, operator CPU captures join the existing native profiler and start without another heap scan. The five-second capture, 10 ms sampling interval, admin authorization, cancellation, cleanup, redaction and 1 MiB response limit remain in place. Node captures without an active native profile can still scan the heap; Bun retains its inspector backend.
Why This Change Was Made
A retained inspector Session does not retain V8's profiler after
Profiler.stop. Node'sv8.startCpuProfile()instead shares the runtime-owned profiler used by the recorder's overlapping windows. The shared capture owner now handles both native and inspector lifetimes, with all heap-profile and heap-snapshot callers migrated together. Native JSON decoding and numeric script-ID conversion have one shared implementation used by the RPC and recorder.Production LOC increases by 75 lines. The additional backend lifetime contract preserves the shipped Bun CPU, heap sampling and heap snapshot paths while keeping admission, authority and cleanup in one owner; it avoids duplicating those policies in a separate Node capture implementation. No new dependency, configuration option, persistent profiler or schema change.
Evidence
An isolated Linux sandbox on Node 26.8.2 ran the real dist Gateway, warmed
health,status,sessions.list,models.listanddiagnostics.lanes, and retained approximately 3.46 GB of synthetic objects. Three repeated RPC captures per variant:All completed captures returned valid sanitized graphs and samples. Enable/interval setup was below 0.3 ms; the repeated heap scan dominated startup. Standalone native profiling without an active recorder still took about a second on a 3.2 GB synthetic heap, establishing why sharing the already-active native profiler matters.
Validation: changed-file oxfmt and repo lint; focused CPU, heap, recorder, CPU RPC and heap-snapshot RPC tests with
--maxWorkers=1(101 tests passed across five focused files; the CPU test file took 9.74 s including its real five-second capture, and the latest two-file invocation took 42.50 s). Exact-head PR CI passed production/test typechecks, lint, ratchets, source and architecture guards, changed test lanes and selected UI E2E checks in 1,098 s elapsed (including queue time). The merged head is66022a6ba9ee64a026113650e96cf32c7f1c0612. No Testbox/Crabbox leases. independent subagent review (autoreview route unavailable); no actionable P1/P2 findings.The initial CI run identified a missing
SAFETYinvariant comment on the extracted native JSON assertion. The reviewed follow-up documents the V8-owned input shape without changing behavior; CPU and recorder tests were repeated (56 passed, 59.40 s wall time including compiler preparation).Release-note context: operator CPU profiling on Node reuses the Gateway's existing native sampler to avoid capture-induced main-thread stalls.