fix(telegram): preserve can_edit after transient network errors in progress edits (#27828)
When edit_message_text fails with a transient error (httpx.ConnectError, NetworkError, server disconnected, timeouts), the progress-message sender must not permanently set can_edit = False — that would convert a single Telegram network hiccup into separate per-tool bubbles for the rest of the run. Changes: - gateway/platforms/telegram.py: edit_message now returns retryable=True for transient network errors (ConnectError, NetworkError, timeouts, server disconnects, temporarily unavailable). Permanent failures (flood control, message-not-found, permissions) remain retryable=False. - gateway/run.py: send_progress_messages checks result.retryable before setting can_edit = False. Transient failures skip the fallback-send and continue — the next edit cycle catches up with the accumulated lines. Permanent failures (flood, message-not-found, etc.) still disable editing. Tests: 22 new tests in test_telegram_progress_edit_transient.py covering transient vs permanent error classification, SendResult.retryable semantics, and the can_edit decision logic. Fixes #27828
This commit is contained in:
@@ -1810,6 +1810,33 @@ class TelegramAdapter(BasePlatformAdapter):
|
||||
self.name, retry_err,
|
||||
)
|
||||
return SendResult(success=False, error=str(retry_err))
|
||||
# Transient network errors (ConnectError, timeouts, server
|
||||
# disconnects) should not permanently disable progress-message
|
||||
# editing. Mark the result retryable so the caller knows it
|
||||
# can keep trying on the next update cycle.
|
||||
_transient_markers = (
|
||||
"connecterror",
|
||||
"connect error",
|
||||
"connection error",
|
||||
"networkerror",
|
||||
"network error",
|
||||
"timed out",
|
||||
"readtimeout",
|
||||
"writetimeout",
|
||||
"server disconnected",
|
||||
"temporarily unavailable",
|
||||
"temporary failure",
|
||||
"httpx",
|
||||
)
|
||||
_is_transient = any(m in err_str for m in _transient_markers)
|
||||
if _is_transient:
|
||||
logger.warning(
|
||||
"[%s] Transient network error editing message %s (will retry): %s",
|
||||
self.name,
|
||||
message_id,
|
||||
e,
|
||||
)
|
||||
return SendResult(success=False, error=str(e), retryable=True)
|
||||
logger.error(
|
||||
"[%s] Failed to edit Telegram message %s: %s",
|
||||
self.name,
|
||||
|
||||
@@ -15462,6 +15462,17 @@ class GatewayRunner:
|
||||
)
|
||||
if not result.success:
|
||||
_err = (getattr(result, "error", "") or "").lower()
|
||||
# Transient network errors (ConnectError, timeouts)
|
||||
# must not permanently disable progress-message
|
||||
# editing — the next cycle can catch up. Only
|
||||
# permanent failures (flood control, message not
|
||||
# found, permissions) should set can_edit = False.
|
||||
if getattr(result, "retryable", False):
|
||||
logger.debug(
|
||||
"[%s] Transient edit failure — keeping can_edit=True",
|
||||
adapter.name,
|
||||
)
|
||||
continue
|
||||
if "flood" in _err or "retry after" in _err:
|
||||
# Flood control hit — backoff but keep editing.
|
||||
# Only disable edits for non-recoverable errors.
|
||||
|
||||
Reference in New Issue
Block a user