Skip to content

Commit 4f540c7

Browse files
committed
fix(telegram): warn on stale polling status
1 parent 39f8109 commit 4f540c7

4 files changed

Lines changed: 189 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Docs: https://docs.openclaw.ai
2222
- Channels/Telegram: honor `ALL_PROXY` / `all_proxy` and service-level `OPENCLAW_PROXY_URL` when constructing the HTTP/1-only Telegram Bot API transport, so Windows and service installs that rely on those proxy settings no longer fall back to direct egress. Fixes #74014; refs #74086. Thanks @SymbolStar.
2323
- Channels/Telegram: continue polling when `deleteWebhook` hits a transient network failure but `getWebhookInfo` confirms no webhook is configured, so startup does not retry cleanup forever after the webhook was already removed. Refs #74086; carries forward #47384. Thanks @clovericbot.
2424
- Channels/Telegram: apply strict safe-send retry to inbound final replies when grammY wraps a pre-connect failure, while leaving ambiguous plain network envelopes single-shot to avoid duplicate visible messages. Fixes #74203. Thanks @nanli2000cn.
25+
- Channels/Telegram: surface polling liveness warnings in channel status and doctor when a running long-poller has not completed `getUpdates` after startup grace or its transport activity is stale, so silent polling failures no longer look clean. Refs #74299. Thanks @lolaopenclaw.
2526
- ACP/commands: accept forwarded ACP timeout config controls in the OpenClaw bridge, treat unsupported discard-close controls as recoverable cleanup, and restore native `/verbose full` plus no-arg status behavior, so Discord command menus and nested ACP turns no longer fail on supported session controls. Thanks @vincentkoc.
2627
- TUI/status: clear stale `streaming` footer state when a final event arrives after the active run was already cleared and no tracked runs remain, while preserving concurrent-run ownership and inactive local `/btw` terminal handling. Fixes #64825; carries forward #64842, #64843, #64847, and #64862. Thanks @briandevans and @Yanhu007.
2728
- Channels/Discord: fail startup closed when Discord cannot resolve the bot's own identity and keep mention gating active when only configured mention patterns can detect mentions, so the provider no longer continues with a missing bot id. Fixes #42219; carries forward #46856 and #49218. Thanks @education-01 and @BenediktSchackenberg.

