[data-veracity] Business cycle boundaries use server local time and ignore facility_utc_offset_minutes #27
Labels
No labels
blocked
bug
enhancement
high-priority
low-priority
needs-info
needs-triage
ready-for-agent
ready-for-human
referenced
research
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gabogg/hikcentral#27
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Every business-cycle boundary is computed in the server's timezone:
Same pattern in
get_completed_business_cycle_bounds(:160),get_active_schedule_info_async(:190),get_today_midnight_epoch(:110), and in SQL viaDATE(..., 'unixepoch', 'localtime')inquarantine_and_deduplicate_calibration_logs_async.Meanwhile
settings.facility_utc_offset_minutesexists and is broadcast to every client (monitor_service.py:39,49,117,151,occupancy_service.py:550,995,1040,1335,1693). Its existence is an explicit acknowledgement that the server clock and the facility clock are not assumed to be the same — but it is used only for display, never for cycle math.Why this destroys the data, not just the labels
If the gateway runs UTC (the default for most VPS and container images) and the facility is UTC−4, then:
The second one is the serious one: the quiet-window residual
Δ = I − k·Eis the entire basis of the proportional calibration model. Evaluating it during closing traffic produces a large spurious residual, which driveskaway from truth viacompute_ewma_multiplier, which then mis-scales every calibrated occupancy figure the deck publishes.Secondary: DST and the exact-86400 assumption
time.struct_timeis built by copyingtm_isdstfrom the current time and then passed tomktime; around a DST transition this yields an ambiguous or wrong epoch. The code then hardcodescycle_start + 86400.0, andRFC-ARCH-2026-004§2.2 asserts "Duration is exactly 86,400 seconds". On a DST-observing deployment a business cycle is genuinely 23 or 25 hours. Venezuela does not observe DST, so impact is currently nil — but the assumption is baked into both the code and the RFC and should be stated rather than assumed.KPIs corrupted
All of them, plus cycle attribution itself (traffic assigned to the wrong day), plus
kand therefore Trust Index and the calibrated occupancy envelope.Suggested fix
facility_now()/facility_bounds()seam that appliessettings.facility_utc_offset_minutes(or, better, a real IANAfacility_timezonesetting) and route all cycle math through it.time.mktime+ copiedtm_isdstwith explicitdatetime+ZoneInfoarithmetic.'localtime'modifiers with epoch ranges computed by that seam.Being addressed in draft PR #69, one of four [data-veracity] drafts declared on 2026-09-23 (#68, #69, #70, #71). Each will be triaged, reviewed and implemented in order; the PR description lists the open design points to settle first.
gabogg referenced this issue2026-09-24 13:13:51 +00:00