fix(ui): surface model retry status (NAN-34) (#5504)
This commit is contained in:
1 parent
0b1fa0c3e4
commit
b581a496a6
52 files changed
+1697
-55
No files matched your search
@@ -29,6 +29,8 @@ from nanobot.bus.outbound_events import (
|
||||
GoalStatusEvent,
|
||||
ProgressEvent,
|
||||
RecoveryStateEvent,
|
||||
RetryStatusEvent,
|
||||
RetryWaitEvent,
|
||||
RuntimeModelUpdatedEvent,
|
||||
SessionUpdatedEvent,
|
||||
TurnEndEvent,
|
||||
@@ -2806,6 +2808,106 @@ async def test_send_turn_end_emits_turn_end_event() -> None:
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_retry_status_is_transient_and_turn_scoped(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr("nanobot.webui.outbound_wire.time.time", lambda: 120.0)
|
||||
bus = MagicMock()
|
||||
channel = WebSocketChannel(
|
||||
{"enabled": True, "allowFrom": ["*"]},
|
||||
bus,
|
||||
gateway=_basic_handler(bus),
|
||||
)
|
||||
mock_ws = AsyncMock()
|
||||
channel._attach(mock_ws, "chat-1")
|
||||
|
||||
await channel.send(OutboundMessage(
|
||||
channel="websocket",
|
||||
chat_id="chat-1",
|
||||
content="",
|
||||
metadata={WEBUI_TURN_METADATA_KEY: "turn-1"},
|
||||
event=RetryStatusEvent(
|
||||
state="waiting",
|
||||
attempt=2,
|
||||
max_attempts=4,
|
||||
error_kind="connection",
|
||||
next_retry_at=123.5,
|
||||
),
|
||||
))
|
||||
|
||||
assert _sent_ws_payloads(mock_ws) == [{
|
||||
"event": "retry_status",
|
||||
"chat_id": "chat-1",
|
||||
"turn_id": "turn-1",
|
||||
"state": "waiting",
|
||||
"attempt": 2,
|
||||
"max_attempts": 4,
|
||||
"error_kind": "connection",
|
||||
"retry_after_s": 3.5,
|
||||
}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_legacy_retry_wait_is_not_sent_or_persisted() -> None:
|
||||
bus = MagicMock()
|
||||
channel = WebSocketChannel(
|
||||
{"enabled": True, "allowFrom": ["*"]},
|
||||
bus,
|
||||
gateway=_basic_handler(bus),
|
||||
)
|
||||
mock_ws = AsyncMock()
|
||||
channel._attach(mock_ws, "chat-1")
|
||||
channel._persist_turn_transcript_event = MagicMock(return_value=True)
|
||||
|
||||
await channel.send(OutboundMessage(
|
||||
channel="websocket",
|
||||
chat_id="chat-1",
|
||||
content="Model request failed, retry in 2s (attempt 1).",
|
||||
event=RetryWaitEvent(
|
||||
content="Model request failed, retry in 2s (attempt 1).",
|
||||
),
|
||||
))
|
||||
|
||||
assert _sent_ws_payloads(mock_ws) == []
|
||||
channel._persist_turn_transcript_event.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_failed_turn_end_exposes_safe_terminal_outcome() -> None:
|
||||
bus = MagicMock()
|
||||
channel = WebSocketChannel(
|
||||
{"enabled": True, "allowFrom": ["*"]},
|
||||
bus,
|
||||
gateway=_basic_handler(bus),
|
||||
)
|
||||
mock_ws = AsyncMock()
|
||||
channel._attach(mock_ws, "chat-1")
|
||||
|
||||
await channel.send(OutboundMessage(
|
||||
channel="websocket",
|
||||
chat_id="chat-1",
|
||||
content="",
|
||||
event=TurnEndEvent(
|
||||
outcome="failed",
|
||||
failure_kind="model",
|
||||
failure_error_kind="connection",
|
||||
failure_attempts=4,
|
||||
failure_message="Model provider request failed.",
|
||||
),
|
||||
))
|
||||
|
||||
assert _sent_ws_payloads(mock_ws)[0] == {
|
||||
"event": "turn_end",
|
||||
"chat_id": "chat-1",
|
||||
"outcome": "failed",
|
||||
"failure_kind": "model",
|
||||
"failure_error_kind": "connection",
|
||||
"failure_attempts": 4,
|
||||
"failure_message": "Model provider request failed.",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_context_compaction_started_is_live_only() -> None:
|
||||
bus = MagicMock()
|
||||
|
||||
Reference in new issue
Block a user