always return debug sessions that are <30s fresh (#3132)
This commit is contained in:
@@ -3492,6 +3492,28 @@ class AgentDB:
|
|||||||
|
|
||||||
return DebugSession.model_validate(debug_session)
|
return DebugSession.model_validate(debug_session)
|
||||||
|
|
||||||
|
async def get_latest_debug_session_for_user(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
organization_id: str,
|
||||||
|
user_id: str,
|
||||||
|
workflow_permanent_id: str,
|
||||||
|
) -> DebugSession | None:
|
||||||
|
async with self.Session() as session:
|
||||||
|
query = (
|
||||||
|
select(DebugSessionModel)
|
||||||
|
.filter_by(organization_id=organization_id)
|
||||||
|
.filter_by(deleted_at=None)
|
||||||
|
.filter_by(status="created")
|
||||||
|
.filter_by(user_id=user_id)
|
||||||
|
.filter_by(workflow_permanent_id=workflow_permanent_id)
|
||||||
|
.order_by(DebugSessionModel.created_at.desc())
|
||||||
|
)
|
||||||
|
|
||||||
|
model = (await session.scalars(query)).first()
|
||||||
|
|
||||||
|
return DebugSession.model_validate(model) if model else None
|
||||||
|
|
||||||
async def complete_debug_sessions(
|
async def complete_debug_sessions(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Annotated, Any
|
from typing import Annotated, Any
|
||||||
@@ -2100,8 +2101,32 @@ async def new_debug_session(
|
|||||||
sessions associated with those completed debug sessions.
|
sessions associated with those completed debug sessions.
|
||||||
|
|
||||||
Return the new debug session.
|
Return the new debug session.
|
||||||
|
|
||||||
|
CAVEAT: if an existing debug session for this user is <30s old, then we
|
||||||
|
return that instead. This is to curtail damage from browser session
|
||||||
|
spamming.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if current_user_id:
|
||||||
|
debug_session = await app.DATABASE.get_latest_debug_session_for_user(
|
||||||
|
organization_id=current_org.organization_id,
|
||||||
|
user_id=current_user_id,
|
||||||
|
workflow_permanent_id=workflow_permanent_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
if debug_session:
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
if now - debug_session.created_at < timedelta(seconds=30):
|
||||||
|
LOG.info(
|
||||||
|
"Existing debug session is less than 30s old, returning it",
|
||||||
|
debug_session_id=debug_session.debug_session_id,
|
||||||
|
browser_session_id=debug_session.browser_session_id,
|
||||||
|
organization_id=current_org.organization_id,
|
||||||
|
user_id=current_user_id,
|
||||||
|
workflow_permanent_id=workflow_permanent_id,
|
||||||
|
)
|
||||||
|
return debug_session
|
||||||
|
|
||||||
completed_debug_sessions = await app.DATABASE.complete_debug_sessions(
|
completed_debug_sessions = await app.DATABASE.complete_debug_sessions(
|
||||||
organization_id=current_org.organization_id,
|
organization_id=current_org.organization_id,
|
||||||
user_id=current_user_id,
|
user_id=current_user_id,
|
||||||
|
|||||||
0
skyvern/forge/sdk/schemas/scripts.py
Normal file
0
skyvern/forge/sdk/schemas/scripts.py
Normal file
Reference in New Issue
Block a user