fix(ui): surface model retry status (NAN-34) (#5504)

This commit is contained in:
chengyongru authored and GitHub committed 2026-09-07 15:12:39 +08:00
1 parent 0b1fa0c3e4
commit b581a496a6
52 files changed
+1697 -55

No files matched your search

+6 -1
View File
@@ -12,6 +12,8 @@ from nanobot.bus.outbound_events import (
GoalStateSyncEvent,
GoalStatusEvent,
ProgressEvent,
RetryStatusEvent,
RetryWaitEvent,
RuntimeModelUpdatedEvent,
SessionUpdatedEvent,
TurnEndEvent,
@@ -134,6 +136,8 @@ class WebUIOutboundProjector:
async def send(self, msg: OutboundMessage) -> None:
event = msg.event
if isinstance(event, RetryWaitEvent):
return
progress_event = event if isinstance(event, ProgressEvent) else None
if isinstance(event, RuntimeModelUpdatedEvent):
await self._transport.send_runtime_model_updated(
@@ -146,6 +150,7 @@ class WebUIOutboundProjector:
if not conns:
quiet_events = (
ProgressEvent,
RetryStatusEvent,
UserInputEvent,
TurnEndEvent,
SessionUpdatedEvent,
@@ -179,7 +184,7 @@ class WebUIOutboundProjector:
provenance=event.provenance,
)
return
notification = project_notification(msg.chat_id, event)
notification = project_notification(msg.chat_id, event, msg.metadata)
if notification is not None:
if conns or notification.deliver_offline:
kwargs: dict[str, Any] = (
+53 -2
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import time
from collections.abc import Mapping
from dataclasses import dataclass
from typing import Any, Literal, NotRequired, TypeAlias, TypedDict
@@ -9,6 +10,7 @@ from typing import Any, Literal, NotRequired, TypeAlias, TypedDict
from nanobot.bus.outbound_events import (
ContextCompactionEvent,
RecoveryStateEvent,
RetryStatusEvent,
TurnEndEvent,
)
from nanobot.events import AgentEvent
@@ -29,6 +31,15 @@ class RecoveryStateWirePayload(_ChatWirePayload):
can_continue: NotRequired[bool]
class RetryStatusWirePayload(_ChatWirePayload):
event: Literal["retry_status"]
state: str
attempt: int
max_attempts: NotRequired[int]
error_kind: str
retry_after_s: NotRequired[float]
class TurnEndWirePayload(_ChatWirePayload):
event: Literal["turn_end"]
latency_ms: NotRequired[int]
@@ -36,6 +47,11 @@ class TurnEndWirePayload(_ChatWirePayload):
usage: NotRequired[dict[str, int]]
round_usages: NotRequired[list[dict[str, int]]]
context_window_tokens: NotRequired[int]
outcome: NotRequired[str]
failure_kind: NotRequired[str]
failure_error_kind: NotRequired[str]
failure_attempts: NotRequired[int]
failure_message: NotRequired[str]
class ContextCompactionWirePayload(_ChatWirePayload):
@@ -45,7 +61,7 @@ class ContextCompactionWirePayload(_ChatWirePayload):
WebUIWirePayload: TypeAlias = (
ContextCompactionWirePayload | RecoveryStateWirePayload | TurnEndWirePayload
RetryStatusWirePayload | ContextCompactionWirePayload | RecoveryStateWirePayload | TurnEndWirePayload
)
WebUIWirePersistence: TypeAlias = Literal[
"transient",
@@ -97,7 +113,9 @@ class NotificationProjection:
attach_turn_metadata: bool = False
def project_notification(chat_id: str, event: AgentEvent | None) -> NotificationProjection | None:
def project_notification(
chat_id: str, event: AgentEvent | None, metadata: Mapping[str, object] | None = None,
) -> NotificationProjection | None:
"""Keep notification serialization and persistence decisions at one boundary."""
if isinstance(event, ContextCompactionEvent):
return NotificationProjection(
@@ -106,11 +124,34 @@ def project_notification(chat_id: str, event: AgentEvent | None) -> Notification
deliver_offline=True,
attach_turn_metadata=True,
)
if isinstance(event, RetryStatusEvent):
return NotificationProjection(encode_retry_status(chat_id, event, metadata))
if isinstance(event, RecoveryStateEvent):
return NotificationProjection(encode_recovery_state(chat_id, event))
return None
def encode_retry_status(
chat_id: str,
event: RetryStatusEvent,
metadata: Mapping[str, object] | None = None,
) -> RetryStatusWirePayload:
"""Project one transient retry transition onto its stable wire shape."""
payload: RetryStatusWirePayload = {
"event": "retry_status",
"chat_id": chat_id,
"state": event.state,
"attempt": event.attempt,
"error_kind": event.error_kind,
}
turn_id = (metadata or {}).get(WEBUI_TURN_METADATA_KEY)
if isinstance(turn_id, str) and turn_id:
payload["turn_id"] = turn_id
if event.max_attempts is not None:
payload["max_attempts"] = event.max_attempts
if event.next_retry_at is not None:
payload["retry_after_s"] = max(0.0, event.next_retry_at - time.time())
return payload
def encode_turn_end(
chat_id: str,
event: TurnEndEvent,
@@ -134,4 +175,14 @@ def encode_turn_end(
payload["round_usages"] = [item.to_turn_dict() for item in event.round_usages]
if event.context_window_tokens is not None:
payload["context_window_tokens"] = int(event.context_window_tokens)
if event.outcome != "completed":
payload["outcome"] = event.outcome
if event.failure_kind is not None:
payload["failure_kind"] = event.failure_kind
if event.failure_error_kind is not None:
payload["failure_error_kind"] = event.failure_error_kind
if event.failure_attempts is not None:
payload["failure_attempts"] = int(event.failure_attempts)
if event.failure_message is not None:
payload["failure_message"] = event.failure_message
return payload