Repository navigation
Description
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
- 7.24.0, ENABLE_LISTENER=true, LISTEN_REACTIONS=true, an account with several
hundred dialogs and a few high-volume chats. - Set REACTION_RESWEEP_DAYS=3, REACTION_RESWEEP_MAX_PER_CHAT=300.
- Start after an idle period and watch the scheduled sweep.
- Type B FloodWaits appear on the chats whose resweep id count is large, while
chats with a handful of ids pass instantly. - 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
fix: pace the reaction resweep globally and defer on FloodWait (#224) (…
GeiserX commentedon Jul 20, 2026
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
getMessagesReactionscalls against different chats draw from one shared bucket, which is whyREACTION_RESWEEP_MAX_PER_CHATstructurally 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-exhaustedFloodWaitErrorwas being swallowed by the fallback handler and fell through toget_messages— a second rate bucket with five more retries — which is how one dialog reached ~385s.What shipped, mapped to your options:
REACTION_RESWEEP_BATCH_DELAY_SECONDS(default2): 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.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: thebefore retrying <TelegramClient object>line is gone entirely.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. AtMAX_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=3with 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 theretrying <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_CHATsettings keep working and the new knob has a sane default. Closing as shipped; please reopen if the pacing misbehaves at either of your scales.fix: resume the reaction resweep within the run once a FloodWait expi…
GeiserX commentedon Jul 21, 2026
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:
get_messagesbucket, and message iteration continues untouched (exactly the properties you asked to keep).MAX_PER_CHATfinding 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=300config: 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 agetMessagesReactionsFloodWait (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.
fix: pace the reaction resweep globally and defer on FloodWait (#224) (…
fix: resume the reaction resweep within the run once a FloodWait expi…
fix(backup): a premium flood no longer makes the re-sweep hammer a ra…
fix: pace the reaction resweep globally and defer on FloodWait (#224) (…
fix: resume the reaction resweep within the run once a FloodWait expi…
fix(backup): a premium flood no longer makes the re-sweep hammer a ra…