fix(api): report checkpoint deletion failures and classify SSE errors

Delete checkpoints before removing business fields. Suppress only an
explicit CheckpointNotFoundError; propagate storage failures and
cancellation so the endpoint cannot report false success. Prefer async
checkpoint deletion and fail clearly when cleanup is unsupported.

Classify SSE error events as 401 for authentication, 429 for rate limits,
and 500 for other failures, using the same fixed messages as non-stream
responses. Errors terminate the stream without a success done event or
provider exception text in the response.

Validation: 286 offline tests passed (19 added), including failed-delete
HTTP retry with preserved business/checkpoint state, explicit missing
threads, cancellation, missing cleanup capability, and HTTP SSE errors
before and after text output.
This commit is contained in:
Eric Wang
2026-10-23 19:48:29 +08:00
parent 24e2cfbe10
commit 3caf17494f
9 changed files with 260 additions and 15 deletions
+5 -1
View File
@@ -14,6 +14,10 @@
from typing import Protocol
class CheckpointNotFoundError(Exception):
"""存储适配器明确确认线程不存在;不能用一般存储异常代替。"""
class SessionRepository(Protocol):
"""业务字段存储接口(作业 7 由 PostgreSQL 实现替换)。"""
@@ -49,4 +53,4 @@ class InMemorySessionRepository:
self._store.pop(session_id, None)
__all__ = ["SessionRepository", "InMemorySessionRepository"]
__all__ = ["CheckpointNotFoundError", "SessionRepository", "InMemorySessionRepository"]