{"record":{"id":"178e062c06c5c1dc","repo":"siyuan-note/siyuan","slug":"get-block-tree-by-id-s-failed-after-create","errorCode":null,"errorMessage":"get block tree by id [%s] failed after create","messagePattern":"get block tree by id \\[(.+?)\\] failed after create","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/shortcuts.go","lineNumber":319,"sourceCode":"\tretID, err = createDocsByHPathSync(box.ID, hPath, dom, \"\", docID, false)\n\tif nil != err {\n\t\treturn\n\t}\n\n\tbt := treenode.GetBlockTree(retID)\n\tif err = verifyShorthandDocPersisted(bt, retID); nil != err {\n\t\treturn\n\t}\n\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)","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/shortcuts.go#L301-L337","documentation":"After creating a shorthand document the code verifies persistence. verifyShorthandDocPersisted is given the block tree record of the newly created document; if that record is nil (the block tree never registered the new document ID), it returns \"get block tree by id [%s] failed after create\" — the create apparently succeeded but left no index entry.","triggerScenarios":"createShorthandDocByDOM completes but treenode.GetBlockTree(returnedID) returns nil — e.g. the block tree index was not flushed, the create transaction was lost, or an ID mismatch between the created doc and the indexed record.","commonSituations":"Index/queue races under heavy load; crashes between writing the .sy file and updating blocktree.db; corrupt blocktree.db missing recent entries.","solutions":["Retry the shorthand document creation; the second pass usually rebuilds the index entry","Rebuild the block tree index (reindex the notebook) if entries are persistently missing","Check for errors from the create path (createDocsByHPathSync) that may have been swallowed"],"exampleFix":"// before\nbt := treenode.GetBlockTree(retID)\nerr = verifyShorthandDocPersisted(bt, retID)\n// after\nbt := treenode.GetBlockTree(retID)\nif bt == nil {\n    treenode.IndexTree(boxID) // force reindex, then retry\n    bt = treenode.GetBlockTree(retID)\n}\nerr = verifyShorthandDocPersisted(bt, retID)","handlingStrategy":"retry","validationCode":"const bt = await api.getBlockTree(retID)\nif (!bt) { await api.reindex(boxID); }","typeGuard":"function hasBlockTree(bt) { return bt != null && !!bt.id && !!bt.path }","tryCatchPattern":"try { await createShorthand(boxID, hPath, dom) } catch (e) { if (String(e).includes('failed after create')) { await sleep(1000); return createShorthand(boxID, hPath, dom); } throw e }","preventionTips":["Allow the index queue a moment to flush before verifying persistence","Rebuild indexes if blocktree.db entries go missing repeatedly","Avoid killing the app between create and verification steps"],"tags":["index","persistence","siyuan"],"backgroundTag":"record-not-found","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"}