From e5fdf6dd2d303464afcb29927572a13bb32e1c68 Mon Sep 17 00:00:00 2001 From: Galin Iliev Date: Wed, 19 Aug 2026 07:40:03 -0700 Subject: [PATCH] fix(memory): package broker child entry --- extensions/memory-core/index.test.ts | 10 ++++++++++ extensions/memory-core/index.ts | 13 ++++++++----- src/memory-broker/process.ts | 4 +++- tsdown.config.ts | 3 +++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/extensions/memory-core/index.test.ts b/extensions/memory-core/index.test.ts index 31ab7321ee9c..66154d3d8ee9 100644 --- a/extensions/memory-core/index.test.ts +++ b/extensions/memory-core/index.test.ts @@ -362,6 +362,16 @@ describe("memory-core plugin runtime registration", () => { }); }); + it("uses the packaged plugin entry as the selected broker child module", () => { + const capability = registerMemoryCoreCapability(); + + expect(capability.broker).toEqual({ + version: 1, + kind: "local-child", + moduleUrl: new URL("./index.ts", import.meta.url).href, + }); + }); + it("binds the host local-service hook to the registered memory runtime", async () => { const runtime = registerMemoryCoreRuntime(); const cfg = {} as OpenClawConfig; diff --git a/extensions/memory-core/index.ts b/extensions/memory-core/index.ts index f9407ec13939..e7f73c8ac0a5 100644 --- a/extensions/memory-core/index.ts +++ b/extensions/memory-core/index.ts @@ -36,6 +36,11 @@ import { registerScopedMemorySharingGatewayMethods } from "./src/memory/scoped-m import { buildPromptSection } from "./src/prompt-section.js"; import { registerSessionBackfillGatewayMethods } from "./src/session-backfill-gateway.js"; +export { + createMemoryBrokerHandler, + initializeMemoryBroker, +} from "./src/memory/broker-entry.js"; + type MemoryToolsModule = typeof import("./src/tools.js"); type StandingIntentToolModule = typeof import("./src/standing-intents-tool.js"); @@ -69,11 +74,9 @@ const loadScopedMemorySharingModule = createLazyRuntimeModule( () => import("./src/memory/scoped-memory-sharing.js"), ); -// Source-checkout workers inherit the TypeScript loader; packaged brokers load the emitted JS. -const memoryBrokerEntryUrl = new URL( - import.meta.url.endsWith(".ts") ? "./src/memory/broker-entry.ts" : "./src/memory/broker-entry.js", - import.meta.url, -).href; +// The selected broker imports this packaged extension entry, which re-exports its private +// handler. Do not point at a source-relative helper: package builds only guarantee this entry. +const memoryBrokerEntryUrl = import.meta.url; function getToolConfig(options: MemoryToolOptions): OpenClawConfig | undefined { return options.getConfig?.() ?? options.config; diff --git a/src/memory-broker/process.ts b/src/memory-broker/process.ts index df6f7b3ec7a5..caf31b39181a 100644 --- a/src/memory-broker/process.ts +++ b/src/memory-broker/process.ts @@ -60,8 +60,10 @@ export async function startMemoryBrokerProcess(params: { const socketPath = path.join(directory, "broker.sock"); const brokerEpoch = randomUUID(); const secret = randomBytes(32); + // The bundled parent can be a code-split chunk at dist/, while the child is a + // deliberate stable entry. Keep the source sibling path for tsx-based development. const defaultChildModuleUrl = new URL( - import.meta.url.endsWith(".ts") ? "./child.ts" : "./child.js", + import.meta.url.endsWith(".ts") ? "./child.ts" : "./memory-broker/child.js", import.meta.url, ); const childModuleUrl = params.childModuleUrl ?? defaultChildModuleUrl; diff --git a/tsdown.config.ts b/tsdown.config.ts index c6059299af7e..e161c1603960 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -395,6 +395,9 @@ function buildCoreDistEntries(): Record { "process/supervisor/service-child-relay": "src/process/supervisor/service-child-relay.ts", "process/supervisor/service-child-group-anchor": "src/process/supervisor/service-child-group-anchor.ts", + // Forked by the selected-memory supervisor; this must remain a stable packaged file rather + // than an implementation chunk whose hashed location can change independently of the parent. + "memory-broker/child": "src/memory-broker/child.ts", // Durable host-side PID for per-session process-isolated worker containers. "node-host/node-worker-container-shim": "src/node-host/node-worker-container-shim.ts", "telegram-ingress-worker.runtime": bundledPluginFile(