feat: automatic recovery from hung calendar sync processes#50
Merged
Conversation
- Change readAppleCalendar() to return Result<CalendarEvent[], CalendarReadError> - Add discriminated CalendarReadError union type (timeout, osascript_failed, parse_error, exception) - Use SIGKILL (signal 9) for timeout to ensure hard termination - Update CalendarChannel.sync() to handle Result type with proper error reporting - Update tests to verify new Result-based error handling AC1: Result type differentiation AC2: SIGKILL on timeout
- Add consecutiveFailures field to ChannelStats interface - Add consecutiveFailures to CalendarChannelState (persisted) - Increment consecutiveFailures on any sync error (timeout, osascript_failed, etc.) - Reset consecutiveFailures to 0 on successful sync - Log consecutive count on timeout for visibility - Add tests for consecutive failure tracking AC3: Consecutive timeout tracking + ChannelStats shows consecutiveFailures
- Add RecoverFn type + default implementation for process recovery - Recovery triggers after 3 consecutive timeouts (RECOVERY_THRESHOLD) - Step 1: Kill hung osascript processes (pkill -9 -f osascript.*Calendar) - Step 2: At 6 failures (double threshold), also restart Calendar.app - Rate-limited to once per 5 minutes (RECOVERY_COOLDOWN_MS) - Add lastRecoveryAt to CalendarChannelState for persistence - RecoverFn injectable for testing AC4: Recovery logic - kill hung osascript after 3 timeouts, escalate to Calendar.app restart
- Add consecutive_failures to ChannelStatsResponse API response - Update formatChannelStats() to include consecutiveFailures - Update dashboard ChannelStats interface with consecutive_failures - Display 'Consecutive Failures' in red when > 0, hidden when 0 AC5: Dashboard displays consecutive failures when > 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Result<CalendarEvent[], CalendarReadError>type fromreadAppleCalendar()Changes
AC1 + AC2: Result type and SIGKILL
readAppleCalendar()now returnsResult<CalendarEvent[], CalendarReadError>CalendarReadErroris a discriminated union:timeout | osascript_failed | parse_errorAC3: Consecutive failure tracking
consecutiveFailurestoChannelStatsinterfaceAC4: Recovery logic
pkill -9 -f "osascript.*Calendar")lastRecoveryAttrackingRecoverFntype allows injection for testingAC5: Dashboard display
Testing
All 165 tests pass. Added tests for:
readAppleCalendar()