Skip to content

Plugin architecture: register() called multiple times causes closure variables not shared (affects @mem0/openclaw-mem0) #77822

Description

@wanmeime

In OpenClaw 5.3+, plugins' register() function is called multiple times per conversation, which creates separate closures for each call. This causes module-level variables (like currentSessionId) to not be shared across instances.

Impact on @mem0/openclaw-mem0 plugin (v1.0.11):

  1. Agent memory isolation broken: user_id not concatenated with :agent:<agent_id> suffix
  2. run_id missing: Always None, can't filter memories by session
  3. autoCapture broken: Memories not auto-saved after conversations

Root cause: When before_prompt_build hook sets currentSessionId in Instance A, the memory_add tool reads from Instance B — always undefined.

Our fix: We added a module-level _globalSessionIdMap to share state across instances. Patch repo: https://github.com/wanmeime/openclaw-mem0-fix

Suggestion: Perhaps the plugin architecture could provide a shared state mechanism or ensure register() is only called once per session?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions