-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: dedupe conversation-persistence session flow into one owner #3170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+178
−64
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """ | ||
| Shared conversation-store operations. | ||
|
|
||
| Single owner for the *create-or-resume session* flow over a | ||
| ``ConversationStore``. Both ``PraisonAIDB`` (``db/adapter.py``) and | ||
| ``PersistenceOrchestrator`` (``persistence/orchestrator.py``) call these helpers | ||
| so the store-level session semantics live in one place instead of being copied | ||
| across the sync/async surfaces of both classes. | ||
|
|
||
| The helpers only touch the store (``get_session`` / ``create_session`` / | ||
| ``get_messages``); each caller keeps its own return-type contract, caching, and | ||
| lock/cooldown machinery by wrapping the result. | ||
| """ | ||
|
|
||
| from typing import Any, Awaitable, Callable, List, Optional | ||
|
|
||
| from .base import ConversationSession, ConversationMessage | ||
|
|
||
|
|
||
| def resume_or_create_session( | ||
| store: Any, | ||
| session: Optional[ConversationSession], | ||
| session_id: str, | ||
| build_session: Callable[[], ConversationSession], | ||
| get_messages: Callable[[], List[ConversationMessage]], | ||
| ) -> Optional[List[ConversationMessage]]: | ||
| """Create the session if missing, else return its messages (sync). | ||
|
|
||
| Args: | ||
| store: The conversation store. | ||
| session: Result of the caller's ``get_session`` lookup (``None`` when | ||
| the session does not yet exist). | ||
| session_id: The session identifier (unused directly; kept for parity | ||
| and readability at call sites). | ||
| build_session: Factory returning the ``ConversationSession`` to create | ||
| when ``session`` is ``None`` — lets each caller keep its own name/ | ||
| metadata conventions. | ||
| get_messages: Callable returning the existing messages when resuming. | ||
|
|
||
| Returns: | ||
| ``None`` when a new session was created (no history), otherwise the list | ||
| of previously persisted messages. | ||
| """ | ||
| if session is None: | ||
| store.create_session(build_session()) | ||
| return None | ||
| return get_messages() | ||
|
|
||
|
|
||
| async def aresume_or_create_session( | ||
| store: Any, | ||
| session: Optional[ConversationSession], | ||
| session_id: str, | ||
| build_session: Callable[[], ConversationSession], | ||
| create_session: Callable[[ConversationSession], Awaitable[Any]], | ||
| get_messages: Callable[[], Awaitable[List[ConversationMessage]]], | ||
| ) -> Optional[List[ConversationMessage]]: | ||
| """Async variant of :func:`resume_or_create_session`. | ||
|
|
||
| ``create_session`` and ``get_messages`` are awaitables supplied by the | ||
| caller so each keeps its own async-dispatch discipline (dedicated async | ||
| method vs. ``asyncio.to_thread`` off-loading). | ||
| """ | ||
| if session is None: | ||
| await create_session(build_session()) | ||
| return None | ||
| return await get_messages() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win
Preserve async-store dispatch in the synchronous creation path.
The sync helper directly calls
create_session, bypassing the orchestrator’s coroutine bridge.src/praisonai/praisonai/persistence/conversation/_ops.py#L20-L47: accept and invoke a caller-providedcreate_sessioncallback.src/praisonai/praisonai/persistence/orchestrator.py#L191-L203: passlambda s: self._sync(self.conversation.create_session(s))before caching the session.📍 Affects 2 files
src/praisonai/praisonai/persistence/conversation/_ops.py#L20-L47(this comment)src/praisonai/praisonai/persistence/orchestrator.py#L191-L203🤖 Prompt for AI Agents