Skip to content

fix(messages): don't export whole history when unread_count is 0 - #307

Merged
chigwell merged 1 commit into
chigwell:mainfrom
axisrow:ao/telegram-mcp-2/fix/296-export-unread-empty
Oct 17, 2026
Merged

chigwell merged 1 commit into
chigwell:mainfrom
axisrow:ao/telegram-mcp-2/fix/296-export-unread-empty

Conversation

@axisrow

@axisrow axisrow commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed

export_unread_messages is annotated read-only, but with unread_count == 0 its batching loop fell back to a limit of 100 per page and the unread-based stop condition never fired — so it exported the entire chat history to disk. The loop is now gated on while unread_count:; a zero-unread chat still gets an entry with unread_count_at_export: 0 and an empty message list.

Before

Chat with 350 messages in history, unread_count = 0 (fully read):

export_unread_messages(chat_ids=[123])
→ {"status": "ok", "chats_processed": 1, "messages_exported": 350, ...}
out.json: all 350 messages written to disk

The read-only tool dumped the whole history — nothing is unread, everything was exported.

After

Same chat, same call:

export_unread_messages(chat_ids=[123])
→ {"status": "ok", "chats_processed": 1, "messages_exported": 0, ...}
out.json: "chats": {"123": {"unread_count_at_export": 0, "messages_exported": 0, "messages": []}}

No get_messages calls are made; only truly unread messages are exported.

Tests

  • tests/test_export_unread_messages.py: new test_export_skips_chat_with_zero_unread — 350 messages, unread_count=0 → no get_messages calls, messages_exported: 0.
  • Full suite: uv run pytest -q → 1196 passed.

Fixes #296

🤖 Generated with Claude Code

export_unread_messages ran its batching loop unconditionally, so a fully
read chat (unread_count == 0, or the chat missing from the first 500
dialogs) exported its entire history to disk. Gate the loop on
unread_count so zero-unread chats record an empty export.

Fixes chigwell#296 (chigwell/telegram-mcp)

Co-Authored-By: Claude Code <[email protected]>
@chigwell
chigwell merged commit c4f5047 into chigwell:main Oct 17, 2026
4 checks 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.

export_unread_messages exports the entire chat history when unread_count is 0

2 participants