Skip to content

refactor(gateway): extract message/config helpers from run.py (slice 2 of #54962) - #77438

Open
andrexibiza wants to merge 3 commits into
NousResearch:mainfrom
andrexibiza:fix/gateway-home-channel-helpers
Open

refactor(gateway): extract message/config helpers from run.py (slice 2 of #54962)#77438
andrexibiza wants to merge 3 commits into
NousResearch:mainfrom
andrexibiza:fix/gateway-home-channel-helpers

Conversation

@andrexibiza

@andrexibiza andrexibiza commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Related #54962 #55138 #77433

What does this PR do?

Second slice of the Extract Gateway Platform Routing from
gateway/run.py
refactor (#54962, #55138) — follow-up to #77433 (slice 1:
display helpers).

This slice pulls the message/config helper cluster out of the
26,700-line god-file into gateway/message_config_helpers.py:

  • _csv_or_list_to_set — config list / comma-scalar normalization
  • _slack_ignored_channels_from_gateway_config — runner-level Slack
    channel blacklist guard (fail-safe below the adapter's first-line drop)
  • _slack_parent_channel_id — thread-scoped chat ID → parent channel
  • _is_slack_ignored_channel — the dispatch-time blacklist check
  • _message_timestamps_enabled — gateway.message_timestamps opt-in

No behavior change: pure move + import. gateway/run.py shrinks by
65 lines; the extracted functions are module-attribute-imported so
existing tests that reference them via gateway.run stay green.

The extracted module has no module state — everything derives from
arguments, so the helpers are directly unit-testable (the existing
test_message_timestamps.py and test_slack_runner_ignored_channels.py
cover them; 5 pure-logic tests pass on this branch).

Scope honesty

The full platform-routing extraction from a 26.7K-line file is a
multi-PR effort. This is slice 2 of that series, using the same verified
pattern as slice 1 (module + import + shrink). Platform adapters and the
dispatch loop remain for follow-up slices.

How to test

pytest tests/gateway/test_message_timestamps.py tests/gateway/test_slack_runner_ignored_channels.py -q
# 5 passed; 1 env-dependent test requires pytest-asyncio (not in this venv,
# runs in CI where the plugin is installed)

What platforms were tested?

  • Windows 11 native: both files parse, imports resolve, 5 pure-logic
    tests pass, git diff --check clean, attribution audit clean.

Why this matters

Every slice shrinks the largest file in the codebase and gives extracted
helpers direct coverage. gateway/run.py is down from 26,819 to 26,600
lines across slices 1-2, with more to come.

Part of #54962
Part of #55138 (Extract Gateway Platform Routing)

  • Refactor (no behavior change)
  • Bug fix
  • Breaking change

Checklist

  • Code follows repo style (extraction, no new deps)
  • Self-review complete
  • Existing tests cover the extracted helpers (5 pass)
  • git diff --check clean
  • Attribution audit clean

Part of #78647

…2 of NousResearch#54962)

Second slice of the gateway god-file unpacking: extract the Slack
ignored-channel guard, CSV/list-to-set normalization, parent-channel
resolution, and message-timestamp opt-in check into
gateway/message_config_helpers.py with no behavior change.

- gateway/run.py: -65 lines; the 5 helpers are now imported from the
  module (module-attribute imports keep existing tests green)
- gateway/message_config_helpers.py: new module, pure functions, no
  module state — directly unit-testable

Follow-up to NousResearch#77433 (display helpers, slice 1). Progress on NousResearch#54962.

Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
… of NousResearch#54962)

Third slice of the gateway god-file unpacking: extract
build_resume_recovery_note, _build_replay_entry and the shared
_ASSISTANT_REPLAY_FIELDS whitelist into
gateway/resume_replay_helpers.py.

- Byte-identical extraction (AST-verified against origin/main): no
  behavior change
- gateway/run.py: -172 lines; helpers imported at the extraction point
  (module-attribute imports keep existing tests green)
- 43 tests pass across replay-entry, resume-pending, and message
  timestamp suites

Follow-up to NousResearch#77433 (slice 1) and NousResearch#77438 (slice 2). Progress on NousResearch#54962.

Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
@andrexibiza

Copy link
Copy Markdown
Contributor Author

Update: this PR now also carries slice 3 (same branch, second commit).

Slice 3 — resume/replay helpers (gateway/resume_replay_helpers.py)

Slices landed on this branch: 2 (message/config, #77438) + 3 (resume/replay).
Slice 1 (display helpers) is PR #77433. Continuing toward #54962.

@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Aug 3, 2026
andrexibiza added a commit to andrexibiza/hermes-agent that referenced this pull request Aug 3, 2026
… 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: -78 lines; helpers imported at the extraction point
- 46 tests pass (loop exception handler + compression notices)

Follow-up to NousResearch#77433 (slice 1), NousResearch#77438 (slices 2-3), NousResearch#77450 (slice 4).
Progress on NousResearch#54962.

Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants