Skip to content

fix(memory): avoid repeated local provider initialization across registrations - #142417

Closed
artdaal wants to merge 1 commit into
openclaw:mainfrom
artdaal:fix/memory-local-service-acquirer-identity
Closed

artdaal wants to merge 1 commit into
openclaw:mainfrom
artdaal:fix/memory-local-service-acquirer-identity

Conversation

@artdaal

@artdaal artdaal commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #142414

What Problem This Solves

Fixes an issue where users of local memory embeddings could pay repeated provider initialization and hit memory-search timeouts when the same memory configuration crossed repeated runtime or plugin registration paths.

Why This Change Was Made

The runtime now exposes one process-stable host acquirer, the plugin registry reuses one scoped acquirer per host callback and plugin ID, and memory-core reads that reference lazily instead of allocating another forwarding function. Different plugins and genuinely different host callbacks remain isolated. The change does not alter memory configuration, index schema, ranking, or provider fallback behavior.

User Impact

Repeated native, HTTP, CLI, or plugin registration paths can reuse a compatible local memory manager instead of replacing it solely because a wrapper function received a new identity. This avoids unnecessary local-provider cold starts while preserving plugin ownership scope.

Evidence

  • Before the production change, four new assertions fail at the runtime facade, plugin scope, and memory-core registration boundaries because the callback identity changes.
  • Focused regression and sibling tests: 77 passed across src/plugins/runtime/index.test.ts, src/plugins/registry.runtime-config.test.ts, and extensions/memory-core/index.test.ts.
  • Plugin contract suite: 47 files and 1117 tests passed.
  • pnpm check:changed passed for the selected core, core-test, extension, and extension-test lanes.
  • pnpm build passed, including CLI bootstrap imports, plugin SDK exports, runtime postbuild checks, and Control UI budgets.
  • Independent autoreview found no actionable P0-P2 findings (scoped-clean, confidence 0.96).

Redacted real-runtime proof

Before opening this PR, the equivalent three-boundary identity repair was exercised on an installed OpenClaw 2026.9.2 runtime using a real local GGUF embedding provider and a populated native SQLite memory index. A content-free profiler observed a cold native search, an HTTP search, and a fresh native search in one process:

route   acquirer_token   manager_token   acquire_ms   search_ms   completed
native  1                2               352          5626        yes
HTTP    1                2               0            851         yes
native  1                2               0            1046        yes

All three requests reached search-end; the acquirer and manager tokens stayed identical across the registration/route transitions, and the two warm acquisitions returned immediately. The profiler was then removed byte-for-byte. A separate uninstrumented cold native -> HTTP -> native sequence completed without the prior 15-second timeout (8,886 ms, 839 ms, and 1,051 ms respectively), and every search returned without an error.

Queries, result content, paths, hostnames, endpoints, IP addresses, and credentials are omitted. This operational run used the installed 2026.9.2 build with the equivalent guarded fix at the same host-runtime, plugin-scope, and memory-core boundaries; the regression suites above validate the source implementation in this PR.

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@artdaal
artdaal marked this pull request as ready for review September 8, 2026 18:30
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed October 8, 2026, 6:16 AM ET / 10:16 UTC (Revision 5).

ClawSweeper review

What this changes

This PR stabilizes local-service acquisition callbacks across runtime creation and plugin registrations so compatible memory managers can be reused.

Example: A user runs native, HTTP, then native memory searches in one process

  • Before: Registration wrappers can give the same local embedding host different identities and replace its reusable memory manager.
  • After: Compatible registrations share the acquisition callback and reuse the manager, as shown by unchanged acquirer and manager tokens in the supplied runtime trace.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and supported by real search observations, but current registry integration and retirement safety remain unresolved.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied installed-runtime native → HTTP → native trace credibly demonstrates manager reuse with a real local provider, preserving the earlier positive assessment. It does not exercise current-main integration or show that a retired registration and its retained manager are rejected before local-service acquisition or process startup. Add redacted logs or terminal output for those cases; updating the PR body triggers review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Local memory searches can repeatedly initialize the same embedding provider when requests cross registration paths.
Reason: Avoiding unnecessary manager replacement has clear value. Cross-registration reuse now intersects owner-built lifecycle fencing, requiring agreement on resource lifetime before integration.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep open: the callback-identity defect remains on current main, and this PR contains useful unique work. It needs real behavior proof before merge for retirement safety after integration with the current registry; the earlier successful search trace remains valid evidence for manager reuse.

Priority: P2
Reviewed head: 22c515336d41830f6abee7030bd649ac291afa4f
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should compatible memory resources survive registration replacement through a separate stable resource identity, or should reuse remain limited to one live registration?
  • Recommendation: Separate resource identity from execution authority: Preserve compatible manager reuse across registrations while keeping acquisition callbacks and retirement checks bound to the live record.
  • Why: Cross-registration callback identity and record-bound execution authority now have different lifetimes; neither the supplied proof nor a recorded owner decision settles their relationship.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied installed-runtime native → HTTP → native trace credibly demonstrates manager reuse with a real local provider, preserving the earlier positive assessment. It does not exercise current-main integration or show that a retired registration and its retained manager are rejected before local-service acquisition or process startup. Add redacted logs or terminal output for those cases; updating the PR body triggers review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security concern: Cross-registration reuse needs live-owner fencing - The proposed callback cache retains plugin ID and host callback rather than a concrete live record. Current main checks record authority and owning registry before host acquisition; the conflicting integration has not demonstrated rejection of a retired registration before service I/O.
  • Resolve merge risk (P1) - The conflicting registry integration has no verified merged result preserving current main's record-scoped authority; reusing a callback by plugin ID alone may permit a retired registration or retained manager to acquire a local service.
  • Complete next step (P2) - Refresh the conflicting registry integration against current main using the agreed resource-lifetime design.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [medium] Cross-registration reuse needs live-owner fencing — src/plugins/registry-runtime.ts:50

Tests

  • Missing end-to-end proof: After resolving the registry conflict, demonstrate compatible search reuse through the integrated production path and show that a retired or replaced registration cannot cause a service spawn or acquisition, including through a retained manager. The reported base-failing assertions were not rerun in this read-only review.
Agent review details

How this fits together

Memory Core turns memory-search requests into searches of an indexed workspace using an embedding provider. The plugin runtime supplies host-owned local-service acquisition, whose callback identity also determines whether a memory manager can be reused.

flowchart TD
 A[Native or HTTP memory search] --> B[Memory Core registration]
 B --> C[Plugin scoped acquisition callback]
 C --> D[Live registration authority]
 D --> E[Host local embedding service]
 B --> F[Memory manager compatibility key]
 F --> G[Reuse or replace manager]
 G --> H[Memory search results]
Loading

Technical review

Best possible solution:

Keep resource compatibility identity stable while binding every acquisition and retained-manager operation to the correct live registration and registry.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main callback allocation and the manager compatibility key establish the identity defect, supported by the supplied isolated reproduction. This review did not execute contributor code or measure current-main provider initialization.

Is this the best way to solve the issue?

Unclear: stabilizing identity addresses the demonstrated cache mismatch, but the current registry requires a design that separates resource reuse from live registration authority.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 245b7f6fb2ad.

Merge-risk options

Maintainer options:

  1. Preserve record fencing during integration (recommended)
    Resolve the registry conflict with the selected ownership design, retaining live-record and owning-registry checks before local-service acquisition.

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 3.

Security

Needs attention: No discrete introduced exploit is established, but callback reuse across registration lifetimes leaves current lifecycle fencing unresolved.

Evidence

Security concerns:

  • [medium] Cross-registration reuse needs live-owner fencing — src/plugins/registry-runtime.ts:50
    The proposed callback cache retains plugin ID and host callback rather than a concrete live record. Current main checks record authority and owning registry before host acquisition; the conflicting integration has not demonstrated rejection of a retired registration before service I/O.
    Confidence: 0.91

What I checked:

  • Verified introduced patch: The pinned delta adds a process-level callback cache keyed by host callback and plugin ID, shares the host runtime acquirer, and replaces Memory Core's forwarding closure with lazy reference access. (src/plugins/registry-runtime.ts:34, 22c515336d41)
  • Current main retains the identity defect: Fetched main still creates an acquisition callback inside each LLM facade, allocates a new registry acquisition wrapper on each access, and gives Memory Core another registration-local forwarding closure. (src/plugins/registry-runtime.ts:471, 245b7f6fb2ad)
  • Current lifecycle contract: Current main binds runtime access to a concrete record and owning registry. Local-service acquisition calls runWithPluginScope, which checks capturePluginLifecycleAuthority before invoking the host. The proposed cache retains only the plugin ID and host callback; no verified merged integration establishes preservation of the current checks. (src/plugins/registry-runtime.ts:221, 245b7f6fb2ad)
  • Identity affects manager reuse: The compatibility key includes the host identity assigned from the acquisition function. Existing manager-registry coverage verifies that different host callbacks replace managers while repeated use of one callback reuses them. (extensions/memory-core/src/memory/manager-registry.ts:67, 22c515336d41)
  • Real runtime evidence and its scope: The fully supplied PR body reports an installed OpenClaw 2026.9.2 runtime with an equivalent repair, a real GGUF embedding provider, and populated SQLite memory. Native → HTTP → native requests retained acquirer token 1 and manager token 2; warm acquisitions took 0 ms. An uninstrumented sequence completed in 8,886 ms, 839 ms, and 1,051 ms. This proves successful reuse, but not rejection of retired registrations.
  • Prior review concern remains unresolved: The previous review examined the same head and requested preservation of live-record scope and retirement checks. The October 8 contributor comment independently reports callback differences on main and explicitly distinguishes that identity reproduction from a measured Gateway search. The head remains unchanged: fix(memory): avoid repeated local provider initialization across registrations #142417 (comment). (22c515336d41)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +28, Tests +48. Total +76 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 38 10 +28
Tests 3 50 2 +48
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 88 12 +76

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #142414
Summary: This PR is the proposed fix for the linked callback-identity bug; the managed-readiness deadline repair is adjacent work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: Process-level callback reuse crosses registration lifetimes, while current main requires live-record authority before acquiring a host-managed service.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied installed-runtime native → HTTP → native trace credibly demonstrates manager reuse with a real local provider, preserving the earlier positive assessment. It does not exercise current-main integration or show that a retired registration and its retained manager are rejected before local-service acquisition or process startup. Add redacted logs or terminal output for those cases; updating the PR body triggers review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: Repeated local embedding initialization can delay memory searches, with a bounded blast radius and no demonstrated emergency.
  • merge-risk: 🚨 security-boundary: Process-level callback reuse crosses registration lifetimes, while current main requires live-record authority before acquiring a host-managed service.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied installed-runtime native → HTTP → native trace credibly demonstrates manager reuse with a real local provider, preserving the earlier positive assessment. It does not exercise current-main integration or show that a retired registration and its retained manager are rejected before local-service acquisition or process startup. Add redacted logs or terminal output for those cases; updating the PR body triggers review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Show successful reuse by the live registration and rejection of the replaced registration, including retained-manager calls, before any local-service acquisition or spawn.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-08T18:38:48.512Z sha 22c5153 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-08T18:51:59.865Z sha 22c5153 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T18:58:12.771Z sha 22c5153 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-23T13:14:06.081Z sha 22c5153 :: blocked before merge. :: none

@artdaal

artdaal commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 8, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 8, 2026
@obviyus

obviyus commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

The callback-identity defect still reproduces on current main 34b093e3db1fc8b6acbadd475d5bb96d327eb089; record-scoped acquisition has not eliminated it.

I ran the real createPluginRuntime, createPluginRegistry / createApi, and Memory Core resolveMemoryCoreLocalServiceHostIdentity implementations in a secretless Node 24 container on that exact source revision. Two runtime facades return different host callbacks. More narrowly, two reads of api.runtime.llm.acquireLocalService for the same record in the same registry also return different callbacks; the Memory Core identity mapper assigns those callbacks "1" and "2". The reproduction exited successfully with assertions confirming those differences. This establishes the reported identity defect, not a measured provider initialization count or a built-Gateway memory-search result; no model request was made.

The blocking integration concern is real: current registry acquisition runs through runWithPluginScope, which checks the current record's lifecycle authority and carries its owning registry. This PR's process-level host-callback/plugin-ID cache cannot simply replace that path: it lacks those record-scoped checks. Caching a guarded callback per record would preserve authority but would not itself satisfy the proposed cross-registration reuse guarantee.

Handing this off for an owner-level design rather than weakening lifecycle fencing. The open question is how to preserve compatible local-provider resource identity across registrations while keeping acquisition, retained managers, and retirement bound to the correct live record/registry. No production changes or pushes were made; this is not landing-ready.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Oct 9, 2026
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @artdaal. The repeated-initialization problem is addressed on main by a different ownership boundary. #144252 resolves the memory manager registry per plugin instance, and #167679 / #167756 bind background work and restarts to plugin lifecycle owners. A live check against a real managed EmbeddingGemma server showed one provider creation and one reused manager across repeated memory_search calls over WebSocket and HTTP.

A process-wide cache keyed by host callback and plugin id would now be unsafe, because the per-registration wrapper closes over the current plugin record's authority, which a replacement must not inherit. Closing as superseded; details are in #142414.

@steipete steipete closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Local memory search reinitializes the same provider across registrations

3 participants