loop-metrics timeframe uses 23/25-hour days across daylight saving transitions
[bug] loop-metrics timeframe changes by one hour across daylight-saving transitions
Describe the bug
loop-metrics --timeframe 1d is intended to show the last day of runs, but its cutoff subtracts a local calendar day using Date.setDate(). Across a daylight-saving transition, the window becomes 23 or 25 elapsed hours. The same log and current instant can therefore yield different token totals, run counts, and ROI depending on the host timezone. The run-log pruner already defines a day as 24 elapsed hours.
Steps to reproduce
- Use Node with
TZ=America/New_York. - Freeze the current time to
2026-03-08T12:00:00Z(after spring-forward). - Feed the normal run-log format with entries at
2026-03-07T12:30:00Z,2026-03-07T12:00:00Z, and2026-03-07T11:30:00Z. - Run
node tools/loop-metrics/dist/cli.js --timeframe 1d --log <synthetic-log.md>. - Repeat with current time
2026-11-01T12:00:00Z(after fall-back), using runs at2026-10-31T12:30:00Z,2026-10-31T12:00:00Z, and2026-10-31T11:30:00Z.
Expected behavior
Both dashboards should show 2 runs: retain ages 23.5h and exactly 24h, exclude age 24.5h. The timeframe should be timezone-independent.
Actual behavior
Original CLI showed 0 runs in the spring case and 3 in the fall case. These were reproduced using the real CLI, a data-URL Date preload, and synthetic logs, without a service or credentials.
Environment
Windows; Node v22.16.0; @cobusgreyling/loop-metrics 1.0.0; base 68ccc887ccf1e0cf3a1a1d787ce2da48f4959081.
Duplicate check
All-state issue/PR queries for metrics, timeframe, DST, and daylight at 2026-11-08 13:40 Beijing found no corresponding report/fix. Previously merged #499/#610 concern run-ID parsing, and #537 concerns success-rate calculations; none changes elapsed-day cutoff arithmetic.
This is a local draft only. No issue has been created.