{"record":{"id":"71f577c2f556a7b4","repo":"thedotmack/claude-mem","slug":"cloud-sync-identity-unavailable-refusing-an-unrep","errorCode":null,"errorMessage":"cloud sync identity unavailable; refusing an unreplicated delete","messagePattern":"cloud sync identity unavailable; refusing an unreplicated delete","errorType":"http","errorClass":null,"httpStatus":503,"severity":"error","filePath":"src/services/worker/http/routes/DataRoutes.ts","lineNumber":362,"sourceCode":"      this.badRequest(res, 'id must be a positive canonical decimal string');\n      return;\n    }\n\n    const store = this.dbManager.getSessionStore();\n    const row = store.db.prepare(`\n      SELECT CAST(id AS TEXT) AS id FROM ${table}\n      WHERE id = ? AND origin_device_id IS NULL\n    `).get(originLocalId) as { id: string } | undefined;\n    if (!row) {\n      this.notFound(res, `${kind} #${originLocalId} not found`);\n      return;\n    }\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    }","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/worker/http/routes/DataRoutes.ts#L344-L380","documentation":"deleteSyncedContent refuses to delete observations/summaries/prompts when cloud sync is configured but the device has no sync identity (no deviceId). Deleting such rows would create unreplicated deletes that strand replicas, so the route returns 503 instead.","triggerScenarios":"DELETE /api/observations/:id, /api/summaries/:id, or /api/prompts/:id while cloudSync.isConfigured() is true but cloudSync.status().deviceId is null/undefined — i.e. sync is set up but the device has never completed identity registration.","commonSituations":"Cloud sync credentials configured but initial sync/registration never ran or failed; device record removed server-side; sync service temporarily unable to report its identity; fresh install with imported settings but no first sync.","solutions":["Complete cloud sync setup/registration so the device obtains a deviceId, then retry the delete","Check the sync status endpoint/logs to see why identity registration failed (auth token, network, server reachability)","Re-run the initial sync or re-pair the device with the sync server","As a last resort, disable cloud sync for this store if you accept the delete being unreplicated"],"exampleFix":"// before\ndeleteSyncedContent(...) // 503: no deviceId\n// after\nawait cloudSync.register();            // obtain deviceId\nif (cloudSync.status().deviceId) {\n  deleteSyncedContent(store, kind, table, originLocalId);\n}","handlingStrategy":"retry","validationCode":"const status = await getCloudSyncStatus();\nif (status.configured && !status.deviceId) throw new Error('Sync identity not registered yet; complete initial sync before deleting synced content');","typeGuard":"function hasSyncIdentity(s: { configured: boolean; deviceId?: string | null }): s is { configured: true; deviceId: string } {\n  return s.configured && typeof s.deviceId === 'string' && s.deviceId.length > 0;\n}","tryCatchPattern":"const res = await fetch(`/api/observations/${id}`, { method: 'DELETE' });\nif (res.status === 503) {\n  // identity unavailable: schedule retry after sync registration completes\n  await waitForSyncIdentity();\n  return deleteObservation(id);\n}","preventionTips":["Complete cloud-sync registration during onboarding before exposing delete actions","Disable delete UI while sync identity is absent","Monitor sync status and alert when deviceId is missing for an extended period","Never bypass the guard by writing raw DELETE SQL against synced tables"],"tags":["http","sync","data-integrity"],"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"}