Commit 624823a
fix(heartbeat): scale pulsetime with poll_time to prevent missing time (#131)
* fix(heartbeat): scale pulsetime with poll_time to prevent missing time
At high poll_time values (>2s), OS scheduling jitter regularly exceeds
the fixed 1s pulsetime margin (poll_time+1), breaking heartbeat chains and
causing missing time in the activity timeline.
Simulation (200 trials, 3h session) verified against measured user data:
- poll_time=5s: 11.6% time lost with old formula → 0.09% with fix
- poll_time=10s: 30.0% time lost with old formula → 0.12% with fix
Fix: max(poll_time * 1.5, poll_time + 1) ensures jitter tolerance scales
proportionally while staying backward-compatible at poll_time ≤ 2s.
Closes ActivityWatch/activitywatch#1177
* refactor(heartbeat): extract compute_pulsetime() so test exercises production code
Greptile review noted the pulsetime parametrized test duplicated the formula
inline (max(poll_time * 1.5, poll_time + 1.0)) instead of calling the
production code path. If someone later edits the formula in main.py, the
inline test would still pass — a silent regression path.
Fix: extract compute_pulsetime() as a module-level function, use it at the
call site, and import it in the test. The test now catches drift in main.py.
No behavior change; formula is identical.
---------
Co-authored-by: TimeToBuildBob <timetolearnalice@gmail.com>1 parent a121b81 commit 624823a
2 files changed
Lines changed: 33 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
29 | 41 | | |
30 | 42 | | |
31 | 43 | | |
| |||
170 | 182 | | |
171 | 183 | | |
172 | 184 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | 185 | | |
177 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
178 | 190 | | |
179 | 191 | | |
180 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
0 commit comments