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
Closed
Conversation
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>
Author
|
Closing — maintainer appears inactive (no merges in recent weeks). Happy to reopen if there's interest. |
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.
Problem
The plugin re-initializes on every tool execution, causing 1-2 second delays per operation and showing
supermemory: initializedrepeatedly 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 newSupermemoryClient, re-registered all hooks and tools, and logged "initialized" each time.Fix
Add a module-level
_initializedflag. Theregister()function returns early if already initialized, ensuring:Changes
index.ts: Added_initializedguard at the top ofregister()Testing
node_modules, but the change is syntactically minimal (9 lines added)Fixes #12