Skip to content

fix(openclaw): skip heavy register() side effects on cli-metadata pass (#5371)#5382

Open
Bartok9 wants to merge 1 commit into
mem0ai:mainfrom
Bartok9:fix/5371-register-cli-metadata-guard
Open

fix(openclaw): skip heavy register() side effects on cli-metadata pass (#5371)#5382
Bartok9 wants to merge 1 commit into
mem0ai:mainfrom
Bartok9:fix/5371-register-cli-metadata-guard

Conversation

@Bartok9
Copy link
Copy Markdown
Contributor

@Bartok9 Bartok9 commented Jun 5, 2026

Summary

Fixes #5371. The OpenClaw plugin loader invokes register() twice per gateway startup:

  1. A main pass with registrationMode: "full" (the real registration).
  2. A second pass with registrationMode: "cli-metadata", used only to collect CLI command metadata for openclaw mem0 help.

The mem0 plugin's register(api) never checked api.registrationMode, so it ran its full side effects on both passes:

  • emitted the openclaw-mem0: registered (...) info log line twice (visible in openclaw doctor),
  • constructed a second provider + Backend instance,
  • called api.registerService(...) and api.registerMemoryCapability(...) a second time,
  • fired the openclaw.plugin.registered telemetry event twice (double-counted).

Fix

Guard register() against the metadata pass. The cli-metadata pass still needs the CLI surface, so on that pass we register only the CLI commands (mirroring the existing needsSetup code path, with null backend/provider) and return early. Everything else — provider/backend construction, memory capability, service, lifecycle hooks, telemetry, and the registered log line — now runs exactly once on the "full" pass.

Cores that don't set registrationMode pass undefined, 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 helper isCliMetadataPass() and an early-return guard in register().
  • openclaw/openclaw-plugin-sdk.d.ts: document registrationMode on OpenClawPluginApi.
  • openclaw/index.test.ts: unit tests for isCliMetadataPass (full / cli-metadata / undefined / unknown modes).

Testing

  • pnpm test438 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 full pass.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openclaw-mem0: register() invoked twice per gateway startup without mode guard (full + cli-metadata passes)

1 participant