Skip to content

fix(memory): make registerMemoryCorpusSupplement idempotent to prevent supplement loss during lazy re-register#3

Closed
mgustimz wants to merge 19 commits into
mainfrom
fix/memory-corpus-supplement-v2
Closed

fix(memory): make registerMemoryCorpusSupplement idempotent to prevent supplement loss during lazy re-register#3
mgustimz wants to merge 19 commits into
mainfrom
fix/memory-corpus-supplement-v2

Conversation

@mgustimz
Copy link
Copy Markdown
Owner

@mgustimz mgustimz commented May 4, 2026

Summary

When a plugin registers a MemoryCorpusSupplement from inside api.registerService({ start }), the supplement is correctly added to the global corpus supplements array.

However, when lazy tool-load triggers a subsequent non-activating re-register of the same plugin, the loader:

  1. Snapshots the supplements BEFORE register
  2. Runs register() which does NOT re-register the supplement (because service.start() only runs once)
  3. Calls restoreMemoryPluginState() with the pre-register snapshot (which is empty of this plugin's supplement)

This ZAPS the previously registered supplement.

Fix

registerMemoryCorpusSupplement now checks if the plugin already has a registered supplement and skips adding a duplicate instead of replacing. This makes the registration idempotent: re-registering during lazy tool-load no longer wipes existing registrations.

Testing

  • Plugin with MemoryCorpusSupplement registers inside service.start()
  • Lazy tool-load triggers a second register() call
  • Verify supplement is NOT lost after the re-register
  • Verify memory_search corpus=wiki still returns results from the supplement

Fixes openclaw#77039

vincentkoc and others added 19 commits May 3, 2026 19:54
…t supplement loss during lazy re-register

When a plugin registers a MemoryCorpusSupplement from inside api.registerService({ start }),
the supplement is correctly added to the global corpus supplements array.

However, when lazy tool-load triggers a subsequent non-activating re-register of the same
plugin, the loader snapshots the supplements BEFORE register and restores AFTER. Since the
plugin's register() call does not re-add the supplement (service.start() doesn't re-run),
the restoreMemoryPluginState() call effectively ZAPS the previously registered supplement
by overwriting the array with the pre-register snapshot.

The fix makes registerMemoryCorpusSupplement idempotent: if the plugin already has a
registered supplement, re-registering does nothing instead of wiping the existing entry.

Fixes: openclaw#77039
@mgustimz mgustimz closed this May 4, 2026
@mgustimz mgustimz deleted the fix/memory-corpus-supplement-v2 branch May 4, 2026 07:12
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.

registerMemoryCorpusSupplement registrations get wiped on lazy tool-load re-register of non-activating plugins

3 participants