diff --git a/src/config/sessions/combined-store-gateway.ts b/src/config/sessions/combined-store-gateway.ts index d07bbde42cbc..2f2ca678fb15 100644 --- a/src/config/sessions/combined-store-gateway.ts +++ b/src/config/sessions/combined-store-gateway.ts @@ -9,7 +9,7 @@ import { import { normalizeAgentId } from "../../routing/session-key.js"; import type { OpenClawConfig } from "../types.openclaw.js"; import { resolveStorePath } from "./paths.js"; -import { loadSessionStore } from "./store-load.js"; +import { listSessionEntries } from "./session-accessor.js"; import { resolveAgentSessionStoreTargetsSync, resolveAllAgentSessionStoreTargetsSync, @@ -22,6 +22,15 @@ function isStorePathTemplate(store?: string): boolean { return typeof store === "string" && store.includes("{agentId}"); } +function loadGatewayStoreEntries(storePath: string): Record { + return Object.fromEntries( + listSessionEntries({ clone: false, storePath }).map(({ sessionKey, entry }) => [ + sessionKey, + entry, + ]), + ); +} + function mergeSessionEntryIntoCombined(params: { cfg: OpenClawConfig; combined: Record; @@ -76,7 +85,7 @@ export function loadCombinedSessionStoreForGateway( // A single shared store still needs keys canonicalized as if owned by the default agent. const storePath = resolveStorePath(storeConfig); const defaultAgentId = normalizeAgentId(resolveDefaultAgentId(cfg)); - const store = loadSessionStore(storePath, { clone: false }); + const store = loadGatewayStoreEntries(storePath); const combined: Record = {}; for (const [key, entry] of Object.entries(store)) { const canonicalKey = resolveStoredSessionKeyForAgentStore({ @@ -108,7 +117,7 @@ export function loadCombinedSessionStoreForGateway( for (const target of targets) { const agentId = target.agentId; const storePath = target.storePath; - const store = loadSessionStore(storePath, { clone: false }); + const store = loadGatewayStoreEntries(storePath); for (const [key, entry] of Object.entries(store)) { const canonicalKey = resolveStoredSessionKeyForAgentStore({ cfg, diff --git a/src/gateway/session-utils.ts b/src/gateway/session-utils.ts index 1f11c71c45bd..864212ac898e 100644 --- a/src/gateway/session-utils.ts +++ b/src/gateway/session-utils.ts @@ -57,7 +57,6 @@ import { resolveStateDir } from "../config/paths.js"; import { buildGroupDisplayName, getSessionStoreCacheVersion, - loadSessionStore, resolveAllAgentSessionStoreTargetsSync, resolveAgentMainSessionKey, resolveFreshSessionTotalTokens, @@ -67,6 +66,7 @@ import { type SessionStoreTarget, type SessionScope, } from "../config/sessions.js"; +import { listSessionEntries as listAccessorSessionEntries } from "../config/sessions/session-accessor.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import { openRootFileSync } from "../infra/boundary-file-read.js"; import { projectPluginSessionExtensionsSync } from "../plugins/host-hook-state.js"; @@ -1346,6 +1346,18 @@ function resolveGatewaySessionStoreCandidates( return [...targets.values()]; } +function loadGatewaySessionLookupStore( + storePath: string, + clone: boolean | undefined, +): Record { + return Object.fromEntries( + listAccessorSessionEntries({ + ...(clone === false ? { clone: false } : {}), + storePath, + }).map(({ sessionKey, entry }) => [sessionKey, entry]), + ); +} + function resolveGatewaySessionStoreLookup(params: { cfg: OpenClawConfig; key: string; @@ -1364,9 +1376,9 @@ function resolveGatewaySessionStoreLookup(params: { agentId: params.agentId, storePath: resolveStorePath(params.cfg.session?.store, { agentId: params.agentId }), }; - const loadOptions = params.clone === false ? { clone: false } : undefined; + const loadStore = (storePath: string) => loadGatewaySessionLookupStore(storePath, params.clone); let selectedStorePath = fallback.storePath; - let selectedStore = params.initialStore ?? loadSessionStore(fallback.storePath, loadOptions); + let selectedStore = params.initialStore ?? loadStore(fallback.storePath); let selectedMatch = findFreshestStoreMatch(selectedStore, ...scanTargets); let selectedUpdatedAt = selectedMatch?.entry.updatedAt ?? Number.NEGATIVE_INFINITY; @@ -1375,7 +1387,7 @@ function resolveGatewaySessionStoreLookup(params: { if (!candidate) { continue; } - const store = loadSessionStore(candidate.storePath, loadOptions); + const store = loadStore(candidate.storePath); const match = findFreshestStoreMatch(store, ...scanTargets); if (!match) { continue; @@ -1433,12 +1445,11 @@ function resolveExplicitDeletedLegacyMainStoreTarget(params: { match: { entry: SessionEntry; key: string }; } | undefined; - const loadOptions = params.clone === false ? { clone: false } : undefined; for (const target of resolveAllAgentSessionStoreTargetsSync(params.cfg)) { if (target.agentId !== legacyAgentId) { continue; } - const store = loadSessionStore(target.storePath, loadOptions); + const store = loadGatewaySessionLookupStore(target.storePath, params.clone); const match = findFreshestStoreMatch(store, ...lookupSeeds); if (!match) { continue;