claude-memory/graph/insights/systemd-oncalendarweekly-and-oncalendardaily-fire-simultaneo-b33e23.md
2026-02-20 00:47:17 -06:00

1.5 KiB

id type title tags importance confidence created updated relations
b33e2316-6313-4ed9-b95a-3a469b820101 insight Systemd OnCalendar=weekly and OnCalendar=daily fire simultaneously on Sundays/Mondays - always stagger shared-state timers
systemd
timer
gotcha
race-condition
cognitive-memory
scheduling
0.5 0.8 2026-02-20T06:47:13.739265+00:00 2026-02-20T06:47:17.701728+00:00
target type direction strength edge_id
59268a95-4712-48b4-bccb-6171c7885301 CAUSES incoming 0.9 6f7d12e4-b494-4aea-9be9-f43a5492719c

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:

# 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.