‎docs/channels/telegram.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ Per-account, per-group, and per-topic overrides are supported (same inheritance
867867
- Some hosts resolve `api.telegram.org` to IPv6 first; broken IPv6 egress can cause intermittent Telegram API failures.
868868
- If logs include `TypeError: fetch failed` or `Network request for 'getUpdates' failed!`, OpenClaw now retries these as recoverable network errors.
869869
- If logs include `Polling stall detected`, OpenClaw restarts polling and rebuilds the Telegram transport after 120 seconds without completed long-poll liveness by default.
870+
- `openclaw channels status --probe` and `openclaw doctor` warn when a running polling account has not completed `getUpdates` after startup grace, or when its last successful polling transport activity is stale.
870871
- Increase `channels.telegram.pollingStallThresholdMs` only when long-running `getUpdates` calls are healthy but your host still reports false polling-stall restarts. Persistent stalls usually point to proxy, DNS, IPv6, or TLS egress issues between the host and `api.telegram.org`.
871872
- Telegram also honors process proxy env for Bot API transport, including `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, and their lowercase variants. `NO_PROXY` / `no_proxy` can still bypass `api.telegram.org`.
872873
- If the OpenClaw managed proxy is configured through `OPENCLAW_PROXY_URL` for a service environment and no standard proxy env is present, Telegram uses that URL for Bot API transport too.

‎extensions/telegram/src/status-issues.ts‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@ import type {
22
ChannelAccountSnapshot,
33
ChannelStatusIssue,
44
} from "openclaw/plugin-sdk/channel-contract";
5+
import { formatCliCommand } from "openclaw/plugin-sdk/cli-runtime";
56
import {
67
appendMatchMetadata,
78
asString,
89
isRecord,
910
resolveEnabledConfiguredAccountId,
1011
} from "openclaw/plugin-sdk/status-helpers";
1112

13+
const TELEGRAM_POLLING_CONNECT_GRACE_MS = 120_000;
14+
const TELEGRAM_POLLING_STALE_TRANSPORT_MS = 30 * 60_000;
15+
1216
type TelegramAccountStatus = {
1317
accountId?: unknown;
1418
enabled?: unknown;
1519
configured?: unknown;
20+
running?: unknown;
21+
connected?: unknown;
22+
mode?: unknown;
23+
lastStartAt?: unknown;
24+
lastTransportActivityAt?: unknown;
25+
lastError?: unknown;
1626
allowUnmentionedGroups?: unknown;
1727
audit?: unknown;
1828
};
@@ -38,11 +48,82 @@ function readTelegramAccountStatus(value: ChannelAccountSnapshot): TelegramAccou
3848
accountId: value.accountId,
3949
enabled: value.enabled,
4050
configured: value.configured,
51+
running: value.running,
52+
connected: value.connected,
53+
mode: value.mode,
54+
lastStartAt: value.lastStartAt,
55+
lastTransportActivityAt: value.lastTransportActivityAt,
56+
lastError: value.lastError,
4157
allowUnmentionedGroups: value.allowUnmentionedGroups,
4258
audit: value.audit,
4359
};
4460
}
4561

62+
function asFiniteNumber(value: unknown): number | null {
63+
return typeof value === "number" && Number.isFinite(value) ? value : null;
64+
}
65+
66+
function appendTelegramRuntimeError(message: string, lastError: unknown): string {
67+
const error = asString(lastError);
68+
return error ? `${message}: ${error}` : message;
69+
}
70+
71+
function collectTelegramPollingRuntimeIssues(params: {
72+
account: TelegramAccountStatus;
73+
accountId: string;
74+
issues: ChannelStatusIssue[];
75+
now: number;
76+
}) {
77+
const { account, accountId, issues, now } = params;
78+
if (account.running !== true || asString(account.mode) !== "polling") {
79+
return;
80+
}
81+
82+
const lastStartAt = asFiniteNumber(account.lastStartAt);
83+
const lastTransportActivityAt = asFiniteNumber(account.lastTransportActivityAt);
84+
const fix = `Run: ${formatCliCommand("openclaw channels status --probe")} (or restart the gateway). Check the bot token, proxy/network settings, and logs if it persists.`;
85+
86+
if (account.connected === false) {
87+
const withinStartupGrace =
88+
lastStartAt != null && now - lastStartAt < TELEGRAM_POLLING_CONNECT_GRACE_MS;
89+
if (!withinStartupGrace) {
90+
issues.push({
91+
channel: "telegram",
92+
accountId,
93+
kind: "runtime",
94+
message: appendTelegramRuntimeError(
95+
"Telegram polling is running but has not completed a successful getUpdates call since startup",
96+
account.lastError,
97+
),
98+
fix,
99+
});
100+
}
101+
return;
102+
}
103+
104+
if (account.connected === true && lastTransportActivityAt != null) {
105+
if (lastStartAt != null && lastTransportActivityAt < lastStartAt) {
106+
const lifecycleAgeMs = Math.max(0, now - lastStartAt);
107+
if (lifecycleAgeMs <= TELEGRAM_POLLING_STALE_TRANSPORT_MS) {
108+
return;
109+
}
110+
}
111+
const ageMs = now - lastTransportActivityAt;
112+
if (ageMs > TELEGRAM_POLLING_STALE_TRANSPORT_MS) {
113+
issues.push({
114+
channel: "telegram",
115+
accountId,
116+
kind: "runtime",
117+
message: appendTelegramRuntimeError(
118+
`Telegram polling transport is stale (last successful getUpdates ${Math.max(0, Math.floor(ageMs / 60_000))}m ago)`,
119+
account.lastError,
120+
),
121+
fix,
122+
});
123+
}
124+
}
125+
}
126+
46127
function readTelegramGroupMembershipAuditSummary(
47128
value: unknown,
48129
): TelegramGroupMembershipAuditSummary {
@@ -94,6 +175,13 @@ export function collectTelegramStatusIssues(
94175
continue;
95176
}
96177

178+
collectTelegramPollingRuntimeIssues({
179+
account,
180+
accountId,
181+
issues,
182+
now: Date.now(),
183+
});
184+
97185
if (account.allowUnmentionedGroups === true) {
98186
issues.push({
99187
channel: "telegram",

‎extensions/telegram/src/status.test.ts‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,105 @@ describe("collectTelegramStatusIssues", () => {
7373
expect(issues[0]?.message).toContain("channels.telegram.groups");
7474
});
7575

76+
it("reports polling runtime state that never completed getUpdates after startup grace", () => {
77+
const issues = collectTelegramStatusIssues([
78+
{
79+
accountId: "main",
80+
enabled: true,
81+
configured: true,
82+
running: true,
83+
mode: "polling",
84+
connected: false,
85+
lastStartAt: Date.now() - 121_000,
86+
lastError: "network timeout",
87+
} as ChannelAccountSnapshot,
88+
]);
89+
90+
expect(issues).toEqual([
91+
expect.objectContaining({
92+
channel: "telegram",
93+
accountId: "main",
94+
kind: "runtime",
95+
message: expect.stringContaining("has not completed a successful getUpdates call"),
96+
}),
97+
]);
98+
expect(issues[0]?.message).toContain("network timeout");
99+
expect(issues[0]?.fix).toContain("channels status --probe");
100+
});
101+
102+
it("does not report polling startup before the connect grace expires", () => {
103+
const issues = collectTelegramStatusIssues([
104+
{
105+
accountId: "main",
106+
enabled: true,
107+
configured: true,
108+
running: true,
109+
mode: "polling",
110+
connected: false,
111+
lastStartAt: Date.now() - 60_000,
112+
} as ChannelAccountSnapshot,
113+
]);
114+
115+
expect(issues).toEqual([]);
116+
});
117+
118+
it("reports stale polling transport activity after successful getUpdates stops refreshing", () => {
119+
const issues = collectTelegramStatusIssues([
120+
{
121+
accountId: "main",
122+
enabled: true,
123+
configured: true,
124+
running: true,
125+
mode: "polling",
126+
connected: true,
127+
lastStartAt: Date.now() - 60 * 60_000,
128+
lastTransportActivityAt: Date.now() - 31 * 60_000,
129+
} as ChannelAccountSnapshot,
130+
]);
131+
132+
expect(issues).toEqual([
133+
expect.objectContaining({
134+
channel: "telegram",
135+
accountId: "main",
136+
kind: "runtime",
137+
message: expect.stringContaining("polling transport is stale"),
138+
}),
139+
]);
140+
});
141+
142+
it("does not report inherited stale transport activity during a fresh polling lifecycle", () => {
143+
const issues = collectTelegramStatusIssues([
144+
{
145+
accountId: "main",
146+
enabled: true,
147+
configured: true,
148+
running: true,
149+
mode: "polling",
150+
connected: true,
151+
lastStartAt: Date.now() - 60_000,
152+
lastTransportActivityAt: Date.now() - 2 * 60 * 60_000,
153+
} as ChannelAccountSnapshot,
154+
]);
155+
156+
expect(issues).toEqual([]);
157+
});
158+
159+
it("does not report webhook accounts with polling-only runtime diagnostics", () => {
160+
const issues = collectTelegramStatusIssues([
161+
{
162+
accountId: "main",
163+
enabled: true,
164+
configured: true,
165+
running: true,
166+
mode: "webhook",
167+
connected: false,
168+
lastStartAt: Date.now() - 10 * 60_000,
169+
} as ChannelAccountSnapshot,
170+
]);
171+
172+
expect(issues).toEqual([]);
173+
});
174+
76175
it("ignores accounts that are not both enabled and configured", () => {
77176
expect(
78177
collectTelegramStatusIssues([

0 commit comments

Comments
 (0)