惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
A
About on SuperTechFans
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
D
DataBreaches.Net
B
Blog
博客园 - 【当耐特】
爱范儿
爱范儿
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
WordPress大学
WordPress大学
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
雷峰网
雷峰网
量子位
G
Google Developers Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor: migrate command session persistence to accessor...
jalehman · 2026-06-24 · via Recent Commits to openclaw:main
1+

import fs from "node:fs/promises";

2+

import os from "node:os";

3+

import path from "node:path";

4+

import { describe, expect, it } from "vitest";

5+

import { loadSessionStore, saveSessionStore } from "../../config/sessions.js";

6+

import type { SessionEntry } from "../../config/sessions/types.js";

7+

import { persistAbortTargetEntry, persistSessionEntry } from "./commands-session-store.js";

8+9+

async function withTempStore<T>(run: (storePath: string) => Promise<T>): Promise<T> {

10+

const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-command-session-store-"));

11+

try {

12+

return await run(path.join(dir, "sessions.json"));

13+

} finally {

14+

await fs.rm(dir, { recursive: true, force: true });

15+

}

16+

}

17+18+

describe("commands session store persistence", () => {

19+

it("persists a single command session entry through the accessor", async () => {

20+

await withTempStore(async (storePath) => {

21+

const sessionKey = "agent:main:command";

22+

const otherKey = "agent:main:other";

23+

const entry: SessionEntry = {

24+

sessionId: "command-session",

25+

updatedAt: 1,

26+

model: "gpt-5.5",

27+

};

28+

const otherEntry: SessionEntry = {

29+

sessionId: "other-session",

30+

updatedAt: 2,

31+

};

32+

await saveSessionStore(

33+

storePath,

34+

{

35+

[sessionKey]: { ...entry },

36+

[otherKey]: { ...otherEntry },

37+

},

38+

{ skipMaintenance: true },

39+

);

40+

const sessionStore: Record<string, SessionEntry> = { [sessionKey]: entry };

41+42+

await expect(

43+

persistSessionEntry({

44+

sessionEntry: entry,

45+

sessionStore,

46+

sessionKey,

47+

storePath,

48+

}),

49+

).resolves.toBe(true);

50+51+

const persisted = loadSessionStore(storePath, { skipCache: true });

52+

expect(sessionStore[sessionKey]).toBe(entry);

53+

expect(entry.updatedAt).not.toBe(1);

54+

expect(persisted[sessionKey]).toMatchObject({

55+

sessionId: "command-session",

56+

model: "gpt-5.5",

57+

updatedAt: entry.updatedAt,

58+

});

59+

expect(persisted[otherKey]).toStrictEqual(otherEntry);

60+

});

61+

});

62+63+

it("falls back to the supplied abort target when the persisted row is missing", async () => {

64+

await withTempStore(async (storePath) => {

65+

const sessionKey = "agent:main:abort-target";

66+

const entry: SessionEntry = {

67+

sessionId: "abort-session",

68+

updatedAt: 1,

69+

model: "gpt-5.5",

70+

};

71+

const sessionStore: Record<string, SessionEntry> = { [sessionKey]: entry };

72+

await fs.writeFile(storePath, JSON.stringify({}, null, 2), "utf8");

73+74+

await expect(

75+

persistAbortTargetEntry({

76+

entry,

77+

key: sessionKey,

78+

sessionStore,

79+

storePath,

80+

abortCutoff: { messageSid: "42", timestamp: 123 },

81+

}),

82+

).resolves.toBe(true);

83+84+

const persisted = loadSessionStore(storePath, { skipCache: true })[sessionKey];

85+

expect(sessionStore[sessionKey]).toBe(entry);

86+

expect(entry.abortedLastRun).toBe(true);

87+

expect(entry.abortCutoffMessageSid).toBe("42");

88+

expect(entry.abortCutoffTimestamp).toBe(123);

89+

expect(persisted).toMatchObject({

90+

sessionId: "abort-session",

91+

model: "gpt-5.5",

92+

abortedLastRun: true,

93+

abortCutoffMessageSid: "42",

94+

abortCutoffTimestamp: 123,

95+

});

96+

});

97+

});

98+99+

it("patches the persisted abort target when it already exists", async () => {

100+

await withTempStore(async (storePath) => {

101+

const sessionKey = "agent:main:abort-target";

102+

const otherKey = "agent:main:other";

103+

const entry: SessionEntry = {

104+

sessionId: "memory-session",

105+

updatedAt: 1,

106+

};

107+

const persistedEntry: SessionEntry = {

108+

sessionId: "persisted-session",

109+

updatedAt: 2,

110+

model: "sonnet-4.6",

111+

};

112+

const otherEntry: SessionEntry = {

113+

sessionId: "other-session",

114+

updatedAt: 3,

115+

};

116+

await saveSessionStore(

117+

storePath,

118+

{

119+

[sessionKey]: persistedEntry,

120+

[otherKey]: otherEntry,

121+

},

122+

{ skipMaintenance: true },

123+

);

124+125+

await expect(

126+

persistAbortTargetEntry({

127+

entry,

128+

key: sessionKey,

129+

sessionStore: { [sessionKey]: entry },

130+

storePath,

131+

}),

132+

).resolves.toBe(true);

133+134+

const persisted = loadSessionStore(storePath, { skipCache: true });

135+

expect(entry.abortedLastRun).toBe(true);

136+

expect(persisted[sessionKey]).toMatchObject({

137+

sessionId: "persisted-session",

138+

model: "sonnet-4.6",

139+

abortedLastRun: true,

140+

});

141+

expect(persisted[otherKey]).toStrictEqual(otherEntry);

142+

});

143+

});

144+

});