## Problem
The weekly freeze/thaw system had a state flag initialization bug that prevented
both Monday freeze operations and Saturday thaw operations from executing.
## Root Cause (Introduced in commit 07f69eb on Oct 25, 2025)
The `weekly_warning_sent` boolean flag was being used for TWO different purposes:
1. Preventing duplicate freeze/thaw operations (state machine)
2. Preventing duplicate error notifications
The flag was initialized to `False`, but the Monday freeze condition required
it to be `True`:
- Line 205: `if ... and self.weekly_warning_sent:` (required True)
- Line 160: `self.weekly_warning_sent = False` (initialized to False)
This created a deadlock:
- Monday freeze: Never ran (flag was False, needed True)
- Saturday thaw: Never ran (freeze flag in DB never set to True)
## Impact
- First failure: Monday October 27, 2025
- Affected weeks: 2+ weeks of missed freeze/thaw operations
- Result: Week did NOT increment, transactions did NOT execute
## Solution
Separated the two concerns and replaced boolean flag with week tracking:
1. **Deduplication**: Track `last_freeze_week` and `last_thaw_week` (int | None)
- Monday: Execute if `last_freeze_week != current.week`
- Saturday: Execute if `last_thaw_week != current.week`
- Prevents duplicate operations during same hour (loop runs every minute)
2. **Error notifications**: Separate `error_notification_sent` boolean flag
- Only used for preventing duplicate error notifications
- Clear separation of concerns
## Validation
Created and ran validation script simulating 7 scenarios across multiple weeks:
- ✅ Monday freeze executes on first check
- ✅ Monday freeze skips on subsequent checks same hour
- ✅ Saturday thaw executes on first check
- ✅ Saturday thaw skips on subsequent checks same hour
- ✅ Next Monday freeze executes for new week
- ✅ Week numbers increment correctly (19→20→21→22)
- ✅ All state transitions work as expected
## Files Changed
- tasks/transaction_freeze.py:157-167 - Separated state tracking from error flags
- tasks/transaction_freeze.py:211-231 - Fixed freeze/thaw conditions with week tracking
- tasks/transaction_freeze.py:248-250 - Updated error notification flag name
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>