Skip to content

fix(telegram): prevent duplicate replies after attachment delivery failures - #128181

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-telegram-partial-delivery-20260823
Aug 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-telegram-partial-delivery-20260823

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Telegram users receiving multiple attachments could see an incorrect duplicate fallback reply after one photo, document, voice note, or voice fallback had already arrived and a later attachment failed to load or send.

Why This Change Was Made

Telegram's private delivery owner now records each accepted media message and each media-owned fallback or caption-follow-up text chunk immediately at its authoritative acceptance boundary, before fallible topic validation or bookkeeping. One outer owner boundary merges the complete accepted-message history into the existing partial-delivery contract; initial failures with no accepted message still propagate unchanged.

User Impact

Already delivered Telegram messages remain visible to native commands and channel lifecycle handling even when a later album item fails. Operators no longer receive a misleading duplicate empty-response fallback, and accepted media, voice-fallback, and caption-follow-up message IDs remain available for recovery and diagnostics.

Evidence

  • Exact reviewed head: e3308ba36908796dff91cf8099e15c939c3056a1.
  • Eight authentic before-fix failures now pass: photo, document, and voice second-item rejection; later media download failure; accepted-message bookkeeping failure; voice fallback followed by either later send or download failure; and caption-follow-up receipt preservation. The first-send/no-delivery control remains unwrapped.
  • Full targeted validation: OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-autoqa-telegram-partial-delivery-vitest-cache node scripts/run-vitest.mjs extensions/telegram/src/bot/delivery.test.ts extensions/telegram/src/bot-native-command-dispatch.delivery.test.ts extensions/telegram/src/bot-message-dispatch.delivery-basics.test.ts extensions/telegram/src/chunk-delivery.test.ts extensions/telegram/src/send.test.ts --configLoader runner — 5 files, 406 tests passed.
  • Targeted extension lint, formatting, max-lines ratchet, assertion-safety ratchet, and git diff --check all pass.
  • Full extension production/test typecheck currently reports only existing unrelated ACpx promptStarted / elicitationModes diagnostics; there are no errors in either changed Telegram file.
  • Both independent owner-boundary review and authenticated full committed-branch review are clean.
  • Production delta: 26 additions / 30 deletions (net −4); regression coverage: 196 test lines.
  • Live Telegram credentialed proof was not run because this isolated repair has no authorized live-channel credential access; all proof uses the real Telegram delivery owner, native-command consumer, durable-send sibling, and channel partial-delivery contract.
  • No public Plugin SDK, configuration, authentication, storage, or protocol changes.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: M maintainer Maintainer-authored PR labels Aug 23, 2026
@steipete
steipete marked this pull request as ready for review August 23, 2026 10:11
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. 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. labels Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 23, 2026, 7:02 AM ET / 11:02 UTC.

ClawSweeper review

What this changes

The PR records accepted Telegram media and follow-up message IDs across later attachment failures so the channel can report partial delivery instead of treating the whole reply as absent.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked by patch quality or review findings - 6 items remain

The patch records partial Telegram delivery, but ordinary final-reply dispatch still treats that rejection as a failed answer and sends the duplicate fallback; it needs one consumer-side repair before merge.

Priority: P2
Reviewed head: e3308ba36908796dff91cf8099e15c939c3056a1

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has focused source coverage but misses the ordinary fallback consumer, and the attached live evidence does not show an after-fix improvement.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 7 items Changed delivery boundary: The branch records accepted media IDs before fallible topic reporting and converts later errors to the existing partial-delivery envelope.
Ordinary dispatcher misses the outcome: A rejected final delivery becomes dispatchError, while the fallback guard only checks finalAnswerDelivered; that flag is set only after sendPayload resolves.
Existing sibling handles partial delivery: Native-command delivery explicitly marks a partial final as delivered before its fallback decision, demonstrating the required consumer behavior.
Findings 1 actionable finding [P1] Honor partial final delivery before sending the fallback
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/telegram/src/bot/delivery.test.ts --configLoader runner

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs extensions/telegram/src/bot/delivery.test.ts --configLoader runner: terminal command did not produce output within 20 seconds: "node scripts/run-vitest.mjs extensions/telegram/src/bot/delivery.test.ts --configLoader runner"

