refactor(gateway): extract transient-error helpers from run.py (slice 5 of #54962) - #77455
Open
andrexibiza wants to merge 1 commit into
Open
refactor(gateway): extract transient-error helpers from run.py (slice 5 of #54962)#77455andrexibiza wants to merge 1 commit into
andrexibiza wants to merge 1 commit into
Conversation
… 5 of NousResearch#54962) Fifth slice of the gateway god-file unpacking: extract _is_transient_network_error and _gateway_loop_exception_handler into gateway/error_helpers.py. - Byte-identical extraction (AST-verified against origin/main): the classifier walks the exception cause chain (NousResearch#31066/NousResearch#31110); the loop handler wires it into the event-loop safety net - gateway/run.py: -76 lines; helpers imported at the extraction point - 8 tests pass (loop exception handler) Follow-up to NousResearch#77433 (slice 1), NousResearch#77438 (slice 2), NousResearch#77452 (slice 3), Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com> NousResearch#77450 (slice 4). Progress on NousResearch#54962.
This was referenced Aug 3, 2026
Open
9 tasks
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.
Related #31066 #31110 #54962 #55138 #77433 #77438 #77450 #77452
What does this PR do?
Fifth slice of the Extract Gateway Platform Routing from
gateway/run.py refactor (#54962, #55138) — standalone PR for the
transient-error helper cluster (follow-up to #77433 slice 1, #77438
slice 2, #77452 slice 3, #77450 slice 4).
This slice pulls the transient-error safety-net helpers out of the
god-file into
gateway/error_helpers.py:_is_transient_network_error— pure classifier: walks the exceptioncause chain (bounded, cycle-safe) and matches known transient class
names (TimedOut, NetworkError, httpx connect/timeout errors) — the
Gateway crashes on Telegram Timeout - unhandled
telegram.error.TimedOutexception #31066/Telegram TimedOut exceptions crash entire gateway (affects all profiles) #31110 gateway-crash class_gateway_loop_exception_handler— the asyncio loop-level safety netthat swallows transient errors (WARNING log with traceback) and
forwards everything else to the default handler
No behavior change: byte-identical extraction (AST-verified against
origin/main).
gateway/run.pyshrinks by 76 lines; the helpers areimported at the extraction point so the loop-install site and existing
tests stay green.
Scope honesty
The full platform-routing extraction from a 26.7K-line file is a
multi-PR effort. This is slice 5, standalone, same verified pattern as
slices 1-4 (module + import + shrink + AST-fidelity). Platform adapters
and the dispatch loop remain for follow-up slices.
How to test
pytest tests/gateway/test_loop_exception_handler.py -q # 8 passedWhat platforms were tested?
AST-identical to origin/main, 8 tests pass,
git diff --checkclean,attribution audit clean.
Why this matters
Every slice shrinks the largest file in the codebase and gives extracted
helpers direct coverage.
gateway/run.pyis down ~450 lines acrossslices 1-5, with more to come.
Part of #54962
Part of #55138 (Extract Gateway Platform Routing)
Checklist
git diff --checkcleanPart of #78647