fix(proxy): model_call_details wins for timing; skip post-guardrail task when no chunks

- utils: let model_call_details override start_time/end_time in kwargs merge; add comment
- proxy_server: only create post-guardrail log task when _streaming_chunks_for_log is non-empty

Made-with: Cursor
This commit is contained in:
devarakondasrikanth 2026-03-13 20:06:12 -07:00
parent f96681495f
commit c5878c3474
2 changed files with 7 additions and 2 deletions

View file

@ -5609,8 +5609,8 @@ async def async_data_generator(
except Exception as e:
yield f"data: {str(e)}\n\n"
# Post-guardrail log: only for successful stream completion, not when we got an SSE error
if error_message is None:
# Post-guardrail log: only for successful stream completion with chunks to process
if error_message is None and _streaming_chunks_for_log:
def _discard_task(t: asyncio.Task[None]) -> None:
_post_guardrail_log_tasks.discard(t)

View file

@ -1994,7 +1994,12 @@ class ProxyLogging:
if logging_obj is not None and getattr(
logging_obj, "model_call_details", None
):
# Merge so request data wins overall, but model_call_details wins for
# LLM-lifecycle timing fields so callbacks get accurate start/end times.
kwargs = {**logging_obj.model_call_details, **kwargs}
for key in ("start_time", "end_time"):
if key in logging_obj.model_call_details:
kwargs[key] = logging_obj.model_call_details[key]
kwargs["user_api_key_dict"] = user_api_key_dict
start_time = None
if logging_obj is not None: