Skip to content

The agent that grows with you

fix(agent): bind finalize_turn at import time

Erosikaa9f94022b02f
diff --git a/agent/conversation_loop.py b/agent/conversation_loop.py
index 663e130f08c..57b5f13268d 100644
--- a/agent/conversation_loop.py
+++ b/agent/conversation_loop.py
@@ -86,6 +86,11 @@ from agent.retry_utils import (
zai_coding_overload_retry_ceiling,
)
from agent.trajectory import has_incomplete_scratchpad
+# Bound at import time deliberately: a lazy end-of-turn import reads the
+# module fresh from disk, so a mid-session git switch/pull in a source
+# checkout loads a version-skewed finalizer and kills the finished turn.
+# Safe to hoist: turn_finalizer defers its own conversation_loop import.
+from agent.turn_finalizer import finalize_turn
from agent.usage_pricing import estimate_usage_cost, normalize_usage
from hermes_constants import PARTIAL_STREAM_STUB_ID
from hermes_logging import set_session_context
@@ -7513,7 +7518,6 @@ def run_conversation(
# Post-loop turn finalization extracted to agent/turn_finalizer.finalize_turn
# (god-file decomposition Phase 1 step 4). Behavior-neutral: the assembled
# result dict is returned exactly as before.
- from agent.turn_finalizer import finalize_turn
return finalize_turn(
agent,
final_response=final_response,