Skip to content

fix(telegram): avoid permanent getFile retries without losing temporary files - #117798

Merged
steipete merged 1 commit into
mainfrom
codex/qa-telegram-getfile-owner-4ea3060
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-telegram-getfile-owner-4ea3060

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Telegram repeatedly retried permanent media-file lookup failures, delaying attachment handling, while preserving Telegram's documented temporary-file-unavailable response that legitimately succeeds on retry.

Why This Change Was Made

Replace the method owner's permissive retry-all policy with the existing canonical Telegram network/rate-limit/server-error classifier plus one tightly scoped, typed grammY getFile exception for Telegram's explicitly temporary HTTP 400 response. Keep the special file-too-large path, cancellation, flood waits, and document/sticker ownership unchanged.

User Impact

Permanent invalid-file, unauthorized, forbidden, missing, and conflict errors now fail immediately instead of being retried three times. Temporary Telegram file-storage delays still recover automatically for both ordinary attachments and stickers.

Evidence

  • Genuine unchanged-main regression: five actual typed grammY failures—400, 401, 403, 404, and 409—each invoke getFile three times instead of once.
  • Frozen candidate 4ea3060bd3209e7f3c94ef76de8af8630247f72f: the complete Telegram media owner suite passes 38/38, covering permanent errors, temporary 400 recovery for both documents and stickers, 429 retry-after, 500/502, network errors, abort/deadline, and file-too-large behavior.
  • Four independently fresh hostile reviewers directly inspected pinned grammY 1.45.1 source/types, the shared Telegram retry owner, document/sticker callers, shipped release behavior, and the exact method/status/description dependency contract.
  • Genuine official gpt-5.6-sol high-reasoning P0–P3 review explicitly rechecked the previously discovered temporary-400 regression: zero findings, confidence 0.98; native TruffleHog 3.96.0 scan clean.
  • Existing generic polling/webhook classifiers are untouched; production owner net change is +4 lines for the real method-specific upstream contract.

Redacted real resolver + controlled Bot API proof

The exact frozen production owner ran against actual local HTTP Bot API responses using pinned grammY 1.45.1, an actual Bot.api.getFile client, real OpenClaw resolveMedia, a real PNG, its configured trusted-local-root guard, and isolated media persistence. No getFile/resolver mock or Vitest harness was used.

[controlled Bot API] status=dependency attempts=0 result=grammy-1.45.1-real-http
[controlled Bot API] status=400 attempts=1 result=typed-getFile-failure
[controlled Bot API] status=401 attempts=1 result=typed-getFile-failure
[controlled Bot API] status=403 attempts=1 result=typed-getFile-failure
[controlled Bot API] status=404 attempts=1 result=typed-getFile-failure
[controlled Bot API] status=409 attempts=1 result=typed-getFile-failure
[controlled Bot API] status=400 attempts=2 result=persisted-document
[controlled Bot API] status=400 attempts=2 result=persisted-sticker
[controlled Bot API] status=summary attempts=9 result=passed-exact-4ea3060bd320

Compatibility is deliberately method-scoped: pinned grammY out/core/error.js and out/core/error.d.ts directly define GrammyError.method, numeric error_code, and server description; only method === "getFile", status 400, and the documented temporary-file phrase receive the existing bounded retry. Generic polling/webhook classification remains unchanged.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 1:05 AM ET / 05:05 UTC.

ClawSweeper review

What this changes

The PR changes Telegram media resolution so permanent getFile failures stop after one attempt while the temporary-file-unavailable 400 response still retries and can persist documents or stickers.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for maintainer review: current main still retries every getFile error except the file-too-large case, while the branch replaces that broad policy with a focused classifier and covers both permanent failures and the temporary-file exception. The added controlled Bot API resolver transcript is meaningful after-fix behavior proof, but the compatibility choice to preserve only the documented temporary 400 path remains intentionally maintainer-visible.

