Skip to content

feat(telegram): add error policy for suppressing repetitive error messages#51914

Merged
obviyus merged 4 commits intoopenclaw:mainfrom
chinar-amrutkar:fix/telegram-error-policy-v2
Apr 1, 2026
Merged

feat(telegram): add error policy for suppressing repetitive error messages#51914
obviyus merged 4 commits intoopenclaw:mainfrom
chinar-amrutkar:fix/telegram-error-policy-v2

Conversation

@chinar-amrutkar
Copy link
Copy Markdown
Contributor

@chinar-amrutkar chinar-amrutkar commented Mar 21, 2026

Summary

  • Problem: Telegram channels can experience error floods (repetitive 429, ECONNRESET, etc.) that clutter logs and confuse users.
  • What changed: Introduces per-account error policy configuration that can suppress repetitive error messages. New errorPolicy field in Telegram provider config with suppressRepeatErrors and errorWindowSec options.
  • What did NOT change: Error handling logic, retry behavior, or non-Telegram channels.

Change Type

  • Feature

Scope

  • Integrations

Linked Issue/PR

User-visible / Behavior Changes

New optional errorPolicy configuration for Telegram providers. When enabled, repeated identical errors within a configurable time window are suppressed from user-facing output.

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Steps

  1. Configure Telegram with errorPolicy: { suppressRepeatErrors: true, errorWindowSec: 60 }
  2. Trigger repeated errors (e.g., rate limit)
  3. Observe only first error surfaces to user

Expected

Repeated identical errors suppressed within configured window.

Actual (before fix)

All errors surface to user, creating noise.

Compatibility / Migration

  • Backward compatible? Yes (opt-in config)
  • Config/env changes? New optional field
  • Migration needed? No

Failure Recovery

  • Revert: git revert HEAD on branch
  • Bad symptoms: legitimate errors suppressed (unlikely — only affects repeated identical errors)

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 21, 2026

Greptile Summary

This PR introduces a per-account Telegram error policy ("always" / "once" / "silent") with a configurable cooldown window to reduce log noise from repetitive errors. The schema additions are clean and backward-compatible, but the core suppression logic has two correctness bugs that need fixing before this is ready to ship.

Issues found:

  • "always" policy doesn't work as documentedshouldSuppressTelegramError is called unconditionally for both "always" and "once" policies in the onError handler. The first error for a given chat arms the cooldown store, and all subsequent errors within the default 4-hour window are silently dropped even when the user has opted into "always". The call should be guarded by errorPolicy.policy === "once".

  • Error identity is never checkedErrorCooldownEntry stores errorMessage but shouldSuppressTelegramError never compares it against the new incoming error. Any error within the cooldown window is suppressed, not just identical ones as the PR description promises. A distinct (and potentially more critical) error arriving shortly after a 429 would be silently dropped for up to 4 hours.

  • errorCooldownStore grows unbounded — the module-level Map has no eviction or size cap; in a long-lived process serving many chats this will accumulate without bound.

  • TelegramTopicSchema.errorPolicy is a dead field — the schema accepts errorPolicy on topics, but resolveTelegramErrorPolicy never reads topic-level config, and errorCooldownMs is missing from the topic schema entirely. The field should either be wired up or removed.

Confidence Score: 2/5

  • Not safe to merge — the primary feature has two bugs that invert or undermine its documented semantics.
  • Two P1 logic bugs in the core implementation: (1) the "always" policy silently suppresses errors due to the unconditional cooldown check, and (2) error identity is never compared so distinct errors are suppressed within the cooldown window. Both contradict the documented behavior and would mislead users relying on this feature for observability.
  • src/telegram/error-policy.ts and src/telegram/bot-message-dispatch.ts require targeted fixes before merge.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/telegram/bot-message-dispatch.ts
Line: 672-680

Comment:
**`"always"` policy still suppresses errors via cooldown**

`shouldSuppressTelegramError` is called unconditionally for both `"always"` and `"once"` policies. When policy is `"always"`, the intent is that every error surfaces — but because the cooldown check runs regardless, the first error for a given `chatId` gets recorded, and all subsequent errors within the 4-hour window are silently dropped even though the user explicitly asked for `"always"`.

The guard should only apply when policy is `"once"`:

