Skip to content

[Bug]: REACTION_RESWEEP trips FloodWait on getMessagesReactions (burst rate, not volume) #224

Closed

Description

@625801

Version

7.24.0

Deployment Method

Docker Compose

Database Type

PostgreSQL

Bug Description

Thanks for the fast turnaround on both #221 and #222 - the phantom chat-action
cleanup in migration 019 removed 99 rows on my instance and joins now render
correctly, and the resweep works and found real discrepancies. Reporting a
pacing issue with the latter.

The resweep trips FloodWait after only a few getMessagesReactions requests,
accumulated ACROSS chats rather than within one chat, so a per-chat cap cannot
avoid it.

Two distinct FloodWait signatures appear in these logs and should not be
confused:
A) "before resuming (last_msg_id=...)" - ordinary message iteration
B) "before retrying " - the resweep

CONTROL, REACTION_RESWEEP_DAYS=0, 429 dialogs, completed in 264s:
Only type A, 7 occurrences, at dialogs 58/118/178/238/298/358/418 - a regular
~60-dialog cadence, clearly the baseline iteration limit for an account this
size. Zero type B.

WITH RESWEEP, DAYS=3, MAX_PER_CHAT=300, fresh start after hours idle:
[1/429] -> checked 145 ids (2 requests), reconciled 8 - OK
[2/429] -> checked 58 ids (1 request), reconciled 3 - OK
[3/429] -> checked 6 ids (1 request), reconciled 0 - OK
[4/429] type B FloodWait 60.45s, then checked 300, reconciled 5
[5-8] -> 1, 6, 9, 2 ids - OK
[9/429] type B FloodWait 61.02s, then checked 300, reconciled 0

So ~4 batched requests are enough to trip it, and the budget appears to refill
over roughly a minute.

Impact scales sharply with MAX_PER_CHAT. At 300 the run completes normally
(387s vs 264s with the resweep disabled) - the ~120s delta is almost entirely
the two type B sleeps, so the cost is wasted wall-clock rather than failure.
At 2000 the first dialog exhausted all five retries (89s, 24s, 61s, 59s, 152s)
and the run never advanced past dialog 1.

Note the resweep fired on only ~14 of 429 dialogs at DAYS=3, since the rest had
no messages in the window - so total request volume is low. The trip appears to
be burst rate over a short window, not aggregate volume, which is why a per-chat
cap cannot express it.

Concretely: a short sleep between getMessagesReactions batches (configurable,
defaulting to something small like 0.5s) would cost a few seconds per sweep
while removing ~120s currently spent in FloodWait backoff - i.e. faster overall,
not slower.

Expected Behavior

The resweep should pace itself so a scheduled sweep does not trip FloodWait.
Options, in rough order of preference:

  • A small configurable delay between getMessagesReactions batches
  • A global per-sweep request budget rather than a per-chat cap
  • Skipping the resweep for the remainder of a run after the first type B
    FloodWait (cheap safety net, complements the delay rather than replacing it)

Steps to Reproduce

  1. 7.24.0, ENABLE_LISTENER=true, LISTEN_REACTIONS=true, an account with several
    hundred dialogs and a few high-volume chats.
  2. Set REACTION_RESWEEP_DAYS=3, REACTION_RESWEEP_MAX_PER_CHAT=300.
  3. Start after an idle period and watch the scheduled sweep.
  4. Type B FloodWaits appear on the chats whose resweep id count is large, while
    chats with a handful of ids pass instantly.
  5. Set REACTION_RESWEEP_DAYS=0 and repeat - only type A FloodWaits remain.

Logs

Type B (resweep), DAYS=3 / MAX_PER_CHAT=300:
  02:54:37 FloodWait: sleeping 60.45s ... before retrying <TelegramClient ...> (retry=1/5)
  02:55:39 FloodWait: sleeping 61.02s ... before retrying <TelegramClient ...> (retry=1/5)

Type B at MAX_PER_CHAT=2000 - all five retries on dialog 1, run never advanced:
  wait=89s (1/5), 24s (2/5), 61s (3/5), 59s (4/5), 152s (5/5)

Type A (baseline iteration, present with the resweep disabled too):
  FloodWait: sleeping 24.82s ... before resuming (last_msg_id=209691, retry=1/5)

Environment

Telegram-Archive: 7.24.0 (backup + viewer)
Database: PostgreSQL 17
Deployment: Docker Compose on Ubuntu 24.04, behind Caddy
Account size: 429 dialogs after filtering (537 total, 88 archived),
~183k messages, 500 chats
Config:
REACTION_RESWEEP_DAYS=3
REACTION_RESWEEP_MAX_PER_CHAT=300
ENABLE_LISTENER=true, LISTEN_REACTIONS=true
REACTION_DEBOUNCE_SECONDS=1.5
SYNC_DELETIONS_EDITS=false
SCHEDULE=0 */6 * * *
CHAT_TYPES=private,groups

Checklist

  • I have searched existing issues to ensure this isn't a duplicate
  • I am using the latest version

Activity

  1. added
    bug
    on Jul 20, 2026
  2. GeiserX commented on Jul 20, 2026

    @GeiserX
    Owner

    Fixed in v7.25.0 (PR #225). Thank you for another exemplary report — the control run, the separation of the two FloodWait signatures, and the bucket/refill estimate turned this into a one-day fix with the design essentially handed over.

    Your diagnosis was exactly right, and it goes one level deeper than we'd documented: flood buckets are keyed per (account, method) — both Telethon and gotd/td key their internal flood caches purely by RPC constructor ID, with no peer dimension — so getMessagesReactions calls against different chats draw from one shared bucket, which is why REACTION_RESWEEP_MAX_PER_CHAT structurally couldn't bound it. Your back-calculated ~12-15s sustainable rate matches the official guidance for this method family ("no more frequently than once every 15 seconds"). One more thing your 2000-cap pathology exposed: a retry-exhausted FloodWaitError was being swallowed by the fallback handler and fell through to get_messages — a second rate bucket with five more retries — which is how one dialog reached ~385s.

    What shipped, mapped to your options:

    • (a) Spacing — REACTION_RESWEEP_BATCH_DELAY_SECONDS (default 2): a minimum gap between the resweep's API requests, measured across chat boundaries via one per-run clock. Your own data showed ~1 request per chat, so a delay between batches within a chat would never have fired for your trip pattern — it had to be global. Documented honestly as burst smoothing: a delay sized to make floods impossible (~15s) would cost more than it saves.
    • (c) Skip after first FloodWait — promoted to the primary bound: on the first resweep FloodWaitError (raw or fallback path) the run's remaining resweep defers immediately — no sleeping into the live window, no retries, no second-bucket fallback. Your two log signatures can no longer coexist: the before retrying <TelegramClient object> line is gone entirely.
    • (b) Global budget — deliberately not added as a knob: with defer-on-flood the server's actual bucket is the budget, so a static number would be redundant and one more thing to tune. Instead the resweep keeps a persisted cycle cursor (completed chats + mid-chat progress of the chat that flooded), so the next scheduled sweep resumes exactly where the previous one stopped. Forward progress is guaranteed for any chat size — including one whose window needs more requests than the bucket holds — and over a few sweeps every chat in the window gets covered without ever fighting the limiter.

    For your two configurations: at MAX_PER_CHAT=300, requests are spaced 2s apart and a trip costs one warning plus a deferral that resumes next sweep — none of the ~120s of flood sleeps. At MAX_PER_CHAT=2000, the first flood defers immediately and the cursor spreads that chat across consecutive sweeps instead of never advancing past it.

    Live validation on one of our production instances (~2,000 dialogs, resweep freshly enabled at DAYS=3 with the default 2s spacing): the first sweep executed 27 resweep requests across consecutive chats at an exact 2-second cadence, then hit its first FloodWait (7s) — which produced exactly one warning and an immediate deferral of the rest of the run. No retries into the live window, no fallback onto the second bucket, and the retrying <TelegramClient object> signature never appeared. The deferred chats resume on the next scheduled sweep via the cursor. Interestingly our account absorbed ~27 spaced requests before tripping versus your ~4-5 back-to-back — the bucket evidently varies by account, which is another reason the reactive deferral is the primary bound rather than any fixed number.

    No action needed on upgrade — existing DAYS/MAX_PER_CHAT settings keep working and the new knob has a sane default. Closing as shipped; please reopen if the pacing misbehaves at either of your scales.

  3. GeiserX commented on Jul 21, 2026

    @GeiserX
    Owner

    Shipped in v7.25.1 (PR #226) — your middle ground, implemented faithfully. Thank you for coming back with numbers instead of impressions; the 2-covered/498-deferred snapshot made the over-correction undeniable, and your bucket-degradation caveat directly shaped the design.

    What changed:

    • On a re-sweep FloodWait the run now records the expiry deadline and pauses — nothing sleeps, nothing retries, no fallback onto the get_messages bucket, and message iteration continues untouched (exactly the properties you asked to keep).
    • Once wall-clock passes the server-requested window (plus a 2s margin), the re-sweep resumes within the same run. Chats reached while it was still cooling skip to the next-run cursor as before.
    • Full deferral now happens only when the window outlives the run — or after 3 floods in a single run: your own evening data (tripping after ~1 request by the end) is exactly the degrading-bucket case where continuing to poke, however politely, is the wrong move.
    • Your MAX_PER_CHAT finding is now README sizing guidance: each 100 messages ≈ one request, so on small-bucket accounts a low cap (e.g. 100) spends ~1 request per chat and lets a single run reach every eligible chat, while large caps favor depth over breadth. The docs also now say plainly that the bucket varies a lot between accounts — your ~4 vs our ~27 settles that.

    For your DAYS=3 / MAX_PER_CHAT=300 config: the first flood (~53s) now costs ~53s of re-sweep quiet time inside a ~390s run instead of deferring 498 dialogs to the next sweep — per-run coverage should return to roughly the v7.24 level without any of its retry-burn.

    Live validation on our production instance (~2,000 dialogs, DAYS=3, default 2s spacing) — and it turned out to exercise exactly your scenario: the post-deploy sweep completed cleanly (cursor cleared), then the next scheduled run started with the bucket still hot from the previous run's requests, hit a getMessagesReactions FloodWait (21s) 46 seconds in, logged one warning, paused with zero sleeping or retrying, and resumed within the same run 23 seconds later (21s + the 2s margin). No hard-defer, no retry-burn, and the flooded chat parked its mid-chat offset for the next run. Yesterday that identical event deferred everything.

    No config changes needed on upgrade. Closing again — and if your rested-account measurements turn up anything (including on the unexplained trip condition, which didn't look like a simple request count to us either), reopen or file fresh; your reports have been the best QA this project has had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions