refactor(conversation_loop): extract turn persistence slice CL-R5-1 into agent/turn_finalizer.py - #84583
Conversation
…e CL-R5-1 into agent/turn_finalizer Extract the final-message append + best-effort SessionDB flush/warning block (window 7615-7632) from run_conversation into the lightweight helper persist_completed_text_turn in agent/turn_finalizer.py. Behavioral neutrality: exact append -> flush -> catch -> warning order, best-effort failure semantics (flush failure must not abort the turn), logger identity (agent.conversation_loop) + exc_info=True preserved. Caller retains _turn_exit_reason assignment, quiet-mode completion print, loop break, finalize_turn, and __all__. The helper is dependency-injected (agent, messages, conversation_history, final_msg) and resolves logger through the module's established lazy-import seam, so no import cycle and no startup-latency cost. AST-normalized comparison of the moved body against the pinned slice is identical. Adds focused seam tests (append-before-flush ordering, flush-failure warning-only, message/history identity, caller-owned control flow, import/patch transparency, logger/traceback semantics) with no source-reading. Signed-off-by: Hermes Agent <hermes@nousresearch.com> Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
…alizer helper Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
Contributor email mapping required by check-attribution CI for the god-file kill campaign PRs (Axl Ibiza, MBA <andrexibiza@gmail.com>). Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
refactor(conversation_loop): extract turn persistence slice CL-R5-1 into agent/turn_finalizer.pyFaithful extraction; ordering and failure semantics are preserved and pinned by tests. Observations:
|
Summary
Blind extraction of slice CL-R5-1 from
agent/conversation_loop.py(7,757 lines at pinee4bb75b532e932a1055d9a710802a7435163b6a) into the existingagent/turn_finalizer.pymodule, per the repo-wide god-file sharding policy.persist_completed_text_turninagent/turn_finalizer.py(keyword-onlyagent,messages,conversation_history,final_msg→ None)7fd77e562363aaee1d11a39b71f248218f5dc26a8f9b78cab3e1d3b527429b33_turn_exit_reason(7634), quiet-mode completion print (7635–7636),break(7637),finalize_turn, and__all__all remain inrun_conversation. Logger resolves through the module's established lazy-import seam (sameagent.conversation_looplogger identity, same warning text,exc_info=True). No import cycle (the pin already importsturn_finalizerat line 91 forfinalize_turn); startup-latency contract held.tests/run_agent/test_turn_finalizer_seam.py— runtime behavioral probes (append-before-flush ordering, flush-failure warning-only, message/history identity, caller-owned control flow, import/patch transparency, logger/traceback semantics); no source-reading tests.agent/conversation_loop.py25 changed (block removed + import + call); helper added to the existing module; seam test 304 lines.Method
5×2×3 double-blind decomposition (per the All Gods Must Die mandate): 5 blind region analysts → 5 blind adversarial witnesses → 5 consensus adjudicators → blind implementer → 2 blind re-reviewers. Round 1: reviewer 1 REQUEST CHANGES (sole blocker: the golden-byte guard — the pinned window's 8-line #81641 comment block was dropped from the moved helper body; executable statements were byte-identical but the guard is strict); reviewer 2 APPROVED. Fix lane restored the 8 comment lines (commit
e277fcbc274, module only). Round 2: both re-reviewers APPROVED:C:/tmp/tg-Feature Package/conversation-loop/review/CLR51-review-1-r2.md(13,140 B) — all 9 gates PASSC:/tmp/tg-Feature Package/conversation-loop/review/CLR51-review-2-r2.md(13,090 B) — APPROVED, all gates (sole suite delta: a re-verified flaky race test in an untouched file)Suite evidence: pristine-pin vs post-extraction failure sets identical (full tests/run_agent both sides; seam 14/14; #81641 persistence tests 22/22). No new failures.
Coordination table
ee4bb75b532e932a1055d9a710802a7435163b6a(origin/main)agent/turn_finalizer.py(existing — helper added)7fd77e562363aaee1d11a39b71f248218f5dc26a8f9b78cab3e1d3b527429b33Dedup statement
No prior extraction of this window exists. No duplicate work.
Credit
9b9f91b0a83+e277fcbc274)This slice is governed by the conversation_loop (posted on #78641). Former whole: 7,757 lines. Fixer roster: #83437.
Part of #78641
Part of #78647