From 38230547d607a01baba2784c03bf57ed41e05532 Mon Sep 17 00:00:00 2001 From: Ash Brener Date: Wed, 28 Jan 2026 14:49:31 +0200 Subject: [PATCH] fix: skip sync if already in progress, clear locks only on startup --- src/gateway/workspace-sync-manager.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gateway/workspace-sync-manager.ts b/src/gateway/workspace-sync-manager.ts index 0b15c8cdf..d08e60c7e 100644 --- a/src/gateway/workspace-sync-manager.ts +++ b/src/gateway/workspace-sync-manager.ts @@ -31,6 +31,7 @@ type SyncManagerState = { syncCount: number; errorCount: number; hasSuccessfulSync: boolean; + syncInProgress: boolean; }; const state: SyncManagerState = { @@ -40,6 +41,7 @@ const state: SyncManagerState = { syncCount: 0, errorCount: 0, hasSuccessfulSync: false, + syncInProgress: false, }; let currentConfig: MoltbotConfig | null = null; @@ -55,11 +57,14 @@ async function runSync(): Promise { const syncConfig = currentConfig.workspace?.sync; if (!syncConfig?.provider || syncConfig.provider === "off") return; - const logger = currentLogger; + // Skip if a sync is already in progress + if (state.syncInProgress) { + currentLogger.info("[workspace-sync] Sync already in progress, skipping"); + return; + } - // Clear any stale locks before attempting sync - // (handles case where prior sync failed and left a lock behind) - clearStaleLocks(logger); + const logger = currentLogger; + state.syncInProgress = true; try { // Check if rclone is available @@ -133,6 +138,8 @@ async function runSync(): Promise { logger.error( `[workspace-sync] Periodic sync error: ${err instanceof Error ? err.message : String(err)}`, ); + } finally { + state.syncInProgress = false; } }