fix: share diagnostic event listeners across module bundles#11168
Closed
jg-noncelogic wants to merge 2 commits intoopenclaw:mainfrom
Closed
fix: share diagnostic event listeners across module bundles#11168jg-noncelogic wants to merge 2 commits intoopenclaw:mainfrom
jg-noncelogic wants to merge 2 commits intoopenclaw:mainfrom
Conversation
9b4d0c7 to
cfef716
Compare
18 tasks
bfc1ccb to
f92900f
Compare
2088424 to
9181a86
Compare
Open
16 tasks
9181a86 to
7d606f0
Compare
When the plugin-sdk is bundled separately from the main gateway code, each bundle gets its own `listeners` Set. This causes events emitted by the gateway to never reach plugin subscribers. Fix by using globalThis to share the listeners registry across all module instances, ensuring plugins receive diagnostic events properly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
697b441 to
90b94d0
Compare
Make the narrowing intent explicit so future TS changes or refactors cannot introduce a type error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
16 tasks
4 tasks
Contributor
Author
|
Closing — upstream has since implemented globalThis-based sharing for diagnostic event listeners (via |
2 tasks
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
Fixes #5190
When the plugin-sdk is bundled separately from the main gateway code, each bundle gets its own
listenersSet indiagnostic-events.ts. This causes events emitted by the gateway to never reach plugin subscribers usingonDiagnosticEvent().Root cause: The bundler inlines the diagnostic-events module into both
dist/plugin-sdk/index.jsand the main gateway bundles, creating separate module instances with independent state.Fix: Use
globalThisto share the listeners registry across all module instances, ensuring plugins receive diagnostic events properly.Test plan
pnpm test src/infra/diagnostic-events.test.ts)🤖 Generated with Claude Code
Greptile Summary
This PR fixes a bug where diagnostic event listeners in plugins (e.g.,
diagnostics-otel,audit-neon) never received events emitted by the gateway. The root cause was that the bundler inlineddiagnostic-events.tsinto both the plugin-sdk bundle and the main gateway bundle, creating separate module instances with independentlistenersSets andseqcounters.The fix replaces the module-scoped
let seqandconst listenerswith a sharedglobalThis-backed state object keyed by"__openclaw_diagnostic_events__". AgetGlobalState()helper lazily initializes the shared state on first access and returns the existing state on subsequent calls from any bundle.src/infra/diagnostic-events.ts— movesseqandlistenersinto aDiagnosticGlobalStateobject stored onglobalThisemitDiagnosticEvent,onDiagnosticEvent,resetDiagnosticEventsForTest) are updated to use the shared state referenceglobalThisusage in the codebase (e.g.,src/web/test-helpers.ts)Confidence Score: 5/5
Last reviewed commit: 4df7815