Skip to content

refactor(telegram): share exception-graph walk across classifiers - #99193

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:refactor/telegram-exception-graph-walker
Aug 31, 2026
Merged

kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:refactor/telegram-exception-graph-walker

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Contributor

Summary

The two Telegram error classifiers now share one exception-graph walker instead of carrying duplicate 15-line DFS skeletons, and both gain direct unit tests for the first time.

Follow-up to #98094 (review finding): _looks_like_connect_timeout and _looks_like_pool_timeout differed only in their one-line match predicate — the seen-set/stack/__cause__+__context__ descent was copy-pasted. A third copy of the same shape would have made the drift obvious; this extracts it before that happens.

Changes

  • plugins/platforms/telegram/adapter.py: new module-level _iter_exception_graph() (DFS over __cause__/__context__ with identity cycle guard); both classifiers collapse to a predicate loop over it.
  • tests/gateway/test_telegram_network_reconnect.py: +14 tests — walker contracts (flat, cause chain, context chain, cycle, diamond-dedupe) and classifier contracts (real PTB TimedOut pool-timeout message, wrapped httpx.PoolTimeout/ConnectTimeout class names, negative cases, substring conjunction).

Validation

Before After
Classifier behavior (subprocess parity vs origin/main, real telegram.error/httpx fixtures incl. cause+context chains) — identical, 6/6 cases
Direct classifier/walker tests 0 14, all passing
Existing targeted surface (10 files) 99 passed 113 passed
Mutation check — removing __context__ descent from the walker fails the context-chain test; restored → green
ruff / ty — clean / zero new diagnostics

Checked and deliberately NOT consolidated: tools/environments/vercel_sandbox.py::_exception_chain (linear __cause__ or __context__ walk — misses sibling branches), agent/stream_diag.py::flatten_exception_chain (depth-4 string rendering for diagnostics), tools/mcp_tool.py (inline walk with exception-group semantics), gateway/run.py::_is_transient_network_error (depth-capped linear chain, different failure model). None visits the full graph, so they are not consolidation targets for an iterator; unifying those is a separate, wider decision.

Net LOC: +109 in tests, −29/+29 in the adapter (the two classifier bodies shrink by ~26 lines, the walker adds ~26).

_looks_like_connect_timeout and _looks_like_pool_timeout carried two
copies of the same 15-line DFS skeleton (seen-set, stack, __cause__/
__context__ descent) differing only in the one-line match predicate —
follow-up to the NousResearch#98094 review.

Extract _iter_exception_graph() and collapse both classifiers onto it.
Behavior is byte-identical (subprocess parity vs origin/main on real PTB
error fixtures: 6/6 identical), and the two classifiers gain direct unit
tests for the first time, including the cycle/diamond chain shapes the
inline copies had no coverage for.
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 31, 2026 06:00
@kshitijk4poor
kshitijk4poor merged commit 6681f9e into NousResearch:main Aug 31, 2026
35 checks passed
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter labels Aug 31, 2026
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.

2 participants