From b2222fb33838a86ecf593d5d17add570066db972 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 20 Feb 2026 00:47:13 -0600 Subject: [PATCH] store: Systemd OnCalendar=weekly and OnCalendar=daily fire simultaneously on Sundays/Mondays - always stagger shared-state timers --- ...-oncalendardaily-fire-simultaneo-b33e23.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 graph/insights/systemd-oncalendarweekly-and-oncalendardaily-fire-simultaneo-b33e23.md diff --git a/graph/insights/systemd-oncalendarweekly-and-oncalendardaily-fire-simultaneo-b33e23.md b/graph/insights/systemd-oncalendarweekly-and-oncalendardaily-fire-simultaneo-b33e23.md new file mode 100644 index 00000000000..e4e8ef075c6 --- /dev/null +++ b/graph/insights/systemd-oncalendarweekly-and-oncalendardaily-fire-simultaneo-b33e23.md @@ -0,0 +1,34 @@ +--- +id: b33e2316-6313-4ed9-b95a-3a469b820101 +type: insight +title: "Systemd OnCalendar=weekly and OnCalendar=daily fire simultaneously on Sundays/Mondays - always stagger shared-state timers" +tags: [systemd, timer, gotcha, race-condition, cognitive-memory, scheduling] +importance: 0.5 +confidence: 0.8 +created: "2026-02-20T06:47:13.739265+00:00" +updated: "2026-02-20T06:47:13.739265+00:00" +--- + +# Systemd Timer Collision Gotcha + +## The Problem +`OnCalendar=weekly` resolves to `Mon *-*-* 00:00:00` (Monday midnight). If another timer uses `OnCalendar=daily`, both fire at the same second on Monday midnight. Any two services that share a state file will race each other. + +## Consequence +Silent data loss. If both services do read-modify-write on the same JSON file without atomic locking, one will clobber the other's changes. If the loser's write also corrupts the file, a silent `JSONDecodeError` catch can return an empty dict, permanently losing all state. + +## Fix Pattern +Always stagger timers that access shared resources by at least an hour: + +```ini +# Instead of: +OnCalendar=weekly + +# Use: +OnCalendar=Sun *-*-* 02:00:00 +``` + +This avoids the Monday midnight collision and gives the daily timer time to finish first. + +## General Rule +Never schedule two services that share state files at the same `OnCalendar` interval without explicit offset staggering.