refactor(gateway): extract platform routing helpers from run.py - #77376
refactor(gateway): extract platform routing helpers from run.py#77376andrexibiza wants to merge 1 commit into
Conversation
Move the platform routing helper cluster (identity normalization, raw-text surface policy, Discord non-conversational metadata, home-target env var resolution, bot-credential check, config-key mapping) out of the 26k-line gateway/run.py god-file into gateway/platform_routing.py. Bodies are verbatim moves; gateway/run.py re-exports every name so external importers (gateway/slash_commands.py, tests) keep working. Adds focused unit tests for the extracted module plus a re-export compatibility test. Addresses NousResearch#54962; closes duplicate NousResearch#55138.
GottZ
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Summary
One PR addresses this issue complex. #77376 extracts a focused cluster of platform identity, routing-policy, home-target, credential, and config-key helpers from gateway/run.py, but it does not implement the requested platform adapter ABC or move webhook parsing, event translation, and message serialization into adapters.
Related pull requests
- #77376
fixes— (+252/-78) — partial extraction with a concrete salvage path: the diff moves eight existing routing helpers into gateway/platform_routing.py, re-exports them from gateway/run.py for compatibility, and adds focused tests; it reduces the god-file without addressing the issue's broader adapter-interface architecture.
Suggested consolidation
Keep #77376 open with a salvage path focused on the independently testable helper extraction and backward-compatible re-exports. Treat #55138 as a duplicate of canonical issue #54962; there are no duplicate PRs to close in this complex, while the broader ABC and adapter-owned payload/event/serialization work should remain tracked separately from #77376's narrower diff.
Complex graph
flowchart LR
classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
classDef best stroke-width:3px,stroke:#b45309
classDef target stroke-width:3px,stroke:#4338ca
I55138(["issue #55138 (open)"])
P77376["PR #77376 (open)"]
P77376 -->|fixes| I55138
class I55138 open
class P77376 open
class P77376 target
click I55138 "https://github.com/NousResearch/hermes-agent/issues/55138"
click P77376 "https://github.com/NousResearch/hermes-agent/pull/77376"
Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label).
Cross-PR triage: Reviewed 1 pull request and 2 issues in this complex. Each diff was read against this issue; Assessment working set: 16 kB of PR diffs, 5 kB of issue/PR text, 1 kB of discussion (2 comments), 0 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
|
Thanks for the triage — this PR already implements the salvage path the verdict endorses (independently testable helper extraction + backward-compatible re-exports), so no further changes are needed within its scope. The broader platform-adapter ABC and adapter-owned payload/event/serialization work stays tracked separately, per the recommendation. Validation on the PR head
|
…ay_helpers display_helpers.py extracted its own copy of _gateway_platform_value, duplicating the identical helper that the platform-routing slice (NousResearch#77376) extracts into gateway/platform_routing.py. Keep the single definition in gateway.run and pass the caller-normalized platform value into _resolve_gateway_display_bool instead, so the two slices do not overlap. - remove _gateway_platform_value from gateway/display_helpers.py - restore the definition in gateway/run.py (source of truth on main) - _resolve_gateway_display_bool takes platform_value (normalized str) and require_platform_override_for as normalized platform keys - update the show_reasoning call site and mattermost tests - add direct tests for _resolve_gateway_display_bool
Related #54962 #55138 #55190 #55304
What
Extracts the platform-routing helper cluster out of the 26k-line
gateway/run.pygod-file into a focused module,gateway/platform_routing.py:_gateway_platform_value— platform identity normalization (enum/string)_gateway_surface_passes_raw_text+_GATEWAY_RAW_TEXT_PLATFORMS— which surfaces keep raw status/error text_non_conversational_metadata— Discord lifecycle/status marker_home_target_env_var/_home_thread_env_var— home-channel env var resolution_platform_has_bot_credential— token-platform credential check_platform_config_key— Platform enum → config.yaml key mappingAll bodies are verbatim moves — zero behavior change.
gateway/run.pyre-exports every name so existing importers (gateway/slash_commands.py, the/sethometests, the multiplex tests) keep working unchanged. New focused tests land intests/gateway/test_platform_routing.py.Why
This is the extraction requested in issue #54962 (duplicate #55138, same author, same body, filed 5h later — this PR closes #55138 as the duplicate). The repository rubric explicitly wants god-file refactors: "Refactor god-files into clean modules… a declared refactor's request IS the extraction." Sibling extractions from
gateway/run.py(#55190 text_sanitizer, #55304 display_helpers) receivedkeep_open salvageability=mediumsweeper verdicts citing exactly this direction — "consistent with the repository's stated goal of breaking up gateway/run.py" — before dying on execution, not on direction. This PR completes the pattern for the routing policy cluster.How to test
The new test file exercises the real import path and real call paths (no mocks), including a backward-compat assertion that every name is still importable from
gateway.run. The three existing suites cover the external importers (slash_commands.py_home_target_env_var/_platform_config_keyconsumers, multiplex_platform_has_bot_credentialconsumers).Platforms tested
scripts/run_tests.shper-file subprocess isolation, all pass (48 tests across 6 files)python scripts/check-windows-footguns.py --diff HEAD~1— clean (3 files)git diff --check— cleanWhy this matters to users
Nothing user-visible changes today — this is pure code organization. What it buys: the platform routing policy (which surfaces get raw text, how home channels resolve, how credentials are checked) moves from a file so large that a single edit risks touching unrelated gateway logic, into a small module that can be reviewed and tested in isolation. Future gateway fixes and platform additions get a smaller, safer blast radius, and new contributors can find routing policy without scanning 26k lines. Maintainers get a merged precedent for the remaining
gateway/run.pyextraction work.Addresses #54962 · closes #55138
Part of #54962
Part of #55138
Part of #78647
Part of #78791