Field units on unstable internet had RTC time drift wildly (10 min to
half a day), while units with stable internet stayed accurate. Root
cause: syncTimeWithNTP() wrote getLocalTime()'s result straight to the
RTC with no plausibility check, and fires on every WiFi reconnect
(not a fixed schedule) — so flaky links produced far more unguarded
sync attempts than healthy ones. The underlying configTime()/
getLocalTime() API has no request/response correlation, so a stale
reply from an abandoned attempt could be picked up by a later
attempt's window if reconnects outpaced a single attempt's ~5s resolve
time.
Three layers of defense, all in TimeKeeper:
- In-flight de-dup guard (ntpSyncInProgress) so only one sync attempt
is ever listening at a time, closing the window a stale reply could
land in.
- 10s cooldown between attempts to throttle reconnect storms.
- commitNtpResult(): corrections under 2 minutes commit immediately
(normal drift); anything larger is held as a pending candidate and
only written to the RTC once 3 consecutive syncs agree within 5s of
each other, so a single bad reading can no longer move the clock by
hours.
Documented in TimeKeeper/README.md under "NTP sync safety".
Add inline documentation for all src/ subsystems covering purpose,
responsibilities, public API, and usage notes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>