loop-engineering icon indicating copy to clipboard operation
loop-engineering copied to clipboard

loop-metrics timeframe uses 23/25-hour days across daylight saving transitions

Open lhy-dcf opened this issue 3 weeks ago • 0 comments

[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

  1. Use Node with TZ=America/New_York.
  2. Freeze the current time to 2026-03-08T12:00:00Z (after spring-forward).
  3. Feed the normal run-log format with entries at 2026-03-07T12:30:00Z, 2026-03-07T12:00:00Z, and 2026-03-07T11:30:00Z.
  4. Run node tools/loop-metrics/dist/cli.js --timeframe 1d --log <synthetic-log.md>.
  5. Repeat with current time 2026-11-01T12:00:00Z (after fall-back), using runs at 2026-10-31T12:30:00Z, 2026-10-31T12:00:00Z, and 2026-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.

lhy-dcf avatar Nov 08 '26 05:11 lhy-dcf