Repository navigation
feat(diagnostics): bundle diagnostics-otel by default, span pre-model setup, keep lane trace scope - #227
Conversation
A busy command lane dequeues the next task from the previous task's promise continuation, so the dequeued task inherited that task's AsyncLocalStorage context (diagnostic trace scope, session scope) instead of its enqueuer's. Capture AsyncLocalStorage.snapshot() at enqueue and run the task inside it. The field stays optional only for entries queued by an older module copy that shares the global queue state.
context.assembled now carries durationMs since run.started, and the diagnostics-otel exporter uses it as the span duration, so the openclaw.context.assembled span covers run start until the prompt context is assembled (session load, system prompt, context engine). The stability log records the same duration. Previously the span was a zero-duration marker and the time before the first model call was unattributed.
…efault Ship the diagnostics-otel plugin inside the openclaw npm package the same way sentry-monitor ships: drop the files exclude, add its @opentelemetry runtime deps as root deps because the root dist now owns the import, and mark the manifest enabledByDefault. The service stays a no-op until diagnostics.otel.enabled is true, so enabling OTLP export on a fleet gateway becomes config only with no separate plugin install. Remove the plugin from the official external plugin catalog and the optional-bundled-clusters list, make the workspace package private with no standalone publish or install blocks, delete its standalone npm-shrinkwrap, regenerate the plugin inventory docs, and update the OpenTelemetry docs and the tests that used diagnostics-otel as the external-plugin sample.
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
Dependency graph changes notedThis PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of
Security review is still recommended before merge when the dependency graph change is intentional. |
There was a problem hiding this comment.
All reported issues were addressed across 21 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Regenerate the root npm-shrinkwrap.json so the published package resolves the new @opentelemetry root dependencies, and whitelist @opentelemetry/* in the knip config next to @sentry/node because only the bundled plugin imports them. Update the Docker install docs, the OpenTelemetry quick start (plugins.allow note), and the plugin README to describe the bundled, enabled-by-default, config-only setup instead of a standalone ClawHub install.
augusteo
left a comment
There was a problem hiding this comment.
Review: approve (covers 6a4fb6f5 specifically)
Reviewed at module level per repo AGENTS.md (full changed modules + callers/callees + scoped guides), with local test execution as CI substitute. This token cannot read CI (/check-runs and statusCheckRollup 403), so reported green is taken as stated; I re-ran the load-bearing lanes locally.
1. Lane async-context fix (src/process/command-queue.ts) — verified RED-GREEN
- Mechanism confirmed in source:
pump()(line ~401) shifts entries and runs them from an async IIFE inside the previous task's continuation chain, so a dequeued task inherits the prior task's ALS context. The fix capturesAsyncLocalStorage.snapshot()at enqueue and runsentry.taskinside it inrunQueueEntryTask— correct use of the Node API (snapshot returns a fn-runner). Optional field rationale (legacy entries from an older module copy sharing the global singleton) matches the existing legacy-entry test. - RED-GREEN reproduced locally: swapped in
origin/boon'scommand-queue.ts, new test fails with the exact reported assertionexpected 'first' to be 'second'; restored, test passes. Full file 35/35. - Agree with the honest-note framing: defensive primitive fix, per-session gates serialize turns upstream. The unit test proves the primitive; no fleet claim needed.
2. openclaw.context.assembled duration — verified
- Sole emitter is
attempt.ts:4572;durationMs: Date.now() - diagnosticRunStartedAtwherediagnosticRunStartedAtis captured immediately after therun.startedemit (line 1198) — same clock base asrun.completed, so span nesting is coherent. spanWithDuration(service.ts:1973) mapsendTimeMs = evt.ts,startTime = end - durationMs; new service test asserts the 1500ms mapping end-to-end.diagnostic-stability.tspassesdurationMsthrough the sanitizer. Grep confirms no othercontext.assembledemitters broken by the now-required field; tsgo lanes clean locally.
3. Bundling packaging — verified against the sentry-monitor precedent
- Same shape as
sentry-monitor: manifestenabledByDefault: true, activation onStartup, runtime deps mirrored to rootdependencies(root dist owns the import — the extensions/AGENTS.md exception). The 11@opentelemetry/*root additions exactly match the extension's owndependencies;extension-runtime-dependencies.contract.test.tsgreen locally. filesexclude removal is the actual pack gate;shouldBuildBundledClusterno longer treats it as optional; removed from official-external catalog, optional-bundled-clusters, and wizard onboarding (tests updated to diagnostics-prometheus fixtures). Companionknip.config.tswhitelist entry present.- No-op guarantee verified in
service.tsstart(): early return unlessdiagnostics.otel.enabled(and content capture separately defaults off). - Allowlist compatibility verified in code, not docs:
config-activation-shared.tsruns theplugins.allowcheck before bundled default-enablement, so restrictive-allow installs keep the plugin off unless added — the follow-up commit documents exactly this.plugins.entries.diagnostics-otel.enabled: truelegacy configs still work (explicit/entry-enable paths unchanged). - Delta
f6a425fe..6a4fb6f5: all 4 cubic findings re-verified as fixed in code (rootnpm-shrinkwrap.jsonregenerated — spot-checked versions match pnpm-lock: api 1.9.1, sdk-node/exporters 0.219.0; docker.md/README rewritten; allowlist note added; knip whitelist). All 4 review threads resolved (GraphQL).
Local evidence (this host, worktree at f6a425fe; delta touched no runtime code)
vitest runon all 8 touched core/test files: 555/555 passed;extensions/diagnostics-otel/src/service.test.ts: 95/95.pnpm tsgo:core,pnpm tsgo:extensions: clean.- Not re-run locally: oxlint/oxfmt (reported), and
npm pack --dry-run0→6 files (needs a full dist build; mechanism verified instead — the files-exclude was the only pack gate).
Nits (non-blocking)
scripts/lib/official-external-plugin-catalog.jsoncarries formatter noise (unicode escapes, array re-wrapping) unrelated to the removal — fine, but it inflates the diff..github/workflows/docker-release.ymlstill passesOPENCLAW_EXTENSIONS=diagnostics-otel,codex; now redundant for diagnostics-otel (docker.md says so) but harmless as a prune keep-list entry.
Reviews from this host post as augusteo.
augusteo
left a comment
There was a problem hiding this comment.
Hermes Agent Review
Verdict: Approve — clean, well-scoped change with good test coverage. (Note: CI is still mostly queued at review time — 12 green, 0 failed, 80 pending — so merge should wait on the full run.)
What I checked
1. src/process/command-queue.ts — enqueue-context capture ✅
AsyncLocalStorage.snapshot()captured at enqueue and invoked at dequeue viaentry.runInEnqueueContext?.(entry.task) ?? entry.task()is the correct primitive-level fix for the continuation-context inheritance bug.snapshot()returns a(fn, ...args) => Rinvoker, so the call shape is right; a sync throw fromtask()still lands as a rejection insidePromise.resolve().then(...), preserving existing error semantics.- Making the field optional for legacy entries queued by an older module copy sharing the global singleton is a thoughtful migration guard.
- New unit test ("runs a queued task in the async context captured at enqueue") is genuinely red-before-fix and pins the exact regression.
2. durationMs plumbing (attempt.ts → diagnostic-events.ts → service.ts / diagnostic-stability.ts) ✅
- Field is required on the event type, set unconditionally at the single emission site, threaded through the stability recorder, and consumed by the OTel exporter (
spanWithDuration(..., evt.durationMs, { endTimeMs: evt.ts })) soopenclaw.context.assemblednow covers run start → prompt assembled instead of being a zero-duration marker. Assertions updated in both test suites with a red-before-fix duration check.
3. Bundling diagnostics-otel into the package ✅
- All the moving parts are consistent:
filesexclude dropped,@opentelemetry/*deps promoted to root (versions match the deleted standalone shrinkwrap), manifestenabledByDefault: true, workspace package madeprivatewith install/release blocks removed, standalone shrinkwrap deleted, external catalog + optional-bundled-clusters entries removed, knip config updated, inventory docs regenerated, and wizard/bridge tests re-pointed atdiagnostics-prometheusas the canonical external example. - Safe-by-default: service is a no-op until
diagnostics.otel.enabled, and existingplugins.entries.diagnostics-otel.enabled: trueconfigs keep working.
Nits (non-blocking)
- 💡
scripts/lib/official-external-plugin-catalog.jsonpicks up unrelated prettier reformatting (brave / llama.cpp / parallel / perplexity entries) — harmless, but adds diff noise. - 💡
attempt.tsuses wall-clockDate.now()fordurationMs— fine for diagnostics;performance.now()would be monotonic but this matches surrounding code.
Security
No new user-input surface, no secrets, no injection vectors. OTLP endpoint/headers remain config-driven.
LGTM pending green CI.
Rewrite scripts/lib/official-external-plugin-catalog.json from the original text so the diff only drops the diagnostics-otel entry, without the array re-wrapping and unicode escapes a JSON re-serialization introduced.
augusteo
left a comment
There was a problem hiding this comment.
Re-approve (covers ed2bbdb327d specifically)
Re-approving the new head. The previous approval (review 5225014763, on 6a4fb6f5) stopped counting because a later same-account review was dismissed, and GitHub takes the latest per-user review state. All prior verification (module-level review, local RED-GREEN on the lane fix, 555/555 + 95/95 tests, tsgo core/extensions) stands — the delta touches no runtime code.
Delta 6a4fb6f5..ed2bbdb327d verified: single commit, single file (scripts/lib/official-external-plugin-catalog.json), formatting-only. Net diff vs origin/boon for that file is now 0 added lines, 12 deleted lines, all inside the removed diagnostics-otel entry — the pure-deletion claim checks out. Catalog and wizard test changes are unchanged from the already-reviewed head, and the suites covering this file (official-external-plugin-catalog.test.ts, setup.official-plugins.test.ts) were green locally in the earlier run.
Reviews from this host post as augusteo.
…ugin sample diagnostics-otel is bundled now and no longer in the official external plugin catalog, so tests that need a trusted official ClawHub or npm install record (update command payload repair, manifest registry trust, npm update via catalog spec, dual-published release metadata) switch their sample to diagnostics-prometheus, which is still catalog-listed.
|
Delta ed2bbdb..a518529 verified from the review host: 4 test files, all diagnostics-otel -> diagnostics-prometheus sample swaps plus the dual-publish metadata entry removal; no runtime change. Sweep completeness checked: the one remaining diagnostics-otel install-sample test (missing-configured-plugin-install.test.ts) mocks its own catalog fixture, so it is catalog-independent. Ran the 4 changed suites plus 5 catalog-adjacent suites locally: 9 files, 507/507 green. Approval (review 5225063711) stands; reviewDecision reads APPROVED on this head. |
Routine release chore for the next train. Root package.json to 2026.6.11-boon.44, plugin package.json files synced via scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files regenerated via scripts/generate-npm-shrinkwrap.mjs --changed, and a CHANGELOG.md section for boon.44. Ships #225 (ENG-20103), #224, #228 (ENG-20090) and #227. No separately published plugin source changed since boon.43 (#227 moves diagnostics-otel into the gateway bundle), so a gateway roll delivers the whole release.
…226) Routine release chore for the next train. Root package.json to 2026.6.11-boon.44, plugin package.json files synced via scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files regenerated via scripts/generate-npm-shrinkwrap.mjs --changed, and a CHANGELOG.md section for boon.44. Ships #225 (ENG-20103), #224, #228 (ENG-20090) and #227. No separately published plugin source changed since boon.43 (#227 moves diagnostics-otel into the gateway bundle), so a gateway roll delivers the whole release.
What Problem This Solves
Boon fleet gateways run Sentry only: no performance traces, so per-turn bottlenecks (pre-model setup, model latency, tool time, delivery) cannot be drilled into. Upstream already ships a
diagnostics-otelplugin, but it is excluded from the npm package, so a fleet install cannot load it without a separate ClawHub/npm install step. Two gaps also limited what a trace would show even with the plugin on:enqueueCommandInLaneran dequeued tasks from the previous task's promise continuation, so a task queued behind a busy lane inherited the earlier task's async context (diagnostic trace scope) instead of its enqueuer's. Proven at the primitive level (unit test + tsx experiment); gateway E2E runs did not reproduce it because per-session gates serialize turns upstream of the lane, so this is a defensive fix of the primitive rather than a fleet-observed merge.openclaw.context.assembledwas a zero-duration marker, leaving the time from run start to the first model call unattributed (13.8s on a cold turn in the local E2E).Why This Change Was Made
src/process/command-queue.ts: captureAsyncLocalStorage.snapshot()at enqueue and run the dequeued task inside it. Field is optional only for entries queued by an older module copy sharing the global singleton (existing legacy-entry test).src/infra/diagnostic-events.ts,src/agents/embedded-agent-runner/run/attempt.ts,extensions/diagnostics-otel/src/service.ts,src/logging/diagnostic-stability.ts:context.assembledcarriesdurationMssincerun.started; the exporter spans it, soopenclaw.context.assemblednow covers run start -> prompt assembled.diagnostics-otelinto the package the same waysentry-monitoris bundled: drop thefilesexclude, add its@opentelemetry/*deps as root deps (root dist ships the import), mark the manifestenabledByDefault(the service is a no-op untildiagnostics.otel.enabled), remove it from the official external plugin catalog and the optional-bundled-clusters list, make the workspace package private with no standalone publish/install blocks, delete its standalonenpm-shrinkwrap.json, regenerate plugin inventory docs.User Impact
diagnostics.otel.{enabled,endpoint,headers,serviceName}), no plugin install. Existing configs that still setplugins.entries.diagnostics-otel.enabled: truekeep working.openclaw.context.assembledshows pre-model setup time; queued lane tasks keep their own trace scope.diagnostics.otel.enabledis unset.Evidence
pnpm test src/process/command-queue.test.ts35/35 (new: "runs a queued task in the async context captured at enqueue", red before fix:expected 'first' to be 'second').pnpm test extensions/diagnostics-otel/src/service.test.ts src/logging/diagnostic-stability.test.ts95/95 + 11/11 (new duration assertion red before fix:expected +0 to be 1500).pnpm test src/plugins/bundled-plugin-metadata.test.ts36/36 (empty-config startup list red before manifest change).pnpm test src/cli/plugins-location-bridges.test.ts src/infra/package-dist-inventory.test.ts src/plugins/contracts/extension-runtime-dependencies.contract.test.ts src/plugins/contracts/package-manifest.contract.test.ts src/plugins/official-external-plugin-catalog.test.ts src/plugins/prune-docker-plugin-dist.test.ts src/wizard/setup.official-plugins.test.ts src/dockerfile.test.tsall green.pnpm tsgo:core,pnpm tsgo:extensions,pnpm check:test-types, oxlint on changed files,oxfmt,git diff --check,node scripts/generate-plugin-inventory-doc.mjs --check: clean.npm pack --dry-run --json --ignore-scripts:dist/extensions/diagnostics-otel/files 0 -> 6.pnpm build, isolated gateway on 18999 with noplugins.*config, mock OpenAI Responses provider behind a 2.5s latency proxy, stub OTLP/HTTP collector decoding protobuf spans): plugin listed in startup plugins by default; twochat.sendturns on one session infollowupqueue mode produced two traces with distinct trace ids;openclaw.context.assembleddurations 13817ms (cold) / 121ms (warm) starting at run start (+1ms / +0ms), followed byopenclaw.model.call.--lockfile-only): +33 lines, root@opentelemetry/*entries only.Summary by cubic
Bundles
diagnostics-otelinto the OpenClaw package so OTLP export no longer requires a separate plugin install. The plugin is enabled by default but remains a no-op untildiagnostics.otel.enabledistrue.Tracing
openclaw.context.assemblednow spans run start through prompt assembly, attributing pre-model setup time.Packaging
@opentelemetry/*runtime dependencies to the root package and remove standalone install and release metadata.plugins.allowlists must includediagnostics-otel; existingplugins.entries.diagnostics-otel.enabledsettings remain supported.diagnostics-prometheus, which remains in the official catalog.Written for commit 86fcb8f. Summary will update on new commits.