refactor(gateway): extract media/event helpers from run.py (slice 7 of #54962) - #77702
Open
andrexibiza wants to merge 1 commit into
Open
refactor(gateway): extract media/event helpers from run.py (slice 7 of #54962)#77702andrexibiza wants to merge 1 commit into
andrexibiza wants to merge 1 commit into
Conversation
…NousResearch#54962) Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
This was referenced Aug 3, 2026
This was referenced Aug 3, 2026
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
Extracts the media/event-handling cluster (9 pure helpers) out of the 26,823-line
gateway/run.pygod file into a new self-containedgateway/media_helpers.pymodule.Moved functions (verbatim — zero behavior change, docstrings/comments preserved):
_event_media_type_at_event_media_is_image_event_media_is_audio_event_media_is_stt_input_event_media_is_video_build_media_placeholder_build_document_context_note_format_duration_probe_audio_duration(async)The cluster is CLEAN: it only depends on
MessageType(fromgateway.platforms.base),asyncio,os, andtyping.Optional— no module-level state, no move-with constants.gateway/run.pynow re-exports the names via a module-attribute import, sogateway.run.<name>references (call sites inGatewayRunnermethods and any external lazy importers) keep resolving unchanged.Why
Part of the god-file shrink campaign (#54962):
gateway/run.pyis 26,823 lines, and this is one of several pure-cluster extractions into focusedgateway/*_helpers.pymodules. Pure moves only — no behavior change, no refactor of the moved bodies.How to test
Expected:
import OKand all targeted tests green. The single failure (test_73771_media_resend_dedup.py::test_streamed_explicit_media_resend_is_delivered) is a pre-existing Windows path/URL-encoding environment issue — stash-proven to fail identically on pristinemain(it asserts a rawC:\...path against afile://C%3A...URL-encoded form). Not related to this move.Platforms tested
import gateway.run+import gateway.media_helpers+ targeted test suites abovegit diff --checkcleanscripts/check-windows-footguns.py gateway/run.py gateway/media_helpers.py— ✓ No Windows footgunsShrink
gateway/run.py: 26,823 → 26,681 lines (net −142; 153 lines moved out, 11-line re-export import added). New module:gateway/media_helpers.py(169 lines).Part of #54962
Part of #55138
Part of #78647