Repository navigation
Conversation
Release V8 object-move tracking through the shared diagnostic capture owner after heap snapshots. Run runtime lifecycle cleanup at the first plugin instance disposal so reload and install replacement do not retain old subscriptions and buffers. Document that RPC snapshots reset object IDs and preserve snapshot-time heap metadata. Native regressions, plugin recovery coverage, the changed-file gate, build, and Node 26.10.0 synthetic Gateway measurements passed remotely.
steipete
marked this pull request as ready for review
October 7, 2026 17:52
steipete
enabled auto-merge (squash)
October 7, 2026 17:55
steipete
deleted the
steipete/perf-micro-diagnostics-gc-and-buffer-side-effects-20260919
branch
October 7, 2026 18:07
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 8, 2026
…openclaw#166683) Release V8 object-move tracking through the shared diagnostic capture owner after heap snapshots. Run runtime lifecycle cleanup at the first plugin instance disposal so reload and install replacement do not retain old subscriptions and buffers. Document that RPC snapshots reset object IDs and preserve snapshot-time heap metadata. Native regressions, plugin recovery coverage, the changed-file gate, build, and Node 26.10.0 synthetic Gateway measurements passed remotely.
This was referenced Oct 24, 2026
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
Heap snapshots leave a long-lived Gateway doing extra work on every moving GC, and plugin replacement can retain retired plugins' subscriptions and buffers by skipping their runtime cleanup callbacks.
User Impact
Diagnostic snapshots release V8 tracking before returning. Reloading or updating a plugin runs its registered runtime/session cleanup before disposing the old instance, allowing the replacement to acquire shared resources and release retained buffers.
Clearing V8's object-ID map means separate RPC snapshots support individual retaining-path analysis, but not identity-based cross-snapshot comparisons. Use one continuously attached debugger in an isolated process for stable IDs. Snapshot files remain private and local, with the existing heap limit and cooldown. Snapshot capture now shares the existing profiler conflict checks and mutual exclusion. No configuration or schema changes.
Why This Change Was Made
writeHeapSnapshot()releases the in-memory snapshot object after serialization but leavesHeapObjectsMapand object-move tracking active.HeapProfiler.disableclears both (Node 26.10.0 V8 snapshot owner, inspector cleanup). The snapshot owner now uses the existing diagnostic capture lifecycle, including disable/disconnect on failure, instead of maintaining a separate capture lock. Post-capture heap metadata is still sampled synchronously before file metadata I/O.Plugin reload previously called
instance.dispose()before registry retirement supplied the host cleanup callback; retirement then saw an already-disposing instance and skipped that callback. The first disposal now invokes the existing lifecycle callback loop through one extracted owner operation. Scheduler and persistent-state retirement retain their later ordering, when the successor's declarations are available.Production delta: +45 lines (147 added / 102 removed, excluding tests, test support, and docs). The lifecycle callback loop is moved, not duplicated. Growth is required to separate early callback cleanup from later scheduler/persistent-state retirement and pass that cleanup into first disposal; combining these phases would change retained-state semantics. The independent snapshot lock/cleanup path is removed.
Evidence
Real
distGateways on Node 26.10.0, with a 512 MiB synthetic numeric heap plus retained objects and steady allocation churn. Linux AWS measurements use jemalloc 5.3.0. No production snapshots or profiles were taken.The snapshot comparison keeps allocation throughput steady (57.4–59.4 million objects/min). A literal-allocation control becomes dominated by major collections, consistent with pretenuring, and shows a smaller effect (0.355 → 0.426 / 0.387 s/min); the persistent young-allocation fixture exposes the moving-GC cost directly.
A separate 60-second sampling heap profile did not reproduce a leak: external memory 10.235 → 10.233 MB, ArrayBuffers 5.700 → 5.700 MB, returned profile 25,337 bytes, and the isolate-global sampler reports inactive after completion. No sampling production change is made. The earlier observed external-memory step remains unattributed. ESM module-level allocations can also remain in Node's module cache; explicit cleanup of plugin-owned payloads is still necessary.
Validation provider/lease:
aws,cbx_b57cabd385a4(r7a.large, 16 GiB), following a Blacksmith sync timeout. Initial native probes, build, and control rigs ran onblacksmith-testbox,tbx_01m4bcfj1vp6rmvq1x0a1xz6ar(runner).pnpm test <file> --maxWorkers=1remote wall times: snapshot 32.93 s, heap profile 31.47 s, recovery 62.88 s. Added native-state case 0.54 s and added runtime-lifecycle case ~0.3 s of test time; no new suite/process boots for the reload case. Hosted CI run 37662483327 passed on head905cef204b41df607ce6690d986fec29eb9af8e9in 784 wall seconds (13m 04s); its 34 Node jobs used 9,781 aggregate job seconds, with a 659-second longest shard. These are the full selected CI workload costs, not the incremental cost of the new assertions.node --import ./scripts/tsx.mjs scripts/check-export-name-collisions.mts: passed.node scripts/run-vitest.mjs test/scripts/eager-import-closure.test.ts test/scripts/pr-wrapper-source-closure.test.ts: 20 passed (included above). No new test file.node scripts/check-changed.mjs --staged: passed on the final source, including production types, all 27 test type graphs, source guards, dead-export scans, lint, and import cycles.pnpm build: passed in 4m 11.9s on the final source. The first gate passed types/source guards and found one missing-braces lint error in the new test; that error is fixed.The final combined AWS run (
run_cae9451499155d52cd6bbdc0c1ac3c25) completed with exit 0. Its initial coordinator receipt POST returned HTTP 500;crabbox receiptsubsequently returned the signed terminal record confirming exit 0 and an untruncated retained log. No workload rerun was needed. Both final rigs passed after the build:node --import ./scripts/tsx.mjs .local/lane609/rig-moving.mjs snapshot …andnode --import ./scripts/tsx.mjs .local/lane609/plugin-rig.mjs cjs true … runtime. The isolated synthetic fixtures were task-local.