{"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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/transaction.go","lineNumber":2680,"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":2662,"sourceCodeEnd":2698,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/transaction.go#L2662-L2698","documentation":"During rollback/undo handling of template-created documents, the kernel removes the previously created document via removeCreatedDoc, which must return the removed tree so it can be recorded in attemptedRemovedDocs. If removal reports success but returns a nil tree, the kernel's internal invariant is broken and it fails with this error instead of proceeding with a missing snapshot.","triggerScenarios":"Commit path where a created doc is being removed (undo of template creation) and removeCreatedDoc(box, tree.Path, lute) returns (nil, nil) — an unexpected internal result, e.g. the remove implementation found nothing to snapshot despite no error.","commonSituations":"Concurrent deletion of the same created document by another client between creation and rollback; index/disk disagreement so removal succeeds logically but cannot produce the tree; a bug in the pluggable removeCreatedDoc implementation.","solutions":["Refresh/reindex the notebook so disk state and index agree, then retry the rollback/undo","Check whether the document was already deleted by another client or sync; if so, skip the stale undo operation","Inspect kernel logs around removeCreatedDoc to determine why a successful removal produced no tree; report as a kernel bug if reproducible from normal flows"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const docExists = await fetchPost('/api/filetree/getDoc', {id: createdDocId});\nif (docExists.code === 0) throw new Error('doc already removed elsewhere');","typeGuard":null,"tryCatchPattern":"try {\n  await undoTemplateCreation(createdDocId);\n} catch (e) {\n  if (String(e.message).includes('removed created document snapshot is missing')) {\n    await reindexNotebook(boxId);\n    await undoTemplateCreation(createdDocId); // retry once after refresh\n  } else { throw e; }\n}","preventionTips":["Avoid concurrent deletion of the same generated document from multiple clients","Keep the index consistent with disk (refresh after external file changes)","Report reproducible occurrences; success-with-nil-tree indicates an internal defect"],"tags":["transaction","rollback","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}