{"record":{"id":"0d57b24a31c4ad90","repo":"MemPalace/mempalace","slug":"path-is-corrupt-exc-refusing-to-mint-a-seco","errorCode":null,"errorMessage":"{path} is corrupt ({exc}); refusing to mint a second replica identity for this palace — restore or delete the file explicitly","messagePattern":"(.+?) is corrupt \\((.+?)\\); refusing to mint a second replica identity for this palace — restore or delete the file explicitly","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mempalace/replica.py","lineNumber":45,"sourceCode":"def _mint() -> str:\n    return f\"rep_{secrets.token_hex(16)}\"\n\n\ndef get_replica_id(palace_path: str) -> str:\n    \"\"\"Return this palace's stable replica id, minting it on first use.\n\n    The file is written atomically (tmp + rename) so a crash mid-mint can\n    never leave a half-written identity; a corrupt or foreign-shaped file\n    fails loudly rather than silently minting a second identity — two ids\n    for one replica would fork its op-log provenance.\n    \"\"\"\n    path = Path(os.path.expanduser(palace_path)) / REPLICA_FILENAME\n    if path.exists():\n        try:\n            data = json.loads(path.read_text(encoding=\"utf-8\"))\n            replica_id = data[\"replica_id\"]\n        except (ValueError, KeyError, TypeError) as exc:\n            raise ValueError(\n                f\"{path} is corrupt ({exc}); refusing to mint a second replica \"\n                \"identity for this palace — restore or delete the file explicitly\"\n            ) from None\n        if not isinstance(replica_id, str) or not _REPLICA_ID_RE.match(replica_id):\n            raise ValueError(\n                f\"{path} holds an invalid replica_id {replica_id!r}; refusing to \"\n                \"mint a second identity — restore or delete the file explicitly\"\n            )\n        return replica_id\n\n    path.parent.mkdir(parents=True, exist_ok=True)\n    replica_id = _mint()\n    tmp = path.with_suffix(\".json.tmp\")\n    tmp.write_text(\n        json.dumps({\"replica_id\": replica_id, \"minted_at_note\": \"RFC 004 step 0\"}, indent=2) + \"\\n\",\n        encoding=\"utf-8\",\n    )\n    os.replace(tmp, path)","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/replica.py#L27-L63","documentation":"Error \"{path} is corrupt ({exc}); refusing to mint a second replica identity for this palace — restore or delete the file explicitly\" thrown in MemPalace/mempalace.","triggerScenarios":"Thrown at mempalace/replica.py:45 when the library encounters an invalid state.","commonSituations":"Replica identity file is corrupt; auto-overwriting could split-brain the replica set.","solutions":["Restore the identity file from backup or delete it explicitly to mint a fresh replica identity"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}