Repository navigation
fix(telegram): ack the webhook even when the inbound relay throws - #1285
Closed
lilyshen0722 wants to merge 1 commit into
Closed
lilyshen0722 wants to merge 1 commit into
lilyshen0722 wants to merge 1 commit into
Conversation
Telegram redelivers any update the webhook does not 2xx, and relayTelegramMessageToPod is not idempotent: it writes the pod row (PGMessage.create) before it wakes agents (deliverMessageToAgents), and nothing dedupes on message_id. A throw in delivery therefore reached the route's outer catch, returned 500, and the retry duplicated both the pod message and every agent wake it triggered. Wrap the relay call and sendStatus(200) regardless. A dropped relay is recoverable; a doubled one is not. Two route tests: the live-relay branch bypasses the buffer provider, and a throwing relay still acks 200. Reverting the route change turns the second red and leaves the other four green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on
feat/telegram-live-bridge(#1282) so it can land with the demo rather than after it. Merges into that branch, not main.The defect
routes/webhooks/telegram.tsawaitsrelayTelegramMessageToPodwith no local catch, so a throw lands in the route's outer handler and returns 500. Telegram redelivers any update the webhook does not 2xx.The relay is not idempotent, and the ordering is what makes that expensive:
telegramBridgeService.ts:239—PGMessage.create(...)writes the pod rowtelegramBridgeService.ts:248—deliverMessageToAgents(...)wakes agentsBoth are unguarded, so a throw in delivery happens after the row exists. Nothing dedupes on
telegramMessage.message_id. The retry therefore writes the message a second time and wakes every mentioned agent a second time — and it fires precisely when the pod is busy enough for delivery to be the thing that failed.The fix
Wrap the call, log, and
sendStatus(200)regardless. A dropped relay is recoverable — the sender sees nothing arrive and retypes. A doubled one is not: the second wake is already in flight before anyone notices.This does not make the relay idempotent, and is not meant to. Dedupe on
message_idis the durable fix and wants a store; this removes the mechanism that turns any transient delivery failure into a duplicate.Proof
Two route tests. Both mock the bridge, so they exercise the route's contract rather than the relay's internals:
Mutation control — revert only the route change and re-run:
Exactly one red, and it is the new assertion; the other four stay green, so the test discriminates on the fix rather than on the mocking.
Context: #1282 (comment)