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

推荐订阅源

Google DeepMind News
Google DeepMind News
L
LangChain Blog
H
Help Net Security
博客园_首页
T
Tailwind CSS Blog
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
Recent Announcements
Recent Announcements
D
DataBreaches.Net
U
Unit 42
Vercel News
Vercel News
I
InfoQ
Martin Fowler
Martin Fowler
Microsoft Azure Blog
Microsoft Azure Blog
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
Jina AI
Jina AI
博客园 - 叶小钗
博客园 - 【当耐特】
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
Last Week in AI
Last Week in AI

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(telegram): persist plugin state in sqlite · open...
steipete · 2026-05-31 · via Recent Commits to openclaw:main

@@ -2,15 +2,28 @@ import { mkdtempSync, rmSync } from "node:fs";

22

import { tmpdir } from "node:os";

33

import path from "node:path";

44

import type { Message } from "grammy/types";

5-

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

65

import {

6+

createPluginStateKeyedStoreForTests,

7+

createPluginStateSyncKeyedStoreForTests,

8+

resetPluginStateStoreForTests,

9+

} from "openclaw/plugin-sdk/plugin-state-test-runtime";

10+

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

11+

import {

12+

TELEGRAM_MESSAGE_DISPATCH_DEDUPE_MAX_ENTRIES,

13+

TELEGRAM_MESSAGE_DISPATCH_DEDUPE_NAMESPACE,

714

buildTelegramMessageDispatchReplayKey,

815

claimTelegramMessageDispatchReplay,

916

commitTelegramMessageDispatchReplay,

1017

createTelegramMessageDispatchReplayGuard,

1118

releaseTelegramMessageDispatchReplay,

19+

setTelegramMessageDispatchDedupeStoreForTest,

1220

} from "./message-dispatch-dedupe.js";

132122+

type MessageDispatchDedupeStore = NonNullable<

23+

Parameters<typeof setTelegramMessageDispatchDedupeStoreForTest>[0]

24+

>;

25+

type SyncMessageDispatchDedupeStore = Extract<MessageDispatchDedupeStore, { entries(): unknown[] }>;

26+1427

const tempDirs: string[] = [];

15281629

function createStorePath(): string {

@@ -27,7 +40,19 @@ function message(params?: { chatId?: number; messageId?: number }): Message {

2740

} as Message;

2841

}

294243+

beforeEach(async () => {

44+

resetPluginStateStoreForTests({ closeDatabase: false });

45+

const store = createPluginStateKeyedStoreForTests("telegram", {

46+

namespace: TELEGRAM_MESSAGE_DISPATCH_DEDUPE_NAMESPACE,

47+

maxEntries: TELEGRAM_MESSAGE_DISPATCH_DEDUPE_MAX_ENTRIES,

48+

}) as NonNullable<Parameters<typeof setTelegramMessageDispatchDedupeStoreForTest>[0]>;

49+

await store.clear();

50+

setTelegramMessageDispatchDedupeStoreForTest(store);

51+

});

52+3053

