Skip to content

perf(runtime): stop GC telemetry from waking idle workers - #173574

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-gc-observer-loop-20260919
Oct 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-gc-observer-loop-20260919

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Prevents GC telemetry from scheduling event-loop work after every collection in idle Code Mode workers, other instrumented workers, and the main isolate. Related: #173306.

User Impact

Collection counts, kinds, elapsed durations, worker attribution, storm warnings, and the near-limit Code Mode thrash guard remain available. Native GC samples now use reason="other" because the native profiler does not expose callback flags; SDK-provided bounded reason labels remain supported. No configuration, schema, or deployment change.

Why This Change Was Made

Replace per-GC PerformanceObserver instances with one shared v8.GCProfiler per isolate, drained by an unreferenced one-second timer. Code Mode protection and exporter demand subscribe to the same sampler. The last subscriber drains and stops it; new subscribers do not receive earlier collections. Worker metrics retain their existing memory-port batching.

This removes the per-collection native/JavaScript immediate queue and duplicate Code Mode observers. Production delta: +7 lines; sharing sampler ownership and its stop/drain lifecycle is necessary to preserve continuous actual GC counts and durations. Heap size and ELU alone cannot supply those counters. Native profiling does record heap statistics internally, and Node releases stopped native profiler callbacks on subsequent GC rather than immediately; workload measurements below cover that tradeoff.

Evidence

Isolated Linux, Node 26.8.2, synthetic real Code Mode worker with 16 completed cells and metrics enabled; no production mutation. Before/after:

Measurement Before After
Idle major collections over 60 seconds 2 2
Idle GC time 10.72 ms 10.14 ms
Idle worker CPU 21.37 ms 29.32 ms
GC-triggered Immediate allocations in seeded 60-second regression 5 0
Major collections in seeded regression, including one deliberate GC 3 3
Median wall time, 200 allocating cells (five rounds after warmup) 171.00 ms 156.09 ms
Median process CPU for those rounds 350.03 ms 295.22 ms

Gap: the reported ~100 majors/second production storm did not reproduce in this sandbox. Idle collection frequency is neutral; this proves removal of the event-loop feedback mechanism, not a measured production storm reduction. The regression fails on the original observer because it schedules Immediate work, passes after replacement, and also enforces fewer than 10 majors over a real minute. That one-minute test is intentional: fake timers cannot exercise native idle GC scheduling.

Node's stock platform disables V8 idle tasks; schedule_idle is a callback flag, not evidence that worker idle deadlines execute immediately. Source inspection: Node platform, GC observer delivery, native GC profiler.

Focused local proof only (one worker): diagnostic-gc.test.ts 6 passed / 7.82 s; code-mode-node.gc.test.ts 1 passed / 3.30 s; Node code-mode-node.test.ts 15 passed / 16.44 s, including zero-duration near-limit retirement/recovery; Node code-mode-node.watchdog.test.ts 3 passed, 1 Linux-only test skipped / 84.90 s including compiler-cache preparation and the real 60-second idle interval. Changed-file oxfmt, scoped repository oxlint, and git diff --check pass. Broad build/typecheck/suites belong to PR CI; no Testbox/Crabbox lease used.

Simplification pass completed. Independent subagent review (autoreview route unavailable): clean, no actionable P0/P1/P2 findings. The configured autoreview provider selector was refused before launch; operator configuration was not changed.

CI and inherited failure attribution

Exact head f9fb71bc659d32452ac711fc387ad56bf6dbee2c, CI attempt 1: all selected checks passed except checks-node-changed-14 and its downstream openclaw/ci-gate. The sole failed file was test/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts, case settles required native empty workspaces and same-session follow-ups through public RPC. Security, production/test types, scoped lint, docs, other Node shards, and UI checks passed. No CI rerun.

Replayed only that file using Node 24.19.0, private-QA runtime build preparation, unprivileged processes, two CPU cores per run, synthetic state, and isolated loopback network namespaces. Exact CI main parent: 012bb1ccaf0b63696b2608599b1cf4ea869a4245. Exact tested merge: 0dde71949ebe75efd257f2596943394f63d42943; verified ordered parents and merge tree.

Same failure signature PR CI Tested merge replay Main-parent replay
Assertion implicit-main after-agent-wait run failed before settlement same same
agent.wait error for REQUIRED-NATIVE-0-A WorkspaceAccessUnavailableError: Remote workspace skill discovery failed same same
First native HTTP request reached No No No
File duration 84.78 s 60.30 s 67.20 s

