Commit 4365e39
fix(audience-session): clamp livePause in ComputeEngagedSecondsLocked
Cursor Bugbot finding on c43044a.
Resume() clamps pauseDuration ≥ 0 for wall-clock rewinds, but the
mirror calculation in ComputeEngagedSecondsLocked did not. If the
clock rewinds while the session is still paused and End fires (e.g.
Shutdown while backgrounded with NTP pulling time back), livePause
goes negative. Being subtracted, it inflated engagedSeconds past the
wall-clock window. The final engagedSeconds ≥ 0 clamp caught
negatives but not over-credit.
Mirror the Resume-side clamp: livePause < 0 → 0.
Added End_ClockRewindsWhilePaused_DoesNotInflateDuration as a
regression guard. 10s before pause, clock rewinds 5s while paused,
End fires — duration must stay within the 5s wall-clock window.
Without the clamp the test reports 15s.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 4a03d88 commit 4365e39
2 files changed
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
345 | 351 | | |
346 | 352 | | |
347 | 353 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
366 | 395 | | |
367 | 396 | | |
368 | 397 | | |
| |||
0 commit comments