Skip to content

Commit 19a5d19

Browse files
committed
fix(api): prevent session creation with duplicate id
resolves #103
1 parent ea03d0f commit 19a5d19

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/core/src/flux0_core/storage/nanodb_memory.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
override,
1515
)
1616

17+
from fastapi import HTTPException
1718
from flux0_core.agents import Agent, AgentId, AgentStore, AgentType, AgentUpdateParams
1819
from flux0_core.ids import gen_id
1920
from flux0_core.recordings import (
@@ -394,6 +395,12 @@ async def create_session(
394395
metadata: Optional[Mapping[str, JSONSerializable]] = None,
395396
created_at: Optional[datetime] = None,
396397
) -> Session:
398+
# if id set, ensure session with the same id not exists
399+
if id:
400+
existing = await self.read_session(id)
401+
if existing:
402+
raise HTTPException(status_code=409, detail=f"Session with id {id} already exists")
403+
397404
created_at = created_at or datetime.now(timezone.utc)
398405
consumption_offsets: dict[ConsumerId, int] = {"client": 0}
399406
session = Session(

0 commit comments

Comments
 (0)