The tested merge passed once and reproduced the exact failure on its second run. The unchanged main parent passed runs 1, 3, and 4; run 2 exposed a separate live-dispatch-owner failure; run 5 reproduced the exact CI failure above. These are inherited failures, not five clean replays. Earlier root-owned sandbox attempts were invalid for this fixture because workspace quiescence rejects root-owned worker sessions; they are excluded from attribution.

Command: OPENCLAW_E2E_USE_PREBUILT_DIST=1 OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts --maxWorkers=1. Required build preparation: OPENCLAW_BUILD_PRIVATE_QA=1 node --import ./scripts/tsx.mjs scripts/build-all.mts qaRuntime (both pinned revisions passed).

The failing test, remote-workspace adapter, pairing checks, and skill-discovery owner are unchanged between the main parent and tested merge. Its fixture has no GC exporter subscription, and the failure precedes native inference/Code Mode execution. Landing under the explicitly authorized inherited-failure exception; the failed CI run remains red. Follow-up: stabilize native workspace skill discovery during startup; the separate baseline dispatch-owner failure also needs attention.

The automated review's test-cost finding was considered and declined with a recorded reply: the requested real 60-second idle regression intentionally remains in PR coverage because fake clocks cannot exercise native V8 idle GC scheduling.

@clawsweeper

clawsweeper Bot commented Oct 16, 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 agents Agent runtime and tooling size: M labels Oct 16, 2026
@steipete
steipete marked this pull request as ready for review October 16, 2026 00:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T00:07:16.682534Z f9fb71b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9fb71bc65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@steipete

Copy link
Copy Markdown
Contributor Author

Companion containment is in #173577. It leaves gc-observer.ts untouched and consumes the same observeGcSamples contract: two consecutive storm windows (at least 10 seconds each, above 600 majors/minute) send a small retirement signal through the existing memory port. The Code Mode pool lifecycle retires completed warm workers or marks active/parked workers draining until their existing settlement/expiry. Admission is bounded to one draining worker per minute.

The two PRs have no overlapping files. Your one-second sampler preserves the detector input this safety net needs; no observer implementation is duplicated. Synthetic detector/transport and lifecycle regressions pass (23 tests), with four expected failures against the original implementation. Neither PR claims a reproduced native crash or measured elimination of the production storm.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR replaces per-collection GC callbacks with a shared native profiler sampled once per second.

Example: A Node Code Mode worker finishes 16 allocating cells and then remains idle.

  • Before: The supplied seeded probe records 5 GC-triggered Immediate allocations.
  • After: The same probe records 0 Immediate allocations while retaining 3 major-collection observations.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, narrowly scoped sampler replacement with production-owner harness evidence and one concrete test-routing defect.
Proof confidence 🦐 gold shrimp (3/6) The supplied maintainer-authored classification exempts ordinary contributor proof gating; the body supplies synthetic Linux Node 26.8.2 worker measurements and native regression results, without claiming a shipped Gateway reproduction of the production storm.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: GC instrumentation schedules JavaScript work after collections in otherwise idle workers and the main isolate.
Reason: The maintainer-directed change removes the demonstrated wakeup mechanism through one existing owner and explicitly limits its production-storm claims.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this PR provides useful maintainer-directed performance work absent from main, with one test-lane defect to repair.

Priority: P2
Reviewed head: f9fb71bc659d32452ac711fc387ad56bf6dbee2c

Before merge

  • Move the one-minute native probe into the release-only test lane (P2) - Every ordinary Node run selecting this watchdog file now waits for the fixture's real 60,000 ms timer; the Bun gate does not exclude regular Node testing. This adds at least a minute to focused runs and CI selections, contrary to the applicable test cost policy. Preserve the native regression in a separate file registered in RELEASE_ONLY_RUNTIME_TEST_FILES in scripts/lib/ci-proof-test-inventory.mts, leaving the existing fast watchdog tests in their current lane.

Findings

  • [P2] Move the one-minute native probe into the release-only test lane — src/agents/code-mode-node.watchdog.test.ts:23-26
Agent review details

How this fits together

The isolate-local sampler supplies GC counts and durations to the Code Mode pressure guard and diagnostics publishers, which forward worker samples through existing memory ports to metric exporters.

