refactor(telegram): share exception-graph walk across classifiers - #99193
Merged
kshitijk4poor merged 1 commit intoAug 31, 2026
Merged
kshitijk4poor merged 1 commit into
kshitijk4poor merged 1 commit into
Conversation
_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
enabled auto-merge (rebase)
August 31, 2026 06:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_timeoutand_looks_like_pool_timeoutdiffered only in their one-line match predicate — theseen-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 PTBTimedOutpool-timeout message, wrappedhttpx.PoolTimeout/ConnectTimeoutclass names, negative cases, substring conjunction).Validation
origin/main, realtelegram.error/httpxfixtures incl. cause+context chains)__context__descent from the walker fails the context-chain test; restored → greenChecked 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).