This commit is contained in:
zyp
2026-11-27 14:43:37 +08:00
parent 1ae94dfb1f
commit b18c6efe92
64 changed files with 5629 additions and 2414 deletions
+10 -1
View File
@@ -11,6 +11,7 @@ from threading import Lock
from app.core.config import get_settings
_registry_lock = Lock()
_backend_init_lock = Lock()
_locks: dict[str, tuple[Lock, int]] = {}
@@ -37,7 +38,7 @@ def thread_lock(key):
@lru_cache(maxsize=4)
def _backend(url):
def _cached_backend(url):
if url.startswith("sqlite:///"):
from langgraph.checkpoint.sqlite import SqliteSaver
file = url.removeprefix("sqlite:///")
@@ -59,6 +60,14 @@ def _backend(url):
raise ValueError("Unsupported assistant checkpoint database")
def _backend(url):
# lru_cache permits concurrent cache misses to run the initializer twice.
# SQLite setup must be single-flight, or simultaneous first requests can
# race schema/journal initialization before conversation locks are acquired.
with _backend_init_lock:
return _cached_backend(url)
@contextmanager
def planning_session(payload):
from app.modules.work_assistant.orchestration import build_planning_graph