```suggestion
          if (
            errorPolicy.policy === "once" &&
            shouldSuppressTelegramError({
              chatId,
              cooldownMs: errorPolicy.cooldownMs,
              errorMessage: String(err),
            })
          ) {
            return;
          }
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/telegram/error-policy.ts
Line: 122-126

Comment:
**`errorMessage` stored but never used for identity comparison**

The PR description promises that only "repeated identical errors" are suppressed. However, `shouldSuppressTelegramError` never compares the incoming `errorMessage` against `entry.errorMessage` — it suppresses **any** error that arrives within the cooldown window, regardless of type.

In practice: if a chat first sees a `429` rate-limit error, then shortly afterward encounters an auth/connection failure, that second (different, potentially more actionable) error is silently dropped for up to 4 hours.

To match the documented semantics, the comparison needs to incorporate error identity:

```suggestion
  // Check if we're still within cooldown period for the same error
  if (
    now - entry.lastErrorTime < cooldownMs &&
    entry.errorMessage === errorMessage
  ) {
    // Within cooldown and same error - suppress
    return true;
  }
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/telegram/error-policy.ts
Line: 12

Comment:
**Unbounded in-memory growth in `errorCooldownStore`**

`errorCooldownStore` is a module-level `Map` that is never pruned. Every unique `chatId` that ever triggers an error is permanently retained for the lifetime of the process. In a long-running bot serving many chats this will accumulate silently.

Consider evicting stale entries — the information needed is already present (`lastErrorTime`). A simple approach is to delete the entry when the cooldown has expired and the error is being let through:

```ts
// After the "cooldown expired" branch:
errorCooldownStore.set(chatIdStr, { lastErrorTime: now, errorMessage });
// or, at the start of shouldSuppressTelegramError, evict all expired entries
// periodically (e.g. every N calls) to bound memory usage.
```

Alternatively, cap the Map size or use a TTL-based structure.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/config/zod-schema.providers-core.ts
Line: 82

Comment:
**`TelegramTopicSchema` has `errorPolicy` but no `errorCooldownMs`**

`TelegramGroupSchema` and `TelegramDirectSchema` both add `errorCooldownMs` alongside `errorPolicy`, but `TelegramTopicSchema` receives only `errorPolicy`. A user who sets `errorPolicy: "once"` at the topic level has no way to tune the cooldown window.

Additionally, `resolveTelegramErrorPolicy` in `error-policy.ts` does not read topic-level configs at all — so even the `errorPolicy` field on `TelegramTopicSchema` is silently ignored at runtime. This should either be wired up in the resolver or the field should be removed from the schema to avoid misleading users.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "feat(telegram): add ..."

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 206c70404e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd7872e6d3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@openclaw-barnacle openclaw-barnacle bot added the channel: telegram Channel integration: telegram label Apr 1, 2026
@chinar-amrutkar
Copy link
Copy Markdown
Contributor Author

@obviyus could you kindly review this when you have a moment? Thank you!

…sages

Introduces per-account error policy configuration that can suppress
repetitive error messages (e.g., 429 rate limit, ECONNRESET) to
prevent noisy error floods in Telegram channels.

Closes openclaw#34498
@obviyus obviyus force-pushed the fix/telegram-error-policy-v2 branch from 35d91d3 to 71b2b0d Compare April 1, 2026 11:42
@obviyus
Copy link
Copy Markdown
Contributor

obviyus commented Apr 1, 2026

Patched this on the PR branch.

Simple version: the original feature added new config knobs, but runtime was reading them through a separate partial resolver, so DM/topic overrides and multi-account behavior were wrong.

I rewired it to use the Telegram config that is already resolved for the message path, so account/group/direct/topic inheritance now follows the normal code path instead of a second special case. I also keyed the suppression cache by account + chat + thread, so one bot or topic cannot suppress another.

Verified with a focused test for the policy logic and a full pnpm build.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71b2b0dcb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1eeb63e9fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@obviyus obviyus self-assigned this Apr 1, 2026
Copy link
Copy Markdown
Contributor

@obviyus obviyus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed latest changes; landing now.

@obviyus obviyus merged commit 74b9f22 into openclaw:main Apr 1, 2026
8 checks passed
@obviyus
Copy link
Copy Markdown
Contributor

obviyus commented Apr 1, 2026

Landed on main.

Thanks @chinar-amrutkar.

@chinar-amrutkar
Copy link
Copy Markdown
Contributor Author

@obviyus thank you for reviewing 😊

@obviyus
Copy link
Copy Markdown
Contributor

obviyus commented Apr 1, 2026

@chinar-amrutkar thanks for the PR! Feel free to join the Discord server for reporting any other Telegram issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: suppress repetitive error messages in Telegram group chats (configurable policy)

2 participants