runner@runnervm76f27:/tmp/clawsweeper-live-proof-128181-xfAkOY/target$ node scripts/run-vitest.mjs extensions/telegram/src/bot/delivery.test.ts --configLoader r
unner
[test] starting test/vitest/vitest.extension-telegram.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128181-xfAkOY/target

node scripts/run-vitest.mjs extensions/telegram/src/bot/delivery.test.ts --configLoader runner












































Assertions:

  • FAIL expect_output: passed

How this fits together

Telegram’s reply sender delivers media and text through the Bot API, then returns a partial-delivery outcome when a later step fails. The normal dispatch layer uses that outcome to decide whether an error fallback should be sent to the chat.

flowchart LR
  A[Agent final reply] --> B[Normal Telegram dispatch]
  B --> C[Media and text delivery]
  C --> D[Accepted message IDs]
  C --> E[Later attachment failure]
  D --> F[Partial-delivery outcome]
  E --> F
  F --> G[Fallback decision]
  G --> H[Telegram chat]
Loading

Before merge

  • Honor partial final delivery before sending the fallback (P1) - The new error at this site is still stored as dispatchError by ordinary dispatch, while finalAnswerDelivered is set only after sendPayload resolves. An accepted first attachment followed by a failed second one therefore still reaches the error-fallback branch and produces the duplicate this PR intends to prevent. Native commands already consume this outcome; add the same standard-dispatch handling and regression. This was visible on the previous reviewed head, which is unchanged here.
  • Resolve merge risk (P2) - Merging now still permits an accepted first attachment followed by a failed later attachment to produce the ordinary error fallback on the standard Telegram dispatch path.
  • Resolve merge risk (P2) - The supplied Mantis run is real but nondifferential: baseline and candidate both avoid the fallback, so it does not demonstrate the claimed repair.
  • Complete next step (P2) - A narrow code repair is clear, but the protected maintainer item requires owner review before the branch is updated and revalidated.
  • Improve patch quality - Honor CHANNEL_PARTIAL_DELIVERY on the normal final-reply path and add the end-to-end dispatch regression.
  • Improve patch quality - Attach redacted Mantis baseline/candidate evidence where baseline emits the duplicate fallback and the repaired head suppresses it.

Findings

  • [P1] Honor partial final delivery before sending the fallback — extensions/telegram/src/bot/delivery.replies.ts:990-995
Agent review details

Security

None.

PR surface

Source -4, Tests +196. Total +192 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 26 30 -4
Tests 1 196 0 +196
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 222 30 +192

Review metrics

Metric Value Why it matters
Production versus test delta production +26/-30 (net -4); tests +196 The branch is net-negative in production code, but its added coverage currently exercises the sender rather than the final fallback consumer.

Proof path suggestion

A new before/after Telegram Desktop run can directly establish whether normal dispatch emits the duplicate fallback after the injected later attachment failure. Mantis is proof-only, so it must not be asked to change code or mutate GitHub state.
Use ClawSweeper's repair, apply, or automerge lanes for code changes, branch updates, labels, comments, PR repair, closes, or merges.

Merge-risk options

Maintainer options:

  1. Complete standard-dispatch handling (recommended)
    Teach the ordinary final-reply consumer to honor partial delivery and add a regression that proves it sends no second fallback.
  2. Pause this branch
    Do not merge until the standard dispatcher and a differential Telegram proof establish that the claimed duplicate is actually suppressed.

Technical review

Best possible solution:

Consume a partial final-delivery error at the ordinary Telegram dispatch boundary, mark the final as visibly delivered before fallback selection, and prove the no-duplicate outcome through that complete path.

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

Yes—source-reproducible: make normal final delivery reject with CHANNEL_PARTIAL_DELIVERY after one accepted attachment; the current dispatcher records dispatchError and sends its error fallback because finalAnswerDelivered remains false.

Is this the best way to solve the issue?

No: preserving accepted IDs is the correct producer-side repair, but the ordinary fallback consumer must also recognize the partial outcome for the user-visible duplicate to disappear.

