Skip to content

fix(groups): correct get_participants pagination - #171

Merged
chigwell merged 1 commit into
chigwell:mainfrom
antonskiter:fix/iter-participants-offset
Jul 28, 2026
Merged

fix(groups): correct get_participants pagination#171
chigwell merged 1 commit into
chigwell:mainfrom
antonskiter:fix/iter-participants-offset

Conversation

@antonskiter

Copy link
Copy Markdown
Contributor

Fixes #170.

get_participants pagination has two independent defects; this fixes both in telegram_mcp/tools/groups.py.

1. iter_participants has no offset parameter. Telethon's signature is (entity, limit=None, *, search, filter, aggressive) — no offset, in the v1 source or the 1.44.0 docs, and the project requires telethon>=1.44.0. Since offset is passed unconditionally, every call raises TypeError.

2. limit does not bound basic groups. In telethon/requestiter.py:

if await self._init(**self.kwargs):
    self.left = len(self.buffer)

For _EntityType.CHAT, _ParticipantsIter._init buffers the whole participant list and returns True, so left is overwritten with the buffer length and the requested limit is discarded. Channels are unaffected — there _init returns falsy. So limit alone cannot bound a page.

Fix. Skip to the start of the requested page and stop once it is full, relying on neither offset nor limit. limit is still passed so channels do not over-fetch.

Verification. Against a live account on telethon 1.44.0:

  • basic group, 6 members, page_size=2 — pages 1/2/3 each return 2 non-overlapping participants in list order, page 4 returns empty
  • supergroup, page_size=3 — pages 1 and 2 each return 3, disjoint

Before the fix the same calls returned a formatted TypeError; with only defect 1 fixed, page=1, page_size=1 on the basic group returned all 6 participants.

No behaviour change for page=1, page_size=200 (the defaults) beyond it no longer erroring.

@antonskiter
antonskiter force-pushed the fix/iter-participants-offset branch 2 times, most recently from 38c3762 to 1438a11 Compare July 28, 2026 10:58
Two independent defects made every page beyond the first wrong:

1. TelegramClient.iter_participants takes no `offset` kwarg — its signature
   is (entity, limit=None, *, search, filter, aggressive) — so passing
   offset= raised TypeError for page > 1.

2. `limit` does not bound basic groups. _ParticipantsIter._init buffers the
   whole participant list and returns True, and RequestIter.__anext__ then
   sets `left` to the buffer length, discarding the requested limit. A page
   of a basic group therefore ran past page_size.

Skip to the start of the requested page and stop once it is full. `limit`
is still passed so channels, where it is honoured, do not over-fetch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@antonskiter
antonskiter force-pushed the fix/iter-participants-offset branch from 1438a11 to db87ad2 Compare July 28, 2026 11:01
@chigwell
chigwell merged commit 85dbf2a into chigwell:main Jul 28, 2026
4 checks passed
@antonskiter
antonskiter deleted the fix/iter-participants-offset branch July 28, 2026 11:10
KiaroSama pushed a commit to KiaroSama/telegram-mcp that referenced this pull request Aug 25, 2026
…s-offset

fix(groups): correct get_participants pagination
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.

get_participants is non-functional: unexpected 'offset' kwarg on every call, and page_size ignored for basic groups

2 participants