fix(conversation,voice_worker): going on survives the answer starting, ignores empty finals; cancel checks before every model call; context finals stay batched
- A speaker who starts their next utterance within call.continueMs holds their request open for that final, also if the answer starts playing meanwhile; an empty final (rejected noise) joins nothing and asks nothing again - The engine checks the cancel before the tool router, the planner and a planned tool call too - Finals with a context are batched again: each context is cut from its end to the shortest one in the batch (ctranslate2 needs the start token at one position); ten finals at once 1.3 s - Measured harsh conditions (docs/v2/stt-accuracy-plan.md): the context never made them worse Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,14 @@ TRACE_RESULT_CHARS = 2000
|
||||
TRACE_THINKING_CHARS = 8000
|
||||
|
||||
|
||||
def _cancelled(before: str) -> bool:
|
||||
"""The answer is no longer wanted (turn_state.cancel): stop before the next model or tool call."""
|
||||
if _turn_state.cancelled():
|
||||
debug_log(f"reply cancelled before {before}", "planning")
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _clip(text: str, limit: int) -> str:
|
||||
return text if len(text) <= limit else text[:limit] + "…"
|
||||
|
||||
@@ -1253,6 +1261,8 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
# Step 0.5: Deterministic on-screen site search. If the user named a site and
|
||||
# asked to search/open it while broadcasting, do it directly — the small chat
|
||||
# model otherwise just narrates without calling the browser tool.
|
||||
if _cancelled("it started"):
|
||||
return None
|
||||
_site_search_reply = _maybe_deterministic_site_search(text, db, cfg, language)
|
||||
if _site_search_reply is not None:
|
||||
return _site_search_reply
|
||||
@@ -1390,6 +1400,8 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
routed_tools = list(_cached_routed)
|
||||
debug_log("tool router served from hot-window cache", "planning")
|
||||
else:
|
||||
if _cancelled("the tool router"):
|
||||
return None
|
||||
routed_tools = _route_tools(cfg, redacted, _builtin_tools, mcp_tools, recent_messages)
|
||||
# Don't cache the router's "fall open to all tools" fallback. That
|
||||
# path fires when the LLM router times out, returns empty, or emits
|
||||
@@ -1532,6 +1544,8 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
if _one_step_tool:
|
||||
debug_log(f"intent judge: one-step tool {_one_step_tool}, no plan", "planning")
|
||||
elif not intent_judge or _turn_needs_tools:
|
||||
if _cancelled("the planner"):
|
||||
return None
|
||||
action_plan = plan_query(
|
||||
cfg=cfg,
|
||||
query=redacted,
|
||||
@@ -2376,8 +2390,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
_one_step_nudged = False
|
||||
|
||||
while turn < max_turns:
|
||||
if _turn_state.cancelled():
|
||||
debug_log("reply cancelled: no longer wanted", "planning")
|
||||
if _cancelled("a model call"):
|
||||
return None
|
||||
turn += 1
|
||||
debug_log(f"🔁 messages loop turn {turn}", "planning")
|
||||
@@ -2496,6 +2509,8 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
}
|
||||
],
|
||||
})
|
||||
if _cancelled("a planned tool call"):
|
||||
return None
|
||||
tools_started += 1
|
||||
_plan_result = run_tool_with_retries(
|
||||
db=db,
|
||||
@@ -2844,8 +2859,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
continue
|
||||
|
||||
# Execute tool (not for an answer that is no longer wanted: no actions on its behalf)
|
||||
if _turn_state.cancelled():
|
||||
debug_log("reply cancelled before a tool call", "planning")
|
||||
if _cancelled("a tool call"):
|
||||
return None
|
||||
tools_started += 1
|
||||
result = run_tool_with_retries(
|
||||
|
||||
Reference in New Issue
Block a user