fix(openclaw): skip heavy register() side effects on cli-metadata pass (#5371)#5382
Open
Bartok9 wants to merge 1 commit into
Open
fix(openclaw): skip heavy register() side effects on cli-metadata pass (#5371)#5382Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
mem0ai#5371) The OpenClaw plugin loader invokes register() twice per gateway startup: a "full" pass and a "cli-metadata" pass used to collect CLI command metadata for `openclaw mem0 help`. The mem0 plugin's register() did not check api.registrationMode, so on the metadata pass it constructed a second provider + backend, double-registered the service and memory capability, fired a duplicate openclaw.plugin.registered telemetry event, and emitted a duplicate "registered" info log line. Guard register() with isCliMetadataPass(api.registrationMode): on the metadata pass, register only the CLI commands (which that pass needs) and return early, so all other side effects run exactly once. Cores that do not set registrationMode are treated as a full registration for backwards compatibility. Adds registrationMode to the plugin SDK type and unit tests for the guard. Closes mem0ai#5371
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 #5371. The OpenClaw plugin loader invokes
register()twice per gateway startup:registrationMode: "full"(the real registration).registrationMode: "cli-metadata", used only to collect CLI command metadata foropenclaw mem0 help.The mem0 plugin's
register(api)never checkedapi.registrationMode, so it ran its full side effects on both passes:openclaw-mem0: registered (...)info log line twice (visible inopenclaw doctor),provider+Backendinstance,api.registerService(...)andapi.registerMemoryCapability(...)a second time,openclaw.plugin.registeredtelemetry event twice (double-counted).Fix
Guard
register()against the metadata pass. Thecli-metadatapass still needs the CLI surface, so on that pass we register only the CLI commands (mirroring the existingneedsSetupcode path, withnullbackend/provider) and return early. Everything else — provider/backend construction, memory capability, service, lifecycle hooks, telemetry, and theregisteredlog line — now runs exactly once on the"full"pass.Cores that don't set
registrationModepassundefined, which is treated as a full registration, so this is backwards compatible.This matches the maintainer-suggested fix in the issue.
Changes
openclaw/index.ts: add exported pure helperisCliMetadataPass()and an early-return guard inregister().openclaw/openclaw-plugin-sdk.d.ts: documentregistrationModeonOpenClawPluginApi.openclaw/index.test.ts: unit tests forisCliMetadataPass(full / cli-metadata / undefined / unknown modes).Testing
pnpm test→ 438 tests pass (15 files), including the 4 new guard tests.pnpm build→ success (ESM + DTS).npx tsc --noEmit→ clean.Diff is +74 / -0, no behavior change on the
fullpass.