Repository navigation
Feed long-poll updates to the stream as raw Bot API JSON - #311
Merged
Merged
Conversation
Long polling let carapax parse getUpdates into typed updates and then re-serialized them for the update stream. That round trip is lossy: a GIF message carries both `animation` and its `document` mirror, carapax keeps only the document, and the shared decoder downstream never sees the animation. Webhook ingress already stores the raw request body, so the two modes produced different stream entries for the same update. getUpdates now returns each update as raw JSON. Webhook and long-poll ingress share one inspection step (update ID via the shared decoder plus the ingress guard), so both append the same raw payload and every consumer decodes it with decode_telegram_update_value.
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.
Problem
In long-poll mode, carapax parsed
getUpdatesinto typed updates, and then the producer re-serialized them for the update stream. This round trip loses data. A GIF message carriesanimationplus adocumentmirror. carapax keeps only the document, so the shared decoder (decode_telegram_update_value, #309/#310) never sees the animation. If production fell back from the webhook to polling, GIFs would again reach ASR as videos.Webhook ingress already stores the raw request body. The two modes therefore wrote different stream entries for the same update.
Change
GetUpdatesExecutor::get_updatesreturns each update as raw JSON. It calls carapax through aRawGetUpdatesmethod that has an untyped result. The request payload has not changed.RawIngressUpdate. It reads the update ID through the shared decoder and applies the ingress guard. Both modes now append the same raw payload, and every consumer decodes it in the same way.long_poll_batch, a pure function. Stale updates are still skipped before the ingress guard counts them, and the cursor still advances past dropped updates.WebhookUpdateSender::accept_update. Nothing called it, and it re-serialized a typed update.LongPollUpdateSource, which is not wired in the app, also decodes through the shared decoder.docs/CODEBASE_MAP.mdstates the invariant: the stream holds raw Bot API JSON, and compatibility fixes belong indecode_telegram_update_value.Verification
cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warningswith the pinned toolchain 1.99.0cargo test -p openplotva-telegram --lib: 246 passed. This includes the live Redis tests, run against a disposableredis:7container withOPENPLOTVA_TEST_REDIS_URLset.carapax_get_updates_returns_raw_bot_api_jsonsends a real carapax client to a local Bot API fixture and gets the GIF update back unchanged. If the typedgetUpdatespath is restored temporarily, the test fails:animationis missing and onlydocumentremains.long_poll_batch_keeps_raw_bot_api_json_for_the_shared_decoderchecks that the stream entry keeps the Telegram JSON and decodes asAnimation.long_poll_batch_skips_stale_updates_before_the_ingress_guardchecks the stale-update filter and the guard ordering.live_webhook_and_long_poll_store_the_same_raw_updatesends one GIF update through both ingress modes into Redis Streams and checks that the payloads are equal and decode asAnimation.Production runs on the webhook, so this changes nothing at runtime until polling is enabled.