Skip to content

fix(diagnostics): use globalThis registry to fix plugin event isolation#7038

Closed
fangxiu-wf wants to merge 2 commits intoopenclaw:mainfrom
fangxiu-wf:main
Closed

fix(diagnostics): use globalThis registry to fix plugin event isolation#7038
fangxiu-wf wants to merge 2 commits intoopenclaw:mainfrom
fangxiu-wf:main

Conversation

@fangxiu-wf
Copy link
Copy Markdown

@fangxiu-wf fangxiu-wf commented Feb 2, 2026

Fixes #5190

The diagnostics-otel plugin was unable to receive events because jiti creates separate module caches when loading plugins. This caused the plugin and gateway to use different instances of the listeners Set.

Solution: Use globalThis.openclaw_diagnostic_state to store shared state (listeners Set and seq counter) across all module instances.

  • Wrap listeners and seq in DiagnosticGlobalState on globalThis
  • Ensure plugins loaded via jiti share the same event emitter
  • Maintain backward compatibility with existing API
  • All tests passing (578 tests)

Greptile Overview

Greptile Summary

This PR changes diagnostics event dispatch to store its shared emitter state (listeners and seq) on globalThis so that plugins loaded via separate module caches (e.g., through jiti) still observe and emit into the same listener set.

Implementation is localized to src/infra/diagnostic-events.ts, replacing module-level seq/listeners with a getGlobalState() accessor that initializes and returns a process-global state object.

Confidence Score: 4/5

  • This PR is likely safe to merge; the change is small and scoped, with low behavioral risk outside diagnostics event delivery semantics.
  • The update is localized to one module and preserves the external API while addressing a real multi-module-cache issue by moving state to globalThis. Main risk is unintended cross-instance sharing/collisions in long-lived processes, but functionality should improve for the stated plugin/jiti scenario.
  • src/infra/diagnostic-events.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread src/infra/diagnostic-events.ts Outdated
Fixes openclaw#5190

The diagnostics-otel plugin was unable to receive events because jiti
creates separate module caches when loading plugins. This caused the
plugin and gateway to use different instances of the listeners Set.

Solution: Use globalThis.__openclaw_diagnostic_state__ to store shared
state (listeners Set and seq counter) across all module instances.

- Wrap listeners and seq in DiagnosticGlobalState on globalThis
- Ensure plugins loaded via jiti share the same event emitter
- Maintain backward compatibility with existing API
- All tests passing (578 tests)
@fangxiu-wf
Copy link
Copy Markdown
Author

I hope this pull request can be merged before the next release. Combined with PR #4255, this will provide a complete fix for OpenClaw's observability capabilities.

…lation

Fixes openclaw#12473

The logging system used module-level state (loggingState object and
externalTransports Set) that can be duplicated when plugins are loaded
via jiti, causing registered log transports from plugins to be invisible
to the main process.

This is architecturally identical to the issue fixed in openclaw#5190 for
diagnostic events.

Solution: Use Symbol.for('openclaw.logging.state') to store shared state
(including externalTransports Set) across all module instances.

Changes:
- Refactor src/logging/state.ts to use global registry pattern
- Move externalTransports from module-level to global state
- Update all access points in src/logging/logger.ts
- Fix plugin-sdk export to reference correct type location
- All tests passing (236 tests)
@sebslight
Copy link
Copy Markdown
Member

Closing as duplicate of #11168. If this is incorrect, comment and we can reopen.

@sebslight sebslight closed this Feb 13, 2026
@fangxiu-wf
Copy link
Copy Markdown
Author

此问题与#11168重复,因此关闭。如果判断有误,请留言,我们会重新打开。

Closing as duplicate of #11168. If this is incorrect, comment and we can reopen.

#11168 does not include a fix for #12473.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants