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:
@@ -71,14 +71,19 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
|
||||
async def delete_chat_session(thread_id: str) -> None:
|
||||
"""langgraph 模式下删除会话:清理图 checkpoint(对照计划作业 6 的
|
||||
完整语义——业务字段、事件、路由持久化清理在接入 repository 后补齐)。
|
||||
"""
|
||||
"""删除图 checkpoint;缺少清理能力或存储出错必须报告失败。"""
|
||||
if _langgraph_graph is None:
|
||||
raise RuntimeError("LangGraph backend not initialized")
|
||||
checkpointer = getattr(_langgraph_graph, "checkpointer", None)
|
||||
if checkpointer is not None and hasattr(checkpointer, "delete_thread"):
|
||||
checkpointer.delete_thread(thread_id)
|
||||
async_delete = getattr(checkpointer, "adelete_thread", None)
|
||||
if callable(async_delete):
|
||||
await async_delete(thread_id)
|
||||
return
|
||||
sync_delete = getattr(checkpointer, "delete_thread", None)
|
||||
if callable(sync_delete):
|
||||
sync_delete(thread_id)
|
||||
return
|
||||
raise RuntimeError("LangGraph checkpointer does not support thread deletion")
|
||||
|
||||
|
||||
def get_fastgpt_client() -> AsyncChatClient:
|
||||
|
||||
Reference in New Issue
Block a user