{"record":{"id":"9ab3959b09174911","repo":"MemPalace/mempalace","slug":"pgvector-marker-is-unreadable-marker-path","errorCode":null,"errorMessage":"pgvector marker is unreadable: {marker_path}","messagePattern":"pgvector marker is unreadable: (.+?)","errorType":"exception","errorClass":"BackendMismatchError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/pgvector.py","lineNumber":1419,"sourceCode":"                \"table_prefix\": self._table_prefix(palace=palace, config=config),\n            }\n        )\n        return target\n\n    def _marker_exists(self, palace: PalaceRef) -> bool:\n        return bool(palace.local_path and os.path.isfile(self._marker_path(palace.local_path)))\n\n    def _read_marker(self, palace: PalaceRef) -> Optional[dict]:\n        if not palace.local_path:\n            return None\n        marker_path = self._marker_path(palace.local_path)\n        if not os.path.isfile(marker_path):\n            return None\n        try:\n            with open(marker_path, encoding=\"utf-8\") as f:\n                marker = json.load(f)\n        except (OSError, json.JSONDecodeError) as exc:\n            raise BackendMismatchError(f\"pgvector marker is unreadable: {marker_path}\") from exc\n        return marker if isinstance(marker, dict) else {}\n\n    def _validate_marker_target(self, palace: PalaceRef, config: _PgVectorConfig) -> None:\n        marker = self._read_marker(palace)\n        if marker is None:\n            return\n        if marker.get(\"backend\") != self.name:\n            raise BackendMismatchError(\"pgvector marker does not identify the pgvector backend\")\n        expected = self._marker_target(palace, config)\n        actual = marker.get(\"pgvector\")\n        if not isinstance(actual, dict):\n            raise BackendMismatchError(\"pgvector marker is missing target metadata\")\n        mismatched = [\n            key for key, expected_value in expected.items() if actual.get(key) != expected_value\n        ]\n        if mismatched:\n            details = \", \".join(mismatched)\n            raise BackendMismatchError(","sourceCodeStart":1401,"sourceCodeEnd":1437,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/pgvector.py#L1401-L1437","documentation":"The pgvector backend stores a marker JSON file inside the local palace directory to pin the palace to a specific database (DSN + namespace). When that file exists but cannot be read (I/O error) or does not parse as JSON, the backend raises BackendMismatchError rather than guessing — a corrupt anchor is treated as a potential wrong-database situation. The original OSError/JSONDecodeError is chained as __cause__.","triggerScenarios":"Truncation of the marker file by a crash mid-write, disk issues, manual editing that breaks JSON, or a non-UTF-8 file at <palace>/.pgvector marker path; any get_collection()/open on that palace then fails.","commonSituations":"Process killed during _write_marker; syncing the palace dir with a tool that mangles small JSON files; restoring a palace from a partial backup.","solutions":["Inspect the marker file (path is in the message) for truncation or corruption.","If the correct DSN/namespace is known, delete the corrupt marker and reopen with create=True so a fresh marker is written.","Otherwise start a fresh palace directory and re-ingest."],"exampleFix":"# before\n# marker file is corrupt JSON -> BackendMismatchError on open\ncol = palace.get_collection(\"notes\")\n\n# after\n# remove corrupt marker, then reopen with create to rewrite it\nos.remove(marker_path)\ncol = palace.get_collection(\"notes\", create=True)","handlingStrategy":"try-catch","validationCode":"import json, os\nmarker = backend._marker_path(palace.local_path)\nif os.path.isfile(marker):\n    try:\n        json.load(open(marker, encoding=\"utf-8\"))\n    except (OSError, json.JSONDecodeError):\n        os.remove(marker)  # only if you can safely re-anchor with create=True","typeGuard":null,"tryCatchPattern":"try:\n    col = palace.get_collection(\"notes\", create=True)\nexcept BackendMismatchError as e:\n    if \"unreadable\" in str(e):\n        # re-anchor: remove corrupt marker and reopen with create=True\n        raise","preventionTips":["Back up the palace marker file before any manual edits.","Never hand-edit markers; use the backend to (re)create them.","Treat marker corruption as a stop-the-world event: fix the anchor before further writes."],"tags":["pgvector","marker-file","corruption","backend-mismatch"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}