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
@@ -4,19 +4,24 @@ import json
|
||||
import tarfile
|
||||
from pathlib import Path
|
||||
|
||||
from nanobot.events import ContextCompactionEvent, RecoveryStateEvent
|
||||
from nanobot.events import ContextCompactionEvent, RecoveryStateEvent, RetryStatusEvent
|
||||
from nanobot.webui.outbound_wire import project_notification
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def test_wire_fixtures_are_real_python_projections():
|
||||
def test_wire_fixtures_are_real_python_projections(monkeypatch):
|
||||
monkeypatch.setattr("nanobot.webui.outbound_wire.time.time", lambda: 100.0)
|
||||
fixtures = json.loads((ROOT / "packages/client-events/fixtures.json").read_text())
|
||||
for expected in fixtures:
|
||||
fields = {key: value for key, value in expected.items() if key not in {"event", "chat_id"}}
|
||||
event_type = (
|
||||
ContextCompactionEvent if expected["event"] == "context_compaction" else RecoveryStateEvent
|
||||
)
|
||||
event_type = {
|
||||
"context_compaction": ContextCompactionEvent,
|
||||
"recovery_state": RecoveryStateEvent,
|
||||
"retry_status": RetryStatusEvent,
|
||||
}[expected["event"]]
|
||||
if "retry_after_s" in fields:
|
||||
fields["next_retry_at"] = 100.0 + fields.pop("retry_after_s")
|
||||
projection = project_notification(expected["chat_id"], event_type(**fields))
|
||||
assert projection is not None
|
||||
assert projection.payload == expected
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.bus.outbound_events import (
|
||||
ContextCompactionEvent,
|
||||
RecoveryStateEvent,
|
||||
RetryStatusEvent,
|
||||
TurnEndEvent,
|
||||
)
|
||||
from nanobot.providers.base import LLMUsage
|
||||
@@ -10,6 +13,7 @@ from nanobot.webui.metadata import WEBUI_TURN_METADATA_KEY
|
||||
from nanobot.webui.outbound_wire import (
|
||||
encode_context_compaction,
|
||||
encode_recovery_state,
|
||||
encode_retry_status,
|
||||
encode_turn_end,
|
||||
)
|
||||
|
||||
@@ -74,6 +78,35 @@ def test_encode_recovery_state_preserves_false_can_continue() -> None:
|
||||
}
|
||||
|
||||
|
||||
def test_encode_retry_status_projects_relative_wait_and_turn_id(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr("nanobot.webui.outbound_wire.time.time", lambda: 120.0)
|
||||
|
||||
payload = encode_retry_status(
|
||||
"chat-1",
|
||||
RetryStatusEvent(
|
||||
state="waiting",
|
||||
attempt=2,
|
||||
max_attempts=4,
|
||||
error_kind="connection",
|
||||
next_retry_at=123.5,
|
||||
),
|
||||
{WEBUI_TURN_METADATA_KEY: "turn-1", "private": "must-not-leak"},
|
||||
)
|
||||
|
||||
assert payload == {
|
||||
"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,
|
||||
}
|
||||
|
||||
|
||||
def test_encode_turn_end_omits_absent_fields_and_private_metadata() -> None:
|
||||
payload = encode_turn_end(
|
||||
"chat-1",
|
||||
@@ -100,6 +133,11 @@ def test_encode_turn_end_projects_complete_wire_contract() -> None:
|
||||
usage=usage,
|
||||
round_usages=(usage,),
|
||||
context_window_tokens=128_000,
|
||||
outcome="error",
|
||||
failure_kind="provider",
|
||||
failure_error_kind="connection",
|
||||
failure_attempts=4,
|
||||
failure_message="Connection refused",
|
||||
),
|
||||
{WEBUI_TURN_METADATA_KEY: "turn-1", "private": "must-not-leak"},
|
||||
)
|
||||
@@ -113,4 +151,9 @@ def test_encode_turn_end_projects_complete_wire_contract() -> None:
|
||||
"usage": usage.to_turn_dict(),
|
||||
"round_usages": [usage.to_turn_dict()],
|
||||
"context_window_tokens": 128_000,
|
||||
"outcome": "error",
|
||||
"failure_kind": "provider",
|
||||
"failure_error_kind": "connection",
|
||||
"failure_attempts": 4,
|
||||
"failure_message": "Connection refused",
|
||||
}
|
||||
Reference in new issue
Block a user