afterEach(() => {

54+

setTelegramMessageDispatchDedupeStoreForTest(undefined);

55+

resetPluginStateStoreForTests();

3156

for (const dir of tempDirs.splice(0)) {

3257

rmSync(dir, { recursive: true, force: true });

3358

}

@@ -73,6 +98,161 @@ describe("Telegram message dispatch replay guard", () => {

7398

).resolves.toEqual({ kind: "duplicate" });

7499

});

75100101+

it("preserves concurrent commits that share dedupe buckets", async () => {

102+

const storePath = createStorePath();

103+

const writer = createTelegramMessageDispatchReplayGuard({ storePath });

104+

const keys = Array.from({ length: 400 }, (_, index) =>

105+

JSON.stringify(["message", "1234", index + 1]),

106+

);

107+108+

await commitTelegramMessageDispatchReplay({

109+

guard: writer,

110+

accountId: "default",

111+

keys,

112+

});

113+114+

const reader = createTelegramMessageDispatchReplayGuard({ storePath });

115+

await expect(reader.warmup("default")).resolves.toBe(keys.length);

116+

});

117+118+

it("falls back to same-process replay protection when plugin-state cannot open", async () => {

119+

setTelegramMessageDispatchDedupeStoreForTest(undefined);

120+

const errors: unknown[] = [];

121+

const storePath = createStorePath();

122+

const guard = createTelegramMessageDispatchReplayGuard({

123+

storePath,

124+

onDiskError: (error) => errors.push(error),

125+

});

126+

const first = await claimTelegramMessageDispatchReplay({

127+

guard,

128+

accountId: "default",

129+

msg: message(),

130+

});

131+

if (first.kind !== "claimed") {

132+

throw new Error("expected initial claim");

133+

}

134+135+

await expect(guard.commit(first.key, { namespace: "default" })).resolves.toBe(false);

136+137+

await expect(

138+

claimTelegramMessageDispatchReplay({

139+

guard,

140+

accountId: "default",

141+

msg: message(),

142+

}),

143+

).resolves.toEqual({ kind: "duplicate" });

144+

await expect(guard.hasRecent(first.key, { namespace: "default" })).resolves.toBe(true);

145+

expect(errors.length).toBeGreaterThan(0);

146+

});

147+148+

it("keeps same-process replay protection when plugin-state commit fails", async () => {

149+

const failingStore = createPluginStateKeyedStoreForTests("telegram", {

150+

namespace: TELEGRAM_MESSAGE_DISPATCH_DEDUPE_NAMESPACE,

151+

maxEntries: TELEGRAM_MESSAGE_DISPATCH_DEDUPE_MAX_ENTRIES,

152+

}) as NonNullable<Parameters<typeof setTelegramMessageDispatchDedupeStoreForTest>[0]>;

153+

setTelegramMessageDispatchDedupeStoreForTest({

154+

...failingStore,

155+

async register() {

156+

throw new Error("state write failed");

157+

},

158+

});

159+

const storePath = createStorePath();

160+

const guard = createTelegramMessageDispatchReplayGuard({ storePath });

161+

const first = await claimTelegramMessageDispatchReplay({

162+

guard,

163+

accountId: "default",

164+

msg: message(),

165+

});

166+

if (first.kind !== "claimed") {

167+

throw new Error("expected initial claim");

168+

}

169+170+

await expect(guard.commit(first.key, { namespace: "default" })).resolves.toBe(false);

171+172+

await expect(

173+

claimTelegramMessageDispatchReplay({

174+

guard,

175+

accountId: "default",

176+

msg: message(),

177+

}),

178+

).resolves.toEqual({ kind: "duplicate" });

179+

await expect(guard.hasRecent(first.key, { namespace: "default" })).resolves.toBe(true);

180+

await expect(guard.warmup("default")).resolves.toBe(1);

181+

});

182+183+

it("keeps same-process replay protection when lookup fails after a successful commit", async () => {

184+

const backingStore = createPluginStateSyncKeyedStoreForTests("telegram", {

185+

namespace: TELEGRAM_MESSAGE_DISPATCH_DEDUPE_NAMESPACE,

186+

maxEntries: TELEGRAM_MESSAGE_DISPATCH_DEDUPE_MAX_ENTRIES,

187+

}) as SyncMessageDispatchDedupeStore;

188+

let failLookup = false;

189+

setTelegramMessageDispatchDedupeStoreForTest({

190+

...backingStore,

191+

lookup(key) {

192+

if (failLookup) {

193+

throw new Error("state read failed");

194+

}

195+

return backingStore.lookup(key);

196+

},

197+

});

198+

const storePath = createStorePath();

199+

const guard = createTelegramMessageDispatchReplayGuard({ storePath });

200+

const first = await claimTelegramMessageDispatchReplay({

201+

guard,

202+

accountId: "default",

203+

msg: message(),

204+

});

205+

if (first.kind !== "claimed") {

206+

throw new Error("expected initial claim");

207+

}

208+

await expect(guard.commit(first.key, { namespace: "default" })).resolves.toBe(true);

209+210+

failLookup = true;

211+212+

await expect(

213+

claimTelegramMessageDispatchReplay({

214+

guard,

215+

accountId: "default",

216+

msg: message(),

217+

}),

218+

).resolves.toEqual({ kind: "duplicate" });

219+

});

220+221+

it("keeps replay histories isolated by session store path", async () => {

222+

const firstStorePath = createStorePath();

223+

const secondStorePath = createStorePath();

224+

const firstGuard = createTelegramMessageDispatchReplayGuard({

225+

storePath: firstStorePath,

226+

});

227+

const first = await claimTelegramMessageDispatchReplay({

228+

guard: firstGuard,

229+

accountId: "default",

230+

msg: message(),

231+

});

232+

if (first.kind !== "claimed") {

233+

throw new Error("expected initial claim");

234+

}

235+

await commitTelegramMessageDispatchReplay({

236+

guard: firstGuard,

237+

accountId: "default",

238+

keys: [first.key],

239+

});

240+241+

const secondGuard = createTelegramMessageDispatchReplayGuard({

242+

storePath: secondStorePath,

243+

});

244+

await expect(

245+

claimTelegramMessageDispatchReplay({

246+

guard: secondGuard,

247+

accountId: "default",

248+

msg: message(),

249+

}),

250+

).resolves.toEqual({

251+

kind: "claimed",

252+

key: first.key,

253+

});

254+

});

255+76256

it("keeps accounts isolated and releases retryable pre-dispatch claims", async () => {

77257

const storePath = createStorePath();

78258

const guard = createTelegramMessageDispatchReplayGuard({ storePath });

@@ -112,4 +292,34 @@ describe("Telegram message dispatch replay guard", () => {

112292

key: first.key,

113293

});

114294

});

295+296+

it("lets an in-flight duplicate retry after the first claim is released", async () => {

297+

const storePath = createStorePath();

298+

const guard = createTelegramMessageDispatchReplayGuard({ storePath });

299+

const first = await claimTelegramMessageDispatchReplay({

300+

guard,

301+

accountId: "default",

302+

msg: message(),

303+

});

304+

if (first.kind !== "claimed") {

305+

throw new Error("expected initial claim");

306+

}

307+308+

const duplicate = claimTelegramMessageDispatchReplay({

309+

guard,

310+

accountId: "default",

311+

msg: message(),

312+

});

313+

releaseTelegramMessageDispatchReplay({

314+

guard,

315+

accountId: "default",

316+

keys: [first.key],

317+

error: new Error("retry"),

318+

});

319+320+

await expect(duplicate).resolves.toEqual({

321+

kind: "claimed",

322+

key: first.key,

323+

});

324+

});

115325

});