{"record":{"id":"9f505d1aab955f8f","repo":"siyuan-note/siyuan","slug":"verify-created-shorthand-document-s-failed","errorCode":null,"errorMessage":"verify created shorthand document [%s] failed","messagePattern":"verify created shorthand document \\[(.+?)\\] failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/shortcuts.go","lineNumber":328,"sourceCode":"\tbox.setSortByConf(path.Dir(bt.Path), retID)\n\n\tFlushTxQueue()\n\tPushCreate(box, bt.Path, nil)\n\treturn\n}\n\nfunc verifyShorthandDocPersisted(bt *treenode.BlockTree, expectedID string) (err error) {\n\tif nil == bt {\n\t\treturn fmt.Errorf(\"get block tree by id [%s] failed after create\", expectedID)\n\t}\n\t// 清除写入缓存，确保从文件系统重新读取并验证文档。\n\tcache.RemoveTreeDataInBox(expectedID, bt.BoxID)\n\tpersisted, err := loadTreeByBlockTree(bt)\n\tif nil != err {\n\t\treturn fmt.Errorf(\"load created shorthand document [%s] failed: %w\", expectedID, err)\n\t}\n\tif nil == persisted || persisted.ID != expectedID {\n\t\treturn fmt.Errorf(\"verify created shorthand document [%s] failed\", expectedID)\n\t}\n\treturn nil\n}\n\nvar consumeShorthandsLock = sync.Mutex{}\nvar shorthandSaveBoxUnavailableNotified bool\n\nfunc isShorthandSaveBoxAvailable(box *Box) bool {\n\treturn nil != box && !box.Closed && !box.Encrypted && !IsUserGuide(box.ID)\n}\n\nfunc selectShorthandSaveBox(configuredID string, boxes []*Box) *Box {\n\tif \"\" != configuredID {\n\t\tfor _, box := range boxes {\n\t\t\tif nil != box && box.ID == configuredID && isShorthandSaveBoxAvailable(box) {\n\t\t\t\treturn box\n\t\t\t}\n\t\t}","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/shortcuts.go#L310-L346","documentation":"Final verification step: after reloading the created shorthand document from disk, the tree must exist and its root ID must equal the expected document ID. If the tree is nil or the IDs differ, the created document did not persist correctly and \"verify created shorthand document [%s] failed\" is returned.","triggerScenarios":"loadTreeByBlockTree succeeds but returns a tree whose ID differs from expectedID — a document was created under a different ID than the one handed to verification, or the file on disk belongs to another/replaced document (e.g. overwritten by a concurrent create or sync).","commonSituations":"Concurrent document creation reusing paths so the loaded tree is a different document; ID mismatch between createDocsByHPathSync's return value and the persisted tree root; sync overwriting the new file with an older version.","solutions":["Re-run the creation and compare the returned ID with the persisted tree ID; investigate the mismatch source","Avoid concurrent creates on the same hPath while shorthand import runs","Check sync/history for an overwrite of the newly created document and restore it if needed"],"exampleFix":"// before\nretID, _ := createDocsByHPathSync(...)  // assume retID == persisted root\n// after\nif persisted == nil || persisted.ID != expectedID {\n    logging.LogErrorf(\"id mismatch: expected %s got %v\", expectedID, persisted)\n}","handlingStrategy":"try-catch","validationCode":"// compare the create call's returned ID with the ID you pass to verification\nif (returnedID !== expectedID) throw new Error('create returned a different doc ID')","typeGuard":"function idMatches(persisted, expectedID) { return persisted != null && persisted.ID === expectedID }","tryCatchPattern":"try { await createShorthand(boxID, hPath, dom) } catch (e) { if (String(e).includes('verify created shorthand document')) { await api.exitSiYuan(); /* or */ flagDataIntegrityIssue(e); } throw e }","preventionTips":["Never run concurrent creates targeting the same hPath","Pause sync during bulk shorthand import to avoid file overwrites","Treat persistent ID mismatches as data-integrity incidents and check sync/history"],"tags":["persistence","id-mismatch","siyuan"],"backgroundTag":"internal-invariant-violation","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"}