Skip to content

fix(diagnostics): allow captures on the supported Bun runtime - #166933

Merged
steipete merged 1 commit into
mainfrom
fix/diagnostics-runtime-capabilities
Oct 8, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/diagnostics-runtime-capabilities

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes CPU profiles, allocation profiles, and heap snapshots being rejected when the Gateway runs on OpenClaw's supported Bun runtime.

User Impact

Administrators can capture diagnostics on Node and the bundled Bun runtime with the existing authorization, cancellation, size limits, redaction, and cleanup behavior. Captures open no debugger listener. Bun heap-space readings describe its aggregate JavaScriptCore heap rather than separate V8 regions.

The shared runtime dependency is now satisfied: #167092 pins 42bd1d282ad16189ff71789ddbf81fa89dcd9d3a, including integral allocation accounting and snapshot metadata cleanup.

Why This Change Was Made

The shared diagnostics owner rejected Bun by runtime identity after the fork implemented the required native APIs. It now uses its existing capability and capture checks, with additional conflict detection for Bun's environment-started debugger, which can be absent from inspector.url().

Native CPU, allocation, and snapshot tests explicitly launch their current runtime and assert its identity. The V8 object-ID cleanup regression explicitly selects genuine Node, even when the suite runs under Bun. The fork's separate native regression proves JavaScriptCore snapshot metadata cleanup. The existing Windows CPU-smoke exclusion and the distinction between opt-in capture and lightweight memory heartbeats remain intact.

Evidence

Rebased without conflicts onto the shared-pin merge 4c099357f6f35c3cc0ecff8015c14141ff910f9b; range-diff confirms the diagnostics patch is unchanged. Qualified head: 3a46a8b73d581077eb62a98bd7801c65a2facffd.

Linux x64 (Node 24.19.0) and macOS arm64 (Node 24.21.0) each pass 112/112 on Node and 112/112 on pinned Bun 42bd, zero skips. Both Bun binaries were staged through the maintained pin-verification script. Each complete file ran once per runtime with isolated home/state/temp directories; no reruns, changed assertions, or raised limits.

Test file Cases Linux Node / Bun macOS Node / Bun
src/logging/diagnostic-cpu-profile.test.ts 41 35.49 / 32.05 s 35.24 / 27.43 s
src/logging/diagnostic-heap-profile.test.ts 21 23.36 / 27.00 s 23.53 / 17.85 s
src/gateway/server-methods/diagnostics.heap-snapshot.test.ts 9 38.64 / 34.00 s 34.48 / 23.17 s
src/logging/diagnostic-memory.test.ts 26 24.63 / 22.95 s 26.21 / 20.23 s
src/gateway/server-methods/diagnostics.cpu-profile.test.ts 15 25.97 / 28.71 s 26.15 / 18.28 s

Measured with the maintained Vitest wrapper and --maxWorkers=1, matching the original comparison. Native captures validate real output, runtime identity, attribution, private snapshot permissions, size limits, and listener-free cleanup; mocked writes cannot establish those contracts.

P2 AutoReview is scoped-clean. The previous pinned runtime produced 111 passes and one real heap-profile failure from fractional allocation sizes; that dependency evidence remains in the earlier qualification. The selected 42bd runtime contains both required native repairs.

Static validation: all selected typechecks, formatting, changed-file lint, repository guardrails, and both runtime/Madge import-cycle checks pass. The original changed-check run remains failed at the full-tree unused-export scan. The identical five-symbol failure reproduces on clean main 245b7f6fb2ad8974a5c481359635f9fa50070caf: LocalRemoteShellSpawnResult in src/agents/sandbox/remote-fs-bridge.test-helpers.ts, and TURN_MODEL_PERSISTED_CHANNEL_REF, TURN_MODEL_PERSISTED_PEER_REF, TURN_MODEL_SESSION_REF, and TurnModelSelectionPath in src/test-utils/turn-model-selection-differential.ts. Merged #167089 removed their last external users; neither defining helper is changed by this PR. All checks that followed the failed scan were executed separately and passed. No failure was rerun to green or suppressed.

Exact-head CI run 37762723772 passed on the exact reviewed head: 47 successful jobs, 25 intentional skips, and a green aggregate gate. Emitted CI wrapper costs: CPU-profile file 78.45s, heap-profile file 8.52s, Bun memory file 12.58s, and the shared Gateway-methods group 11.39s. The last number includes sibling files and is not a per-file snapshot/RPC timing.

Release-note context: diagnostics captures now support the bundled Bun runtime, with existing privacy and lifecycle limits retained. Known debugger, profiler, coverage, and tracing conflicts remain visible refusals.

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 6:23 AM ET / 10:23 UTC (Revision 2).

ClawSweeper review

What this changes

The branch enables CPU profiles, allocation profiles, and heap snapshots on OpenClaw’s Bun runtime while refusing environment-started debugger conflicts.

Example: An administrator requests diagnostics.cpuProfile on a Bun Gateway.

  • Before: The capture returns unavailable with reason unsupported.
  • After: The capture returns a sanitized CPU profile without opening a debugger listener.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation is useful and has no findings, with meaningful native boundary proof but no shipped-entry-point capture evidence.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): Contributor-recorded Linux and macOS runs exercise the production CPU, allocation, and snapshot owners with genuine Node and pinned Bun APIs, producing valid profiles and private snapshots without listeners. The previous native dependency gap is resolved by the merged 42bd pin; proof is at the native owner boundary rather than the shipped Gateway entry point, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes
