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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
Google Developers Blog
博客园 - 司徒正美
J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
D
Docker
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
腾讯CDC
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
M
MIT News - Artificial intelligence
Jina AI
Jina AI
I
InfoQ
雷峰网
雷峰网
The Cloudflare Blog
美团技术团队
Engineering at Meta
Engineering at Meta

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): share bot api throttler · openclaw/opencla...
obviyus · 2026-05-09 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -9,6 +9,7 @@ Docs: https://docs.openclaw.ai

99

- CLI: make parser, startup, config, guardrail, channel, agent, task, session, and MCP failures explain what happened and point to the next recovery command.

1010

- GitHub Copilot: refresh the model catalog from `${baseUrl}/models` so per-account entitlement and accurate context windows surface at runtime; static manifest catalog (now including `gpt-5.5`) remains the fallback when discovery is disabled or the API is unreachable.

1111

- Active Memory: support concrete `plugins.entries.active-memory.config.toolsAllow` recall tool names for custom memory plugins while keeping the built-in memory-core default on `memory_search`/`memory_get` and preserving `memory_recall` automatically for `plugins.slots.memory: "memory-lancedb"`.

12+

- Telegram: share the grammY API throttler across polling and ad hoc send clients for the same bot token, so visible draft previews and CLI sends use one quota gate. Thanks @anagnorisis2peripeteia.

1213

- Telegram/Feishu: honor configured per-agent and global `reasoningDefault` values when deciding whether channel reasoning previews should stream or stay hidden, addressing the preview-default part of #73182. Thanks @anagnorisis2peripeteia.

1314

- Docker: run the runtime image under `tini` so long-lived containers reap orphaned child processes and forward signals correctly. (#77885) Thanks @VintageAyu.

1415

- Google/Gemini: normalize retired `google/gemini-3-pro-preview` and `google-gemini-cli/gemini-3-pro-preview` selections to `google/gemini-3.1-pro-preview` before they are written to model config.

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,17 @@

1+

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

2+

import { clearAccountThrottlersForTest, getOrCreateAccountThrottler } from "./account-throttler.js";

3+
4+

describe("getOrCreateAccountThrottler", () => {

5+

beforeEach(() => {

6+

clearAccountThrottlersForTest();

7+

});

8+
9+

it("shares throttlers per bot token", () => {

10+

const first = getOrCreateAccountThrottler("tok");

11+

const second = getOrCreateAccountThrottler("tok");

12+

const other = getOrCreateAccountThrottler("other");

13+
14+

expect(second).toBe(first);

15+

expect(other).not.toBe(first);

16+

});

17+

});

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,21 @@

1+

import { apiThrottler } from "./bot.runtime.js";

2+
3+

type ApiThrottlerTransformer = ReturnType<typeof apiThrottler>;

4+
5+

const throttlerByToken = new Map<string, ApiThrottlerTransformer>();

6+
7+

export function getOrCreateAccountThrottler(

8+

token: string,

9+

createThrottler: () => ApiThrottlerTransformer = apiThrottler,

10+

): ApiThrottlerTransformer {

11+

let throttler = throttlerByToken.get(token);

12+

if (!throttler) {

13+

throttler = createThrottler();

14+

throttlerByToken.set(token, throttler);

15+

}

16+

return throttler;

17+

}

18+
19+

export function clearAccountThrottlersForTest(): void {

20+

throttlerByToken.clear();

21+

}

Original file line numberDiff line numberDiff line change

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

2323

normalizeOptionalLowercaseString,

2424

normalizeOptionalString,

2525

} from "openclaw/plugin-sdk/text-runtime";

26+

import { getOrCreateAccountThrottler } from "./account-throttler.js";

2627

import { resolveTelegramAccount } from "./accounts.js";

2728

import { normalizeTelegramApiRoot } from "./api-root.js";

2829

import type { TelegramBotDeps } from "./bot-deps.js";

