Repository navigation
fix(telegram): prevent duplicate sends after delivery observer failures - #130643
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
d107a38 to
0b53324
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 1:46 AM ET / 05:46 UTC. ClawSweeper reviewWhat this changesThis PR unifies Telegram’s direct-reply and durable-send physical delivery paths so an accepted message remains partial delivery rather than triggering fallback or continued sends when later observation fails. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessNo blocking correctness defect found. Keep this maintainer-owned Telegram delivery refactor open for the already-active owner review and recovery evidence covering the remaining Gateway-visible paths. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherTelegram has two outbound paths: streaming replies from the bot and durable sends from public message APIs. Both now pass through one plugin-local sender that performs transport fallback, records accepted message IDs, and then runs fallible delivery observers. flowchart LR
A[Direct replies] --> C[Prepared Telegram sender]
B[Durable sends] --> C
C --> D[Telegram API request and fallback]
D --> E[Accepted message ledger]
E --> F[Delivery observers]
F --> G[Receipt or partial-delivery result]
Decision needed
Why: The central duplicate-send regression has real Telegram differential proof, but the branch deliberately centralizes two broad delivery funnels and its own evidence identifies broader scenario coverage still in progress. Before merge
Agent review detailsSecurityNone. PR surfaceSource -104, Tests +358, Docs +1. Total +255 across 12 files. View PR surface stats
Review metrics
Mantis proof suggestionTelegram Desktop proof would materially show that an injected observer failure changes a duplicate visible reply into one accepted bubble while preserving the follow-on delivery behavior. A maintainer can ask Mantis to capture proof by posting this exact PR comment: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Retain the single plugin-local acceptance ledger and land only after the Telegram owner accepts the completed recovery evidence for the remaining Gateway-visible scenarios. Do we have a high-confidence way to reproduce the issue? Yes. The supplied authenticated Telegram differential reproduces two baseline bubbles after a post-acceptance observer error versus one candidate bubble and a partial-delivery result; the relevant Telegram paths are unchanged on current main from that baseline. Is this the best way to solve the issue? Yes. A single Telegram-local sender places accepted-message recording before fallible observers for both existing funnels, rather than retaining two independently drifting fallback implementations. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2c3a54f9e4c1. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
0b53324 to
2688c4e
Compare
Mantis Telegram proof — PASSSummary: Current main and the synthetic PR candidate each completed five real Gateway turns through the leased user's native Telegram Desktop DM: paged durable delivery with a last-page button, authenticated callback ingress, fixture photo plus ordered follow-up pages, a manually selected native quote, and controlled incremental preview with same-ID edits plus one overflow message. Every durable turn has a captured pending-to-acknowledged/removal queue transition and every turn has terminal, idle-session, transcript, cache, and applicable projection evidence. The candidate preserves all existing visible behavior. Combined with the already-recorded authenticated observer-failure differential from run 33040833542 (main accepted a duplicate; PR head accepted one message and retained its accepted ID), this closes the required integration-regression gate and supports that the pull request fixes the reported duplicate-send defect.
Motion-trimmed clips: |
|
The current-head recovery proof is complete: run33043057550 exercised five real Gateway turns on both current main and the candidate through the authorized test-user Telegram Desktop DM. It covered ordered pages with the button on the final page, a real button click creating a new inbound turn, a photo with follow-up pages, a user-selected native quote, and incremental previews with two edits to the same message followed by one overflow message. The selected baseline was The settlement evidence is deliberately precise. Five durable pending-to-removal timelines were retained. The baseline pages watcher output was not retained, so its queue ID and pending row remain unknown. That case instead has a positive successful The separate authenticated observer-failure run33040833542 supplies the actual bug differential: main accepted two messages, while the candidate accepted one and returned partial delivery with the accepted ID. Its earlier incomplete scenario coverage is not relabeled; the recovery above supplies the missing Gateway regression matrix. The first attempt's changelog conflict and the second attempt's incomplete instruction ingestion remain documented proof-harness failures, not product failures or passing full runs. This addresses the latest ClawSweeper Rank-up moves and its request to finish the broader Gateway recovery evidence. The owner-level design and independent source/live reviews accept the single Telegram-local transport/acceptance owner; there is no new core queue, schema, configuration or authority contract. Exact-head CI33040709911 passed, and the complete-branch isolated P1 review is clean. Production is −104 lines; tests +358; one user-facing fix note. Native landing checks remain enforced. Remaining scoped follow-ups: deeper authority revalidation after dependency throttling/internal retries; independent history/mirror ownership redesign; proof-harness whole-instruction delivery and complete raw queue-capture retention. No physical voice-privacy failure, universal retry fence, or missing raw record is claimed by this proof. |
|
Merged via squash.
|


What Problem This Solves
Fixes an issue where Telegram could receive a duplicate reply after accepting the original message if subsequent delivery bookkeeping threw an error that looked like a formatting rejection. Accepted message IDs must survive observer failures and later send failures, rather than being retried or reported as absent.
Why This Change Was Made
The direct-reply and durable-send paths independently assembled the same physical send, fallback, acceptance and continuation sequence. This consolidates that sequence in one Telegram-local prepared sender and deletes the obsolete
bot/delivery.send.tsimplementation. Transport recovery ends before fallible acceptance observers run; partial errors retain every accepted message ID.Caller-owned behavior stays distinct: direct and durable keyboard placement, reply consumption, native quote facts, voice recovery, hooks and prompt projection retain their existing contracts. Core queue custody, preview lifecycle, public APIs, configuration and schemas are unchanged. This does not claim a new authorization check below dependency throttling or internal HTTP retries.
Production LOC: +596/-700, net -104. Tests: +391/-33, net +358. Changelog: +1.
Related existing acceptance repairs: #128181 and #129342. This retains their accepted-delivery protections while removing duplicate execution ownership.
User Impact
Already accepted Telegram messages are not resent because an observer throws a formatting-like error. Partial delivery continues to report what Telegram actually accepted. Existing direct replies, native quote handling, media-plus-text delivery, inline buttons and preview finalization are preserved.
Evidence
Current candidate:
2688c4eb1d844ec23aadb247a29ab39057fcb41c, rebased ontod9506ff26ef3f7d1db83109bf8507dcc8387bcffafter the live workflow encountered a changelog-only conflict. All 11 Telegram production/test files remain byte-identical to the previously verified0b533245d29c7a56dc1419a24378f1428464b863and original candidated107a381bbdca5ab0ddd155a85946241306aa7db. All main changelog entries were retained; this PR's note now sits beside an existing Telegram fix. Fresh complete-branch P1 and independent exact-commit binding passed on the new head.The original local baseline was
86e208310ff2f7a66e4f0c5968e74b319234f6aa. The subsequent0b533245candidate on064b0ddfseparately passed 20 HTTP/rich-edit integration tests and a clean full build with exact source inventory and installed-lock verification. These are evidence for the unchanged implementation, not newly executed whole-tree tests on2688c4eb. Broader main changes in Responses handling, model preparation and session-write lifecycle require the fresh integrated live run below.Actual grammY HTTP characterization reproduced three observer/fallback failures on the untouched baseline; the corrected candidate passes the corresponding assertions. Additional review caught and fixed lost media receipts and rich-quote fallback buttons before this commit.
On the original frozen candidate, 629 local tests across 12 files and
node scripts/check-changed.mjspassed. Its clean-machine full build passed in 5m34.7s; all 34,094 source paths, content/modes and the installed lock were verified. These receipts are not relabeled as execution on the refreshed main/dependency base.A real isolated Gateway with a deterministic mock provider and Telegram-compatible HTTP server passed the transport proof in 50.974s: 10 actual HTTP calls, ordered text pages, photo plus follow-up pages, native selected-quote parameters, same-message preview edits and final overflow with exact ordered content. This is Gateway wire-behavior proof, not an authenticated Telegram account test.
Fresh complete-bundle isolated Codex P1 review on the refreshed candidate found no blocking defects. Separate independent review bound the original commit, preserved source hashes, local checks and observed transport proof. All original proof Gateway processes and the remote test environment were stopped.
Extended real Gateway proof retained actual terminal run/session, positive durable queue custody followed by acknowledgement/removal, accepted message IDs/content, stored history and final projections. All four candidate and four parent scenarios passed the identity-aware evaluation of those retained records. Earlier script exits remain failures: their universal one-history-row assertion was wrong for the existing direct-delivery model-row-plus-named-mirror contract. The corrected evaluation ran offline, not as a new Gateway run. Photo evidence establishes accepted media/cache identity; the decorated photo has no transcript projection on either version.
The refreshed
2688c4ebexact-head CI run passed. Independent review bound the unchanged source and the original generic-runtime evidence. All owned generic proof resources were stopped.The fresh authenticated run completed and supplies a narrower real Telegram differential: the public physical sender on main accepted the HTML message, then sent duplicate plain text after a deterministic post-acceptance observer error. The candidate accepted one message and returned
CHANNEL_PARTIAL_DELIVERYwith its accepted ID. Real Bot API records and additional Desktop captures show the two baseline bubbles versus one candidate bubble. The run used the authorized test-user DM after the configured group rejected the bot with a membership-related 403. Its baseline wase2e030e2b0ae59580422ef8f20bdccc149862536; synthetic candidateff2873d1b73387280a8583748051a6eb39dff4c8has that baseline and PR head2688c4ebas parents. Cleanup and account release succeeded.The earlier run directly invoked the sender, not the complete Gateway matrix. Its direct-helper pivot preceded the separate group403 after incomplete instruction ingestion; it remains narrow defect proof. The first attempt failed before build/account use on a changelog conflict. Neither failure nor unlinked bot claims are counted as full live proof.
Recovery33043057550 completed all five actual Gateway/Desktop scenarios on each version: ordered pages/final-page buttons, a real callback-created turn, photo/follow-up text, user-selected native quote, and same-ID preview edits plus overflow. Selected baseline
dd7e0ea97498862f679845b94234eaae3afb5d83; syntheticb0fb178a85718eec83d1951d48a54819b5b7aa32has that baseline and published2688c4ebas parents. Both built freshly. Real Bot API requests, native DM captures, all ten terminal run/session outcomes and canonical history/cache/applicable projections were personally and independently inspected. Cleanup and leased-account release passed. Published media and evidence.Five durable pending-to-removal timelines are retained. Baseline pages watcher stdout was not retained, so its queue ID/pending row remain unknown. Its successful accepted-ID/session/full-content-hash receipt is instead source-validated post-ACK evidence: this ordinary marked model final is promoted to required queue durability, with no queue-less fallback and no success hook before acknowledgement. This is not a blanket claim about best-effort callers. Baseline photo tail cache has identity/length/start-end evidence, not a full cached-text hash; complete wire text and model history are retained. Decorated photos have no prompt projection by the unchanged contract; direct quote/preview retain the separate named mirror. Initial cache-selection mistakes and an oversized first preview read are preserved; later bounded exact-ID receipts are accepted.
The task fixture registers exact typed callback handlers for normal inbound submission; its old unclaimed-opaque-callback assumption was a fixture error, not a production change. The recovery loaded the complete thirteen-file guidance. Canonical provider requests include a topic-label call and quote seed; preview uses a separate controlled SSE producer. These corrections preserve actual provenance rather than treating the workflow judgment as raw evidence.
The latest ClawSweeper request and Rank-up move to complete/publish broader current-head recovery evidence are fulfilled. Maintainer-directed owner consolidation, independent source/live reviews, clean complete-branch P1 and exact-head CI are complete; normal native landing guards remain enforced.
Known scoped follow-up: authority revalidation after dependency throttle waits and internal transport retries needs a separate reproduction and producer-owned design; this PR preserves existing operation-level dispatch timing.
The existing direct-delivery transcript/mirror ownership is another named follow-up; this PR does not redesign history or persistence to suppress its intentionally separate rows.