mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(responses): warn when spend-log session query hits row cap
This commit is contained in:
parent
bbb407b657
commit
3b1ebbc7cb
2 changed files with 46 additions and 0 deletions
|
|
@ -295,6 +295,15 @@ class ResponsesSessionHandler:
|
|||
query, previous_response_id, DEFAULT_MAX_SPEND_LOGS_PER_RESPONSES_SESSION
|
||||
)
|
||||
|
||||
if len(spend_logs) >= DEFAULT_MAX_SPEND_LOGS_PER_RESPONSES_SESSION:
|
||||
verbose_proxy_logger.warning(
|
||||
"Responses session for previous_response_id=%s hit the %d-row cap "
|
||||
"(DEFAULT_MAX_SPEND_LOGS_PER_RESPONSES_SESSION); the oldest turns were dropped. "
|
||||
"Raise the limit if you need more history.",
|
||||
previous_response_id,
|
||||
DEFAULT_MAX_SPEND_LOGS_PER_RESPONSES_SESSION,
|
||||
)
|
||||
|
||||
verbose_proxy_logger.debug(
|
||||
"Found the following spend logs for previous response id %s: %s",
|
||||
previous_response_id,
|
||||
|
|
|
|||
|
|
@ -491,3 +491,40 @@ async def test_get_all_spend_logs_returns_most_recent_in_ascending_order():
|
|||
executed_query = mock_prisma_client.db.query_raw.await_args.args[0]
|
||||
assert 'ORDER BY "endTime" DESC' in executed_query
|
||||
assert executed_query.rstrip().rstrip(";").endswith('ORDER BY "endTime" ASC')
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_all_spend_logs_warns_when_cap_is_hit():
|
||||
"""
|
||||
Operators need a runtime signal when a session is truncated: when the query returns
|
||||
the full cap of rows (older turns silently dropped), a warning must be emitted.
|
||||
"""
|
||||
cap = litellm.constants.DEFAULT_MAX_SPEND_LOGS_PER_RESPONSES_SESSION
|
||||
mock_prisma_client = AsyncMock()
|
||||
mock_prisma_client.db.query_raw = AsyncMock(return_value=[{} for _ in range(cap)])
|
||||
|
||||
with _patched_prisma_client(mock_prisma_client):
|
||||
with patch.object(session_handler.verbose_proxy_logger, "warning") as mock_warning:
|
||||
await ResponsesSessionHandler.get_all_spend_logs_for_previous_response_id(
|
||||
"resp_previous_id"
|
||||
)
|
||||
|
||||
mock_warning.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_all_spend_logs_does_not_warn_below_cap():
|
||||
"""
|
||||
Below the cap nothing is truncated, so no truncation warning should be emitted.
|
||||
"""
|
||||
cap = litellm.constants.DEFAULT_MAX_SPEND_LOGS_PER_RESPONSES_SESSION
|
||||
mock_prisma_client = AsyncMock()
|
||||
mock_prisma_client.db.query_raw = AsyncMock(return_value=[{} for _ in range(cap - 1)])
|
||||
|
||||
with _patched_prisma_client(mock_prisma_client):
|
||||
with patch.object(session_handler.verbose_proxy_logger, "warning") as mock_warning:
|
||||
await ResponsesSessionHandler.get_all_spend_logs_for_previous_response_id(
|
||||
"resp_previous_id"
|
||||
)
|
||||
|
||||
mock_warning.assert_not_called()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue