fix: share diagnostic event bus across bundle chunks via globalThis#18894
Closed
aiwithabidi wants to merge 1 commit intoopenclaw:mainfrom
Closed
fix: share diagnostic event bus across bundle chunks via globalThis#18894aiwithabidi wants to merge 1 commit intoopenclaw:mainfrom
aiwithabidi wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Open
16 tasks
Member
|
Closing as duplicate of #11168. If this is incorrect, please contact us. |
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.
Summary
The diagnostic event bus in
src/infra/diagnostic-events.tsuses module-level variables (let seqandconst listeners = new Set()). When Rolldown (or tsdown) splits this module into separate chunks — one for the gateway and one for the plugin-SDK — each chunk gets its own copy of these variables. The gateway emits events to onelistenersSet, while plugins (likediagnostics-otel) register on a different one. They never meet, so zero diagnostic events reach any plugin.This PR replaces the module-level state with a
globalThis[Symbol.for()]singleton, ensuring a single shared bus across all chunks in the same process. This is the same pattern already used insrc/plugins/runtime.tsfor the plugin registry (REGISTRY_STATE).Changes
src/infra/diagnostic-events.tslet seq+const listenerswith aglobalThis[Symbol.for("openclaw.diagnosticEventBus")]singletonemitDiagnosticEvent,onDiagnosticEvent,resetDiagnosticEventsForTest) reference the sharedbusobjectRoot Cause
dist/pi-embedded-*.js(gateway)listeners$1dist/plugin-sdk/reply-*.js(plugins)listeners$1Two separate Sets — events emitted to one are invisible to the other.
Fix Pattern
Test Plan
diagnostic-events.test.tstests pass (same public API)pnpm buildsucceeds —Symbol.for("openclaw.diagnosticEventBus")appears in all relevant output chunksdiagnostics-otelplugin — confirmed the OTel plugin initializes and receives eventsdiagnostics-otel: logs exporter enabled (OTLP/HTTP)in gateway logs after processing Telegram messagesGreptile Summary
Fixes diagnostic event bus isolation caused by Rolldown chunk splitting by replacing module-level
seqandlistenersvariables with aglobalThis[Symbol.for()]singleton. This ensures the gateway and plugin-SDK share a single event bus instance at runtime.let seqandconst listenerswith a sharedglobalThis[Symbol.for("openclaw.diagnosticEventBus")]singleton objectsrc/plugins/runtime.ts(REGISTRY_STATE)emitDiagnosticEvent,onDiagnosticEvent,resetDiagnosticEventsForTest) continue to work identicallytypeof globalThis &intersection instead ofas any, consistent with project style guidelinesConfidence Score: 5/5
any.Last reviewed commit: 77b8387
(2/5) Greptile learns from your feedback when you react with thumbs up/down!
Context used:
dashboard- CLAUDE.md (source)