Skip to content

Commit bfbfc10

Browse files
committed
fix(runtime): use session accessor projection for abort cleanup
1 parent 0daedfd commit bfbfc10

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/gateway/server-methods/sessions.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ import {
6363
preflightSessionTranscriptForManualCompact,
6464
trimSessionTranscriptForManualCompact,
6565
} from "../../config/sessions/session-accessor.js";
66-
import { updateSessionStore } from "../../config/sessions/store.js";
6766
import type { OpenClawConfig } from "../../config/types.openclaw.js";
6867
import {
6968
measureDiagnosticsTimelineSpan,
@@ -158,9 +157,11 @@ async function clearPersistedNoActiveRunSessionState(params: {
158157
return false;
159158
}
160159
let candidateSessionKeys: string[] = [];
161-
const target = await updateSessionStore(
162-
params.storePath,
163-
async (store) => {
160+
let primarySessionKey: string | undefined;
161+
const target = await applySessionPatchProjection({
162+
storePath: params.storePath,
163+
resolveTarget: ({ entries }) => {
164+
const store = Object.fromEntries(entries.map(({ sessionKey, entry }) => [sessionKey, entry]));
164165
const resolvedTarget = resolveGatewaySessionStoreTarget({
165166
cfg: params.cfg,
166167
key: params.key,
@@ -169,25 +170,27 @@ async function clearPersistedNoActiveRunSessionState(params: {
169170
});
170171
const targetEntry = resolveFreshestSessionEntryFromStoreKeys(store, resolvedTarget.storeKeys);
171172
if (!targetEntry) {
172-
return undefined;
173+
return { primaryKey: resolvedTarget.canonicalKey, candidateKeys: resolvedTarget.storeKeys };
173174
}
174-
const { primaryKey } = migrateAndPruneGatewaySessionStoreKey({
175+
const { target: migratedTarget, primaryKey } = migrateAndPruneGatewaySessionStoreKey({
175176
cfg: params.cfg,
176177
key: params.key,
177178
store,
178179
agentId: params.agentId,
179180
});
180-
candidateSessionKeys = resolvedTarget.storeKeys;
181-
return { primaryKey, storeKeys: resolvedTarget.storeKeys };
181+
candidateSessionKeys = migratedTarget.storeKeys;
182+
primarySessionKey = primaryKey;
183+
return { primaryKey, candidateKeys: migratedTarget.storeKeys };
182184
},
183-
{ skipSaveWhenResult: (value) => value === undefined },
184-
);
185-
if (!target?.primaryKey) {
185+
project: ({ existingEntry }) =>
186+
existingEntry ? { ok: true, entry: existingEntry } : { ok: false },
187+
});
188+
if (!target.ok || !primarySessionKey) {
186189
return false;
187190
}
188191
const result = await reconcilePersistedRunningSession({
189192
storePath: params.storePath,
190-
sessionKey: target.primaryKey,
193+
sessionKey: primarySessionKey,
191194
candidateSessionKeys,
192195
activeRunPresent: false,
193196
reason: "sessions_abort_no_active_run",

0 commit comments

Comments
 (0)