Repository navigation
feat(diagnostics): retain event-loop delays across health reads - #138249
Conversation
Record completed health-monitor windows through existing diagnostics so Prometheus and OpenTelemetry retain intervals consumed by earlier readers. Preserve readiness and lifecycle behavior and exclude reader trace identity. Cover cumulative retention, disabled consumers, queue and series limits, real SDK context handling, and managed-install Gateway authentication and graceful shutdown.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Producer/exporter split looks right. Publishing each completed observation window once preserves historical spikes without changing readiness semantics, and keeping the metrics free of request labels avoids attribution and cardinality problems.
Merge the landed RPC diagnostics owner with cumulative event-loop windows. Preserve exporter subscriptions, disabled-metrics behavior and trace isolation. Keep the event-loop Prometheus tests in their own file with a shared harness.
|
Codex review: blocked before merge. Reviewed September 4, 2026, 12:08 PM ET / 16:08 UTC. ClawSweeper reviewWhat this changesThe branch emits each completed Gateway event-loop health window once and exports cumulative delay and represented-duration metrics through Prometheus and OpenTelemetry. Merge readiness⛔ Blocked before merge - 2 items remain No blocking correctness or security defect was found. This current maintainer-authored PR remains open; the only unresolved review limitation is direct verification of the OpenTelemetry context API used by the new exporter call. Priority: P3 Review scores
Verification
How this fits togetherGateway health readers convert event-loop measurements into readiness and liveness snapshots. Completed windows now flow through the private diagnostics stream to enabled metrics exporters for operator monitoring. flowchart LR
A[Gateway health reader] --> B[Committed event-loop window]
B --> C[Private diagnostics stream]
C --> D[Prometheus exporter]
C --> E[OpenTelemetry exporter]
D --> F[Metrics scrape]
E --> G[Telemetry collector]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +74, Tests +620, Docs +53. Total +747 across 20 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the health monitor as the sole committed-window producer, preserve exporter-only collection and trace isolation, and verify the pinned OpenTelemetry context call against upstream source or types before merge. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds operator diagnostics rather than repairing a reported current defect. Is this the best way to solve the issue? Yes, subject to the remaining dependency check: recording at the health-monitor owner preserves completed windows before later readers can replace the snapshot, while existing exporters aggregate them. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 300c092d8b4a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Re-read the complete ClawSweeper review for 7aafc20 and verified the requested OpenTelemetry dependency contract directly. The pinned @opentelemetry/api 1.9.1 types declare Counter.add and Histogram.record with an optional Context as their third argument (build/src/metrics/Metric.d.ts:74,101); ROOT_CONTEXT is a Context backed by an empty BaseContext (context/context.d.ts:13; context.js:24–51). The pinned sdk-metrics 2.10.0 implementation forwards that third argument through Instruments.js:16–30,53–58,81–86. MultiWritableMetricStorage.js:19–25 and SyncMetricStorage.js:31–35 substitute ambient context only when none was supplied. Thus these calls retain ROOT_CONTEXT and do not inherit the health reader's active span. The installed package/importer lock entries and the recorder plus real-SDK test match this exact PR head. Existing service.event-loop.test.ts proof exercises a preloaded SDK under an active reader trace and checks that process-wide metrics have no reader trace attached. This is a fresh source/type audit of the pinned implementation, not a claim of another test run. It resolves both dependency-access checklist items and the Rank-up request; exact-head CI remains a separate landing requirement. Exact-head CI 33892086778, attempt 2, is now successful (111 successful jobs, 16 intentional skips). The prior unacquired-runner cancellation and old-head startup failure remain historical failure evidence. No policy or gate was bypassed. The retained 320-test composition proof used: node scripts/run-vitest.mjs src/gateway/server/event-loop-health.test.ts src/infra/diagnostic-events.event-loop.test.ts src/infra/diagnostic-events.test.ts src/infra/diagnostic-trace-context.test.ts src/plugins/services.test.ts extensions/diagnostics-otel/src/service.event-loop.test.ts extensions/diagnostics-otel/src/service.gateway-rpc.test.ts extensions/diagnostics-otel/src/service.test.ts extensions/diagnostics-prometheus/src/service.test.ts test/gateway-rpc-exporters.test.tsThe final 39-command changed-check coverage and P2 proof retain the qualifications already documented in the PR body; this is not a new full-wrapper or packaged-load run. Current main was checked through |
|
Merged via squash.
|
…penclaw#138249) Record completed health-monitor windows through existing diagnostics so Prometheus and OpenTelemetry retain intervals consumed by earlier readers. Preserve readiness and lifecycle behavior and exclude reader trace identity. Cover cumulative retention, disabled consumers, queue and series limits, real SDK context handling, and managed-install Gateway authentication and graceful shutdown.
…39247) Observe process close under the existing test lifetime instead of invoking the five-second forced reaper as the graceful-shutdown assertion path. Keep exact exit and signal assertions, forced teardown, and install/metrics coverage. Retain termination state and post-stop Gateway logs on failure. Follow up the graceful-shutdown coverage added in #138249.
…enclaw#139247) Observe process close under the existing test lifetime instead of invoking the five-second forced reaper as the graceful-shutdown assertion path. Keep exact exit and signal assertions, forced teardown, and install/metrics coverage. Retain termination state and post-stop Gateway logs on failure. Follow up the graceful-shutdown coverage added in openclaw#138249.
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Operators polling event-loop health can miss a high-delay interval when another readiness or status reader consumes it first. A later healthy snapshot can correctly show recovery while leaving cumulative monitoring without evidence of the earlier delay.
Why This Change Was Made
The health monitor publishes each completed observation window after committing its existing snapshot and baselines. The existing Prometheus and OpenTelemetry exporters retain maximum delay and represented duration cumulatively. Readiness and lifecycle decisions stay unchanged; existing diagnostics and consumer-interest gates control collection, with no new timer, configuration, dependency, store or public RPC.
The final composition incorporates the landed RPC diagnostics from #138015. It preserves both metric families, asynchronous delivery, exporter-only subscriptions, the metrics-disabled no-op meter, and exclusion of event-loop samples from traces-only consumers. Against integration base
068ef71bd20e0b22f92c26364b758551aa13363b, production is +80/-6 (net +74) for the cumulative measurement capability. Tests/support are +723/-103, including moved cases and a shared fixture; docs are +115/-62.User Impact
Operators using the existing diagnostics exporters can retain completed high-delay windows across later health reads and repeated scrapes:
openclaw_gateway_event_loop_delay_max_secondsandopenclaw_gateway_event_loop_observed_seconds_total.openclaw.gateway.event_loop.delay_max_msandopenclaw.gateway.event_loop.observed_ms.These metrics have no request or identity labels and do not create reader-attributed spans or logs. Counts and quantiles describe reader-defined window maxima, not individual stalls or native overall percentiles. Queue drops, series limits, export failures and process restarts still bound coverage; JavaScript stack and causal request attribution remain separate capabilities.
Evidence
c9199d919ca4d1a8075d322f5dbb11556d293f04had native-monitor/HTTP red-green proof, 426 focused tests, and an isolated managed-install Gateway E2E on Linux with Node 24.18.1 and pnpm 12.1.0. That run exercised real plugin installation and trusted runtime checks, rejected unauthenticated scraping, retained authenticated cumulative metrics across readiness reads, and exited cleanly within the existing five-second shutdown budget. The registry was synthetic and no provider/channel messages were sent. Original numeric-tuple, metrics-disabled fixture and test-file-size failures remain recorded as repaired, with their failed wrapper receipts preserved. This remains proof of its original source and dependency closure, not a new packaged-install or load test of the RPC composition.startup_failure. Those results are historical, not clearance for the composed head. Normal exact-new-head CI is still required after publication; no workflow or recovery policy was bypassed.