Skip to content

fix(telegram): classify bare pre-connect grammY errors as recoverable for send context#80367

Closed
hclsys wants to merge 4 commits into
openclaw:mainfrom
hclsys:fix/telegram-bare-network-error-retry-80362
Closed

fix(telegram): classify bare pre-connect grammY errors as recoverable for send context#80367
hclsys wants to merge 4 commits into
openclaw:mainfrom
hclsys:fix/telegram-bare-network-error-retry-80362

Conversation

@hclsys

@hclsys hclsys commented May 10, 2026

Copy link
Copy Markdown

Closes #80362

Summary

isRecoverableTelegramNetworkError was returning false for bare pre-connect grammY errors ("Network request for 'sendMessage' failed!" — no "after" suffix) when context: "send" was passed, causing the bot to silently drop messages instead of retrying. Bare pre-connect errors occur before any bytes reach the Telegram server, making them safe to retry for all contexts including send.

Root cause: The existing GRAMMY_NETWORK_REQUEST_FAILED_RE matched the "failed! After N tries..." form, not the bare "failed!" form. The send-context guard in isRecoverableTelegramNetworkError checked only the "after" variant, so bare socket-drop errors were not classified as safe to retry.

Changes

  • extensions/telegram/src/network-errors.ts: Add GRAMMY_NETWORK_REQUEST_FAILED_BARE_RE to match bare pre-connect form; check it in isRecoverableTelegramNetworkError before the send-context rejection guard.
  • extensions/telegram/src/network-errors.test.ts: 2 new tests for bare pre-connect classification and non-grammY snippet rejection for send context.
  • extensions/ollama/src/stream.ts + test: route think parameter through options block (independent fix on same branch).
  • src/commands/sessions-table.ts: expose subagent runtime metadata fields in --json (independent fix on same branch).

Real Behavior Proof

Behavior or issue addressed: isRecoverableTelegramNetworkError(new Error("Network request for 'sendMessage' failed!"), { context: "send" }) returned false (reply dropped). Now returns true (retry triggered).

Real environment tested: Node.js v22.22.0, tsx/esm TypeScript loader, branch fix/telegram-bare-network-error-retry-80362, Linux.

Exact steps or command run after this patch:

node --import tsx/esm --input-type=module <<'PROOF'
import { isRecoverableTelegramNetworkError } from './extensions/telegram/src/network-errors.ts';
const networkRequestErr = new Error("Network request for 'sendMessage' failed!");
console.log("bare grammY send:", isRecoverableTelegramNetworkError(networkRequestErr, { context: "send" }));
console.log("undici blocked send:", isRecoverableTelegramNetworkError(new Error("undici fetch failed"), { context: "send" }));
console.log("bare grammY polling:", isRecoverableTelegramNetworkError(networkRequestErr, { context: "polling" }));
PROOF

Evidence after fix:

bare grammY send: true
undici blocked send: false
bare grammY polling: true

Bare pre-connect grammY errors now return true for send context. Non-grammY snippets (e.g. "undici") remain blocked.

Observed result after fix: isRecoverableTelegramNetworkError(new Error("Network request for 'sendMessage' failed!"), { context: "send" }) now returns true. Messages that previously dropped silently on socket-close-before-send will be retried. Non-grammY network errors remain non-recoverable for send context.

What was not tested: Live Telegram integration with actual dropped connections (no Telegram test account available on test host).

hclsys and others added 3 commits May 11, 2026 00:19
Top-level `think` causes 400 for non-thinking Ollama models; placing it
inside `options.think` is accepted by every model while still controlling
reasoning budget on thinking-capable models.

- createOllamaThinkingWrapper: patch options.think instead of payloadRecord.think
- resolveOllamaModelOptions: include think from params in options block
- resolveOllamaTopLevelParams: remove think (no longer a top-level param)
- Update 6 tests to assert options.think placement

Fixes openclaw#80332
`sessions --json` projected through `SessionDisplayRow` which omitted
`spawnedBy`, `sessionFile`, `label`, `status`, `spawnDepth`,
`sessionStartedAt`, `lastInteractionAt`, `startedAt`, `endedAt`, and
`runtimeMs` — all present in the underlying `SessionEntry` store.

Read-only consumers (lineage detectors, governance audits, fleet
observability) couldn't distinguish subagent sessions or compute
lineage coverage from the supported CLI surface.

Fixes openclaw#80286.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… for send context

grammY raises two distinct network error forms:
- Post-connect: "Network request for 'X' failed after N attempts." — grammy's
  own retry budget exhausted; may have reached Telegram. Risky to retry.
- Pre-connect: "Network request for 'X' failed!" — socket dropped before bytes
  hit the wire; message was never delivered. Safe to retry.

The existing GRAMMY_NETWORK_REQUEST_FAILED_AFTER_RE regex only matches the
post-connect form. For context "send", allowMessageMatch=false blocks the
RECOVERABLE_MESSAGE_SNIPPETS path that would otherwise catch the pre-connect
form, leaving it unclassified → shouldRetry returns false → reply dropped.

Add GRAMMY_NETWORK_REQUEST_FAILED_BARE_RE for the pre-connect form and check
it unconditionally (before the allowMessageMatch gate) so send-context calls
treat pre-connect failures as recoverable. Non-grammy snippet matches (e.g.
"undici") remain blocked for send context.

Fixes openclaw#80362

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram commands Command implementations size: S proof: supplied External PR includes structured after-fix real behavior proof. labels May 10, 2026
@clawsweeper

clawsweeper Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR adds a bare grammY network-error match and tests for Telegram send-context recovery, while also changing Ollama think payload placement and adding sessions JSON metadata fields.

Reproducibility: no. high-confidence live reproduction is present. Source inspection does show current main returns false for the bare send-context message targeted by the PR, but the real Telegram transport failure path is not proven.

Real behavior proof
Needs stronger real behavior proof before merge: Needs redacted live Telegram transport proof before merge; the supplied terminal output only calls the helper with constructed errors, so update the PR body with logs, live output, recording, or artifacts and ask for @clawsweeper re-review if it does not rerun automatically.

Next step before merge
Contributor or maintainer action is needed to narrow the branch and provide live Telegram proof; automation cannot supply proof from the contributor's environment.

Security
Cleared: No concrete security or supply-chain concern was found; the diff changes TypeScript runtime and test logic without dependency, workflow, secret, or install-path changes.

Review findings

  • [P2] Require pre-connect evidence before retrying send envelopes — extensions/telegram/src/network-errors.ts:267-269
  • [P2] Split unrelated provider and sessions changes — extensions/ollama/src/stream.ts:236-239
Review details

Best possible solution:

Keep the Telegram fix focused on nested pre-connect evidence, split unrelated Ollama and sessions work into separate PRs, and require redacted live Telegram transport proof before merge.

Do we have a high-confidence way to reproduce the issue?

No high-confidence live reproduction is present. Source inspection does show current main returns false for the bare send-context message targeted by the PR, but the real Telegram transport failure path is not proven.

Is this the best way to solve the issue?

No, not as submitted. The safer solution is a Telegram-only patch that ties retry eligibility to nested pre-connect evidence rather than the outer grammY envelope alone.

Full review comments:

  • [P2] Require pre-connect evidence before retrying send envelopes — extensions/telegram/src/network-errors.ts:267-269
    The new bare grammY envelope match returns true for send context from the outer HttpError message alone. grammY uses that same envelope for failed fetches, timeouts, stream errors, and transformer failures, while the current send retry contract requires nested pre-connect evidence before retrying non-idempotent sends.
    Confidence: 0.88
  • [P2] Split unrelated provider and sessions changes — extensions/ollama/src/stream.ts:236-239
    This Telegram PR also changes Ollama request payload behavior and sessions --json output, but the stated issue and proof cover only the Telegram retry helper. Split those changes into separate PRs so each behavior change gets the right review and proof.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.89

What I checked:

  • Current send-context gate: Current main disables broad message-snippet matching for context: "send" and only whitelists the existing grammY failed after envelope before that gate. (extensions/telegram/src/network-errors.ts:242, 4ad9286e19f4)
  • Current regression target: Current tests expect the bare Network request for 'sendMessage' failed! message to be false for send context and true for polling context. (extensions/telegram/src/network-errors.test.ts:130, 4ad9286e19f4)
  • Existing send safety contract: The current tests explicitly avoid inferring safe non-idempotent send retry from a plain grammY network envelope unless nested pre-connect evidence is present. (extensions/telegram/src/network-errors.test.ts:249, d9fe18c57445)
  • Non-idempotent send path: Normal Telegram message delivery uses isSafeToRetrySendError plus rate-limit handling under strictShouldRetry, so the intended contract is narrower than the broad recoverable-network helper. (extensions/telegram/src/send.ts:581, 4ad9286e19f4)
  • Dependency contract: grammY 1.42.0's HttpError stores the underlying thrown error, and toHttpError builds the same bare Network request for '<method>' failed! envelope for fetch/timeout/stream failures; its error docs also say transformer errors are treated as network failures. (raw.githubusercontent.com)
  • Maintainer review context: The matching Telegram maintainer note says Telegram transport PRs need real Telegram proof and prefers the bot-to-bot QA lane or equivalent live probe over synthetic-only validation. (.agents/maintainer-notes/telegram.md:37, 4ad9286e19f4)

Likely related people:

  • Peter Steinberger: Available blame for network-errors.ts, network-errors.test.ts, send.ts, bot/delivery.send.ts, and the unrelated Ollama/sessions files points to this author in the local history, and the prior review linked the current Telegram retry surface to commit aa6ec9f. (role: recent area contributor; confidence: medium; commits: d9fe18c57445, aa6ec9f74220; files: extensions/telegram/src/network-errors.ts, extensions/telegram/src/network-errors.test.ts, extensions/telegram/src/send.ts)

Remaining risk / open question:

Codex review notes: model gpt-5.5, reasoning high; reviewed against 4ad9286e19f4.

Re-review progress:

@hclsys

This comment was marked as low quality.

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

Labels

channel: telegram Channel integration: telegram commands Command implementations proof: supplied External PR includes structured after-fix real behavior proof. size: S

Projects

None yet

1 participant