User problem: Administrators running a Bun Gateway cannot capture CPU profiles, allocation profiles, or heap snapshots.
Reason: This extends an intentionally Node-only capability to the maintained Bun runtime. Prior merged area ownership establishes direction, and the implementation reuses the existing capture lifecycle.

Merge readiness

✅ Ready for maintainer review

This PR remains useful and has no actionable patch findings. The merged shared Bun update resolves the previous review’s runtime prerequisite; recorded native qualification supports the change, with ordinary exact-head CI still pending.

Priority: P2
Reviewed head: 3a46a8b73d581077eb62a98bd7801c65a2facffd

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No capture through the shipped CLI or a running Gateway is recorded; native child scenarios directly exercise the production capture owners. This read-only review did not execute a base/head regression comparison.
Agent review details

How this fits together

Gateway diagnostics let administrators inspect JavaScript CPU use and memory retention. A shared capture owner checks conflicts and request lifetimes, runs the native profiler, and returns sanitized profiles or metadata for private snapshot files.

flowchart TD
  A[Administrator diagnostic request] --> B[Gateway authorization]
  B --> C[Shared capture owner]
  C --> D[Debugger and lifetime checks]
  D --> E[Node or Bun native capture]
  E --> F[Native cleanup and validation]
  F --> G[Sanitized profile or private snapshot metadata]
Loading

Technical review

Best possible solution:

Use the existing shared capture owner with the qualified bundled Bun runtime, preserving its privacy and lifecycle contracts.

Do we have a high-confidence way to reproduce the issue?

Not applicable as an existing-behavior regression: Bun rejection was an explicit restriction, confirmed in current-main source.

Is this the best way to solve the issue?

Yes, extending the existing capture owner is the narrowest maintainable solution, and the required native runtime repairs are now selected by the merged shared pin.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against bcd0d15a431d.

Provenance checked

  • src/logging/diagnostic-profile.ts runtime admission changes intended behavior with a stated reason (8a55d87: Share CPU and allocation profiling lifecycle and redaction while refusing unsupported runtimes.)
  • src/logging/diagnostic-profile.ts debugger conflicts keeps the original intent (8a55d87: Avoid disturbing known debugger, profiler, coverage, and tracing owners.)
  • src/logging/diagnostic-heap-snapshot.ts and snapshot documentation keeps the original intent (32f13ef: Release retained native snapshot tracking through the shared profiler owner after capture.)
  • src/logging/diagnostic-memory.ts and troubleshooting guidance changes intended behavior with a stated reason (fedf378: Replace retired snapshot hints with supported diagnostics export, bundle inspection, and Node allocation-profile guidance.)
  • CPU and allocation native test runtime selection changes intended behavior with a stated reason (test: exercise OpenClaw fixtures under Bun #149699: Retain Bun’s unsupported capture contract while exercising the Node inspector lifecycle through mocks.)
  • docs/gateway/diagnostics.md heap-space interpretation keeps the original intent (b006608: Expose main-isolate V8 heap-space readings while excluding Bun from lightweight V8 heartbeat gauges.)

Testing

Proof path: in-process harness. Added test files: 4.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 8a55d87 adds src/logging/diagnostic-profile.ts:141 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8a55d87dd58d; files: src/logging/diagnostic-profile.ts)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +1, Tests +36, Docs +7. Total +44 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 3 8 7 +1
Tests 4 145 109 +36
Docs 2 22 15 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 175 131 +44

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This enables optional administrator diagnostics on a supported runtime with limited operational scope.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-08T03:28:51.780Z sha 35c3043 :: blocked before merge. :: none

Use the native profiling owner on Node and Bun while preserving admission, redaction, bounds, and cleanup. Exercise CPU, heap, and snapshot captures on the selected runtime, retain a genuine Node oracle for V8 tracking, and reject Bun environment-started debugger conflicts.

The consumer cutover depends on the shared Bun pin including openclaw/bun#140 and openclaw/bun#141. Node 24 and the combined fixed Bun pass all 112 targeted cases; the previous pin still fails the integral heap-profile contract.
@steipete steipete self-assigned this Oct 8, 2026
@steipete
steipete force-pushed the fix/diagnostics-runtime-capabilities branch from 35c3043 to 3a46a8b Compare October 8, 2026 10:18
@steipete
steipete marked this pull request as ready for review October 8, 2026 10:19
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Oct 8, 2026
@steipete
steipete merged commit 24af679 into main Oct 8, 2026
220 of 222 checks passed
@steipete
steipete deleted the fix/diagnostics-runtime-capabilities branch October 8, 2026 10:43
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…aw#166933)

Enable CPU profiles, allocation profiles, and heap snapshots through the existing diagnostics owner on the supported Bun runtime. Preserve debugger/tracing conflicts, authorization, cancellation, redaction, limits, and native cleanup; use the current runtime in native tests and genuine Node for the V8 object-ID regression.

The shared 42bd pin includes integral heap sampling and snapshot metadata cleanup. Linux and macOS each passed 112/112 diagnostics tests on Node 24 and pinned Bun, with zero skips. P2 review and exact-head ClawSweeper found no actionable issues; CI run 37762723772 passed. The unrelated local full-tree unused-export failure from openclaw#167089 was reproduced on clean main and retained in PR evidence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant