{"record":{"id":"feb9b24224672b72","repo":"siyuan-note/siyuan","slug":"invalid-encrypted-index-compatibility-metadata","errorCode":null,"errorMessage":"invalid encrypted index compatibility metadata","messagePattern":"invalid encrypted index compatibility metadata","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/encrypted_index.go","lineNumber":56,"sourceCode":"\t\tif err = db.QueryRow(\"SELECT count(*) FROM sqlite_master WHERE type = 'table'\").Scan(&tables); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif tables != 0 {\n\t\t\treturn errors.New(\"encrypted index has no compatibility metadata\")\n\t\t}\n\t\tif _, err = db.Exec(\"CREATE TABLE encrypted_index_meta (kind TEXT NOT NULL, schema_version INTEGER NOT NULL, cipher_settings TEXT NOT NULL)\"); err != nil {\n\t\t\treturn err\n\t\t}\n\t\t_, err = db.Exec(\"INSERT INTO encrypted_index_meta VALUES (?, ?, ?)\", kind, schema, string(encoded))\n\t\treturn err\n\t}\n\tvar storedKind, storedSettings string\n\tvar storedSchema, rows int\n\tif err = db.QueryRow(\"SELECT count(*) FROM encrypted_index_meta\").Scan(&rows); err != nil {\n\t\treturn err\n\t}\n\tif rows != 1 {\n\t\treturn errors.New(\"invalid encrypted index compatibility metadata\")\n\t}\n\tif err = db.QueryRow(\"SELECT kind, schema_version, cipher_settings FROM encrypted_index_meta\").Scan(&storedKind, &storedSchema, &storedSettings); err != nil {\n\t\treturn err\n\t}\n\tif storedKind != kind || storedSchema != schema || storedSettings != string(encoded) {\n\t\treturn errors.New(\"incompatible encrypted index\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":38,"sourceCodeEnd":66,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/encrypted_index.go#L38-L66","documentation":"The encrypted_index_meta table must contain exactly one row holding the index kind, schema version, and cipher settings. Zero rows (empty table) or multiple rows mean the compatibility metadata is corrupted or was written incorrectly, so the kernel cannot authenticate the index and refuses to open it.","triggerScenarios":"Opening an encrypted index where SELECT count(*) FROM encrypted_index_meta returns anything other than 1 — duplicated metadata rows from a failed partial write, a manually truncated/cleared meta table, or corruption after a crash during meta-table creation.","commonSituations":"Interrupted index creation leaving an empty meta table; concurrent processes writing metadata twice; manual SQL manipulation of the index database; disk corruption.","solutions":["Discard the index and let the kernel rebuild it from the authenticated source documents (delete the affected index DB and restart)","Restore the database from sync or history backup","Avoid opening the same workspace with multiple kernel processes concurrently","Check disk/filesystem health if corruption recurs"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"var rows int\ndb.QueryRow(\"SELECT count(*) FROM encrypted_index_meta\").Scan(&rows)\nif rows != 1 { /* metadata corrupted: rebuild index from source */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid running multiple kernel instances against one workspace","Protect the data directory from disk corruption (monitor disk health)","Do not run ad-hoc SQL against index databases"],"tags":["database","encryption","metadata","corruption"],"backgroundTag":"schema-validation-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}