fix: use consecutive-old-counter for telegram dialog cutoff#16
Merged
Conversation
iter_dialogs() doesn't sort strictly by last_message_date desc — there's a blurred zone where old and new chats are mixed. Replace the immediate break with a consecutive-old-counter (threshold=100) so we skip interleaved old dialogs and only stop after 100 consecutive old ones. Fixes #15 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes #15 — Telegram sync was missing chats with new messages because
iter_dialogs()ordering is not strictly bylast_message_date.breakon first old dialog with a consecutive-old-counter (threshold=100)Root Cause
Telethon's
iter_dialogs()returns dialogs sorted by Telegram's internal "last activity" order, which includes pinned status, admin actions, etc. — not strictly bylast_message_date. This creates a blurred boundary zone where chats with and without new messages are intermixed.The previous code did
breakon the first dialog older than the--sincecutoff. If a single old dialog appeared before newer ones (e.g., a pinned chat), all subsequent dialogs were hidden — including chats with messages from hours ago.Production evidence (2026-03-18):
13:05:54Z13:04:23(1 min before cutoff) → broke immediately18:01:40(never seen)18:55:10(never seen)Performance
Test plan
traul messages -c "AI Agents Lab 01" -l 5shows today's messages after next sync cycleFloodWaitErrorfrom Telegram after several sync cycles🤖 Generated with Claude Code