fix(voice): preserve interrupted searches and report used sources
Retain and revalidate interrupted searches, resolve abandoned provider calls, recover invalid source reports privately, and expose only declared sources. Improve Persian delivery and provider event replay capacity. Include regression coverage and contract updates.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Old-turn durable cancellation must not terminate a healthy voice session."""
|
||||
import asyncio
|
||||
import json
|
||||
from threading import Event
|
||||
from types import SimpleNamespace
|
||||
from uuid import uuid4
|
||||
@@ -76,10 +77,15 @@ def test_old_search_interruption_keeps_session_usable(
|
||||
await asyncio.wait_for(asyncio.shield(task), 3)
|
||||
assert runtime.usable and runtime.failure is None
|
||||
assert runtime.calls["c1"][1]["result"] is None
|
||||
assert not commands(transport, "conversation.item.create")
|
||||
await until(lambda: len(commands(transport, "response.create")) == 2)
|
||||
outputs = commands(transport, "conversation.item.create")
|
||||
assert len(outputs) == 1 and outputs[0]["item"]["call_id"] == "c1"
|
||||
payload = json.loads(outputs[0]["item"]["output"])
|
||||
assert payload["status"] == "cancelled" and payload["sources"] == []
|
||||
assert "Old evidence" not in outputs[0]["item"]["output"]
|
||||
assert not any(isinstance(e, dict) and e.get("type") == "sources" for e in out)
|
||||
if completion == "cancelled":
|
||||
assert state == dict(status="failed", error_code="TOOL_CANCELLED")
|
||||
assert state == dict(status="succeeded")
|
||||
assert runtime.calls["c1"][1]["retained_result"] == result
|
||||
await response(runtime, transport, response_id="r2")
|
||||
await done(runtime, "r2")
|
||||
assert runtime.usable and len(commands(transport, "response.create")) == 2
|
||||
@@ -117,13 +123,22 @@ def test_search_failure_policy(runner, persisted, supersede, exc, code):
|
||||
task = next(iter(runtime.tasks))
|
||||
if supersede:
|
||||
await input_turn(runtime, "u2", 210)
|
||||
if code == "SEARCH_CANCELLED":
|
||||
# Explicit topic discard cancels retrieval; speech alone does not.
|
||||
runtime.calls["c1"][1]["retrieval_cancelled"].set()
|
||||
finish.set()
|
||||
await asyncio.wait_for(asyncio.shield(task), 3)
|
||||
if supersede and code == "SEARCH_CANCELLED":
|
||||
assert runtime.usable and runtime.failure is None
|
||||
else:
|
||||
assert not runtime.usable and runtime.failure == code
|
||||
assert not commands(transport, "conversation.item.create")
|
||||
outputs = commands(transport, "conversation.item.create")
|
||||
if not supersede:
|
||||
assert outputs == []
|
||||
for output in outputs:
|
||||
payload = json.loads(output["item"]["output"])
|
||||
assert output["item"]["call_id"] == "c1"
|
||||
assert payload["status"] == "cancelled" and payload["sources"] == []
|
||||
assert runtime.calls["c1"][1]["result"] is None
|
||||
finally:
|
||||
finish.set()
|
||||
@@ -189,8 +204,10 @@ def test_cancellation_decision_uses_locked_turn_state(runner, persisted, state):
|
||||
old.cancelled.set()
|
||||
else:
|
||||
await runtime.new_turn("u2")
|
||||
if state == "lock_race":
|
||||
runtime.calls["c1"][1]["retrieval_cancelled"].set()
|
||||
if state == "old_without_flag":
|
||||
old.cancelled.clear()
|
||||
runtime.calls["c1"][1]["retrieval_cancelled"].clear()
|
||||
await asyncio.wait_for(asyncio.shield(task), 3)
|
||||
if state == "lock_race":
|
||||
assert runtime.usable and runtime.failure is None
|
||||
|
||||
Reference in New Issue
Block a user