refactor(gateway): extract GatewayPlatformMixin from run.py (slice 25 of #54962) - #77759
Open
andrexibiza wants to merge 2 commits into
Open
refactor(gateway): extract GatewayPlatformMixin from run.py (slice 25 of #54962)#77759andrexibiza wants to merge 2 commits into
andrexibiza wants to merge 2 commits into
Conversation
… of NousResearch#54962) Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
This was referenced Aug 4, 2026
Open
Open
Open
Open
Open
This was referenced Aug 5, 2026
Open
Open
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 #54962 #55138
What
Extract the platform-adapter lifecycle cluster out of
GatewayRunneringateway/run.py(26.8k-line god file) into a newgateway/platform_mixin.pymodule asGatewayPlatformMixin— 34 methods / ~1,668 LOC moved byte-verbatim (zero behavior change).This is slice 25 of the large-file decomposition campaign (Wave 3, mixin lifts), following the codebase's established mixin pattern (
gateway/authz_mixin.py,gateway/kanban_watchers.py,gateway/slash_commands.py).What moved — the adapter lifecycle cluster:
_await_adapter_cleanup_with_timeout,_safe_adapter_disconnect,_bounded_adapter_teardown,_adapter_disconnect_timeout_secs,_platform_connect_timeout_secs,_connect_adapter_with_timeout,_connect_initial_adapter_with_timeout)_handle_adapter_fatal_error*)_platform_reconnect_watcher,_start_secondary_profile_adapters,_start_one_profile_adapters,_configure_profile_adapter,_run_secondary_profile_reconnect,_schedule_secondary_profile_reconnect, ...)_adapter_credential_claim,_adapter_listener_claim,_adapter_credential_fingerprint)_handoff_watcher,_process_handoff), profile-name resolution, systemd watchdog, auth-check factoryWhy
gateway/run.pyis a ~26.8k-line god file.GatewayRunneris the largest class; the platform-adapter cluster is a cohesive, self-contained concern (onlyself.*+ neutral helpers) that lifts cleanly into a mixin, exactly like the three existing ones.GatewayRunnernow readsGatewayPlatformMixinfirst in its bases.How
gateway/platform_mixin.py:class GatewayPlatformMixinwith the 34 methods moved verbatim (docstrings, comments, and bodies byte-identical to the pre-move source).gateway/run.py: methods deleted from the class body;GatewayPlatformMixinadded FIRST inGatewayRunner's bases; module-attribute import added to thefrom gateway.*block.self.*calls resolve unchanged via the MRO. Neutral dependencies import at module top. Helpers that stay inrun.py(_profile_runtime_scope,_reconnect_backoff,_dispose_unused_adapter,_platform_has_bot_credential,_own_policy_open_startup_violation,MultiplexConfigError,SecondaryPortBindingConfigError, the timeout defaults,get_hermes_home,GatewayRunneritself for a staticmethod self-reference) are imported lazily inside the using method (from gateway.run import ...at call time) — the sibling-mixin pattern that avoids the import cycle. The module-levellogger = logging.getLogger("gateway.run")preserves the original logger name so log records are unchanged.@staticmethoddecorators preserved on_adapter_credential_claim/_adapter_listener_claim/_adapter_credential_fingerprint.run.py.How to test
Test results (this PR): 32 + 67 + 46 + 121 + 132 passed = 398 passed, 1 xfailed, 0 failures across the moved-method suites. One unrelated pre-existing failure (
test_api_server.py::TestHealthDetailedEndpoint::test_health_detailed_returns_ok) reproduces identically on pristinemain(stash-proven) and is not touched by this change.git diff --checkclean;check-windows-footguns.pyclean on both changed files.Shrink
gateway/run.py: 26,823 → 25,205 lines (−1,618)gateway/platform_mixin.py: 1,735 lines (34 methods)Scope note
Pure mechanical move — no logic touched, no signatures changed. Byte-verbatim verified per-method against the pre-move source (the only inserted lines are the lazy
from gateway.run import ...statements inside the 9 methods that reference run.py-local helpers, matching the sibling-mixin pattern). The full suite carries ~250 pre-existing environment failures unrelated to this change; only targeted suites were run here.Part of #54962
Part of #55138
Part of #78207
Part of #78647
Part of #78791