feat(rag): retry a failed LLM request before the first token lands — BOR_LLM_RETRIES/BOR_LLM_RETRY_DELAY with a live 'retrying' status
This commit is contained in:
@@ -4,7 +4,12 @@ from __future__ import annotations
|
||||
import json
|
||||
|
||||
from app.api.chat import sse_event
|
||||
from app.schemas import ChatErrorEvent, ChatThinkingEvent, ChatToolEvent
|
||||
from app.schemas import (
|
||||
ChatErrorEvent,
|
||||
ChatRetryEvent,
|
||||
ChatThinkingEvent,
|
||||
ChatToolEvent,
|
||||
)
|
||||
|
||||
|
||||
def _payload(frame: str) -> dict:
|
||||
@@ -100,3 +105,23 @@ def test_tool_event_shape_is_type_name_argument_only() -> None:
|
||||
dumped = ChatToolEvent(name="read_document", argument="S/p.md").model_dump()
|
||||
assert set(dumped.keys()) == {"type", "name", "argument"}
|
||||
assert dumped["type"] == "tool" # default — call sites never spell it out
|
||||
|
||||
|
||||
def test_retry_frame_serializes_exactly() -> None:
|
||||
"""Phase 67: the ``retry`` frame is exactly ``{type: "retry",
|
||||
attempt: int, max_attempts: int}`` — a transient status the client's
|
||||
readSSE handler branches on ("Communication interrupted — retrying
|
||||
(n of N)…"), never an error. ``attempt`` is the attempt the server is
|
||||
about to try next (1-based); the contract the frontend branch and the
|
||||
E2E suite key off, locked here ahead of the JS implementation."""
|
||||
frame = sse_event(ChatRetryEvent(attempt=2, max_attempts=4).model_dump())
|
||||
assert frame == 'data: {"type": "retry", "attempt": 2, "max_attempts": 4}\n\n'
|
||||
assert _payload(frame) == {"type": "retry", "attempt": 2, "max_attempts": 4}
|
||||
|
||||
|
||||
def test_retry_event_shape_is_type_attempt_max_attempts_only() -> None:
|
||||
dumped = ChatRetryEvent(attempt=2, max_attempts=4).model_dump()
|
||||
assert set(dumped.keys()) == {"type", "attempt", "max_attempts"}
|
||||
assert dumped["type"] == "retry" # default — call sites never spell it out
|
||||
assert isinstance(dumped["attempt"], int)
|
||||
assert isinstance(dumped["max_attempts"], int)
|
||||
|
||||
Reference in New Issue
Block a user