fix(voice): attribute provider terminal failures safely
This commit is contained in:
@@ -6,7 +6,7 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
|
||||
from tests.unit.test_realtime_phase1 import (
|
||||
runner, persisted, make, input_turn, response, delta, done, until, commands,
|
||||
runner, persisted, make, input_turn, response, delta, done, until, commands, terminal,
|
||||
)
|
||||
from tests.unit.test_realtime_repairs import Clock, without_ticker
|
||||
|
||||
@@ -368,3 +368,36 @@ def test_no_active_classifier_is_profile_and_signature_bounded(model, voice, acc
|
||||
assert adapter.is_no_active(CAPTURED_NO_ACTIVE) is accepted
|
||||
assert not adapter.is_no_active(dict(CAPTURED_NO_ACTIVE, code="other"))
|
||||
assert not adapter.is_no_active(dict(CAPTURED_NO_ACTIVE, param="response_id"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status,details,reason", [
|
||||
("failed", {"error": {"code": "server_error"}}, "PROVIDER_RESPONSE_SERVER_ERROR"),
|
||||
("failed", {"error": {"code": "rate_limit_exceeded"}}, "PROVIDER_RESPONSE_RATE_LIMIT"),
|
||||
("failed", {"error": {"code": "insufficient_quota"}}, "PROVIDER_RESPONSE_QUOTA"),
|
||||
("incomplete", {"reason": "content_filter"}, "PROVIDER_RESPONSE_CONTENT_FILTER"),
|
||||
("incomplete", {"reason": "PRIVATE_PAYLOAD"}, "PROVIDER_RESPONSE_INCOMPLETE"),
|
||||
("failed", {"error": {"code": ["PRIVATE_PAYLOAD"]}}, "PROVIDER_RESPONSE_FAILED"),
|
||||
("failed", {"error": {"code": "PRIVATE_PAYLOAD"}}, "PROVIDER_RESPONSE_FAILED"),
|
||||
("failed", None, "PROVIDER_RESPONSE_FAILED"),
|
||||
])
|
||||
def test_terminal_failure_attribution_does_not_log_provider_payload(
|
||||
runner, persisted, caplog, status, details, reason):
|
||||
async def scenario():
|
||||
runtime, transport, out = await make(SimpleNamespace(engine=None), runner, persisted)
|
||||
try:
|
||||
await input_turn(runtime)
|
||||
await response(runtime, transport)
|
||||
event = terminal(status=status)
|
||||
event["response"]["status_details"] = details
|
||||
event["response"]["private_text"] = "PRIVATE_PAYLOAD"
|
||||
if isinstance(details, dict):
|
||||
details["message"] = "PRIVATE_PAYLOAD"
|
||||
await runtime.handle(event)
|
||||
assert runtime.failure == "LIVE_PROVIDER_UNAVAILABLE"
|
||||
assert f"reason={reason} " in caplog.text
|
||||
assert f"terminal_{status}=1" in caplog.text
|
||||
assert "PRIVATE_PAYLOAD" not in caplog.text
|
||||
assert "PRIVATE_PAYLOAD" not in str(out)
|
||||
finally:
|
||||
await runtime.close()
|
||||
asyncio.run(scenario())
|
||||
|
||||
@@ -124,7 +124,7 @@ def test_other_terminal_outcomes_fail(runner, persisted, status, details):
|
||||
|
||||
@pytest.mark.parametrize('raw', ['{"query":', '{"query":"q"}'])
|
||||
@pytest.mark.parametrize('argument_done', [False, True])
|
||||
def test_limited_tools_never_execute_or_continue(runner, persisted, raw, argument_done):
|
||||
def test_limited_tools_never_execute_or_continue(runner, persisted, raw, argument_done, caplog):
|
||||
async def scenario():
|
||||
service = SimpleNamespace(engine=None, search=lambda *_: pytest.fail('Cut-off tool executed'))
|
||||
runtime, transport, out = await make(service, runner, persisted)
|
||||
@@ -135,6 +135,8 @@ def test_limited_tools_never_execute_or_continue(runner, persisted, raw, argumen
|
||||
item = dict(type='function_call', id=event['item_id'], call_id='c1',
|
||||
name='search_knowledge', arguments=raw, status='incomplete')
|
||||
await runtime.handle(limited(output=[item]))
|
||||
assert 'reason=TOKEN_LIMIT_WITH_UNFINISHED_TOOLS ' in caplog.text
|
||||
assert 'terminal_limited=1' in caplog.text
|
||||
assert runtime.failure == 'LIVE_PROVIDER_UNAVAILABLE'
|
||||
assert runner._active == runner._admitted == 0
|
||||
assert not commands(transport, 'conversation.item.create')
|
||||
|
||||
Reference in New Issue
Block a user