mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-11 21:10:55 +00:00
refactor: drop stale session load options
This commit is contained in:
@@ -37,7 +37,7 @@ export function resolveLiveSessionModelSelection(params: {
|
||||
const storePath = resolveStorePath(cfg.session?.store, {
|
||||
agentId,
|
||||
});
|
||||
const entry = loadSessionStore(storePath, { skipCache: true })[sessionKey];
|
||||
const entry = loadSessionStore(storePath)[sessionKey];
|
||||
const normalizedSelection = normalizeStoredOverrideModel({
|
||||
providerOverride: entry?.providerOverride,
|
||||
modelOverride: entry?.modelOverride,
|
||||
@@ -159,7 +159,7 @@ export function shouldSwitchToLiveModel(params: {
|
||||
const storePath = resolveStorePath(cfg.session?.store, {
|
||||
agentId: params.agentId?.trim(),
|
||||
});
|
||||
const entry = loadSessionStore(storePath, { skipCache: true })[sessionKey];
|
||||
const entry = loadSessionStore(storePath)[sessionKey];
|
||||
if (!entry?.liveModelSwitchPending) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -896,7 +896,7 @@ function refreshSessionEntryFromStore(params: {
|
||||
return fallbackEntry;
|
||||
}
|
||||
try {
|
||||
const latestStore = loadSessionStore(storePath, { skipCache: true });
|
||||
const latestStore = loadSessionStore(storePath);
|
||||
const latestEntry = latestStore?.[sessionKey];
|
||||
if (!latestEntry) {
|
||||
return fallbackEntry;
|
||||
|
||||
@@ -46,7 +46,7 @@ export function resolveExportCommandSessionTarget(
|
||||
): ExportCommandSessionTarget | ReplyPayload {
|
||||
const targetAgentId = resolveAgentIdFromSessionKey(params.sessionKey) || params.agentId || "main";
|
||||
const storePath = params.storePath ?? resolveDefaultSessionStorePath(targetAgentId);
|
||||
const store = loadSessionStore(storePath, { skipCache: true });
|
||||
const store = loadSessionStore(storePath);
|
||||
const entry = store[params.sessionKey] as SessionEntry | undefined;
|
||||
if (!entry?.sessionId) {
|
||||
return { text: `❌ Session not found: ${params.sessionKey}` };
|
||||
|
||||
@@ -30,7 +30,7 @@ export async function persistAcpDispatchTranscript(params: {
|
||||
const storePath = resolveStorePath(params.cfg.session?.store, {
|
||||
agentId: sessionAgentId,
|
||||
});
|
||||
const sessionStore = loadSessionStore(storePath, { skipCache: true });
|
||||
const sessionStore = loadSessionStore(storePath);
|
||||
const sessionEntry = resolveSessionStoreEntry({
|
||||
store: sessionStore,
|
||||
sessionKey: params.sessionKey,
|
||||
|
||||
@@ -213,9 +213,7 @@ export function initFastReplySessionState(params: {
|
||||
mainKey: cfg.session?.mainKey,
|
||||
});
|
||||
const storePath = resolveStorePath(cfg.session?.store, { agentId });
|
||||
const sessionStore: Record<string, SessionEntry> = loadSessionStore(storePath, {
|
||||
skipCache: true,
|
||||
});
|
||||
const sessionStore: Record<string, SessionEntry> = loadSessionStore(storePath);
|
||||
const existingEntry = sessionStore[sessionKey];
|
||||
const commandSource = ctx.BodyForCommands ?? ctx.CommandBody ?? ctx.RawBody ?? ctx.Body ?? "";
|
||||
const triggerBodyNormalized = stripStructuralPrefixes(commandSource).trim();
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
getOrCreateSessionMcpRuntime,
|
||||
} from "../../agents/pi-bundle-mcp-tools.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { SessionEntry } from "../../config/sessions.js";
|
||||
import { saveSessionStore, type SessionEntry } from "../../config/sessions.js";
|
||||
import { formatZonedTimestamp } from "../../infra/format-time/format-datetime.ts";
|
||||
import {
|
||||
__testing as sessionBindingTesting,
|
||||
@@ -1229,8 +1229,7 @@ describe("initSessionState RawBody", () => {
|
||||
|
||||
vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
|
||||
try {
|
||||
await fs.mkdir(path.dirname(storePath), { recursive: true });
|
||||
await writeSessionStoreFast(storePath, {
|
||||
await saveSessionStore(storePath, {
|
||||
[sessionKey]: {
|
||||
sessionId,
|
||||
sessionFile,
|
||||
|
||||
@@ -271,14 +271,8 @@ export async function initSessionState(params: {
|
||||
const storePath = resolveStorePath(sessionCfg?.store, { agentId });
|
||||
const ingressTimingEnabled = process.env.OPENCLAW_DEBUG_INGRESS_TIMING === "1";
|
||||
|
||||
// CRITICAL: Skip cache to ensure fresh data when resolving session identity.
|
||||
// Stale cache (especially with multiple gateway processes or on Windows where
|
||||
// mtime granularity may miss rapid writes) can cause incorrect sessionId
|
||||
// generation, leading to orphaned transcript files. See #17971.
|
||||
const sessionStoreLoadStartMs = ingressTimingEnabled ? Date.now() : 0;
|
||||
const sessionStore: Record<string, SessionEntry> = loadSessionStore(storePath, {
|
||||
skipCache: true,
|
||||
});
|
||||
const sessionStore: Record<string, SessionEntry> = loadSessionStore(storePath);
|
||||
if (ingressTimingEnabled) {
|
||||
log.info(
|
||||
`session-init store-load agent=${agentId} session=${sessionCtxForState.SessionKey ?? "(no-session)"} ` +
|
||||
|
||||
@@ -97,7 +97,7 @@ export async function exportTrajectoryCommand(
|
||||
const storePath = resolvedOpts.store
|
||||
? path.resolve(resolvedOpts.store)
|
||||
: resolveDefaultSessionStorePath(targetAgentId);
|
||||
const store = loadSessionStore(storePath, { skipCache: true });
|
||||
const store = loadSessionStore(storePath);
|
||||
const entry = store[sessionKey] as SessionEntry | undefined;
|
||||
if (!entry?.sessionId) {
|
||||
runtime.error(
|
||||
|
||||
@@ -251,7 +251,7 @@ async function previewStoreCleanup(params: {
|
||||
fixMissing?: boolean;
|
||||
fixDmScope?: boolean;
|
||||
}) {
|
||||
const beforeStore = loadSessionStore(params.target.storePath, { skipCache: true });
|
||||
const beforeStore = loadSessionStore(params.target.storePath);
|
||||
const previewStore = structuredClone(beforeStore);
|
||||
const staleKeys = new Set<string>();
|
||||
const cappedKeys = new Set<string>();
|
||||
@@ -450,7 +450,7 @@ export async function runSessionsCleanup(params: {
|
||||
};
|
||||
return missing;
|
||||
});
|
||||
const afterStore = loadSessionStore(target.storePath, { skipCache: true });
|
||||
const afterStore = loadSessionStore(target.storePath);
|
||||
const unreferencedArtifacts =
|
||||
mode === "warn"
|
||||
? {
|
||||
|
||||
@@ -68,7 +68,7 @@ export function loadCombinedSessionStoreForGateway(
|
||||
if (storeConfig && !isStorePathTemplate(storeConfig)) {
|
||||
const storePath = resolveStorePath(storeConfig);
|
||||
const defaultAgentId = normalizeAgentId(resolveDefaultAgentId(cfg));
|
||||
const store = loadSessionStore(storePath, { clone: false });
|
||||
const store = loadSessionStore(storePath);
|
||||
const combined: Record<string, SessionEntry> = {};
|
||||
for (const [key, entry] of Object.entries(store)) {
|
||||
const canonicalKey = resolveStoredSessionKeyForAgentStore({
|
||||
@@ -98,7 +98,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 = loadSessionStore(storePath);
|
||||
for (const [key, entry] of Object.entries(store)) {
|
||||
const canonicalKey = resolveStoredSessionKeyForAgentStore({
|
||||
cfg,
|
||||
|
||||
@@ -79,7 +79,7 @@ type SaveSessionStoreOptions = {
|
||||
};
|
||||
|
||||
function loadMutableSessionStoreForWriter(storePath: string): Record<string, SessionEntry> {
|
||||
return loadSessionStore(storePath, { skipCache: true, clone: false });
|
||||
return loadSessionStore(storePath);
|
||||
}
|
||||
|
||||
function resolveMutableSessionStoreKey(
|
||||
|
||||
@@ -319,7 +319,7 @@ export async function appendExactAssistantMessageToSessionTranscript(params: {
|
||||
}
|
||||
|
||||
const storePath = params.storePath ?? resolveDefaultSessionStorePath(params.agentId);
|
||||
const store = loadSessionStore(storePath, { skipCache: true });
|
||||
const store = loadSessionStore(storePath);
|
||||
const normalizedKey = normalizeStoreSessionKey(sessionKey);
|
||||
const entry = (store[normalizedKey] ?? store[sessionKey]) as SessionEntry | undefined;
|
||||
if (!entry?.sessionId) {
|
||||
|
||||
@@ -107,7 +107,7 @@ export async function sweepCronRunSessions(params: {
|
||||
|
||||
if (prunedSessions.size > 0) {
|
||||
try {
|
||||
const store = loadSessionStore(storePath, { skipCache: true });
|
||||
const store = loadSessionStore(storePath);
|
||||
const referencedSessionIds = new Set(
|
||||
Object.values(store)
|
||||
.map((entry) => entry?.sessionId)
|
||||
|
||||
@@ -81,7 +81,7 @@ function snapshotMainSessionMapping(params: {
|
||||
const agentId = resolveAgentIdFromSessionKey(params.sessionKey);
|
||||
const storePath = resolveStorePath(params.cfg.session?.store, { agentId });
|
||||
try {
|
||||
const store = loadSessionStore(storePath, { skipCache: true });
|
||||
const store = loadSessionStore(storePath);
|
||||
const entry = store[params.sessionKey];
|
||||
if (!entry) {
|
||||
return {
|
||||
|
||||
@@ -206,7 +206,7 @@ function getSessionStoreLookup(
|
||||
): SessionStoreLookup {
|
||||
if (!context) {
|
||||
return {
|
||||
store: taskRegistryMaintenanceRuntime.loadSessionStore(storePath, { clone: false }),
|
||||
store: taskRegistryMaintenanceRuntime.loadSessionStore(storePath),
|
||||
};
|
||||
}
|
||||
const cached = context.sessionStoresByPath.get(storePath);
|
||||
@@ -214,7 +214,7 @@ function getSessionStoreLookup(
|
||||
return cached;
|
||||
}
|
||||
const lookup = {
|
||||
store: taskRegistryMaintenanceRuntime.loadSessionStore(storePath, { clone: false }),
|
||||
store: taskRegistryMaintenanceRuntime.loadSessionStore(storePath),
|
||||
};
|
||||
context.sessionStoresByPath.set(storePath, lookup);
|
||||
return lookup;
|
||||
|
||||
Reference in New Issue
Block a user