From 4cf4ae49af9edd8f355368f2f27e1cbaf2f9a4c6 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Sat, 6 Jun 2026 10:26:55 +0800 Subject: [PATCH] Create session mapping entries during prepare --- dist/src/taskState.js | 4 ++++ src/taskState.test.ts | 7 ++++++- src/taskState.ts | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dist/src/taskState.js b/dist/src/taskState.js index 904e7f4..0506021 100644 --- a/dist/src/taskState.js +++ b/dist/src/taskState.js @@ -77,6 +77,10 @@ export async function upsertXWorkmateSessionMapping(api, input) { let mapping; await patchSessionEntry({ sessionKey: input.openclawSessionKey, + fallbackEntry: { + sessionId: input.openclawSessionKey, + updatedAt: Date.now(), + }, preserveActivity: true, update: (entry) => { const existing = readMappingFromEntry(entry); diff --git a/src/taskState.test.ts b/src/taskState.test.ts index 31e0e4b..c202c23 100644 --- a/src/taskState.test.ts +++ b/src/taskState.test.ts @@ -25,12 +25,17 @@ function createApiFixture(tasks: Record = {}) { })), patchSessionEntry: async ({ sessionKey, + fallbackEntry, update, }: { sessionKey: string; + fallbackEntry?: any; update: (entry: any) => Partial | null; }) => { - const current = sessions.get(sessionKey) ?? { sessionId: sessionKey, updatedAt: 0 }; + const current = sessions.get(sessionKey) ?? fallbackEntry; + if (!current) { + return null; + } const patch = update(current); if (patch) { sessions.set(sessionKey, { ...current, ...patch }); diff --git a/src/taskState.ts b/src/taskState.ts index 2e7011b..88b4c6c 100644 --- a/src/taskState.ts +++ b/src/taskState.ts @@ -49,6 +49,7 @@ type SessionEntry = Record & { type PatchSessionEntry = (params: { sessionKey: string; + fallbackEntry?: SessionEntry; preserveActivity?: boolean; update: (entry: SessionEntry) => Partial | null; }) => Promise | SessionEntry | null; @@ -159,6 +160,10 @@ export async function upsertXWorkmateSessionMapping( let mapping: XWorkmateSessionMappingV1 | undefined; await patchSessionEntry({ sessionKey: input.openclawSessionKey, + fallbackEntry: { + sessionId: input.openclawSessionKey, + updatedAt: Date.now(), + }, preserveActivity: true, update: (entry) => { const existing = readMappingFromEntry(entry);