flowchart LR
  A[Native V8 collections] --> B[Shared GC profiler]
  B --> C[One second sampler]
  C --> D[Code Mode pressure guard]
  C --> E[Diagnostics publisher]
  E --> F[Worker memory port]
  F --> G[Metric exporters]
Loading

Technical review

Best possible solution:

Retain the shared sampler and move the native one-minute regression into a separately registered release-only test file.

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

Current-main source schedules per-GC JavaScript callbacks, and the supplied real-worker probe reports their removal after replacement; the reported high-frequency production storm remains unreproduced, and this review executed no target code.

Is this the best way to solve the issue?

Sharing a native sampler at the existing observation boundary addresses per-GC wakeups across consumers; the documented reason-label tradeoff is intentional and the long regression needs different test routing.

Full review comments:

  • [P2] Move the one-minute native probe into the release-only test lane — src/agents/code-mode-node.watchdog.test.ts:23-26
    Every ordinary Node run selecting this watchdog file now waits for the fixture's real 60,000 ms timer; the Bun gate does not exclude regular Node testing. This adds at least a minute to focused runs and CI selections, contrary to the applicable test cost policy. Preserve the native regression in a separate file registered in RELEASE_ONLY_RUNTIME_TEST_FILES in scripts/lib/ci-proof-test-inventory.mts, leaving the existing fast watchdog tests in their current lane.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Shared GC observer and worker attribution changes intended behavior with a stated reason (95e3daf: Provide actual collection counts, durations, kinds, and worker attribution through existing diagnostics transport.)
  • Native GC reason labels changes intended behavior with a stated reason (138e763: Expose bounded callback flags for investigation of Code Mode storms; this PR explains why the replacement native API reports other instead.)
  • Code Mode idle-GC and pressure fixtures keeps the original intent (afdb098: Prove Code Mode does not request inspector full collections while retaining natural GC and pressure protection; the existing assertions remain.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/code-mode-node.watchdog.test.ts --maxWorkers=1
  • pnpm test src/agents/code-mode-node.idle-gc.test.ts --maxWorkers=1
  • git diff --check

What I checked:

  • Introduced change and current main: The pinned introduction replaces the observer implementation; fetched main still uses PerformanceObserver, so the central change remains necessary. (src/infra/gc-observer.ts:50, f9fb71bc659d)
  • Existing consumers retain one sampling owner: Code Mode pressure detection, main-isolate diagnostics, and worker telemetry consume observeGcSamples without introducing a competing observer. (src/infra/gc-observer.ts:25, f9fb71bc659d)
  • Maintainer-directed tradeoffs and scoped evidence: The supplied maintainer-authored body explicitly accepts native reason="other", profiler heap-statistics overhead, and deferred native callback cleanup; its measurements demonstrate removal of per-GC Immediate work without claiming reproduction or elimination of the production storm. (f9fb71bc659d)
  • Authoritative native profiler contract: The patch imports node:v8.GCProfiler and relies on its restart and duration contracts. Node's JavaScript wrapper creates a fresh native profiler on start after stop, while native cost is expressed in microseconds; callback removal occurs in the native destructor. (lib/v8.js:522, f2f2c2f246c3)
  • Regular test-lane cost: The new test is gated only on Bun and waits for a real 60-second worker timer. The cost policy places long compositions in the release-only tier; this test is absent from RELEASE_ONLY_RUNTIME_TEST_FILES. (src/agents/code-mode-node.watchdog.test.ts:25, f9fb71bc659d)
  • CI failure remains unattributed: The failing Node job reports an implicit-main after-agent-wait settlement failure in required-native-same-session.e2e.test.ts; available annotations establish neither a patch-caused defect nor inheritance, so no repair is assigned from that failure. (test/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts:474, f9fb71bc659d)

PR surface

Source +7, Tests +69, Docs +7. Total +83 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 52 45 +7
Tests 5 172 103 +69
Docs 2 20 13 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 244 161 +83

Review metrics

Metric Value Why it matters
Production versus test LOC Production +52/-45; tests and fixtures +172/-103 Net production growth of 7 lines consolidates sampler ownership; test growth exercises native idle behavior and preserves telemetry and pressure-guard coverage.

Labels

Label changes:

  • add P2: This is a focused runtime performance improvement with a concrete regular-test cost regression, without evidence of an urgent production outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This is a focused runtime performance improvement with a concrete regular-test cost regression, without evidence of an urgent production outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 execution lanes are retired.

Reviewed October 15, 2026, 8:17 PM ET / October 16, 2026, 00:17 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Landing under the operator-authorized inherited-failure exception for exact head f9fb71bc659d32452ac711fc387ad56bf6dbee2c.

CI attempt 1 has one root failure: checks-node-changed-14, file test/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts. Its aggregate gate is the only other failed job; all other selected checks, including security-fast, passed.

The exact unchanged main parent 012bb1ccaf0b63696b2608599b1cf4ea869a4245 and tested merge 0dde71949ebe75efd257f2596943394f63d42943 both reproduce the same assertion and error:

implicit-main after-agent-wait run failed before settlement
REQUIRED-NATIVE-0-A: status=error
WorkspaceAccessUnavailableError: Remote workspace skill discovery failed
No native-HTTP-entry observed

Node 24.19.0, unprivileged isolated Linux replay, single failing test file: matching failure took 67.20 s on main parent and 60.30 s on tested merge (CI: 84.78 s). Full repetition outcomes and commands are in the PR body; this is not a claim that CI or all replays passed. No CI rerun. The relevant fixture, adapter, pairing checks, and skill-discovery source blobs are identical across the tested merge boundary.

Independent review is clean; the real-minute test-cost finding was explicitly considered and answered. Using the operator's exact-head REST fallback because the native merge wrapper provisions a separate canonical PR worktree outside this fixed lane. Production was not modified.

@steipete
steipete merged commit 9a8ef35 into main Oct 16, 2026
220 of 225 checks passed
@steipete
steipete deleted the steipete/perf-micro-gc-observer-loop-20260919 branch October 16, 2026 00:39
steipete added a commit that referenced this pull request Oct 16, 2026
The GC profiler fixture introduced in 9a8ef35 (#173574) added an
unbound-method suppression that failed the main suppression ratchet.
Give the captured native stop function its explicit GCProfiler receiver
contract, retaining stop.call(this) and the zero-duration GC pressure probe.
The suppression allowlist and every existing assertion remain unchanged.
No production runtime or update behavior changes.

Node 24 focused proof: watchdog 3 passed / 1 existing Linux-only skip
(131.18s file time including compiler preparation and the real idle interval);
explicit executor consumer 15 passed (pnpm test src/agents/code-mode-node.test.ts
--maxWorkers=1, 83.57s command wall). The combined selector omitted the executor,
so it was run explicitly. Owning agents-tools types, type-aware/boundary lint,
format, and independent P2 review passed.

Suppression ratchet: before 1 failed / 2 passed (12.84s command wall), with this
entry and the independent warm-reload probe entry; after, only
scripts/lib/control-ui-warm-reload-probe.ts remains. No allowlist extension.
check-changed passed its other static gates but exposed unrelated UI render
types and unused exports. Main's 56c3151 fixes render; its failed UI type
graph passed after fast-forward integration. Knip's unrelated unused exports
remain recorded in the lane evidence. No workflow reruns or extra pushes for green.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
The GC profiler fixture introduced in 4f0ce6b (openclaw#173574) added an
unbound-method suppression that failed the main suppression ratchet.
Give the captured native stop function its explicit GCProfiler receiver
contract, retaining stop.call(this) and the zero-duration GC pressure probe.
The suppression allowlist and every existing assertion remain unchanged.
No production runtime or update behavior changes.

Node 24 focused proof: watchdog 3 passed / 1 existing Linux-only skip
(131.18s file time including compiler preparation and the real idle interval);
explicit executor consumer 15 passed (pnpm test src/agents/code-mode-node.test.ts
--maxWorkers=1, 83.57s command wall). The combined selector omitted the executor,
so it was run explicitly. Owning agents-tools types, type-aware/boundary lint,
format, and independent P2 review passed.

Suppression ratchet: before 1 failed / 2 passed (12.84s command wall), with this
entry and the independent warm-reload probe entry; after, only
scripts/lib/control-ui-warm-reload-probe.ts remains. No allowlist extension.
check-changed passed its other static gates but exposed unrelated UI render
types and unused exports. Main's a11e38b fixes render; its failed UI type
graph passed after fast-forward integration. Knip's unrelated unused exports
remain recorded in the lane evidence. No workflow reruns or extra pushes for green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant