Repository navigation
feat(daemon): adaptive pacing for history sync - #137
Merged
Merged
Conversation
While first pages or history are due, each account starts at 0.7 messages.getHistory calls per second, speeds up by 0.05 after every 30 calls without a FLOOD_WAIT up to sync.pacing.maxCallsPerSecond (0.9), halves the pace on any FLOOD_WAIT after waiting it out, and goes back to one job every sync.pacing.calmInterval (3s) once no history is due. The pause counts from each job's start; the main loop wakes inside its 1 s tick when an account's next job comes due, and a job that ends after the next one was due starts it at once. The daemon's activity middleware reports every FLOOD_WAIT to the account's pacer. tg status shows progress.history.calls_per_second (getHistory calls of the last 5 minutes) and progress.history.pacing (the live daemon's mode, target pace and FLOOD_WAITs), per account and summed, and a History Pace row in pretty output. Fixes #133 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A live run on a large account got a FLOOD_WAIT on messages.getDialogs in the dialog pass at start, which halved the history pace to 0.35 calls/s before the first page; climbing back to 0.9 took over ten minutes. Only a FLOOD_WAIT on messages.getHistory, the sync jobs' own method, now slows the pace. Refs #133 Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
feat/adaptive-sync-pacing
branch
from
October 31, 2026 00:11
7890961 to
79208dc
Compare
…rval With calmInterval 1s the floor of the halving was 1 call/s capped at 0.9, so a FLOOD_WAIT sped history up from 0.7 to 0.9. The floor is now a fixed 0.2 calls/s (or the cap, if lower), and history intervals round up, so the pace never goes above the cap. Refs #133 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #133
Problem
A first sync made one
messages.getHistorycall about every 4 seconds: the fixed 3 s pause between jobs counted from the job's end and waited for the main loop's next 1 s tick, and about 92% of the active time was that pause. A probe showed Telegram allows about 0.7 calls/s without a FLOOD_WAIT and 0.85–0.95 through short ones.Change
src/daemon/sync-pacing.ts). The interval counts from each job's start. While first or history pages are due it starts at 0.7 calls/s, speeds up by 0.05 after every 30 calls without a FLOOD_WAIT up tosync.pacing.maxCallsPerSecond(0.9), and halves on any FLOOD_WAIT (never below the calm pace), starting nothing until the wait and one interval at the new pace are over. With no history due it runs one job everysync.pacing.calmInterval(3s). Catch-up keeps its lane turns.waitForNextTick), and a job that ends after the next one was due starts it at once. A stop still ends the wait at once.config.json:sync.pacing.maxCallsPerSecond(number above 0, at most 2) andsync.pacing.calmInterval(duration above 0), validated likecache.retention.*; the daemon reads them once at start and warns on bad values.tg status:progress.history.calls_per_second(getHistory calls of the last 5 minutes fromapi_activity) andprogress.history.pacing({ mode, target_calls_per_second, flood_waits }from the live daemon), per account and summed; pretty output adds a History Pace row. Newdaemon_statuskeyspacing_*.Tests
sync-pacing.test.ts: start at 0.7, speed-up after clean runs, cap, halving and waiting out a FLOOD_WAIT, floor at the calm pace, back to calm.daemon-scheduler.test.ts: history at 0.7 calls/s counted from each start, the next job right after one that outlasted its interval, back to calm 3 s, no job until a FLOOD_WAIT and one interval are over (injected clock).daemon-loop.test.ts: the tick wakes for a job due inside it; a stop during that wait starts nothing (fake clock and sleep).daemon-accounts.test.ts: a FLOOD_WAIT through the daemon's middlewares halves the pace and logs it.bun run check,bun run test(2175 pass), status/multi-account/config/daemon e2e pass locally.🤖 Generated with Claude Code