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

推荐订阅源

The GitHub Blog
The GitHub Blog
Martin Fowler
Martin Fowler
Vercel News
Vercel News
U
Unit 42
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
爱范儿
爱范儿
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
N
Netflix TechBlog - Medium
GbyAI
GbyAI
F
Fortinet All Blogs
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
M
MIT News - Artificial intelligence
D
Docker
IT之家
IT之家
Stack Overflow Blog
Stack Overflow 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
fix(telegram): guard duplicate polling leases · openclaw/...
steipete · 2026-04-25 · via Recent Commits to openclaw:main

@@ -17,6 +17,7 @@ import {

1717

isRecoverableTelegramNetworkError,

1818

isTelegramPollingNetworkError,

1919

} from "./network-errors.js";

20+

import { acquireTelegramPollingLease } from "./polling-lease.js";

2021

import { makeProxyFetch } from "./proxy.js";

21222223

export type { MonitorTelegramOpts } from "./monitor.types.js";

@@ -161,76 +162,96 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {

161162

const { TelegramPollingSession, readTelegramUpdateOffset, writeTelegramUpdateOffset } =

162163

await loadTelegramMonitorPollingRuntime();

163164164-

if (isTelegramExecApprovalHandlerConfigured({ cfg, accountId: account.accountId })) {

165-

registerChannelRuntimeContext({

166-

channelRuntime: opts.channelRuntime,

167-

channelId: "telegram",

168-

accountId: account.accountId,

169-

capability: CHANNEL_APPROVAL_NATIVE_RUNTIME_CONTEXT_CAPABILITY,

170-

context: { token },

171-

abortSignal: opts.abortSignal,

172-

});

173-

}

174-175-

const persistedOffsetRaw = await readTelegramUpdateOffset({

165+

const pollingLease = await acquireTelegramPollingLease({

166+

token,

176167

accountId: account.accountId,

177-

botToken: token,

168+

abortSignal: opts.abortSignal,

178169

});

179-

let lastUpdateId = normalizePersistedUpdateId(persistedOffsetRaw);

180-

if (persistedOffsetRaw !== null && lastUpdateId === null) {

170+

if (pollingLease.waitedForPrevious) {

171+

log(

172+

`[telegram][diag] waited for previous polling session for bot token ${pollingLease.tokenFingerprint} before starting account "${account.accountId}".`,

173+

);

174+

}

175+

if (pollingLease.replacedStoppingPrevious) {

181176

log(

182-

`[telegram] Ignoring invalid persisted update offset (${String(persistedOffsetRaw)}); starting without offset confirmation.`,

177+

`[telegram][diag] previous polling session for bot token ${pollingLease.tokenFingerprint} did not stop within the lease wait; starting a replacement for account "${account.accountId}".`,

183178

);

184179

}

185180186-

const persistUpdateId = async (updateId: number) => {

187-

const normalizedUpdateId = normalizePersistedUpdateId(updateId);

188-

if (normalizedUpdateId === null) {

189-

log(`[telegram] Ignoring invalid update_id value: ${String(updateId)}`);

190-

return;

191-

}

192-

if (lastUpdateId !== null && normalizedUpdateId <= lastUpdateId) {

193-

return;

194-

}

195-

lastUpdateId = normalizedUpdateId;

196-

try {

197-

await writeTelegramUpdateOffset({

181+

try {

182+

if (isTelegramExecApprovalHandlerConfigured({ cfg, accountId: account.accountId })) {

183+

registerChannelRuntimeContext({

184+

channelRuntime: opts.channelRuntime,

185+

channelId: "telegram",

198186

accountId: account.accountId,

199-

updateId: normalizedUpdateId,

200-

botToken: token,

187+

capability: CHANNEL_APPROVAL_NATIVE_RUNTIME_CONTEXT_CAPABILITY,

188+

context: { token },

189+

abortSignal: opts.abortSignal,

201190

});

202-

} catch (err) {

203-

(opts.runtime?.error ?? console.error)(

204-

`telegram: failed to persist update offset: ${String(err)}`,

205-

);

206191

}

207-

};

208192209-

// Preserve sticky IPv4 fallback state across clean/conflict restarts.

210-

// Dirty polling cycles rebuild transport inside TelegramPollingSession.

211-

const createTelegramTransportForPolling = () =>

212-

resolveTelegramTransport(proxyFetch, {

213-

network: account.config.network,

193+

const persistedOffsetRaw = await readTelegramUpdateOffset({

194+

accountId: account.accountId,

195+

botToken: token,

214196

});

215-

const telegramTransport = createTelegramTransportForPolling();

197+

let lastUpdateId = normalizePersistedUpdateId(persistedOffsetRaw);

198+

if (persistedOffsetRaw !== null && lastUpdateId === null) {

199+

log(

200+

`[telegram] Ignoring invalid persisted update offset (${String(persistedOffsetRaw)}); starting without offset confirmation.`,

201+

);

202+

}

216203217-

pollingSession = new TelegramPollingSession({

218-

token,

219-

config: cfg,

220-

accountId: account.accountId,

221-

runtime: opts.runtime,

222-

proxyFetch,

223-

abortSignal: opts.abortSignal,

224-

runnerOptions: createTelegramRunnerOptions(cfg),

225-

getLastUpdateId: () => lastUpdateId,

226-

persistUpdateId,

227-

log,

228-

telegramTransport,

229-

createTelegramTransport: createTelegramTransportForPolling,

230-

stallThresholdMs: account.config.pollingStallThresholdMs,

231-

setStatus: opts.setStatus,

232-

});

233-

await pollingSession.runUntilAbort();

204+

const persistUpdateId = async (updateId: number) => {

205+

const normalizedUpdateId = normalizePersistedUpdateId(updateId);

206+

if (normalizedUpdateId === null) {

207+

log(`[telegram] Ignoring invalid update_id value: ${String(updateId)}`);

208+

return;

209+

}

210+

if (lastUpdateId !== null && normalizedUpdateId <= lastUpdateId) {

211+

return;

212+

}

213+

lastUpdateId = normalizedUpdateId;

214+

try {

215+

await writeTelegramUpdateOffset({

216+

accountId: account.accountId,

217+

updateId: normalizedUpdateId,

218+

botToken: token,

219+

});

220+

} catch (err) {

221+

(opts.runtime?.error ?? console.error)(

222+

`telegram: failed to persist update offset: ${String(err)}`,

223+

);

224+

}

225+

};

226+227+

// Preserve sticky IPv4 fallback state across clean/conflict restarts.

228+

// Dirty polling cycles rebuild transport inside TelegramPollingSession.

229+

const createTelegramTransportForPolling = () =>

230+

resolveTelegramTransport(proxyFetch, {

231+

network: account.config.network,

232+

});

233+

const telegramTransport = createTelegramTransportForPolling();

234+235+

pollingSession = new TelegramPollingSession({

236+

token,

237+

config: cfg,

238+

accountId: account.accountId,

239+

runtime: opts.runtime,

240+

proxyFetch,

241+

abortSignal: opts.abortSignal,

242+

runnerOptions: createTelegramRunnerOptions(cfg),

243+

getLastUpdateId: () => lastUpdateId,

244+

persistUpdateId,

245+

log,

246+

telegramTransport,

247+

createTelegramTransport: createTelegramTransportForPolling,

248+

stallThresholdMs: account.config.pollingStallThresholdMs,

249+

setStatus: opts.setStatus,

250+

});

251+

await pollingSession.runUntilAbort();

252+

} finally {

253+

pollingLease.release();

254+

}

234255

} finally {

235256

unregisterHandler();

236257

}