Skip to content

refactor(gateway): extract resume/replay helpers from run.py (slice 3 of #54962) - #77452

Open
andrexibiza wants to merge 1 commit into
NousResearch:mainfrom
andrexibiza:fix/gateway-resume-replay-helpers
Open

refactor(gateway): extract resume/replay helpers from run.py (slice 3 of #54962)#77452
andrexibiza wants to merge 1 commit into
NousResearch:mainfrom
andrexibiza:fix/gateway-resume-replay-helpers

Conversation

@andrexibiza

@andrexibiza andrexibiza commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Related #2974 #54962 #55138 #57056 #77433 #77438

What does this PR do?

Third slice of the Extract Gateway Platform Routing from
gateway/run.py
refactor (#54962, #55138) — standalone PR for the
resume/replay helper cluster (follow-up to #77433 slice 1 and #77438
slice 2).

This slice pulls the resume/recovery + message-replay helpers out of the
god-file into gateway/resume_replay_helpers.py:

No behavior change: byte-identical extraction (AST-verified against
origin/main). gateway/run.py shrinks by 170 lines; the helpers are
imported at the extraction point so the call sites (resume scheduling,
replay building) and existing tests stay green.

Scope honesty

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

How to test

pytest tests/gateway/test_replay_entry_fields.py tests/gateway/test_restart_resume_pending.py -q
# 40 passed

What platforms were tested?

  • Windows 11 native: both files parse, imports resolve, both functions
    AST-identical to origin/main, 40 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 ~200 lines across
slices 1-3, 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 (40 pass)
  • git diff --check clean
  • Attribution audit clean

Part of #78647

… 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: -170 lines; helpers imported at the extraction point
- 40 tests pass (replay-entry + resume-pending 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

FILE-LIST coordination — _has_replay_payload carry-forward.

#86050 (fix(gateway): preserve reasoning-only assistant turns on reload) adds _has_replay_payload in gateway/run.py immediately beside _build_replay_entry; it derives its predicate by iterating _ASSISTANT_REPLAY_FIELDS. This slice moves exactly that contract (_ASSISTANT_REPLAY_FIELDS, _build_replay_entry) into gateway/resume_replay_helpers.py.

Merge-order handling: if #86050 lands first, this slice's extraction set must include _has_replay_payload so the helper isn't stranded in the godfile; if this slice lands first, #86050's helper resolves against the re-imported names unchanged. Either order is compatible — this note pins the carry-forward so the extraction stays complete. No line-level overlap with #86050's dispatch arm; git context matching resolves adjacency.

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 sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants