Skip to content

Feed long-poll updates to the stream as raw Bot API JSON - #311

Merged
iamwavecut merged 1 commit into
mainfrom
fix/long-poll-raw-updates
Nov 27, 2026
Merged

iamwavecut merged 1 commit into
mainfrom
fix/long-poll-raw-updates

Conversation

@iamwavecut

Copy link
Copy Markdown
Owner

Problem

In long-poll mode, carapax parsed getUpdates into typed updates, and then the producer re-serialized them for the update stream. This round trip loses data. A GIF message carries animation plus a document mirror. 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_updates returns each update as raw JSON. It calls carapax through a RawGetUpdates method that has an untyped result. The request payload has not changed.
  • Webhook and long-poll ingress share one inspection step, 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 batches are built in 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.
  • Removed 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.md states the invariant: the stream holds raw Bot API JSON, and compatibility fixes belong in decode_telegram_update_value.

Verification

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings with the pinned toolchain 1.99.0
  • cargo test -p openplotva-telegram --lib: 246 passed. This includes the live Redis tests, run against a disposable redis:7 container with OPENPLOTVA_TEST_REDIS_URL set.
    • carapax_get_updates_returns_raw_bot_api_json sends a real carapax client to a local Bot API fixture and gets the GIF update back unchanged. If the typed getUpdates path is restored temporarily, the test fails: animation is missing and only document remains.
    • long_poll_batch_keeps_raw_bot_api_json_for_the_shared_decoder checks that the stream entry keeps the Telegram JSON and decodes as Animation.
    • long_poll_batch_skips_stale_updates_before_the_ingress_guard checks the stale-update filter and the guard ordering.
    • live_webhook_and_long_poll_store_the_same_raw_update sends one GIF update through both ingress modes into Redis Streams and checks that the payloads are equal and decode as Animation.

Production runs on the webhook, so this changes nothing at runtime until polling is enabled.

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.
@github-actions

Copy link
Copy Markdown
Messages
📖 Danger checked 3 changed file(s).

Generated by 🚫 dangerJS against 65b3d99

@iamwavecut
iamwavecut merged commit 679d37a into main Nov 27, 2026
12 checks passed
@iamwavecut
iamwavecut deleted the fix/long-poll-raw-updates branch November 27, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant