refactor(gateway): extract history-build helpers from run.py (slice 13 of #54962) - #77711
refactor(gateway): extract history-build helpers from run.py (slice 13 of #54962)#77711andrexibiza wants to merge 2 commits into
Conversation
…3 of NousResearch#54962) Signed-off-by: andrexibiza <84248988+andrexibiza@users.noreply.github.com>
|
FILE-LIST coordination — history-cluster adjacency with #86050. #86050 (fix(gateway): preserve reasoning-only assistant turns on reload) adds a third dispatch arm inside Note: |
|
This was generated by AI during triage. Summary: Problems:
Solution: Evidenceno deterministic fact backs this claim — model belief, not executed or read evidence Checked against |
Related #54962 #55138 #77452 #77706
What / Why
Slice 13 of the
gateway/run.pygod-file unpacking (#54962): extracts the history-build cluster into a newgateway/history_helpers.pymodule — pure move, zero behavior change.Moved (byte-identical, AST-verified against
origin/main):_uses_telegram_observed_group_context_select_cached_agent_history_wrap_current_message_with_observed_context_TELEGRAM_OBSERVED_CONTEXT_PROMPT_MARKER(exclusive to the moved function)_OBSERVED_GROUP_CONTEXT_HEADER(exclusive to the moved function)_CURRENT_ADDRESSED_MESSAGE_HEADER(exclusive to the moved function)gateway/run.pykeeps a module-attribute import sogateway.run.<name>stays green for existing callers and tests — no re-exports, no test churn.Why this matters to users: no user-visible behavior change. This is pure refactor — the same transcript-replay, observed-context wrapping, and cached-history selection logic runs from a smaller, focused module so the 26.8k-line god file becomes reviewable and maintainable.
Scope note (honest)
_build_gateway_agent_historystays ingateway/run.pyfor now. It depends on two helpers that are being extracted in parallel by sibling slices that have not merged yet:_strip_auto_continue_noise→gateway/auto_continue_helpers.py(PR refactor(gateway): extract auto-continue helpers from run.py (slice 8 of #54962) #77706)_build_replay_entry→gateway/resume_replay_helpers.py(PR refactor(gateway): extract resume/replay helpers from run.py (slice 3 of #54962) #77452)Importing them cross-PR would break
import gateway.runtoday (modules don't exist onmain). Once those PRs merge, this function can be moved as a follow-up with zero further change to its body.The Slack-ignored-channel helpers (
_slack_*,_csv_or_list_to_set) and_message_timestamps_enabledadjacent to this cluster were not touched — they belong to other slices.How to test
Verification
origin/main(ast.dumpequality)run.py: no orphaned referencesimport gateway.run+import gateway.history_helpersOKgit diff --checkclean;scripts/check-windows-footguns.pycleanShrink
gateway/run.py: 26,823 → 26,725 lines (−98 net; −104 moved, +6 import block). New module: 77 lines.Part of #54962
Part of #55138
Part of #78207
Part of #78647