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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
Y
Y Combinator Blog
IT之家
IT之家
博客园 - 聂微东
L
LangChain Blog
爱范儿
爱范儿
H
Help Net Security
GbyAI
GbyAI
F
Fortinet All Blogs
B
Blog
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
D
DataBreaches.Net
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享

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
fix(telegram): avoid stealing live spool claims · opencla...
obviyus · 2026-05-16 · via Recent Commits to openclaw:main

@@ -7,19 +7,28 @@ import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";

7788

const SPOOL_VERSION = 1;

99

export const TELEGRAM_SPOOLED_UPDATE_PROCESSING_STALE_MS = 6 * 60 * 60 * 1000;

10+

const TELEGRAM_SPOOLED_UPDATE_PROCESS_ID = `${process.pid}:${randomUUID()}`;

11+12+

type TelegramSpooledUpdateClaimOwner = {

13+

processId: string;

14+

processPid: number;

15+

claimedAt: number;

16+

};

10171118

type TelegramSpooledUpdatePayload = {

1219

version: number;

1320

updateId: number;

1421

receivedAt: number;

1522

update: unknown;

23+

claim?: TelegramSpooledUpdateClaimOwner;

1624

};

17251826

export type TelegramSpooledUpdate = {

1927

updateId: number;

2028

path: string;

2129

update: unknown;

2230

receivedAt: number;

31+

claim?: TelegramSpooledUpdateClaimOwner;

2332

};

24332534

export type ClaimedTelegramSpooledUpdate = TelegramSpooledUpdate & {

@@ -105,12 +114,59 @@ function parseSpooledUpdate(value: unknown, filePath: string): TelegramSpooledUp

105114

if (payload.version !== SPOOL_VERSION || !isValidUpdateId(payload.updateId)) {

106115

return null;

107116

}

108-

return {

117+

const update: TelegramSpooledUpdate = {

109118

updateId: payload.updateId,

110119

path: filePath,

111120

update: payload.update,

112121

receivedAt: typeof payload.receivedAt === "number" ? payload.receivedAt : 0,

113122

};

123+

if (

124+

payload.claim &&

125+

typeof payload.claim.processId === "string" &&

126+

isValidUpdateId(payload.claim.processPid) &&

127+

typeof payload.claim.claimedAt === "number"

128+

) {

129+

update.claim = payload.claim;

130+

}

131+

return update;

132+

}

133+134+

function buildClaimedPayload(update: TelegramSpooledUpdate): TelegramSpooledUpdatePayload {

135+

return {

136+

version: SPOOL_VERSION,

137+

updateId: update.updateId,

138+

receivedAt: update.receivedAt,

139+

update: update.update,

140+

claim: {

141+

processId: TELEGRAM_SPOOLED_UPDATE_PROCESS_ID,

142+

processPid: process.pid,

143+

claimedAt: Date.now(),

144+

},

145+

};

146+

}

147+148+

function processExists(pid: number): boolean {

149+

try {

150+

process.kill(pid, 0);

151+

return true;

152+

} catch (err) {

153+

return (err as { code?: string }).code !== "ESRCH";

154+

}

155+

}

156+157+

function isFreshClaimOwner(claim: TelegramSpooledUpdateClaimOwner): boolean {

158+

return Date.now() - claim.claimedAt < TELEGRAM_SPOOLED_UPDATE_PROCESSING_STALE_MS;

159+

}

160+161+

export function isTelegramSpooledUpdateClaimOwnedByOtherLiveProcess(

162+

claim: ClaimedTelegramSpooledUpdate,

163+

): boolean {

164+

return Boolean(

165+

claim.claim &&

166+

claim.claim.processId !== TELEGRAM_SPOOLED_UPDATE_PROCESS_ID &&

167+

isFreshClaimOwner(claim.claim) &&

168+

processExists(claim.claim.processPid),

169+

);

114170

}

115171116172

export async function writeTelegramSpooledUpdate(params: {

@@ -183,26 +239,32 @@ export async function claimTelegramSpooledUpdate(

183239

update: TelegramSpooledUpdate,

184240

): Promise<ClaimedTelegramSpooledUpdate | null> {

185241

const claimedPath = processingPath(path.dirname(update.path), update.updateId);

186-

try {

187-

// A hard link is an atomic non-overwriting claim in the same spool directory.

188-

await fs.link(update.path, claimedPath);

189-

} catch (err) {

190-

const code = (err as { code?: string }).code;

191-

if (code === "ENOENT") {

192-

return null;

193-

}

194-

if (code === "EEXIST") {

195-

await unlinkIfPresent(update.path);

196-

return null;

197-

}

198-

throw err;

199-

}

242+

const holdPath = path.join(

243+

path.dirname(update.path),

244+

`${spoolFileName(update.updateId)}.${randomUUID()}.claim`,

245+

);

246+

const tempPath = path.join(

247+

path.dirname(update.path),

248+

`${processingFileName(update.updateId)}.${randomUUID()}.tmp`,

249+

);

200250

try {

201251

const claimedAt = new Date();

252+

await fs.writeFile(tempPath, `${JSON.stringify(buildClaimedPayload(update))}\n`, {

253+

mode: 0o600,

254+

});

255+

await fs.link(update.path, holdPath);

256+

await fs.link(tempPath, claimedPath);

257+

await unlinkIfPresent(tempPath);

258+

await unlinkIfPresent(holdPath);

202259

await fs.utimes(claimedPath, claimedAt, claimedAt);

203260

await unlinkIfPresent(update.path);

204261

} catch (err) {

205-

await unlinkIfPresent(claimedPath);

262+

const code = (err as { code?: string }).code;

263+

await unlinkIfPresent(tempPath);

264+

await unlinkIfPresent(holdPath);

265+

if (code === "ENOENT" || code === "EEXIST") {

266+

return null;

267+

}

206268

throw err;

207269

}

208270

return {