Skip to content

fix(gateway): skip stale-socket restarts for Telegram polling#38405

Merged
Takhoffman merged 4 commits intoopenclaw:mainfrom
ql-wade:fix/issue-38395
Mar 7, 2026
Merged

fix(gateway): skip stale-socket restarts for Telegram polling#38405
Takhoffman merged 4 commits intoopenclaw:mainfrom
ql-wade:fix/issue-38395

Conversation

@ql-wade
Copy link
Copy Markdown
Contributor

@ql-wade ql-wade commented Mar 6, 2026

自动修复 Issue #38395

修复内容

为 Telegram long-polling 模式跳过 stale-socket 检查。

根本原因

Telegram 使用 long-polling 架构,每个请求都作为心跳。stale-socket 检查是为 WebSocket 设计的,用于检测半死连接(连接显示活跃但不发送事件),这不适用于 Telegram 的 polling 架构。

修复方案

  1. channel-health-policy.ts: 添加 channelId 到 ChannelHealthPolicy 类型,在 stale-socket 检查前跳过 Telegram
  2. channel-health-monitor.ts: 在创建 policy 时包含 channelId
  3. readiness.ts: 将 policy 创建移到循环内,每个 channel 独立评估

测试

  • TypeScript 类型检查通过
  • 代码符合项目规范
  • 逻辑正确:Telegram 不再触发 stale-socket 重启

Closes #38395

@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime size: XS labels Mar 6, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR fixes Telegram's health-monitor triggering a spurious stale-socket restart every ~35 minutes by skipping the stale-socket check when the channel is "telegram". Because Telegram uses long-polling (each poll acts as its own heartbeat), the half-dead WebSocket detection heuristic doesn't apply to it. The fix is mechanically sound and the three call sites are all updated consistently.

Key observations:

  • The core guard logic in evaluateChannelHealth is correct and will prevent the unwanted Telegram restarts.
  • channelId is typed as string instead of the existing ChannelId union, leaving the hardcoded "telegram" string unverified by the TypeScript compiler — a typo would silently bypass the guard.
  • The wrapping if (policy.channelId !== "telegram") { ... } pattern in channel-health-policy.ts lacks indentation for its body; an early-return/inverse-guard pattern would be cleaner and less error-prone to maintain.
  • The readiness.ts change moves policy creation before the !accountSnapshot null guard — a minor inefficiency and style inconsistency. Worth noting that shouldIgnoreReadinessFailure already ignored stale-socket reasons, so Telegram was never surfaced as unhealthy via the readiness endpoint even before this PR.

Confidence Score: 3/5

  • The fix is logically correct but has type-safety and formatting concerns that should be addressed before merge.
  • The core intent of the PR is sound — skipping the stale-socket check for Telegram long-polling is the right approach. However, using a bare string type for channelId rather than the existing ChannelId union means the hardcoded "telegram" literal has no compile-time safety net, and the wrapping guard brace pattern in channel-health-policy.ts is confusingly formatted. These are style/type-safety issues, not runtime bugs, but they reduce maintainability confidence.
  • src/gateway/channel-health-policy.ts — type safety of channelId field and formatting of the guard block both need attention.

Last reviewed commit: 65dc78f

@Takhoffman Takhoffman changed the title fix: Telegram health-monitor stale-socket restart every ~35min on 2026.3.2 (post-#10795 fix) fix(gateway): skip stale-socket restarts for Telegram polling Mar 7, 2026
ql-wade pushed a commit to ql-wade/openclaw that referenced this pull request Mar 7, 2026
- Import and use ChannelId type for channelId field (type safety)
- Fix guard block indentation for Telegram check
- Move policy creation after null guard in readiness.ts
@Takhoffman Takhoffman merged commit a5c07fa into openclaw:main Mar 7, 2026
8 of 9 checks passed
@Takhoffman
Copy link
Copy Markdown
Contributor

PR #38405 - fix(gateway): skip stale-socket restarts for Telegram polling (#38405)

Merged after verification.

mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 7, 2026
* main: (45 commits)
  chore: update dependencies except carbon
  test(memory): make mcporter EINVAL retry test deterministic
  refactor(extensions): reuse shared helper primitives
  refactor(core): extract shared dedup helpers
  fix(ci): re-enable detect-secrets on main
  docs: reorder 2026.3.7 changelog highlights
  chore: bump version to 2026.3.7
  fix(android): align run command with app id
  docs: add changelog entry for Android package rename (openclaw#38712)
  fix(android): rename app package to ai.openclaw.app
  fix(gateway): stop stale-socket restarts before first event (openclaw#38643)
  fix(gateway): skip stale-socket restarts for Telegram polling (openclaw#38405)
  fix(gateway): invalidate bootstrap cache on session rollover (openclaw#38535)
  docs: update changelog for reply media delivery (openclaw#38572)
  fix: contain final reply media normalization failures
  fix: contain block reply media failures
  fix: normalize reply media paths
  Fix owner-only auth and overlapping skill env regressions (openclaw#38548)
  fix(feishu): disable block streaming to prevent silent reply drops (openclaw#38422)
  fix: suppress ACP NO_REPLY fragments in console output (openclaw#38436)
  ...
mcaxtr pushed a commit to mcaxtr/openclaw that referenced this pull request Mar 7, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
joshavant pushed a commit that referenced this pull request Mar 7, 2026
Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
vincentkoc pushed a commit to BryanTegomoh/openclaw-fork that referenced this pull request Mar 8, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
Saitop pushed a commit to NomiciAI/openclaw that referenced this pull request Mar 8, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
(cherry picked from commit a5c07fa)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
…aw#38405)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: ql-wade <[email protected]>
(cherry picked from commit a5c07fa)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram health-monitor stale-socket restart every ~35min on 2026.3.2 (post-#10795 fix)

2 participants