refactor: trim cron session store startup imports

This commit is contained in:
Shakker
2026-04-01 16:48:39 +01:00
committed by Shakker
parent 1f0c4a624b
commit 6363094e93
3 changed files with 13 additions and 4 deletions

View File

@@ -32,7 +32,6 @@ import {
import type { CliDeps } from "../../cli/outbound-send-deps.js";
import type { OpenClawConfig } from "../../config/config.js";
import { resolveSessionTranscriptPath } from "../../config/sessions/paths.js";
import { updateSessionStore } from "../../config/sessions/store.runtime.js";
import { setSessionRuntimeModel } from "../../config/sessions/types.js";
import { registerAgentRunContext } from "../../infra/agent-events.js";
import { logWarn } from "../../logger.js";
@@ -64,6 +63,15 @@ import { resolveCronSession } from "./session.js";
import { resolveCronSkillsSnapshot } from "./skills-snapshot.js";
import { isLikelyInterimCronMessage } from "./subagent-followup.js";
let sessionStoreRuntimePromise:
| Promise<typeof import("../../config/sessions/store.runtime.js")>
| undefined;
async function loadSessionStoreRuntime() {
sessionStoreRuntimePromise ??= import("../../config/sessions/store.runtime.js");
return await sessionStoreRuntimePromise;
}
function resolveNonNegativeNumber(value: number | undefined): number | undefined {
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
}
@@ -273,6 +281,7 @@ export async function runCronIsolatedAgentTurn(params: {
if (runSessionKey !== agentSessionKey) {
cronSession.store[runSessionKey] = cronSession.sessionEntry;
}
const { updateSessionStore } = await loadSessionStoreRuntime();
await updateSessionStore(cronSession.storePath, (store) => {
store[agentSessionKey] = cronSession.sessionEntry;
if (runSessionKey !== agentSessionKey) {

View File

@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
vi.mock("../../config/sessions/store-load.js", () => ({
vi.mock("../../config/sessions/store.js", () => ({
loadSessionStore: vi.fn(),
}));
@@ -25,7 +25,7 @@ vi.mock("../../agents/bootstrap-cache.js", () => ({
import { clearBootstrapSnapshot } from "../../agents/bootstrap-cache.js";
import { evaluateSessionFreshness } from "../../config/sessions/reset.js";
import { loadSessionStore } from "../../config/sessions/store-load.js";
import { loadSessionStore } from "../../config/sessions/store.js";
import { resolveCronSession } from "./session.js";
const NOW_MS = 1_737_600_000_000;

View File

@@ -6,7 +6,7 @@ import {
evaluateSessionFreshness,
resolveSessionResetPolicy,
} from "../../config/sessions/reset.js";
import { loadSessionStore } from "../../config/sessions/store-load.js";
import { loadSessionStore } from "../../config/sessions/store.js";
import type { SessionEntry } from "../../config/sessions/types.js";
export function resolveCronSession(params: {