{"record":{"id":"070438c0c6b2bab0","repo":"thedotmack/claude-mem","slug":"sync-hub-epoch-changed-cursor-reset-full-re-pul","errorCode":null,"errorMessage":"Sync hub epoch changed — cursor reset, full re-pull required, eligible native revisions requeued","messagePattern":"Sync hub epoch changed — cursor reset, full re-pull required, eligible native revisions requeued","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/sync/SyncApply.ts","lineNumber":404,"sourceCode":"                SELECT 1\n                FROM sync_launch_exclusions AS launch\n                WHERE launch.kind = ?\n                  AND launch.origin_local_id = CAST(${table}.id AS TEXT)\n                  AND (\n                    LENGTH(launch.through_rev) > LENGTH(CAST(${table}.sync_rev AS TEXT))\n                    OR (\n                      LENGTH(launch.through_rev) = LENGTH(CAST(${table}.sync_rev AS TEXT))\n                      AND launch.through_rev >= CAST(${table}.sync_rev AS TEXT)\n                    )\n                  )\n              )\n          `).run(kind).changes;\n        }\n      }\n    });\n    tx();\n    if (stored !== null) {\n      logger.warn('SYNC_APPLY', 'Sync hub epoch changed — cursor reset, full re-pull required, eligible native revisions requeued', {\n        oldEpoch: stored,\n        newEpoch: epoch,\n        requeued,\n      });\n      return true;\n    }\n    logger.info('SYNC_APPLY', 'Adopted initial sync hub epoch', { epoch });\n    return false;\n  }\n\n  // -------------------------------------------------------------------------\n  // applyOps\n  // -------------------------------------------------------------------------\n\n  /**\n   * Apply one pulled batch. Ops must be in ascending seq order (the hub\n   * returns them that way). Runs in ONE transaction: row upserts, mutation\n   * UPDATEs, and the cursor advance commit together or roll back together.","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/sync/SyncApply.ts#L386-L422","documentation":"SyncApply detects that the hub epoch stored locally differs from the epoch reported by the hub, meaning the hub's change history was reset or replaced. The library resets the sync cursor and requeues eligible native revisions because incremental deltas are no longer valid against the new epoch. This is a warning, not a crash: applyOps continues after performing the reset inside a transaction.","triggerScenarios":"applyOps -> handleEpoch when the locally stored epoch is non-null and the incoming hub epoch differs (hub server was recreated, its database wiped/re-seeded, or a different backend URL now serves a fresh epoch).","commonSituations":"Developer points the worker at a new/reset sync hub, restores the hub DB from a snapshot with a different epoch, or runs against a staging hub after previously syncing with production.","solutions":["Accept the full re-pull: let the client re-pull all data from the new epoch (this is the designed recovery path).","Verify the hub URL/DB is the intended one — confirm you did not accidentally point at a fresh or staging hub.","If the epoch change was unintentional (hub rebuilt), restore the hub database that matches the stored epoch.","If old requeued revisions conflict, clear local sync state and perform a clean initial sync."],"exampleFix":"// before: stale hub URL in config\nhubUrl: 'https://sync-staging.internal'\n// after: point back at the hub holding the matching epoch\nhubUrl: 'https://sync-prod.internal'","handlingStrategy":"fallback","validationCode":"const stored = loadStoredEpoch();\nif (stored !== null && stored !== hubEpoch) {\n  console.warn('Epoch mismatch: full re-pull will occur');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the hub URL/instance and avoid switching between environments mid-sync","Back up the hub DB before rebuilds to preserve the epoch","Monitor for epoch-change warnings as a signal of hub rebuilds"],"tags":["sync","state-reset","distributed-systems"],"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"}