Repository navigation
Conversation
…after network errors Two retry regressions introduced by recent upstream refactors: - 3987ca4 broke 429+retry_after classification in shouldRetry - 59895f9 narrowed failed-after regex too aggressively Both caused by createTelegramNonIdempotentRequestWithDiag using isSafeToRetrySendError with strictShouldRetry:true, which bypasses the TELEGRAM_RETRY_RE fallback. isSafeToRetrySendError only checked PRE_CONNECT_ERROR_CODES, missing: 1. 429 rate-limit errors with retry_after (safe: Telegram rejected without delivering) 2. grammY 'Network request for X failed after N attempts' (safe: transport-level failure, never reached Telegram) Expand isSafeToRetrySendError to cover both cases. All 64 send tests pass.
Greptile SummaryThis PR restores two retry-safety behaviours that were inadvertently dropped by recent upstream refactors: Telegram 429 rate-limit errors (where
Confidence Score: 4/5
|
There was a problem hiding this comment.
Pull request overview
This PR fixes two retry regressions in Telegram send operations caused by recent upstream refactors. The isSafeToRetrySendError function (used for non-idempotent send operations like sendMessage) was missing two safe-to-retry error classifications: HTTP 429 rate-limit errors with retry_after parameters, and grammY transport-level "failed after N attempts" errors. Both error types guarantee the message was not delivered.
Changes:
- Added
hasTelegramRetryAfterParameterhelper to detect Telegram 429 rate-limit errors by checking for a validparameters.retry_afternumeric field. - Extended
isSafeToRetrySendErrorwith two new retry-eligible conditions: 429 rate-limit errors and grammY "Network request for X failed after N attempts" transport failures.
|
|
||
| // 429 rate-limit with retry_after: Telegram explicitly rejected the | ||
| // request without delivering it — safe to retry after the indicated delay. | ||
| if (hasTelegramRetryAfterParameter(candidate)) { | ||
| return true; | ||
| } | ||
|
|
||
| // grammY "Network request for X failed after N attempts" indicates a | ||
| // transport-level failure — the request never reached Telegram. | ||
| const message = formatErrorMessage(candidate).trim().toLowerCase(); | ||
| if (message && GRAMMY_NETWORK_REQUEST_FAILED_AFTER_RE.test(message)) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
The isSafeToRetrySendError test suite in network-errors.test.ts does not cover the two new retry cases added here — the 429 retry_after parameter check and the grammY "failed after" message match. While send.test.ts has integration-level coverage, unit tests should be added to network-errors.test.ts for both cases to match the pattern of existing tests and guard against future regressions. For example:
- A test with an error that has
{ parameters: { retry_after: 1 } }should returntrue. - A test with
new Error("Network request for 'sendMessage' failed after 2 attempts.")should returntrue. - A negative test with
{ parameters: {} }(noretry_after) should returnfalse.
There was a problem hiding this comment.
Implemented in commit 55ceb98 — added three unit tests to the isSafeToRetrySendError describe block in network-errors.test.ts: 429+retry_after returns true, no retry_after returns false, and grammY failed-after returns true.
| // 429 rate-limit with retry_after: Telegram explicitly rejected the | ||
| // request without delivering it — safe to retry after the indicated delay. | ||
| if (hasTelegramRetryAfterParameter(candidate)) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
The inline comment correctly notes that Telegram "explicitly rejected the request without delivering it," but this contradicts the function's docstring (line 118-119) which states it "Only matches errors that are guaranteed to have occurred before the request reached Telegram's servers." A 429 with retry_after is a response from Telegram — the request did reach the server, it was just rejected. Consider updating the docstring to say something like "Only matches errors where the message is guaranteed not to have been delivered" to accurately cover both pre-connect failures and server-side rejections like 429.
There was a problem hiding this comment.
Fixed in commit 55ceb98 — docstring updated to: 'Only matches errors where the message is guaranteed not to have been delivered — either before reaching Telegram's servers (pre-connect errors) or server-side rejections that explicitly indicate no delivery occurred (e.g. 429 rate-limit with retry_after).'
| function hasTelegramRetryAfterParameter(err: unknown): boolean { | ||
| if (!err || typeof err !== "object") { | ||
| return false; | ||
| } | ||
| if ("parameters" in err && err.parameters && typeof err.parameters === "object") { | ||
| const retryAfter = (err.parameters as { retry_after?: unknown }).retry_after; | ||
| return typeof retryAfter === "number" && Number.isFinite(retryAfter); | ||
| } | ||
| return false; |
There was a problem hiding this comment.
retry_after could be non-positive
Number.isFinite returns true for any finite number, including negative values (e.g. -1). While Telegram's API documents retry_after as a positive integer (seconds to wait), validating positivity here makes the intent explicit and guards against malformed responses:
| function hasTelegramRetryAfterParameter(err: unknown): boolean { | |
| if (!err || typeof err !== "object") { | |
| return false; | |
| } | |
| if ("parameters" in err && err.parameters && typeof err.parameters === "object") { | |
| const retryAfter = (err.parameters as { retry_after?: unknown }).retry_after; | |
| return typeof retryAfter === "number" && Number.isFinite(retryAfter); | |
| } | |
| return false; | |
| return typeof retryAfter === "number" && Number.isFinite(retryAfter) && retryAfter > 0; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/network-errors.ts
Line: 105-113
Comment:
**`retry_after` could be non-positive**
`Number.isFinite` returns `true` for any finite number, including negative values (e.g. `-1`). While Telegram's API documents `retry_after` as a positive integer (seconds to wait), validating positivity here makes the intent explicit and guards against malformed responses:
```suggestion
return typeof retryAfter === "number" && Number.isFinite(retryAfter) && retryAfter > 0;
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Implemented in commit 55ceb98 — added && retryAfter > 0 guard.
|
|
||
| // grammY "Network request for X failed after N attempts" indicates a | ||
| // transport-level failure — the request never reached Telegram. | ||
| const message = formatErrorMessage(candidate).trim().toLowerCase(); |
There was a problem hiding this comment.
Redundant .toLowerCase() with i flag
GRAMMY_NETWORK_REQUEST_FAILED_AFTER_RE is already defined with the i (case-insensitive) flag at line 55, so .toLowerCase() has no effect. This is the same pattern as in isRecoverableTelegramNetworkError (line 173) which also lowercases before testing against the same regex. The redundancy is harmless but slightly misleading about the regex's own case-insensitivity.
| const message = formatErrorMessage(candidate).trim().toLowerCase(); | |
| const message = formatErrorMessage(candidate).trim(); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/network-errors.ts
Line: 142
Comment:
**Redundant `.toLowerCase()` with `i` flag**
`GRAMMY_NETWORK_REQUEST_FAILED_AFTER_RE` is already defined with the `i` (case-insensitive) flag at line 55, so `.toLowerCase()` has no effect. This is the same pattern as in `isRecoverableTelegramNetworkError` (line 173) which also lowercases before testing against the same regex. The redundancy is harmless but slightly misleading about the regex's own case-insensitivity.
```suggestion
const message = formatErrorMessage(candidate).trim();
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed in commit 55ceb98 — removed .toLowerCase(), now just formatErrorMessage(candidate).trim().
- Add unit tests to network-errors.test.ts for isSafeToRetrySendError (429+retry_after and grammY failed-after paths) - Update isSafeToRetrySendError docstring to accurately describe coverage - Add retryAfter > 0 guard in hasTelegramRetryAfterParameter - Remove redundant .toLowerCase() before case-insensitive regex test
|
All review feedback addressed in commit 55ceb98:
|
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 Unsafe retries for non-idempotent Telegram sends due to overly broad error classification
Description
Vulnerable code: // 429 rate-limit with retry_after ...
if (hasTelegramRetryAfterParameter(candidate)) {
return true;
}
// grammY "Network request ... failed after N attempts" ...
const message = formatErrorMessage(candidate).trim();
if (message && GRAMMY_NETWORK_REQUEST_FAILED_AFTER_RE.test(message)) {
return true;
}Impact:
RecommendationTighten retry classification for non-idempotent Telegram sends:
Example safer approach (structure may need adjustment based on grammY error types used in this repo): function isTelegram429WithRetryAfter(err: unknown): boolean {
if (!err || typeof err !== "object") return false;
const anyErr = err as any;
const retryAfter = anyErr?.parameters?.retry_after;
const errorCode = anyErr?.error_code; // Telegram Bot API field
const status = anyErr?.status ?? anyErr?.response?.status;
return (
(errorCode === 429 || status === 429) &&
typeof retryAfter === "number" &&
Number.isFinite(retryAfter) &&
retryAfter > 0
);
}
export function isSafeToRetrySendError(err: unknown): boolean {
for (const candidate of collectTelegramErrorCandidates(err)) {
const code = normalizeCode(getErrorCode(candidate));
if (code && PRE_CONNECT_ERROR_CODES.has(code)) return true;
if (isTelegram429WithRetryAfter(candidate)) return true;
// Avoid message-regex classification for non-idempotent sends.
}
return false;
}Additionally:
Analyzed PR: #40383 at commit Last updated on: 2026-03-10T20:36:59Z |
…FromEntrySchema/buildCatchallMultiAccountChannelSchema from channel-plugin-common Fix lint:plugins:no-monolithic-plugin-sdk-entry-imports CI failures: - All extension files using 'openclaw/plugin-sdk' monolithic import now use scoped subpaths - createPluginRuntimeStore → openclaw/plugin-sdk/runtime-store - createScopedChannelConfigBase → openclaw/plugin-sdk/channel-config-helpers - AllowFromEntrySchema + buildCatchallMultiAccountChannelSchema → openclaw/plugin-sdk/channel-plugin-common - Added the latter two exports to channel-plugin-common.ts
Problem
Two retry regressions introduced by recent upstream refactors:
3987ca409(refactor(retry): simplify telegram shouldRetry composition) changed the retry path used bycreateTelegramNonIdempotentRequestWithDiag, which callsisSafeToRetrySendErrorwithstrictShouldRetry: true. This bypasses theTELEGRAM_RETRY_REregex fallback and only checkedPRE_CONNECT_ERROR_CODES— missing two safe-to-retry cases.59895f9c5(fix: narrow Telegram failed-after retry match) narrowed the failed-after match too aggressively.Both caused previously-passing tests in
send.test.tsto fail.Root cause
isSafeToRetrySendErrorwas missing two cases:hasTelegramRetryAfterParameter()check.GRAMMY_NETWORK_REQUEST_FAILED_AFTER_REmessage match.Files changed
src/telegram/network-errors.ts— added both missing retry classificationsTest results
Related
Companion to the empty-text silent-skip PR (opening simultaneously).