fix(agent): preserve streamed replies after model failures (#6494)
* fix(agent): preserve streamed replies after model failures * test(webui): settle lazy imports and async settings saves * test(agent): synchronize estimation checks at the operation boundary * docs(webui): explain retained replies after stream failures
This commit is contained in:
1 parent
b6536bfc5e
commit
219c8bb2bc
31 files changed
+462
-27
No files matched your search
@@ -73,6 +73,7 @@ class RecoveryStateWirePayload(_ChatWirePayload):
|
||||
reason: NotRequired[str]
|
||||
can_continue: NotRequired[bool]
|
||||
failure_error_kind: NotRequired[str]
|
||||
reply_preserved: NotRequired[bool]
|
||||
|
||||
|
||||
class RetryStatusWirePayload(_ChatWirePayload):
|
||||
@@ -139,6 +140,8 @@ def encode_recovery_state(
|
||||
payload["can_continue"] = event.can_continue
|
||||
if event.failure_error_kind is not None:
|
||||
payload["failure_error_kind"] = event.failure_error_kind
|
||||
if event.reply_preserved is not None:
|
||||
payload["reply_preserved"] = event.reply_preserved
|
||||
return payload
|
||||
|
||||
|
||||
|
||||
@@ -187,6 +187,8 @@ class RecoveryCoordinator:
|
||||
can_continue=any(message.get("role") == "user" for message in session.messages),
|
||||
)
|
||||
waiting["failure_error_kind"] = failure_error_kind or "unknown"
|
||||
if session.messages and session.messages[-1].get("_interrupted") is True:
|
||||
waiting["reply_preserved"] = True
|
||||
await self.sessions.state.restore_interruption(session)
|
||||
await self._publish(route[1], waiting)
|
||||
return
|
||||
@@ -449,6 +451,7 @@ class RecoveryCoordinator:
|
||||
attempts=cast(int, state.get("attempts", 0)),
|
||||
can_continue=cast(bool | None, state.get("can_continue")),
|
||||
failure_error_kind=cast(str | None, state.get("failure_error_kind")),
|
||||
reply_preserved=cast(bool | None, state.get("reply_preserved")),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user