Full review comments:

  • [P1] Honor partial final delivery before sending the fallback — extensions/telegram/src/bot/delivery.replies.ts:990-995
    The new error at this site is still stored as dispatchError by ordinary dispatch, while finalAnswerDelivered is set only after sendPayload resolves. An accepted first attachment followed by a failed second one therefore still reaches the error-fallback branch and produces the duplicate this PR intends to prevent. Native commands already consume this outcome; add the same standard-dispatch handling and regression. This was visible on the previous reviewed head, which is unchanged here.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9046ecea7303.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: This is a Telegram-specific duplicate-response bug with a bounded but user-visible delivery impact.
  • merge-risk: 🚨 message-delivery: The changed partial-delivery signal decides whether a visible Telegram reply suppresses the channel’s fallback message.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The intended change is directly visible as whether Telegram sends a second fallback message after partial attachment delivery.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the reviewed delivery-boundary change and earlier Telegram delivery work visible in local history. (role: recent Telegram delivery contributor; confidence: high; commits: e3308ba36908, c636060f04f2; files: extensions/telegram/src/bot/delivery.replies.ts, extensions/telegram/src/bot/delivery.send.ts)
  • Ayaan Zaidi: Local history associates this contributor with the shared formatted-to-plain delivery degradation surface used by the Telegram sender. (role: adjacent delivery-degradation contributor; confidence: medium; commits: 79016b415ad9; files: extensions/telegram/src/bot/delivery.replies.ts, extensions/telegram/src/chunk-delivery.ts)

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-23T10:18:50.224Z sha e3308ba :: needs maintainer review before merge. :: none

@openclaw-mantis

openclaw-mantis Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Mantis Telegram Desktop Proof

Summary: Mantis captured native Telegram Desktop before/after GIF evidence with Convex-leased Telegram credentials, but this comparison is blocked because baseline and candidate produced identical visible and Bot API facts.

  • Scenario: telegram-desktop-proof
  • Trigger: clawsweeper_label
  • Run: https://github.com/openclaw/openclaw/actions/runs/32633799930
  • Artifact: https://github.com/openclaw/openclaw/actions/runs/32633799930/artifacts/9491955622
  • Baseline: pass at d26e097263c13239394488b12c4b68bd8fa05cc8 — Baseline should exercise partial attachment delivery: one document accepted, the following photo send fails with the injected Bot API 500, and no duplicate fallback/replay is observed during the 120s window. · facts: 1 sent · 1 bot message · 0 edits · 0 deletes · 1 provider request · 1 injected Bot API fault · 120s observed · attempt 4 · sent: @foremanclawbot Mantis partial delivery proof: send the prepared PDF and PNG at…
  • Baseline assertion: botApiRequests contains ""method":"sendPhoto","status":500" · occurrences: 1 · met
  • Candidate (PR merged onto main): pass at de24d41ad2b3414677808c182bad8b52ac692f10 — Candidate should exercise the same partial attachment delivery path: one document accepted, the following photo send fails with the injected Bot API 500, and no duplicate fallback/replay is observed during the 120s window. · facts: 1 sent · 1 bot message · 0 edits · 0 deletes · 1 provider request · 1 injected Bot API fault · 120s observed · attempt 3 · sent: @foremanclawbot Mantis partial delivery proof: send the prepared PDF and PNG at…
  • Candidate assertion: botApiRequests contains ""method":"sendPhoto","status":500" · occurrences: 1 · met
  • Differential (trusted facts): no count differences; pass rests on payload facts and the lane judgments
  • Overall: pass
Main screenshot This PR merged onto main screenshot
Baseline native Telegram Desktop screenshot Candidate native Telegram Desktop screenshot
Main This PR merged onto main
Baseline native Telegram Desktop proof GIF Candidate native Telegram Desktop proof GIF

Motion-trimmed clips:

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-desktop/pr-128181/run-32633799930-1/index.json

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Aug 23, 2026
@steipete
steipete merged commit 3b14c81 into main Aug 23, 2026
217 checks passed
@steipete
steipete deleted the codex/autoqa-telegram-partial-delivery-20260823 branch August 23, 2026 11:57
@steipete

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 mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant