Fix Git Sync race between startup pull and auto-sync export

syncOnStartup() (pull+import, fired at launch) and autoSync() (export+push,
debounced off chat activity) ran as fully independent, uncoordinated Tasks
with no mutual exclusion. A user launching the app and chatting right away
could hit autoSync's export mid-pull, leaving a freshly-written untracked
file that the pull then refuses to merge over — the same failure class as
the earlier folders.json bug, now much more likely to surface widely since
folders.json/notes.json are brand new for every existing sync repo.

Adds a shared isSyncing guard across all three entry points (syncOnStartup
skips if busy, autoSync waits for a clear slot, syncNow throws
.syncInProgress) and moves Sync Now's pull/import/export/push orchestration
out of SettingsView into GitSyncService.syncNow(), where the guard can
actually protect it.
This commit is contained in:
2026-08-04 08:52:48 +02:00
parent f4086c2563
commit 125e1698f7
3 changed files with 68 additions and 27 deletions
+3
View File
@@ -39,6 +39,7 @@ enum SyncError: LocalizedError {
case repoNotCloned
case secretsDetected([String])
case parseError(String)
case syncInProgress
var errorDescription: String? {
switch self {
@@ -56,6 +57,8 @@ enum SyncError: LocalizedError {
return "Secrets detected in conversations: \(secrets.joined(separator: ", ")). Remove before syncing."
case .parseError(let message):
return "Failed to parse conversation: \(message)"
case .syncInProgress:
return "A sync is already in progress. Try again in a moment."
}
}
}