{"record":{"id":"03f2e5c69492807e","repo":"siyuan-note/siyuan","slug":"removed-created-document-snapshot-is-missing","errorCode":null,"errorMessage":"removed created document snapshot is missing","messagePattern":"removed created document snapshot is missing","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/transaction.go","lineNumber":2768,"sourceCode":"\tfor _, tree := range tx.removedTemplateCreatedDocs {\n\t\tif nil == tree {\n\t\t\tcontinue\n\t\t}\n\t\tattemptedRemovedDocs = append(attemptedRemovedDocs, tree)\n\t\tbox := Conf.Box(tree.Box)\n\t\tif nil == box {\n\t\t\treturn ErrBoxNotFound\n\t\t}\n\t\tremoveCreatedDoc := tx.removeCreatedDoc\n\t\tif nil == removeCreatedDoc {\n\t\t\tremoveCreatedDoc = removeDoc\n\t\t}\n\t\tremovedTree, removeErr := removeCreatedDoc(box, tree.Path, util.NewLute())\n\t\tif nil != removeErr {\n\t\t\treturn removeErr\n\t\t}\n\t\tif nil == removedTree {\n\t\t\treturn errors.New(\"removed created document snapshot is missing\")\n\t\t}\n\t\tattemptedRemovedDocs[len(attemptedRemovedDocs)-1] = removedTree\n\t\trefreshBoxDocInfo(removedTree)\n\t}\n\n\tvar orderedTrees []*parse.Tree\n\trestoredIDs := map[string]struct{}{}\n\tfor _, tree := range tx.restoredTemplateCreatedDocs {\n\t\tif nil == tree {\n\t\t\tcontinue\n\t\t}\n\t\tif current := tx.trees[tree.ID]; nil != current {\n\t\t\torderedTrees = append(orderedTrees, current)\n\t\t\trestoredIDs[tree.ID] = struct{}{}\n\t\t}\n\t}\n\tfor id, tree := range tx.trees {\n\t\tif _, restored := restoredIDs[id]; !restored {","sourceCodeStart":2750,"sourceCodeEnd":2786,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/transaction.go#L2750-L2786","documentation":"When a template-created document must be rolled back, removeCreatedDoc deletes it and is expected to return the removed tree. A nil tree with no error is treated as a broken compensation step — the code cannot record the removed document in attemptedRemovedDocs without its snapshot, so the rollback aborts with this error.","triggerScenarios":"Calling the compensation/undo path where removeCreatedDoc(box, tree.Path, lute) succeeds but returns nil — the removal routine did not return the deleted tree snapshot as its contract requires.","commonSituations":"Internal invariant breakage in the removal path (document already gone so nothing meaningful to return); partially failed transaction compensation; disk state diverging from the in-memory trees.","solutions":["Inspect removeCreatedDoc to see why it returned nil despite no error","Check whether the created doc was already deleted by another process before rollback","Re-run transaction rollback after refreshing the notebook state","Rebuild the index to reconcile disk and blocktree state"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func hasRemovedTree(t *parse.Tree) bool { return t != nil }","tryCatchPattern":"if err := rollback(); err != nil && strings.Contains(err.Error(), \"removed created doc snapshot is missing\") { refreshBoxDocInfo(); retryRollback() }","preventionTips":["Keep removeCreatedDoc's contract: always return the removed tree on success","Refresh notebook state before compensation runs","Guard against double-deletion by checking existence before removing","Add a test covering rollback when the created doc is already gone"],"tags":["transaction","rollback","invariant"],"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"}