{"record":{"id":"7962282ab6a60f38","repo":"thedotmack/claude-mem","slug":"cloud-sync-unavailable-refusing-an-unreplicated-d","errorCode":null,"errorMessage":"cloud sync unavailable; refusing an unreplicated delete","messagePattern":"cloud sync unavailable; refusing an unreplicated delete","errorType":"http","errorClass":null,"httpStatus":503,"severity":"error","filePath":"src/services/worker/http/routes/DataRoutes.ts","lineNumber":374,"sourceCode":"    }\n\n    const cloudSync = this.dbManager.getCloudSync();\n    let entityRev: string | null = null;\n    if (cloudSync?.isConfigured()) {\n      if (!cloudSync.status().deviceId) {\n        res.status(503).json({ error: 'cloud sync identity unavailable; refusing an unreplicated delete' });\n        return;\n      }\n      entityRev = cloudSync.queueDelete(kind, originLocalId);\n    } else {\n      // A row with an acknowledged entity head must never be silently deleted\n      // while its sync identity is unavailable: that would strand replicas.\n      const acknowledged = store.db.prepare(`\n        SELECT 1 AS found FROM sync_entity_heads\n        WHERE kind = ? AND origin_local_id = ? LIMIT 1\n      `).get(kind, originLocalId) as { found: number } | undefined;\n      if (acknowledged) {\n        res.status(503).json({ error: 'cloud sync unavailable; refusing an unreplicated delete' });\n        return;\n      }\n      store.db.prepare(\n        `DELETE FROM ${table} WHERE id = ? AND origin_device_id IS NULL`\n      ).run(originLocalId);\n    }\n\n    res.json({ success: true, id: originLocalId, kind, entity_rev: entityRev });\n  }\n\n  private handleGetStats = this.wrapHandler((req: Request, res: Response): void => {\n    const db = this.dbManager.getSessionStore().db;\n\n    const packageRoot = getPackageRoot();\n    const packageJsonPath = path.join(packageRoot, 'package.json');\n    const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\n    const version = packageJson.version;\n","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/worker/http/routes/DataRoutes.ts#L356-L392","documentation":"deleteSyncedContent also refuses to delete a row that has an acknowledged entity head in sync_entity_heads when cloud sync is not configured/available at all. Such a row is known to replicas elsewhere; deleting it locally without sync would strand those replicas, so the route returns 503.","triggerScenarios":"DELETE of an observation/summary/prompt whose row exists in sync_entity_heads (was previously synced) while cloudSync is unconfigured (cloudSync null or isConfigured() false) — the fallback SQL check finds an acknowledged head and returns 503.","commonSituations":"User disabled or never configured cloud sync but the local database still contains rows synced by a previous configuration; switching sync backends; restoring a database from a synced device onto a machine without sync configured.","solutions":["Re-enable and configure cloud sync so the delete can be replicated, then retry","Delete the row through a device where sync is active","If the data is truly orphaned, clear the matching sync_entity_heads row first so the guard no longer sees an acknowledged head","Verify you are targeting the right record — the entity may be intentionally protected as replicated content"],"exampleFix":"// before\nstore.db.prepare('DELETE FROM observations WHERE id = ?').run(id); // 503 guard fires first\n// after\nstore.db.prepare('DELETE FROM sync_entity_heads WHERE kind = ? AND origin_local_id = ?').run(kind, id);\nstore.db.prepare('DELETE FROM observations WHERE id = ? AND origin_device_id IS NULL').run(id);","handlingStrategy":"validation","validationCode":"const head = db.prepare('SELECT 1 FROM sync_entity_heads WHERE kind = ? AND origin_local_id = ?').get(kind, id);\nif (head && !cloudSyncConfigured) throw new Error('Refusing delete: entity is replicated but sync is not configured');","typeGuard":null,"tryCatchPattern":"const res = await fetch(`/api/summaries/${id}`, { method: 'DELETE' });\nif (res.status === 503) {\n  const body = await res.json();\n  if (body.error.includes('unreplicated delete')) {\n    // re-enable sync or remove the entity head intentionally, then retry\n  }\n}","preventionTips":["Keep cloud sync configured wherever a previously-synced database is used","Treat sync_entity_heads as replication metadata — only clear it deliberately","When migrating between machines, bring the sync configuration along with the database","Surface 503 delete responses to the user instead of silently retrying forever"],"tags":["http","sync","data-integrity","database"],"backgroundTag":"invalid-state-transition","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}