Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(backup): leave CoS config alone when a pre-split restore transfer fails
Adam Eivy898ef858785a
diff --git a/server/services/cosState.js b/server/services/cosState.jsindex d92d240592..ff48b0bc5d 100644--- a/server/services/cosState.js+++ b/server/services/cosState.js@@ -557,10 +557,11 @@ const legacyConfigSlice = (state) => (isPlainObject(state?.config) ? JSON.string* state.json and carries no config.json. Restored over an upgraded install, the* live config.json is newer than the snapshot yet wins every read (and migration* 339 no-ops on its presence), so the restored settings were silently discarded- * and then stripped by the next saveState. Once the transfer has installed the- * snapshot's slice (a failed partial transfer may not have), move config.json- * aside — kept for manual recovery, never deleted — so readConfig() completes- * the split from the restored slice.+ * and then stripped by the next saveState. After a transfer that completed and+ * installed the snapshot's slice, move config.json aside — kept for manual+ * recovery, never deleted — so readConfig() completes the split from the+ * restored slice. A failed transfer is left alone: the live state.json may+ * already hold the same slice without this restore having installed it.*/async function supersedeConfigForRestoredLegacySlice(snapshotLegacyConfig) {if (!existsSync(STATE_FILE) || !existsSync(CONFIG_FILE)) return;@@ -599,7 +600,7 @@ export function withLiveCosRestore(transfer, { snapshotLegacyConfig = null } = {configCache = null;stateCache = null;const [reload] = await Promise.allSettled([(async () => {- if (snapshotLegacyConfig) await supersedeConfigForRestoredLegacySlice(snapshotLegacyConfig);+ if (snapshotLegacyConfig && result.status === 'fulfilled') await supersedeConfigForRestoredLegacySlice(snapshotLegacyConfig);const { reloadAgentIndexAfterRestore } = await import('./cosAgentIndex.js');await reloadAgentIndexAfterRestore();const state = await loadState();diff --git a/server/services/cosState.test.js b/server/services/cosState.test.jsindex 87d93d16b2..98d679d7c5 100644--- a/server/services/cosState.test.js+++ b/server/services/cosState.test.js@@ -420,7 +420,8 @@ describe('live CoS restore boundary', () => {it.each([{ name: 'first restore', liveSlice: null, landed: true, legacy: true, expected: 7, parked: true },{ name: 'repeat restore', liveSlice: { maxConcurrentAgents: 7 }, landed: true, legacy: true, expected: 7, parked: true },- { name: 'transfer failed first', liveSlice: null, landed: false, legacy: true, expected: 3, parked: false },+ // 339 can leave a config-first copy in both files; a failed transfer installed nothing.+ { name: 'failed transfer over a matching live slice', liveSlice: { maxConcurrentAgents: 7 }, landed: false, legacy: true, expected: 3, parked: false },{ name: 'snapshot has config.json', liveSlice: null, landed: true, legacy: false, expected: 5, parked: false },])('restores the snapshot config over a newer config.json: $name', async ({ liveSlice, landed, legacy, expected, parked }) => {writeConfig({ maxConcurrentAgents: 3 });