Skip to content

Commit edb5f7a

Browse files
idryzhovCopilot
andauthored
fix(python): round sub-millisecond durations in to_timedelta_int (#1668)
* 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> * docs(python): clarify banker's rounding in to_timedelta_int comment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b49fbab commit edb5f7a

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

python/copilot/generated/session_events.py

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/codegen/python.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,8 +2538,9 @@ export function generatePythonSessionEventsCode(schema: JSONSchema7): string {
25382538
out.push(`def to_timedelta_int(x: timedelta) -> int:`);
25392539
out.push(` assert isinstance(x, timedelta)`);
25402540
out.push(` milliseconds = x.total_seconds() * 1000.0`);
2541-
out.push(` assert milliseconds.is_integer()`);
2542-
out.push(` return int(milliseconds)`);
2541+
out.push(` # Durations can carry sub-millisecond precision; round to the nearest whole ms`);
2542+
out.push(` # using Python's default banker's rounding (round-half-to-even).`);
2543+
out.push(` return round(milliseconds)`);
25432544
out.push(``);
25442545
out.push(``);
25452546
}

0 commit comments

Comments
 (0)