fix: patch session store updates
This commit is contained in:
@@ -161,11 +161,14 @@ export async function runReplyAgent(params: {
|
|||||||
const steered = queueEmbeddedPiMessage(followupRun.run.sessionId, followupRun.prompt);
|
const steered = queueEmbeddedPiMessage(followupRun.run.sessionId, followupRun.prompt);
|
||||||
if (steered && !shouldFollowup) {
|
if (steered && !shouldFollowup) {
|
||||||
if (activeSessionEntry && activeSessionStore && sessionKey) {
|
if (activeSessionEntry && activeSessionStore && sessionKey) {
|
||||||
activeSessionEntry.updatedAt = Date.now();
|
const updatedAt = Date.now();
|
||||||
|
activeSessionEntry.updatedAt = updatedAt;
|
||||||
activeSessionStore[sessionKey] = activeSessionEntry;
|
activeSessionStore[sessionKey] = activeSessionEntry;
|
||||||
if (storePath) {
|
if (storePath) {
|
||||||
await updateSessionStore(storePath, (store) => {
|
await updateSessionStoreEntry({
|
||||||
store[sessionKey] = activeSessionEntry as SessionEntry;
|
storePath,
|
||||||
|
sessionKey,
|
||||||
|
update: async () => ({ updatedAt }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,11 +180,14 @@ export async function runReplyAgent(params: {
|
|||||||
if (isActive && (shouldFollowup || resolvedQueue.mode === "steer")) {
|
if (isActive && (shouldFollowup || resolvedQueue.mode === "steer")) {
|
||||||
enqueueFollowupRun(queueKey, followupRun, resolvedQueue);
|
enqueueFollowupRun(queueKey, followupRun, resolvedQueue);
|
||||||
if (activeSessionEntry && activeSessionStore && sessionKey) {
|
if (activeSessionEntry && activeSessionStore && sessionKey) {
|
||||||
activeSessionEntry.updatedAt = Date.now();
|
const updatedAt = Date.now();
|
||||||
|
activeSessionEntry.updatedAt = updatedAt;
|
||||||
activeSessionStore[sessionKey] = activeSessionEntry;
|
activeSessionStore[sessionKey] = activeSessionEntry;
|
||||||
if (storePath) {
|
if (storePath) {
|
||||||
await updateSessionStore(storePath, (store) => {
|
await updateSessionStoreEntry({
|
||||||
store[sessionKey] = activeSessionEntry as SessionEntry;
|
storePath,
|
||||||
|
sessionKey,
|
||||||
|
update: async () => ({ updatedAt }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,12 +334,18 @@ export async function runReplyAgent(params: {
|
|||||||
sessionKey &&
|
sessionKey &&
|
||||||
activeSessionEntry.groupActivationNeedsSystemIntro
|
activeSessionEntry.groupActivationNeedsSystemIntro
|
||||||
) {
|
) {
|
||||||
|
const updatedAt = Date.now();
|
||||||
activeSessionEntry.groupActivationNeedsSystemIntro = false;
|
activeSessionEntry.groupActivationNeedsSystemIntro = false;
|
||||||
activeSessionEntry.updatedAt = Date.now();
|
activeSessionEntry.updatedAt = updatedAt;
|
||||||
activeSessionStore[sessionKey] = activeSessionEntry;
|
activeSessionStore[sessionKey] = activeSessionEntry;
|
||||||
if (storePath) {
|
if (storePath) {
|
||||||
await updateSessionStore(storePath, (store) => {
|
await updateSessionStoreEntry({
|
||||||
store[sessionKey] = activeSessionEntry as SessionEntry;
|
storePath,
|
||||||
|
sessionKey,
|
||||||
|
update: async () => ({
|
||||||
|
groupActivationNeedsSystemIntro: false,
|
||||||
|
updatedAt,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,6 +206,37 @@ describe("sessions", () => {
|
|||||||
expect(store[sessionKey]?.origin?.chatType).toBe("group");
|
expect(store[sessionKey]?.origin?.chatType).toBe("group");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("updateSessionStoreEntry preserves existing fields when patching", async () => {
|
||||||
|
const sessionKey = "agent:main:main";
|
||||||
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-"));
|
||||||
|
const storePath = path.join(dir, "sessions.json");
|
||||||
|
await fs.writeFile(
|
||||||
|
storePath,
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
[sessionKey]: {
|
||||||
|
sessionId: "sess-1",
|
||||||
|
updatedAt: 100,
|
||||||
|
reasoningLevel: "on",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
"utf-8",
|
||||||
|
);
|
||||||
|
|
||||||
|
await updateSessionStoreEntry({
|
||||||
|
storePath,
|
||||||
|
sessionKey,
|
||||||
|
update: async () => ({ updatedAt: 200 }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const store = loadSessionStore(storePath);
|
||||||
|
expect(store[sessionKey]?.updatedAt).toBeGreaterThanOrEqual(200);
|
||||||
|
expect(store[sessionKey]?.reasoningLevel).toBe("on");
|
||||||
|
});
|
||||||
|
|
||||||
it("updateSessionStore preserves concurrent additions", async () => {
|
it("updateSessionStore preserves concurrent additions", async () => {
|
||||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-"));
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-sessions-"));
|
||||||
const storePath = path.join(dir, "sessions.json");
|
const storePath = path.join(dir, "sessions.json");
|
||||||
|
|||||||
Reference in New Issue
Block a user