Repository navigation
feat(diagnostics): retain compute worker heap and GC metrics - #179872
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
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. |
959257c to
3a8b8c4
Compare
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.
3a8b8c4 to
47596d4
Compare
There was a problem hiding this comment.
💡 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".
| // 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(); |
There was a problem hiding this comment.
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 👍 / 👎.
|
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 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. |
…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
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.
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; base604a2923292bd985e2f7ccdc19fea9360aed8bc2; 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
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,” withclawhub 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) ata24b17a9227ac56eaf5bc83625429d5a31dd6446has 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.