Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion docs/sessions/session/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ db_url = "sqlite+aiosqlite:///./my_agent_data.db"
session_service = DatabaseSessionService(db_url=db_url)
```

!!! note "Concurrency and Locking"

The `DatabaseSessionService` implements locking mechanisms to prevent race
conditions and ensure data consistency in concurrent environments.

* **In-Process Locking:** The service uses an internal, in-process lock to
serialize `append_event` calls for the same session. This prevents race
conditions when multiple requests try to update the same session
simultaneously within the same process.

* **Row-Level Locking:** For PostgreSQL, MySQL, and MariaDB, the service
uses row-level locking (via `SELECT ... FOR UPDATE`) to prevent race
conditions when multiple processes or replicas try to update the same
session simultaneously.

!!! warning "Async Driver Requirement"

`DatabaseSessionService` requires an async database driver. When using SQLite,
Expand Down Expand Up @@ -344,4 +359,4 @@ during a conversation turn:
it is no longer required.

This cycle highlights how the `SessionService` ensures conversational continuity
by managing the history and state associated with each `Session` object.
by managing the history and state associated with each `Session` object.
Loading