Skip to content

feat(diagnostics): retain compute worker heap and GC metrics - #179872

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-compute-pool-worker-metrics-20260919
Oct 21, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-compute-pool-worker-metrics-20260919

Conversation

@steipete

@steipete steipete commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Short-lived compute-pool workers can retire between diagnostics heartbeats, losing the heap and GC evidence needed to assess provider-prompt work.

User Impact

Operators can compare worker GC seconds and reclaimed heap bytes per completed task or agent turn after workers have retired. Labels use bounded worker class and script names. Reclaimed bytes are an allocation-pressure proxy, not exact allocation; high-water is retained sampled heap context. No config or schema changes.

Why This Change Was Made

Extend the existing worker registry, memory telemetry, native GC sampler, and Prometheus exporter. Terminal task replies carry only an enabled completion marker, without heap reads or another round trip. Healthy retirement flushes the final GC batch and heap high-water over the existing memory channel, with a 100 ms best-effort limit and synchronous retained-operation servicing. Crashes, cancellation, or a flush timeout can lose the last interval.

The existing native sampler drains worker batches every 100 ms while enabled; main remains at one second. This bounds native GC record conversion at retirement. It does not add a second sampler, registry, or per-task heap/GC sampling. Process-owned totals survive worker exits and exporter restarts. The docs list all five new series, limitations, and per-task/per-turn PromQL.

Evidence

Acceptance rule: real provider-prompt WorkerTaskPool history tasks, four clients, cheap and 256 KiB payloads, four bursts per phase, 20,000 timed samples per phase/side and 2,000 warmups. Two concurrent pairs under one exclusive slot, interleaved physical cores, swapped placements in pair 2. Reject >=20% adverse mean paired delta or >=10% adverse in both pairs. p99 gates only at >=1,000 samples/side; p95 only at >=200. Major GC is context below 50 collections/side.

PASS under v5: mean task latency +1.79%/+1.76%, total process CPU +3.02%; no metric meets either rejection condition. Cheap p95 (20,000 samples/side/pair) is +11.96% on the paired mean with opposite signs; this is reported, not treated as a regression under the stated rule. Every reply passed fingerprint verification. Each candidate retains 44,000 completed tasks after all workers close. All times below are milliseconds.

Workload / metric Pair 1 baseline → candidate Pair 2 baseline → candidate Mean paired delta
cheap / meanMs 0.0677 → 0.0660 (-2.49%) 0.0824 → 0.0875 (+6.08%) +1.79%
cheap / p50 (n=20,000/side/pair) 0.0575 → 0.0580 (+1.01%) 0.0551 → 0.0589 (+6.82%) +3.91%
cheap / p95 (n=20,000/side/pair) 0.0775 → 0.0753 (-2.82%) 0.1280 → 0.1622 (+26.74%) +11.96%
cheap / p99 (n=20,000/side/pair) 0.2263 → 0.2304 (+1.82%) 0.6571 → 0.6104 (-7.10%) -2.64%
cheap / elapsedMs 340.0888 → 331.6152 (-2.49%) 414.2118 → 439.4566 (+6.09%) +1.80%
cheap / cpuMs 1141.3060 → 1158.6590 (+1.52%) 1338.9810 → 1369.6170 (+2.29%) +1.90%
cheap / rotationMs (n=4/side/pair) 4.2558 → 4.4623 (+4.85%) 6.8121 → 8.1430 (+19.54%) +12.19%
history-256kib / meanMs 0.6093 → 0.6260 (+2.74%) 0.6109 → 0.6157 (+0.79%) +1.76%
history-256kib / p50 (n=20,000/side/pair) 0.5138 → 0.5243 (+2.06%) 0.5036 → 0.5035 (-0.00%) +1.03%
history-256kib / p95 (n=20,000/side/pair) 1.1271 → 1.1958 (+6.10%) 1.3634 → 1.2920 (-5.24%) +0.43%
history-256kib / p99 (n=20,000/side/pair) 2.6095 → 2.6524 (+1.64%) 2.6289 → 2.6651 (+1.38%) +1.51%
history-256kib / elapsedMs 3061.5362 → 3143.3474 (+2.67%) 3067.8558 → 3091.4306 (+0.77%) +1.72%
history-256kib / cpuMs 16132.8440 → 16674.6170 (+3.36%) 15267.7470 → 15801.4860 (+3.50%) +3.43%
history-256kib / rotationMs (n=4/side/pair) 4.3795 → 4.2851 (-2.16%) 4.0460 → 4.3384 (+7.23%) +2.53%

Total process CPU: pair 1 26014.001 → 26877.254 ms (+3.32%); pair 2 +2.72%; mean +3.02%. CPU includes warmup, setup, idle time, and retirement. Rotation means have four observations per side/pair and are not tail percentiles.

The candidate retained 1,230 GC collections in pair 1 and 1,172 in pair 2 after close (major counts 209 and 171). Baseline workers lose their final GC batch, so GC totals prove new coverage rather than a comparable GC/allocation A/B gate. No exact allocated-byte reduction is claimed. Both before/after deployment windows must have instrumentation enabled.

Earlier implementations were rejected, not averaged into this result: per-task profiler draining failed cheap-task p99 and both workloads' p95 gates; a one-second worker batch failed history rotation (+21.5% with full final memory samples, +29.8% with the minimal envelope). The final change deletes per-task sampling, discards unused retirement fields, and bounds worker batches using the existing timer. One attempted final-envelope pair failed the production event-loop guard and was discarded without using its measurements.

