fix: properly limit runs query (#6357)
* letta * tweak * cancellation to 100 * openapi changes
This commit is contained in:
@@ -10782,7 +10782,8 @@
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "integer",
|
||||
"maximum": 1000
|
||||
"maximum": 1000,
|
||||
"minimum": 1
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
@@ -13722,7 +13723,8 @@
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "integer",
|
||||
"maximum": 1000
|
||||
"maximum": 1000,
|
||||
"minimum": 1
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
|
||||
@@ -1596,6 +1596,7 @@ async def cancel_message(
|
||||
statuses=[RunStatus.created, RunStatus.running],
|
||||
ascending=False,
|
||||
agent_id=agent_id, # NOTE: this will override agent_ids if provided
|
||||
limit=100, # Limit to 10 most recent active runs for cancellation
|
||||
)
|
||||
run_ids = [run.id for run in run_ids]
|
||||
else:
|
||||
|
||||
@@ -52,7 +52,7 @@ async def list_runs(
|
||||
after: Optional[str] = Query(
|
||||
None, description="Run ID cursor for pagination. Returns runs that come after this run ID in the specified sort order"
|
||||
),
|
||||
limit: Optional[int] = Query(100, description="Maximum number of runs to return", le=1000),
|
||||
limit: Optional[int] = Query(100, description="Maximum number of runs to return", ge=1, le=1000),
|
||||
order: Literal["asc", "desc"] = Query(
|
||||
"desc", description="Sort order for runs by creation time. 'asc' for oldest first, 'desc' for newest first"
|
||||
),
|
||||
|
||||
@@ -61,7 +61,7 @@ async def list_runs(
|
||||
after: Optional[str] = Query(
|
||||
None, description="Run ID cursor for pagination. Returns runs that come after this run ID in the specified sort order"
|
||||
),
|
||||
limit: Optional[int] = Query(100, description="Maximum number of runs to return", le=1000),
|
||||
limit: Optional[int] = Query(100, description="Maximum number of runs to return", ge=1, le=1000),
|
||||
order: Literal["asc", "desc"] = Query(
|
||||
"desc", description="Sort order for runs by creation time. 'asc' for oldest first, 'desc' for newest first"
|
||||
),
|
||||
@@ -132,7 +132,7 @@ async def list_active_runs(
|
||||
agent_ids = None
|
||||
|
||||
active_runs = await runs_manager.list_runs(
|
||||
actor=actor, statuses=[RunStatus.created, RunStatus.running], agent_ids=agent_ids, background=background
|
||||
actor=actor, statuses=[RunStatus.created, RunStatus.running], agent_ids=agent_ids, background=background, limit=100
|
||||
)
|
||||
|
||||
return active_runs
|
||||
|
||||
@@ -267,9 +267,11 @@ class RunManager:
|
||||
|
||||
query = await _apply_pagination_async(query, before, after, session, ascending=ascending)
|
||||
|
||||
# Apply limit
|
||||
if limit:
|
||||
query = query.limit(limit)
|
||||
# Apply limit (always enforce a maximum to prevent unbounded queries)
|
||||
# If no limit specified, default to 100; enforce maximum of 1000
|
||||
effective_limit = limit if limit is not None else 100
|
||||
effective_limit = min(effective_limit, 1000)
|
||||
query = query.limit(effective_limit)
|
||||
|
||||
result = await session.execute(query)
|
||||
rows = result.all()
|
||||
|
||||
Reference in New Issue
Block a user