fix: complete SqliteSaver async compatibility in chat routers (#525)
Some checks failed
Development Build / extract-version (push) Has been cancelled
Development Build / build-regular (push) Has been cancelled
Development Build / build-single (push) Has been cancelled
Development Build / summary (push) Has been cancelled

* fix: use sync get_state() for SqliteSaver in chat routers

Replace async aget_state() calls with sync get_state() wrapped in
asyncio.to_thread() to fix SqliteSaver compatibility issues.

SqliteSaver does not support async methods, so we need to run
the sync version in a separate thread.

This is a follow-up to #519 which fixed the same issue in
graph_utils.py but missed four locations:
- chat.py: get_session() and execute_chat()
- source_chat.py: get_source_chat_session() and stream_source_chat_response()

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* chore: translate comments to English

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Luis Novo <lfnovo@gmail.com>
This commit is contained in:
Nikita 2026-02-06 21:55:05 +03:00 committed by GitHub
parent 36ac10d5f6
commit eae429b3bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 8 deletions

View file

@ -190,8 +190,10 @@ async def get_session(session_id: str):
raise HTTPException(status_code=404, detail="Session not found")
# Get session state from LangGraph to retrieve messages
thread_state = await chat_graph.aget_state(
config=RunnableConfig(configurable={"thread_id": full_session_id})
# Use sync get_state() in a thread since SqliteSaver doesn't support async
thread_state = await asyncio.to_thread(
chat_graph.get_state,
config=RunnableConfig(configurable={"thread_id": full_session_id}),
)
# Extract messages from state
@ -348,8 +350,10 @@ async def execute_chat(request: ExecuteChatRequest):
)
# Get current state
current_state = await chat_graph.aget_state(
config=RunnableConfig(configurable={"thread_id": full_session_id})
# Use sync get_state() in a thread since SqliteSaver doesn't support async
current_state = await asyncio.to_thread(
chat_graph.get_state,
config=RunnableConfig(configurable={"thread_id": full_session_id}),
)
# Prepare state for execution