Add invariant assertion after reconcile — log if alreadySafe + needBackup ≠ phoneTotal #2

Closed
opened 2026-05-18 07:34:00 +00:00 by kutesir · 0 comments
Owner

Problem

The dashboard invariant alreadySafe + needBackup == phoneTotal can silently break if a filter mismatch or off-by-one creeps in. Currently there is no runtime check.

Fix

At the end of both the fast-path and full-path in BackupStatusService.reconcile(), assert:

if updated.alreadySafe + updated.needBackup != updated.phoneTotal {
    log.error("Invariant broken: safe=\(updated.alreadySafe) needBackup=\(updated.needBackup) phone=\(updated.phoneTotal)")
}

Acceptance

  • Broken invariant emits a .error log visible in Console.app
  • No crash or user-visible change when invariant holds
## Problem The dashboard invariant `alreadySafe + needBackup == phoneTotal` can silently break if a filter mismatch or off-by-one creeps in. Currently there is no runtime check. ## Fix At the end of both the fast-path and full-path in `BackupStatusService.reconcile()`, assert: ```swift if updated.alreadySafe + updated.needBackup != updated.phoneTotal { log.error("Invariant broken: safe=\(updated.alreadySafe) needBackup=\(updated.needBackup) phone=\(updated.phoneTotal)") } ``` ## Acceptance - Broken invariant emits a `.error` log visible in Console.app - No crash or user-visible change when invariant holds
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kutesir/Kisani#2
No description provided.