fix: share one TelemetryService across repeated register() calls#8
Open
yzdong wants to merge 1 commit intoknostic:mainfrom
Open
fix: share one TelemetryService across repeated register() calls#8yzdong wants to merge 1 commit intoknostic:mainfrom
yzdong wants to merge 1 commit intoknostic:mainfrom
Conversation
OpenClaw may call plugin.register(api) multiple times per plugin
lifetime — e.g. once for CLI plugin metadata, once for the full
gateway load. The previous code instantiated a fresh svc inside
register(), so:
- start(ctx) sets fileWriter on instance A
- api.on("before_tool_call", ...) hooks fire on instance B, whose
fileWriter is still null
- every write() silently no-ops, and ~/.openclaw/logs/telemetry.jsonl
is never created
Hoist svc to module scope with a null-coalescing init so every
register() call wires hooks to the same service that receives
start()/stop(). Verified via a 20s bounded agent session: events
land in telemetry.jsonl as expected.
Also updates README to:
- Fix the config file path (openclaw.json, not config.json)
- Clarify that plugins.entries.telemetry.config MUST contain a
nested `{"enabled": true}`; without the inner config object
start() bails silently and no events are written. This was the
most common misconfiguration we hit during CRUX-Windows setup.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
index.ts,svcis instantiated insideregister(api):OpenClaw calls
register()multiple times per plugin lifetime (CLI metadata load, then gateway full load — observed 4+ calls in 2026.4.15). The result:start(ctx)setsfileWriteron instance Abefore_tool_call/after_tool_call/ etc. hooks fire on instance B, whosefileWriteris stillnullwrite()silently no-ops;~/.openclaw/logs/telemetry.jsonlis never createdNo error surfaces — users see "plugin loaded" in
openclaw plugins list, no events.Fix
Hoist
svcto module scope with a null-coalescing init. Allregister()calls wire hooks to the same service that receivesstart()/stop().Verification
Bounded 20-second agent session after applying the fix:
telemetry.jsonlcreated, 5 events (agent.start ×2, tool.start read, tool.end read, agent.end)Also included
config.json→openclaw.json(the actual file name)plugins.entries.telemetry.config.enabled(the nested field) must betrue, not just the outerplugins.entries.telemetry.enabled. Misconfiguring this was the most common silent-failure mode we saw during a real experiment setup; adding a troubleshooting note up front.Update (2026-04-21) — field evidence
This fix has been used in a real multi-day production run: CRUX-Windows (reproduction of the CRUX #1 capability eval on the Microsoft Store). 77h 48m of wall-clock, ~2,700 agent messages, ran cleanly with telemetry capture the whole way. Full scrubbed traces are public on Docent: https://docent.transluce.org/dashboard/0c8eb800-22da-49ae-b017-2315382ed539
A separate regression we noticed during that run
Tool events (
tool.start/tool.end) flow correctly in the post-fix plugin, butagent.usageevents are not being captured. Across 140M+ tokens of model usage, zeroagent.usageevents appear intelemetry.jsonl. This means cost telemetry via the plugin is incomplete in current OpenClaw versions.This is a different bug from the svc-singleton issue this PR fixes — likely a missing or broken hook registration on the
llm.usage/agent.usagepath. I have not isolated the root cause yet, but wanted to flag it here in case it's within scope to fix in the same pass. Happy to open a separate issue/PR if preferred.Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com