Skip to content

fix(python): round sub-millisecond durations in to_timedelta_int#1668

Open
idryzhov wants to merge 1 commit into
github:mainfrom
idryzhov:idryzhov/fix-python-to-timedelta-int-subms
Open

fix(python): round sub-millisecond durations in to_timedelta_int#1668
idryzhov wants to merge 1 commit into
github:mainfrom
idryzhov:idryzhov/fix-python-to-timedelta-int-subms

Conversation

@idryzhov

Copy link
Copy Markdown

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.

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>
Copilot AI review requested due to automatic review settings June 14, 2026 04:54
@idryzhov idryzhov requested a review from a team as a code owner June 14, 2026 04:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates Python session event codegen to handle timedelta values with sub-millisecond precision by rounding to milliseconds instead of asserting exact millisecond alignment.

Changes:

  • Adjust to_timedelta_int generation to round milliseconds rather than assert integer-ness.
  • Regenerate python/copilot/generated/session_events.py to reflect the new rounding behavior.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
scripts/codegen/python.ts Updates the generated Python helper to round timedelta values to whole milliseconds.
python/copilot/generated/session_events.py Regenerated output reflecting the new timedelta conversion logic.

Comment thread scripts/codegen/python.ts
Comment on lines 2538 to +2542
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)`);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we care about such precision here, so bankers rounding is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants