From 30c4dd7ba9e80cdd78f363f249f80e6b319952fe Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Sat, 13 Jun 2026 21:16:27 -0700 Subject: [PATCH] fix(python): round sub-millisecond durations in to_timedelta_int A timedelta carries microsecond precision, so `x.total_seconds() * 1000.0` in `to_timedelta_int` can be a non-integer float (e.g. 1.234). The old `is_integer()` assert then failed on such durations and aborted SessionEvent serialization. Round to the nearest whole millisecond instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- python/copilot/generated/session_events.py | 4 ++-- scripts/codegen/python.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/copilot/generated/session_events.py b/python/copilot/generated/session_events.py index f2e155f49..604a165c3 100644 --- a/python/copilot/generated/session_events.py +++ b/python/copilot/generated/session_events.py @@ -51,8 +51,8 @@ def from_timedelta(x: Any) -> timedelta: def to_timedelta_int(x: timedelta) -> int: assert isinstance(x, timedelta) milliseconds = x.total_seconds() * 1000.0 - assert milliseconds.is_integer() - return int(milliseconds) + # Durations can carry sub-millisecond precision; round to the nearest whole ms. + return round(milliseconds) def to_timedelta(x: timedelta) -> float: diff --git a/scripts/codegen/python.ts b/scripts/codegen/python.ts index 0ba72db50..280e185cb 100644 --- a/scripts/codegen/python.ts +++ b/scripts/codegen/python.ts @@ -2538,8 +2538,8 @@ export function generatePythonSessionEventsCode(schema: JSONSchema7): string { out.push(`def to_timedelta_int(x: timedelta) -> int:`); out.push(` assert isinstance(x, timedelta)`); out.push(` milliseconds = x.total_seconds() * 1000.0`); - out.push(` assert milliseconds.is_integer()`); - out.push(` return int(milliseconds)`); + out.push(` # Durations can carry sub-millisecond precision; round to the nearest whole ms.`); + out.push(` return round(milliseconds)`); out.push(``); out.push(``); }