Skip to content

refactor(telegram): extract config and mention mixin from adapter - #84042

Open
andrexibiza wants to merge 1 commit into
NousResearch:mainfrom
andrexibiza:refactor/telegram-config-mention-c11
Open

andrexibiza wants to merge 1 commit into
NousResearch:mainfrom
andrexibiza:refactor/telegram-config-mention-c11

Conversation

@andrexibiza

@andrexibiza andrexibiza commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Related #78791 #78792 #79010 #81709

What

Extract the Telegram adapter's config, mention, and group-observation cluster into TelegramConfigMentionMixin as the first fresh-current-main shard in the adapter decomposition train.

  • Move exactly 35 methods from plugins/platforms/telegram/adapter.py to plugins/platforms/telegram/telegram_config_mention.py.
  • Compose the mixin MRO-first through the original TelegramAdapter class.
  • Preserve original-namespace patch surfaces for the lazy imports used by moved methods.
  • Add a seam-identity regression covering every moved method.
  • Add the contributor email mapping for this signed commit.

adapter.py moves from 10,271 to 9,494 lines: a 777-line reduction. The new mixin is 855 lines and the seam test is 99 lines. This is one coherent extraction, not the all-at-once decomposition attempted in #79010.

Behavior contract

This is a mechanical extraction with no intended behavior change.

The candidate was checked against source pin c0106e50e7ecedb3ce34e785d949725dc4e0e457:

  • all 35 authorized methods moved once, in the agreed order;
  • signatures, decorators, sync/async identity, and method ASTs match the source pin;
  • the only permitted differences are explicit lazy imports resolving through the original Telegram adapter namespace;
  • TelegramAdapter resolves every moved method through TelegramConfigMentionMixin;
  • no direct duplicate definitions remain in adapter.py;
  • the candidate is exactly one signed commit over the pin.

The bounded Telegram surface remained unchanged through upstream f51aa6a9b5ce514e15f8e337777f522fd5cc6fa2 immediately before publication.

Verification

Parent-run canonical files, each with an isolated external pytest temp directory:

File Result
tests/gateway/test_telegram_config_mention_seam.py 3 passed
tests/gateway/test_telegram_format.py 42 passed
tests/gateway/test_telegram_mention_boundaries.py 12 passed
tests/gateway/test_telegram_group_gating.py 23 passed
tests/gateway/test_telegram_auth_check.py 11 passed
tests/gateway/test_telegram_callback_auth_fail_closed.py 2 passed
tests/scripts/test_contributor_map.py 7 passed

Parent canonical total: 100 passed, 0 failed.

Additional gates:

  • python -m compileall -q plugins/platforms/telegram: pass
  • git diff --check: pass
  • changed-file Windows-footgun scan: pass
  • candidate-diff secret scan: pass
  • contributor mapping and exact DCO signoff: pass
  • structural seam/orphan/patch-surface verifier: pass

Two mutually blind exact-head reviewers independently returned PASS with no findings. Their own focused/regression probes returned 97 + 130 passing tests and 80 + 6 passing tests respectively; those are reviewer-specific invocations and are not added to the parent canonical total.

Graph gate

This shard advanced through the Feature Package's 5×2×3 gate before implementation:

  • five blind regional analyses;
  • five blind witnesses;
  • five-slot adjudication union;
  • one blind implementer;
  • two mutually blind exact-head reviewers;
  • parent-side identity, transcript, schema, hash, semantic, and test admission.

One defective adjudication artifact that circularly required post-candidate evidence at the pre-implementation gate remains preserved as dissent with no role authority. Its same logical slot was recovered independently; no sixth vote was created.

Coordination and credit

Part of #78791.
Tracks the decomposition graph in #78792.

Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter P3 Low — cosmetic, nice to have labels Aug 11, 2026
@Enough1122

Copy link
Copy Markdown
Contributor

AI code review — automated review for reference, author can ignore or act on any point.

refactor(telegram): extract config and mention mixin from adapter

  1. Per-call imports from the adapter namespace on hot pathsplugins/platforms/telegram/telegram_config_mention.py: virtually every method starts with from plugins.platforms.telegram.adapter import os/re/time/asyncio/json/dataclasses/.... This preserves the monkeypatch seam, but the per-message routing methods (_telegram_require_mention, _message_mentions_bot, _should_observe_unmentioned_group_message, _telegram_allowed_chats) now pay a sys.modules lookup + attribute resolution on every message. Python caches module imports so the cost is small, but hoisting the pure stdlib names (os, re, time, asyncio, json, dataclasses) to module top and keeping function-level imports only for adapter-local symbols (_scoped_gate_env, logger, compile_mention_patterns, _escape_mdv2, _wrap_markdown_tables, TelegramAdapter, MessageEvent, MessageType) would be cleaner.

  2. re imported from the adapter namespaceformat_message (line 909): from plugins.platforms.telegram.adapter import _escape_mdv2, _wrap_markdown_tables, re — importing the stdlib re through the adapter module is confusing to readers. If the local-import approach stays, import re directly alongside.

  3. Implicit mixin contract — the mixin relies on attributes that remain on TelegramAdapter: _GENERAL_TOPIC_THREAD_ID, _FOREIGN_BOT_HANDLE_RE, _BOT_IDENTITY_TTL_SECONDS, _BOT_IDENTITY_PROBE_TIMEOUT, _background_tasks, _bot, _mention_patterns, _bot_username_observed, _bot_identity_checked_at. MRO resolves them, so behavior is preserved, but the mixin is unusable standalone and the coupling is invisible. A short "required attributes" comment at the top of the mixin would make the contract explicit for the next extraction.

  4. Change-detector risk in the seam testtests/gateway/test_telegram_config_mention_seam.py:27-43: MOVED_METHODS (35 hardcoded names) plus assert len(MOVED_METHODS) == 35 snapshots the extraction's shape. If a method is intentionally moved back or renamed later, this fails for the wrong reason. The MRO-order assertion (mixin index < BasePlatformAdapter index) is the load-bearing invariant; the name list could be derived from TelegramConfigMentionMixin.__dict__ instead of hardcoding. No blocking issues otherwise — the extraction is faithful and the mixin composes correctly.

@andrexibiza

Copy link
Copy Markdown
Contributor Author

Telegram adapter extraction recorded at bfb6dc1fd5e8f8167fb4286d8d8dfc9156289d2d

The uncovered commit bfb6dc1fd5e8f8167fb4286d8d8dfc9156289d2d moves 35 configuration, mention, and group-observation methods into TelegramConfigMentionMixin, composed MRO-first by TelegramAdapter. The original adapter namespace remains available to the moved lazy imports, preserving patch surfaces while removing the duplicate method definitions from adapter.py.

The source-pinned contract records matching signatures, decorators, sync/async identity, and method ASTs; the only permitted differences are the explicit namespace-preserving imports. The seam test covers every moved method. The canonical verification total is 100 passed, 0 failed, with compileall, diff, Windows-footgun, secret, attribution, and structural seam checks also passing.

For refactor(telegram): extract config and mention mixin from adapter, GitHub reports check rollup SUCCESS on exact head bfb6dc1fd5e8f8167fb4286d8d8dfc9156289d2d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants