clawdbot-ce2: route gateway session entries through accessor

This commit is contained in:
Josh Lehman
2026-05-31 18:19:12 -07:00
parent b39023fc3c
commit 897eb03e29
2 changed files with 29 additions and 9 deletions

View File

@@ -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<string, SessionEntry> {
return Object.fromEntries(
listSessionEntries({ clone: false, storePath }).map(({ sessionKey, entry }) => [
sessionKey,
entry,
]),
);
}
function mergeSessionEntryIntoCombined(params: {
cfg: OpenClawConfig;
combined: Record<string, SessionEntry>;
@@ -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<string, SessionEntry> = {};
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,

View File

@@ -55,7 +55,6 @@ import { resolveStateDir } from "../config/paths.js";
import {
buildGroupDisplayName,
getSessionStoreCacheVersion,
loadSessionStore,
resolveAllAgentSessionStoreTargetsSync,
resolveAgentMainSessionKey,
resolveFreshSessionTotalTokens,
@@ -65,6 +64,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";
@@ -1340,6 +1340,18 @@ function resolveGatewaySessionStoreCandidates(
return [...targets.values()];
}
function loadGatewaySessionLookupStore(
storePath: string,
clone: boolean | undefined,
): Record<string, SessionEntry> {
return Object.fromEntries(
listAccessorSessionEntries({
...(clone === false ? { clone: false } : {}),
storePath,
}).map(({ sessionKey, entry }) => [sessionKey, entry]),
);
}
function resolveGatewaySessionStoreLookup(params: {
cfg: OpenClawConfig;
key: string;
@@ -1358,9 +1370,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;
@@ -1369,7 +1381,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;
@@ -1427,12 +1439,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;