Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix: only sync to CloudKit when session content actually changes

libokaif355fa6ea11a
diff --git a/CodePulse-macOS/Services/CloudKitSync.swift b/CodePulse-macOS/Services/CloudKitSync.swift
index d6b0fd47..6bb40235 100644
--- a/CodePulse-macOS/Services/CloudKitSync.swift
+++ b/CodePulse-macOS/Services/CloudKitSync.swift
@@ -24,32 +24,41 @@ final class CloudKitSync {
}
private func syncToCloud(_ sessions: [SessionState]) {
- // Don't start a new sync if one is already running (e.g. retrying)
guard !isSyncing else {
logger.debug("Sync skipped — already in progress")
return
}
+
+ // Filter to only changed sessions
+ let changed = sessions.filter { session in
+ previousStates[session.sessionId]?.updatedAt != session.updatedAt
+ }
+
+ guard !changed.isEmpty else {
+ logger.debug("Sync skipped — no changes (\(sessions.count) sessions unchanged)")
+ return
+ }
+
isSyncing = true
+ logger.info("Syncing \(changed.count) changed sessions to CloudKit...")
Task {
defer { isSyncing = false }
var syncedCount = 0
- for session in sessions {
- let previous = previousStates[session.sessionId]
- guard session.updatedAt != previous?.updatedAt else { continue }
-
+ for session in changed {
do {
try await CloudKitManager.shared.save(session)
previousStates[session.sessionId] = session
syncedCount += 1
+ // Small delay between saves to avoid rate limiting
+ try? await Task.sleep(for: .seconds(1))
} catch {
logger.error("Sync failed for \(session.sessionId): \(error.localizedDescription)")
- // Don't block other sessions on one failure
}
}
if syncedCount > 0 {
- logger.info("Synced \(syncedCount) sessions to CloudKit")
+ logger.info("Synced \(syncedCount)/\(changed.count) sessions to CloudKit")
}
}
}
diff --git a/CodePulse-macOS/Services/SessionStateManager.swift b/CodePulse-macOS/Services/SessionStateManager.swift
index bca1adce..d01407ee 100644
--- a/CodePulse-macOS/Services/SessionStateManager.swift
+++ b/CodePulse-macOS/Services/SessionStateManager.swift
@@ -41,6 +41,16 @@ final class SessionStateManager: ObservableObject {
?? indexEntry?.firstPrompt.map { String($0.prefix(50)) }
?? projectName
+ // Only update timestamp if content actually changed
+ let existingSession = sessions.first { $0.sessionId == sessionId }
+ let contentChanged = existingSession == nil
+ || existingSession?.status != status
+ || existingSession?.tasks != tasks
+ || existingSession?.contextPct != jsonlInfo.contextPct
+ || existingSession?.currentTask != currentTask
+
+ let updatedAt = contentChanged ? Date() : (existingSession?.updatedAt ?? Date())
+
let session = SessionState(
sessionId: sessionId,
projectName: projectName,
@@ -55,7 +65,7 @@ final class SessionStateManager: ObservableObject {
startedAt: startDate,
durationSec: duration,
deviceId: deviceId,
- updatedAt: Date()
+ updatedAt: updatedAt
)
updated.append(session)
}