Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,25 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati
// Track disconnected state for reconnection logic
switch state {
case .unavailable:
if !disconnectedServers.contains(server.identifier) {
let wasDisconnected = disconnectedServers.contains(server.identifier)
if !wasDisconnected {
Comment on lines +55 to +56
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable wasDisconnected is assigned but never used. It was created to replace the inline check in the if statement, but since it's only used once and the variable name doesn't add clarity beyond the original expression, consider removing it and keeping the original inline check !disconnectedServers.contains(server.identifier).

Suggested change
let wasDisconnected = disconnectedServers.contains(server.identifier)
if !wasDisconnected {
if !disconnectedServers.contains(server.identifier) {

Copilot uses AI. Check for mistakes.
Current.Log.info("Server \(server.identifier.rawValue) local push became unavailable")
Current.Log
.verbose(
"Adding server \(server.identifier.rawValue) to disconnected set. Current disconnected servers: \(disconnectedServers.map(\.rawValue))"
)
disconnectedServers.insert(server.identifier)
Current.Log.verbose("Disconnected servers after insert: \(disconnectedServers.map(\.rawValue))")
scheduleReconnection()
} else {
Current.Log.verbose("Server \(server.identifier.rawValue) already in disconnected set")
}
// Always attempt to schedule reconnection for unavailable servers.
// scheduleReconnectionIfNeeded() is idempotent and will only schedule if:
// 1. No timer is already active (prevents duplicate timers)
// 2. There are disconnected servers needing reconnection
// This ensures both initial disconnections and failed reconnection attempts
// properly schedule the next attempt with appropriate backoff.
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments at lines 67-72 exceed the 120-character line width limit specified in the SwiftFormat configuration. These comment lines should be wrapped to stay within the 120-character maximum line width.

Suggested change
// properly schedule the next attempt with appropriate backoff.
// properly schedule the next attempt with appropriate backoff and timing.

Copilot uses AI. Check for mistakes.
scheduleReconnectionIfNeeded()
case .available, .establishing:
if disconnectedServers.contains(server.identifier) {
Current.Log.info("Server \(server.identifier.rawValue) local push reconnected successfully")
Expand Down Expand Up @@ -159,15 +166,28 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati

// MARK: - Reconnection Logic

/// Schedules a reconnection attempt with gradual backoff
private func scheduleReconnection() {
/// Schedules a reconnection attempt with gradual backoff if one is not already scheduled.
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment at line 169 exceeds the 120-character line width limit specified in the SwiftFormat configuration. This comment line should be wrapped to stay within the 120-character maximum line width.

Suggested change
/// Schedules a reconnection attempt with gradual backoff if one is not already scheduled.
/// Schedules a reconnection attempt with gradual backoff.
/// If a reconnection is already scheduled, this method does nothing.

Copilot uses AI. Check for mistakes.
/// This method is idempotent and safe to call multiple times - it will only schedule a new
/// timer if one is not already active. This prevents rapid successive reconnection attempts
/// and ensures proper backoff timing.
Comment on lines +170 to +172
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments at lines 170-172 exceed the 120-character line width limit specified in the SwiftFormat configuration. These comment lines should be wrapped to stay within the 120-character maximum line width.

Suggested change
/// This method is idempotent and safe to call multiple times - it will only schedule a new
/// timer if one is not already active. This prevents rapid successive reconnection attempts
/// and ensures proper backoff timing.
/// This method is idempotent and safe to call multiple times - it will only schedule a new timer
/// if one is not already active.
/// This prevents rapid successive reconnection attempts and ensures proper backoff timing.

Copilot uses AI. Check for mistakes.
private func scheduleReconnectionIfNeeded() {
Current.Log
.verbose(
"scheduleReconnection called. Current attempt: \(reconnectionAttempt), timer active: \(reconnectionTimer != nil)"
"scheduleReconnectionIfNeeded called. Current attempt: \(reconnectionAttempt), timer active: \(reconnectionTimer != nil), disconnected servers: \(disconnectedServers.count)"
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message at line 176 exceeds the 120-character line width limit specified in the SwiftFormat configuration. This line should be wrapped to stay within the 120-character maximum line width.

Suggested change
"scheduleReconnectionIfNeeded called. Current attempt: \(reconnectionAttempt), timer active: \(reconnectionTimer != nil), disconnected servers: \(disconnectedServers.count)"
"scheduleReconnectionIfNeeded called. "
+ "Current attempt: \(reconnectionAttempt), "
+ "timer active: \(reconnectionTimer != nil), "
+ "disconnected servers: \(disconnectedServers.count)"

Copilot uses AI. Check for mistakes.
)

// Cancel any existing timer
reconnectionTimer?.invalidate()
// If a timer is already active, don't schedule a new one
// This ensures we maintain proper backoff timing and don't reset the timer
guard reconnectionTimer == nil else {
Current.Log.verbose("Reconnection timer already active, skipping scheduling")
return
}

// If there are no disconnected servers, don't schedule a reconnection
guard !disconnectedServers.isEmpty else {
Current.Log.verbose("No disconnected servers, skipping reconnection scheduling")
return
}

// Determine the delay based on the current attempt
let delayIndex = min(reconnectionAttempt, reconnectionDelays.count - 1)
Expand All @@ -193,6 +213,11 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati

/// Attempts to reconnect by reloading managers
private func attemptReconnection() {
// Clear the timer reference first since it has now fired.
// This allows scheduleReconnectionIfNeeded() to schedule a new timer
// if this reconnection attempt fails.
reconnectionTimer = nil

reconnectionAttempt += 1
Current.Log
.info(
Expand All @@ -209,8 +234,8 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati
reloadManagersAfterSave()

Current.Log.verbose("reloadManagersAfterSave() called, waiting for state change to determine next action")
// If still unavailable after this attempt, schedule the next one
// This will be triggered by the state didSet when the connection fails
// If still unavailable after this attempt, the status observer will trigger
// and scheduleReconnectionIfNeeded() will schedule the next attempt with proper backoff
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment at line 237 exceeds the 120-character line width limit specified in the SwiftFormat configuration. This comment line should be wrapped to stay within the 120-character maximum line width.

Suggested change
// and scheduleReconnectionIfNeeded() will schedule the next attempt with proper backoff
// and scheduleReconnectionIfNeeded() will schedule the next attempt
// with proper backoff

Copilot uses AI. Check for mistakes.
}

/// Cancels any pending reconnection timer and resets the attempt counter
Expand Down
Loading