Reproduce: node --import ./scripts/tsx.mjs scripts/perf/worker-task-metrics-measure.ts --start-at <shared-future-epoch-ms> --output <result.json>. Linux/Node 26.12.1; base 604a2923292bd985e2f7ccdc19fea9360aed8bc2; unchanged benchmark copied to both sides. Later main rebases did not change any measured worker/prompt owner. Each side ran in a systemd scope with CPUWeight=10, IOWeight=10, MemoryMax=8G. Slot B sides were 64,66,…,94 versus 65,67,…,95, swapped in pair 2, under .quiet-b.lock. The shared read-only load/dirty/event-loop guard ran before and during each pair. Synthetic fixtures only; no Gateway or provider was contacted.

Proof

  • Focused worker registry, task server, diagnostic GC, Code Mode GC, and exporter text tests passed. The exporter test verifies retained counters without double-counting repeat heartbeats.
  • Package retirement tests passed (19), including native-section ordering and synchronous cleanup; registry/GC tests cover aggregation through retirement, final-batch ordering, timeout, and no duplicate batch.
  • The first CI run found the diagnostic-memory fixture missing the new required collection. Updated the fixture and its exact event expectations; all 30 tests in that file pass.
  • Changed-file formatting/lint, export-name collision and closure guards passed. Core typecheck passed using tsrs before the retirement refinements; exact-head PR CI owns broad validation. No Testbox/Crabbox lease was used.
  • Independent reviews of the initial change and every production refinement are clean at P0–P2.

Production grows by 285 lines to supply the explicitly requested retained telemetry and bounded retirement hook. The existing owners remain authoritative; no compatibility branch or alternate task protocol is kept.

Final CI run 39671608144 completed on 47596d4da3a9c9502eb8a6b46cee3d77cdd60c39. All non-aggregate jobs passed except the inherited UI gutter assertion below; the aggregate CI gate failed solely because of that job. Landing uses the authorized pre-existing-failure exception. The earlier diagnostic-memory fixture failure is fixed, and all typechecks now pass.

The PR job checks-ui-e2e (4/9) fails ui/src/e2e/chat-mobile-bubble-margin.e2e.test.ts:147, “preserves clawhub gutters across viewports and themes, restoring desktop geometry,” with clawhub at 390 px in light: expected 8 to be less than or equal to 0.5. Scheduled main run 39662150265, checks-ui-e2e (8/9) at a24b17a9227ac56eaf5bc83625429d5a31dd6446 has the identical case, line, and 8 px assertion. The file and its test helper have no changes between that main revision and this PR. This browser test uses a mock Gateway and tests desktop geometry restoration; the telemetry diff does not enter its path. Logs were inspected once; no CI rerun or new build was used to chase green.

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 21, 2026 20:23
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-21T20:48:04.517975Z 47596d4 New commits
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling extensions: diagnostics-prometheus size: L labels Oct 21, 2026
@steipete
steipete force-pushed the steipete/perf-micro-compute-pool-worker-metrics-20260919 branch 2 times, most recently from 959257c to 3a8b8c4 Compare October 21, 2026 20:32
Keep bounded per-class and script GC totals, reclaimed heap evidence, task counts, and sampled heap high-water after workers retire. Capture short-task GC in existing replies and reuse the worker registry and native sampler.
@steipete
steipete force-pushed the steipete/perf-micro-compute-pool-worker-metrics-20260919 branch from 3a8b8c4 to 47596d4 Compare October 21, 2026 20:35
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 21, 2026

@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: 47596d4da3

ℹ️ 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".

Comment thread src/infra/gc-observer.ts
// can sustain a collection loop. Native profiling only wakes JS on this cadence.
timer = setInterval(() => drain(true), 1000).unref();
// Bound worker batches so retirement does not drain a full second of native GC records.
timer = setInterval(() => drain(true), isMainThread ? 1000 : 100).unref();

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.

P2 Badge Scope the faster GC cadence to metric workers

In every worker isolate this changes the shared GCProfiler timer from one second to 100 ms. src/agents/code-mode-node.worker.ts installs an always-on observer at module load for GC-storm detection, so every live Code Mode worker now wakes JavaScript and stops/restarts the profiler ten times per second even when diagnostics and pool-task metrics are disabled. Keep the default cadence at one second and opt only metric-enabled pool workers into the shorter interval so unrelated Code Mode workloads do not pay this continuous overhead.

AGENTS.md reference: AGENTS.md:L64-L66

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 548a331 into main Oct 21, 2026
150 of 155 checks passed
@steipete
steipete deleted the steipete/perf-micro-compute-pool-worker-metrics-20260919 branch October 21, 2026 20:50
@steipete

Copy link
Copy Markdown
Contributor Author

Landed as 548a331 under the authorized pre-existing-failure exception.

On reviewed head 47596d4, all non-aggregate CI jobs passed except UI e2e shard 4/9. Its chat-mobile-bubble-margin.e2e.test.ts:147 failure — clawhub at 390 px in light: expected 8 to be less than or equal to 0.5 — matches scheduled main CI shard 8/9 exactly. The test and helper are unchanged; the aggregate gate failed downstream of this one inherited UI assertion. No CI rerun was used.

Focused tests, typechecks, independent review, and the v5 swapped-pair performance evaluation passed. The PR body contains the complete measurements and sample counts. The isolated benchmark sandbox has been removed.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…w#179872)

* feat(diagnostics): retain compute worker heap and GC metrics

Keep bounded per-class and script GC totals, reclaimed heap evidence, task counts, and sampled heap high-water after workers retire. Capture short-task GC in existing replies and reuse the worker registry and native sampler.

* perf(diagnostics): flush worker metrics at retirement

* perf(diagnostics): sample only retained fields at worker retirement

* perf(diagnostics): bound native GC batches before worker retirement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:feature Preliminary submission classification; full source review pending. docs Improvements or additions to documentation extensions: diagnostics-prometheus gateway Gateway runtime scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant