Skip to content

fix: cache plugin initialization to prevent re-init on every tool call (fixes #12)#29

Closed
kagura-agent wants to merge 1 commit intosupermemoryai:mainfrom
kagura-agent:fix/12-plugin-re-initializes-on-every
Closed

fix: cache plugin initialization to prevent re-init on every tool call (fixes #12)#29
kagura-agent wants to merge 1 commit intosupermemoryai:mainfrom
kagura-agent:fix/12-plugin-re-initializes-on-every

Conversation

@kagura-agent
Copy link
Copy Markdown

Problem

The plugin re-initializes on every tool execution, causing 1-2 second delays per operation and showing supermemory: initialized repeatedly in logs. As reported in #12, users see 14+ initializations in 6 minutes during normal operation.

Root Cause

OpenClaw calls register() multiple times (on every tool execution or agent start). The plugin was not guarding against this, so it created a new SupermemoryClient, re-registered all hooks and tools, and logged "initialized" each time.

Fix

Add a module-level _initialized flag. The register() function returns early if already initialized, ensuring:

  • Client creation happens once
  • Hook registration happens once
  • Tool registration happens once
  • The "initialized" log appears exactly once

Changes

  • index.ts: Added _initialized guard at the top of register()

Testing

  • The fix is a simple boolean guard with no side effects
  • Type checking can't run locally without node_modules, but the change is syntactically minimal (9 lines added)
  • No behavioral change for the first initialization call

Fixes #12

fixes supermemoryai#12)

OpenClaw was calling register() multiple times (likely on every tool
execution or agent start), causing the plugin to re-initialize and log
"supermemory: initialized" repeatedly with 1-2 second delays.

Solution: Add module-level _initialized flag to guard against
re-registration. The register() function now returns early if already
initialized, ensuring client creation and hook registration only
happens once per session.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kagura-agent
Copy link
Copy Markdown
Author

Closing — maintainer appears inactive (no merges in recent weeks). Happy to reopen if there's interest.

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.

Plugin Re-initializes on Every Tool Execution - Performance Impact

1 participant