@@ -353,7 +354,7 @@ export function createTelegramBotCore(

353354

? { ...(client ? { client } : {}), ...(opts.botInfo ? { botInfo: opts.botInfo } : {}) }

354355

: undefined;

355356

const bot = new botRuntime.Bot(opts.token, botConfig);

356-

bot.api.config.use(botRuntime.apiThrottler());

357+

bot.api.config.use(getOrCreateAccountThrottler(opts.token, botRuntime.apiThrottler));

357358

// Catch all errors from bot middleware to prevent unhandled rejections

358359

bot.catch((err) => {

359360

runtime.error?.(danger(`telegram bot error: ${formatUncaughtError(err)}`));

Original file line numberDiff line numberDiff line change

@@ -47,6 +47,7 @@ const {

4747

getTelegramSequentialKey,

4848

setTelegramBotRuntimeForTest,

4949

} = await import("./bot-core.js");

50+

const { clearAccountThrottlersForTest } = await import("./account-throttler.js");

5051

const { resetTelegramForumFlagCacheForTest } = await import("./bot/helpers.js");

5152

let createTelegramBot: (

5253

opts: TelegramBotOptions,

@@ -173,6 +174,8 @@ describe("createTelegramBot", () => {

173174

});

174175

beforeEach(() => {

175176

resetTelegramForumFlagCacheForTest();

177+

clearAccountThrottlersForTest();

178+

throttlerSpy.mockReset();

176179

setTelegramBotRuntimeForTest(

177180

telegramBotRuntimeForTest as unknown as Parameters<typeof setTelegramBotRuntimeForTest>[0],

178181

);

@@ -191,6 +194,15 @@ describe("createTelegramBot", () => {

191194

expect(useSpy).toHaveBeenCalledWith("throttler");

192195

});

193196
197+

it("reuses the grammY throttler for the same token", () => {

198+

createTelegramBot({ token: "tok" });

199+

createTelegramBot({ token: "tok" });

200+

createTelegramBot({ token: "other" });

201+
202+

expect(throttlerSpy).toHaveBeenCalledTimes(2);

203+

expect(useSpy).toHaveBeenCalledTimes(3);

204+

});

205+
194206

it("logs middleware errors through grammY catch without rethrowing", () => {

195207

const runtime = {

196208

error: vi.fn(),

Original file line numberDiff line numberDiff line change

@@ -8,7 +8,8 @@ import {

88

import type { MockFn } from "openclaw/plugin-sdk/plugin-test-runtime";

99

import { beforeEach, vi } from "vitest";

1010
11-

const { botApi, botCtorSpy } = vi.hoisted(() => ({

11+

const { botApi, botConfigUseSpy, botCtorSpy } = vi.hoisted(() => ({

12+

botConfigUseSpy: vi.fn(),

1213

botApi: {

1314

deleteMessage: vi.fn(),

1415

editForumTopic: vi.fn(),

@@ -87,7 +88,8 @@ const {

8788

}));

8889
8990

type TelegramSendTestMocks = {

90-

botApi: Record<string, MockFn>;

91+

botApi: typeof botApi;

92+

botConfigUseSpy: MockFn;

9193

botCtorSpy: MockFn;

9294

loadConfig: MockFn;

9395

resolveStorePath: MockFn;

@@ -107,7 +109,12 @@ vi.mock("grammy", () => ({

107109

ALL_UPDATE_TYPES: ["message"],

108110

},

109111

Bot: class {

110-

api = botApi;

112+

api = {

113+

...botApi,

114+

config: {

115+

use: botConfigUseSpy,

116+

},

117+

};

111118

catch = vi.fn();

112119

constructor(

113120

public token: string,

@@ -171,6 +178,7 @@ vi.mock("./target-writeback.js", () => ({

171178

export function getTelegramSendTestMocks(): TelegramSendTestMocks {

172179

return {

173180

botApi,

181+

botConfigUseSpy,

174182

botCtorSpy,

175183

loadConfig,

176184

resolveStorePath,

@@ -198,6 +206,7 @@ export function installTelegramSendTestHooks() {

198206

undiciEnvHttpProxyAgentCtor.mockClear();

199207

undiciProxyAgentCtor.mockClear();

200208

botCtorSpy.mockReset();

209+

botConfigUseSpy.mockReset();

201210

for (const fn of Object.values(botApi)) {

202211

fn.mockReset();

203212

}

Original file line numberDiff line numberDiff line change

@@ -18,6 +18,7 @@ installTelegramSendTestHooks();

1818
1919

const {

2020

botApi,

21+

botConfigUseSpy,

2122

botCtorSpy,

2223

imageMetadata,

2324

loadConfig,

@@ -525,6 +526,14 @@ describe("sendMessageTelegram", () => {

525526

);

526527

});

527528
529+

it("installs the shared grammY throttler on send clients", async () => {

530+

botApi.sendMessage.mockResolvedValue({ message_id: 1, chat: { id: "123" } });

531+
532+

await sendMessageTelegram("123", "hi", { cfg: TELEGRAM_TEST_CFG, token: "tok" });

533+
534+

expect(botConfigUseSpy).toHaveBeenCalledWith(expect.any(Function));

535+

});

536+
528537

it("falls back to plain text when Telegram rejects HTML and preserves send params", async () => {

529538

const parseErr = new Error(

530539

"400: Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 9",

Original file line numberDiff line numberDiff line change

@@ -8,6 +8,7 @@ import { createTelegramRetryRunner, type RetryConfig } from "openclaw/plugin-sdk

88

import { createSubsystemLogger, logVerbose } from "openclaw/plugin-sdk/runtime-env";

99

import { formatErrorMessage } from "openclaw/plugin-sdk/ssrf-runtime";

1010

import { normalizeOptionalString, redactSensitiveText } from "openclaw/plugin-sdk/text-runtime";

11+

import { getOrCreateAccountThrottler } from "./account-throttler.js";

1112

import { type ResolvedTelegramAccount, resolveTelegramAccount } from "./accounts.js";

1213

import { withTelegramApiErrorLogging } from "./api-logging.js";

1314

import { normalizeTelegramApiRoot } from "./api-root.js";

@@ -447,7 +448,14 @@ function resolveTelegramApiContext(opts: {

447448

});

448449

const token = resolveToken(opts.token, account);

449450

const client = resolveTelegramClientOptions(account);

450-

const api = (opts.api ?? new Bot(token, client ? { client } : undefined).api) as TelegramApi;

451+

let api: TelegramApi;

452+

if (opts.api) {

453+

api = opts.api as TelegramApi;

454+

} else {

455+

const bot = new Bot(token, client ? { client } : undefined);

456+

bot.api.config.use(getOrCreateAccountThrottler(token));

457+

api = bot.api;

458+

}

451459

return { cfg, account, api };

452460

}

453461