fix: req changes from greptile

This commit is contained in:
Harshit28j 2026-03-10 13:03:29 +05:30
parent b731e432f8
commit afb117f5d3
2 changed files with 13 additions and 16 deletions

View file

@ -1501,20 +1501,21 @@ class Router:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(
self.acompletion(
async def _run_silent_completion():
await self.acompletion(
model=silent_model,
messages=cast(List[AllMessageValues], messages),
**silent_kwargs,
)
)
# Drain any remaining fire-and-forget tasks (e.g. alerting hooks)
# scheduled via asyncio.create_task during the acompletion call.
pending = asyncio.all_tasks(loop)
if pending:
loop.run_until_complete(
asyncio.gather(*pending, return_exceptions=True)
)
# Drain any fire-and-forget tasks (e.g. alerting hooks)
# scheduled via asyncio.create_task during acompletion.
pending = asyncio.all_tasks()
pending.discard(asyncio.current_task())
if pending:
await asyncio.gather(*pending, return_exceptions=True)
loop.run_until_complete(_run_silent_completion())
finally:
loop.close()
except Exception as e:

View file

@ -1,4 +1,5 @@
import asyncio
import time
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
@ -203,15 +204,10 @@ def test_router_silent_experiment_completion():
assert response.choices[0].message.content == "hello"
# The sync background call uses a thread pool. We might need to wait a bit.
import time
# The sync background call uses a thread pool. We might need to wait.
time.sleep(2.0)
# Should have 1 acompletion call (the silent background call)
# The primary completion call still goes to the real litellm.completion (or we can mock it separately, but here it's testing the background one)
# Wait, the primary call in the test is router.completion.
# Actually, let's just mock both to avoid real network calls if it's hitting one.
assert mock_acompletion_mock.call_count == 1
call_args_list = mock_acompletion_mock.call_args_list