Priority: P2
Reviewed head: 4ea3060bd3209e7f3c94ef76de8af8630247f72f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level retry repair with strong controlled runtime proof and regression coverage; maintainer confirmation of the narrow compatibility contract remains the merge decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body supplies redacted after-fix terminal output from the actual OpenClaw resolver and a real grammY client against controlled Bot API responses, showing both the one-attempt permanent path and two-attempt temporary-file recovery.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies redacted after-fix terminal output from the actual OpenClaw resolver and a real grammY client against controlled Bot API responses, showing both the one-attempt permanent path and two-attempt temporary-file recovery.
Evidence reviewed 7 items Current-main behavior: The current resolver rejects only the file-too-large case and otherwise returns true for every getFile error, so permanent Telegram API rejections still consume all three attempts.
Proposed owner-boundary repair: The branch delegates ordinary retryability to the shared Telegram API classifier, then preserves a narrowly typed getFile HTTP 400 exception for the temporary-file description.
Regression and sibling coverage: The branch adds cases for permanent 400/401/403/404/409 responses, temporary 400 recovery for both documents and stickers, and server-error retry coverage; current durable-media tests separately classify 400/401/403/404 as non-retryable.
Findings None None.
Security None None.

How this fits together

Telegram inbound handlers resolve attachment metadata through getFile before downloading and persisting media for the agent. The resolver's retry decision determines whether a failed lookup becomes an immediate typed media failure or proceeds to bounded retry and, where applicable, durable replay handling.

flowchart LR
  A[Telegram inbound update] --> B[Inbound media handler]
  B --> C[Media resolver]
  C --> D[getFile retry decision]
  D -->|retryable| E[Bounded getFile retry]
  D -->|permanent| F[Typed media failure]
  E --> G[Download and persist attachment]
  F --> H[Handler and durable replay policy]
Loading

Decision needed

Question Recommendation
Should the Telegram plugin treat only the typed getFile 400 response containing file is temporarily unavailable as the compatibility exception to the normal non-retryable 4xx policy? Accept the scoped exception: Merge the focused temporary-file exception and keep all other permanent getFile client rejections fail-fast.

Why: The branch has focused regression coverage and controlled runtime proof, but this is a user-visible compatibility contract for Telegram's server-provided error wording rather than a purely mechanical cleanup.

Before merge

  • Resolve merge risk (P1) - This intentionally narrows retry compatibility: a temporary Telegram getFile response whose description does not contain file is temporarily unavailable will now fail immediately rather than use the previous broad retry policy.
  • Complete next step (P2) - No mechanical repair remains; a maintainer should confirm the narrow temporary-file compatibility contract and then decide whether to merge this maintainer-labeled PR.
Agent review details

Security

None.

PR surface

Source +4, Tests +101. Total +105 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 8 +4
Tests 1 101 0 +101
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 113 8 +105

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Accept the documented temporary-file exception (recommended)
    Merge with the current method, status, and description guard because the branch proves the permanent and temporary paths separately.
  2. Confirm broader temporary wording first
    Pause merge if Telegram may return materially different temporary getFile 400 descriptions that should retain bounded retry behavior.

Technical review

Best possible solution:

Retain the method-scoped retry policy: retry shared network, rate-limit, and server failures plus the known temporary getFile 400, while preserving immediate failures for other client rejections.

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

Yes, from current source and the focused branch regression cases: current main retries any non-file-too-large getFile rejection up to three times, while the proposed typed permanent failures demonstrate the intended one-attempt behavior.

Is this the best way to solve the issue?

Yes, subject to the maintainer compatibility choice: the retry owner is the resolver itself, and the patch reuses the shared Telegram retry classifier instead of creating a parallel policy while retaining the explicit temporary-file case.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4b26a15a1f42.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies redacted after-fix terminal output from the actual OpenClaw resolver and a real grammY client against controlled Bot API responses, showing both the one-attempt permanent path and two-attempt temporary-file recovery.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies redacted after-fix terminal output from the actual OpenClaw resolver and a real grammY client against controlled Bot API responses, showing both the one-attempt permanent path and two-attempt temporary-file recovery.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The defect delays Telegram attachment handling for permanent lookup failures but is bounded to the media-resolution retry path.
  • merge-risk: 🚨 compatibility: The branch deliberately changes retry behavior for existing Telegram getFile 4xx responses, with one description-specific temporary exception retained.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies redacted after-fix terminal output from the actual OpenClaw resolver and a real grammY client against controlled Bot API responses, showing both the one-attempt permanent path and two-attempt temporary-file recovery.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies redacted after-fix terminal output from the actual OpenClaw resolver and a real grammY client against controlled Bot API responses, showing both the one-attempt permanent path and two-attempt temporary-file recovery.

