thedotmack/claude-mem · error

cloud sync identity unavailable; refusing an unreplicated…

Error message

cloud sync identity unavailable; refusing an unreplicated delete

What it means

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.

Solutions

  1. Complete cloud sync setup/registration so the device obtains a deviceId, then retry the delete
  2. Check the sync status endpoint/logs to see why identity registration failed (auth token, network, server reachability)
  3. Re-run the initial sync or re-pair the device with the sync server
  4. As a last resort, disable cloud sync for this store if you accept the delete being unreplicated

Example fix

// before
deleteSyncedContent(...) // 503: no deviceId
// after
await cloudSync.register();            // obtain deviceId
if (cloudSync.status().deviceId) {
  deleteSyncedContent(store, kind, table, originLocalId);
}
Defensive patterns

Strategy: retry

Validate before calling

const status = await getCloudSyncStatus();
if (status.configured && !status.deviceId) throw new Error('Sync identity not registered yet; complete initial sync before deleting synced content');

Type guard

function hasSyncIdentity(s: { configured: boolean; deviceId?: string | null }): s is { configured: true; deviceId: string } {
  return s.configured && typeof s.deviceId === 'string' && s.deviceId.length > 0;
}

Try / catch

const res = await fetch(`/api/observations/${id}`, { method: 'DELETE' });
if (res.status === 503) {
  // identity unavailable: schedule retry after sync registration completes
  await waitForSyncIdentity();
  return deleteObservation(id);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/71f577c2f556a7b4. Report an issue: GitHub.

Appendix: source

Thrown at src/services/worker/http/routes/DataRoutes.ts:362

      this.badRequest(res, 'id must be a positive canonical decimal string');
      return;
    }

    const store = this.dbManager.getSessionStore();
    const row = store.db.prepare(`
      SELECT CAST(id AS TEXT) AS id FROM ${table}
      WHERE id = ? AND origin_device_id IS NULL
    `).get(originLocalId) as { id: string } | undefined;
    if (!row) {
      this.notFound(res, `${kind} #${originLocalId} not found`);
      return;
    }

    const cloudSync = this.dbManager.getCloudSync();
    let entityRev: string | null = null;
    if (cloudSync?.isConfigured()) {
      if (!cloudSync.status().deviceId) {
        res.status(503).json({ error: 'cloud sync identity unavailable; refusing an unreplicated delete' });
        return;
      }
      entityRev = cloudSync.queueDelete(kind, originLocalId);
    } else {
      // A row with an acknowledged entity head must never be silently deleted
      // while its sync identity is unavailable: that would strand replicas.
      const acknowledged = store.db.prepare(`
        SELECT 1 AS found FROM sync_entity_heads
        WHERE kind = ? AND origin_local_id = ? LIMIT 1
      `).get(kind, originLocalId) as { found: number } | undefined;
      if (acknowledged) {
        res.status(503).json({ error: 'cloud sync unavailable; refusing an unreplicated delete' });
        return;
      }
      store.db.prepare(
        `DELETE FROM ${table} WHERE id = ? AND origin_device_id IS NULL`
      ).run(originLocalId);
    }

View on GitHub (pinned to d8bc9755e7)