DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
docs(book): state what actually makes BookStorage's writes safe
Bingxi Zhao (Frank)49d8d1bd63fa
diff --git a/deeptutor/book/storage.py b/deeptutor/book/storage.pyindex 8b89e3394..8a0dd0caf 100644--- a/deeptutor/book/storage.py+++ b/deeptutor/book/storage.py@@ -21,7 +21,6 @@ Layout (relative to ``data/user/workspace/book/``)::from __future__ import annotations-import asynciofrom datetime import datetime, timezoneimport jsonimport logging@@ -92,10 +91,20 @@ def _read_json(path: Path) -> Any | None:class BookStorage:- """Async-friendly wrapper around the on-disk book layout."""-- def __init__(self) -> None:- self._lock = asyncio.Lock()+ """Wrapper around the on-disk book layout.++ Every method here is synchronous and every write goes through an atomic+ replace, and that is what keeps the read-modify-write helpers below (e.g.+ :meth:`upsert_learning_capture`) safe: DeepTutor serves from a single+ process, so a sync call from an ``async def`` route holds the event loop for+ its whole duration and cannot interleave with another request.++ That invariant is the thing to preserve. A read-modify-write helper must not+ ``await`` between its read and its write — and if this store ever moves to+ ``asyncio.to_thread`` or a multi-worker server, these helpers need real+ locking before it does. (There used to be an ``asyncio.Lock`` here that+ nothing ever acquired, which read as protection that was not present.)+ """@propertydef path_service(self):