fix(python): round sub-millisecond durations in to_timedelta_int#1668
Open
idryzhov wants to merge 1 commit into
Open
fix(python): round sub-millisecond durations in to_timedelta_int#1668idryzhov wants to merge 1 commit into
idryzhov wants to merge 1 commit into
Conversation
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>
Contributor
There was a problem hiding this comment.
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_intgeneration to round milliseconds rather than assert integer-ness. - Regenerate
python/copilot/generated/session_events.pyto 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 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)`); |
Author
There was a problem hiding this comment.
I don't think we care about such precision here, so bankers rounding is fine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A timedelta carries microsecond precision, so
x.total_seconds() * 1000.0into_timedelta_intcan be a non-integer float (e.g. 1.234). The oldis_integer()assert then failed on such durations and aborted SessionEvent serialization. Round to the nearest whole millisecond instead.