diff --git a/extensions/memory-core/src/dreaming.test.ts b/extensions/memory-core/src/dreaming.test.ts index 22dc38984a4..30edd058400 100644 --- a/extensions/memory-core/src/dreaming.test.ts +++ b/extensions/memory-core/src/dreaming.test.ts @@ -1307,6 +1307,82 @@ describe("gateway startup reconciliation", () => { clearInternalHooks(); } }); + + it("uses live runtime config for heartbeat dreaming reconciliation", async () => { + clearInternalHooks(); + const logger = createLogger(); + const harness = createCronHarness(); + const onMock = vi.fn(); + const runtimeLoadConfig = vi.fn( + () => + ({ + plugins: { + entries: { + "memory-core": { + config: { + dreaming: { + enabled: false, + }, + }, + }, + }, + }, + }) as OpenClawConfig, + ); + const api: DreamingPluginApiTestDouble = { + config: { + plugins: { + entries: { + "memory-core": { + config: { + dreaming: { + enabled: true, + frequency: "15 4 * * *", + timezone: "UTC", + }, + }, + }, + }, + }, + } as OpenClawConfig, + pluginConfig: {}, + logger, + runtime: { + config: { + loadConfig: runtimeLoadConfig, + }, + }, + on: onMock, + }; + + try { + registerShortTermPromotionDreamingForTest(api); + await triggerGatewayStart(onMock, { + config: api.config, + getCron: () => harness.cron, + }); + + const sessionKey = "agent:main:main"; + enqueueSystemEvent(constants.DREAMING_SYSTEM_EVENT_TEXT, { + sessionKey, + contextKey: "cron:memory-dreaming", + }); + + const beforeAgentReply = getBeforeAgentReplyHandler(onMock); + const result = await beforeAgentReply( + { cleanedBody: constants.DREAMING_SYSTEM_EVENT_TEXT }, + { trigger: "heartbeat", workspaceDir: ".", sessionKey }, + ); + + expect(runtimeLoadConfig).toHaveBeenCalled(); + expect(result).toEqual({ + handled: true, + reason: "memory-core: short-term dreaming disabled", + }); + } finally { + clearInternalHooks(); + } + }); }); describe("short-term dreaming trigger", () => { diff --git a/extensions/memory-core/src/dreaming.ts b/extensions/memory-core/src/dreaming.ts index 99b35bcb82e..bb314ad10ce 100644 --- a/extensions/memory-core/src/dreaming.ts +++ b/extensions/memory-core/src/dreaming.ts @@ -638,6 +638,9 @@ export function registerShortTermPromotionDreaming(api: OpenClawPluginApi): void let lastRuntimeConfigKey: string | null = null; let lastRuntimeCronRef: CronServiceLike | null = null; + const resolveCurrentConfig = (): OpenClawConfig => + api.runtime.config?.loadConfig?.() ?? api.config; + const runtimeConfigKey = (config: ShortTermPromotionDreamingConfig): string => [ config.enabled ? "enabled" : "disabled", @@ -660,7 +663,7 @@ export function registerShortTermPromotionDreaming(api: OpenClawPluginApi): void startupCron?: (() => CronServiceLike | null) | null; }): Promise => { const startupCfg = - params.reason === "startup" ? (params.startupConfig ?? api.config) : api.config; + params.reason === "startup" ? (params.startupConfig ?? api.config) : resolveCurrentConfig(); const config = resolveShortTermPromotionDreamingConfig({ pluginConfig: resolveMemoryCorePluginConfig(startupCfg) ??