fix(windows): use GetTickCount64 to prevent overflow after 49.7 days#76
Merged
ErikBjare merged 1 commit intoFeb 27, 2026
Conversation
GetTickCount returns a DWORD (32-bit) that wraps at 2^32 ms (~49.7 days of uptime). After wrapping, the idle time calculation would produce incorrect values (either negative or huge numbers). Switch to GetTickCount64 which returns a 64-bit value with no practical overflow limit. Also handle the 32-bit wraparound of dwTime from GetLastInputInfo (which always returns DWORD per the Windows API). Fixes ActivityWatch#16
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 44b9ff6 in 6 seconds. Click for details.
- Reviewed
53lines of code in1files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_GXWUCFcQNivrQgT1
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Greptile SummaryThis PR fixes a critical bug where Key Changes:
Implementation Notes:
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 44b9ff6 |
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.
Summary
GetTickCountreturns a 32-bit DWORD that wraps at 2^32 ms (~49.7 days of uptime)GetTickCount64which returns a 64-bit value with no practical overflowdwTimefromGetLastInputInfo(always 32-bit per Windows API)Technical details
The
seconds_since_last_input()function computedGetTickCount() - dwTime. After 49.7 days:GetTickCount()wraps to near 0dwTime(last input) could still be a large numberThe fix uses
GetTickCount64()and compares only the lower 32 bits againstdwTime, handling the wrap edge case.Note:
GetTickCount64requires Windows Vista+ (2007), which should be a safe baseline in 2026.Test plan
Fixes #16
Important
Switches to
GetTickCount64inaw_watcher_afk/windows.pyto prevent overflow after 49.7 days and handlesdwTimewraparound.GetTickCountwithGetTickCount64inaw_watcher_afk/windows.pyto prevent overflow after 49.7 days.dwTimefromGetLastInputInfoinseconds_since_last_input()._getTickCount64()to retrieve 64-bit tick count.seconds_since_last_input()to use 64-bit tick count and handle 32-bit wraparound.GetTickCount64.This description was created by
for 44b9ff6. You can customize this summary. It will automatically update as commits are pushed.