Skip to content

Use UTC ticks and atomic operations for startup/heartbeat timing to improve watchdog reliability#393

Merged
CJKmkp merged 1 commit intobetafrom
codex/fix-app-forced-restart-on-launch-ifbjdp
Mar 5, 2026
Merged

Use UTC ticks and atomic operations for startup/heartbeat timing to improve watchdog reliability#393
CJKmkp merged 1 commit intobetafrom
codex/fix-app-forced-restart-on-launch-ifbjdp

Conversation

@CJKmkp
Copy link
Member

@CJKmkp CJKmkp commented Mar 5, 2026

Motivation

  • Replace non-atomic DateTime.Now usage and DateTime globals with UTC tick-based atomic storage to avoid race conditions and timezone/clock issues in startup and watchdog logic.
  • Improve reliability of heartbeat/watchdog checks by reading consistent timestamps under multithreaded access.

Description

  • Replaced DateTime fields (lastHeartbeat, splashScreenStartTime, appStartupStartTime, startupCompleteHeartbeat) with UTC tick long fields (lastHeartbeatTicksUtc, splashScreenStartTimeTicksUtc, appStartupStartTimeTicksUtc) and use Interlocked.Exchange/Interlocked.Read for thread-safe updates and reads.
  • Switched timestamp assignments from DateTime.Now to DateTime.UtcNow and store ticks to the new atomic fields (e.g. when showing splash and at app startup).
  • Added helper ReadUtcTicks to convert stored ticks back to DateTime with DateTimeKind.Utc and to interpret default values as DateTime.MinValue.
  • Updated the heartbeatTimer and watchdogTimer logic to use atomic tick reads and DateTime.UtcNow to compute elapsed times and decide on silent restarts.

Testing

  • No automated tests were run as part of this change.

Codex Task

@CJKmkp CJKmkp merged commit b7eebee into beta Mar 5, 2026
1 check passed
@CJKmkp CJKmkp deleted the codex/fix-app-forced-restart-on-launch-ifbjdp branch March 5, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant