fix(hooks): use live config for memory dreaming runtime

This commit is contained in:
Vincent Koc
2026-04-22 12:46:34 -07:00
parent 6261f42ac0
commit 1ebd8e0bb6
2 changed files with 80 additions and 1 deletions

View File

@@ -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", () => {

View File

@@ -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<ShortTermPromotionDreamingConfig> => {
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) ??