Skip to content

fix: use consecutive-old-counter for telegram dialog cutoff#16

Merged
dandaka merged 1 commit intomainfrom
fix/telegram-sync-dialog-ordering
Mar 18, 2026
Merged

fix: use consecutive-old-counter for telegram dialog cutoff#16
dandaka merged 1 commit intomainfrom
fix/telegram-sync-dialog-ordering

Conversation

@dandaka
Copy link
Owner

@dandaka dandaka commented Mar 18, 2026

Summary

Fixes #15 — Telegram sync was missing chats with new messages because iter_dialogs() ordering is not strictly by last_message_date.

  • Replace immediate break on first old dialog with a consecutive-old-counter (threshold=100)
  • Old dialogs are skipped but scanning continues through the blurred zone
  • Only stops after 100 consecutive old dialogs (one full Telethon internal page)

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 by last_message_date. This creates a blurred boundary zone where chats with and without new messages are intermixed.

The previous code did break on the first dialog older than the --since cutoff. 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):

Performance

Approach Dialogs scanned Time
Previous (broken) 1 <1s
Full scan (no cutoff) 3,334 ~35s
This fix ~300-500 typical ~3-5s

Test plan

  • Restart daemon, verify chats that were previously missed now sync
  • Check traul messages -c "AI Agents Lab 01" -l 5 shows today's messages after next sync cycle
  • Monitor daemon logs for "consecutive old" stop message to confirm early exit works
  • Verify no FloodWaitError from Telegram after several sync cycles

🤖 Generated with Claude Code

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>
@dandaka dandaka merged commit 1a6e004 into main Mar 18, 2026
1 check passed
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.

Telegram sync misses chats due to iter_dialogs ordering assumption

1 participant