Evidence

What I checked:

  • Current-main behavior: The current resolver rejects only the file-too-large case and otherwise returns true for every getFile error, so permanent Telegram API rejections still consume all three attempts. (extensions/telegram/src/bot/delivery.resolve-media.ts:72, 4b26a15a1f42)
  • Proposed owner-boundary repair: The branch delegates ordinary retryability to the shared Telegram API classifier, then preserves a narrowly typed getFile HTTP 400 exception for the temporary-file description. (extensions/telegram/src/bot/delivery.resolve-media.ts:72, 4ea3060bd320)
  • Regression and sibling coverage: The branch adds cases for permanent 400/401/403/404/409 responses, temporary 400 recovery for both documents and stickers, and server-error retry coverage; current durable-media tests separately classify 400/401/403/404 as non-retryable. (extensions/telegram/src/bot/delivery.resolve-media-local.test.ts:361, 4ea3060bd320)
  • Caller and replay boundary: Inbound message and media-group handlers consume resolveMedia; durable replay already retries only transient HTTP statuses and network causes, so the branch's typed permanent HTTP failures do not create a second permanent-retry path. (extensions/telegram/src/bot-handlers.inbound.runtime.ts:230, 4b26a15a1f42)
  • Feature provenance: Blame ties the current permissive retry helper to Peter Steinberger's current-main commit, and the proposed commit is also authored by Peter Steinberger, making the PR a direct repair of the present owner path. (extensions/telegram/src/bot/delivery.resolve-media.ts:72, eda7cab0819a)
  • Current-main and release check: The proposed commit is not an ancestor of current main and no local release tag contains it; the latest supplied release is v2026.7.1, so this remains an unmerged, unshipped repair rather than an implemented-on-main cleanup candidate. (4ea3060bd320)

Likely related people:

  • steipete: Current-main blame attributes the permissive getFile retry helper to Peter Steinberger, and the proposed repair commit is authored by the same contributor. (role: current retry-owner contributor; confidence: high; commits: eda7cab0819a, 4ea3060bd320; files: extensions/telegram/src/bot/delivery.resolve-media.ts, extensions/telegram/src/bot/delivery.resolve-media-local.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm that the exact temporary-file wording is the intended long-term Telegram compatibility contract before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-02T04:51:43.069Z sha 4ea3060 :: needs real behavior proof before merge. :: none

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 2, 2026
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer decision: accept the scoped getFile compatibility exception and its exact current wording.

  • Telegram's official Bot API contract describes description as human-readable server error text; it does not promise stable error phrases. The compatibility exception is therefore deliberately narrow and explicitly owner-maintained, not presented as an upstream-guaranteed permanent API contract.
  • Retry only an actual grammY GrammyError for method getFile, status 400, whose description contains file is temporarily unavailable case-insensitively. This also covers Telegram's observed wrong file_id or the file is temporarily unavailable response without broadening unrelated 400 errors.
  • All other permanent 400/401/403/404/409 responses intentionally fail after one attempt; the canonical Telegram classifier still handles network errors, rate limits, and server failures.
  • Exact-head regressions plus the real grammY client, production OpenClaw resolver, and nine controlled Bot API HTTP requests prove both permanent fail-fast behavior and successful temporary recovery/persistence for documents and stickers.

This explicitly accepts ClawSweeper's sole optional rank-up/owner decision for exact head 4ea3060bd3209e7f3c94ef76de8af8630247f72f.

@steipete
steipete merged commit ceb8a8b into main Aug 2, 2026
203 of 223 checks passed
@steipete
steipete deleted the codex/qa-telegram-getfile-owner-4ea3060 branch August 2, 2026 05:11
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant