{"record":{"id":"c5d8e7c6c016b814","repo":"siyuan-note/siyuan","slug":"template-document-tree-plan-is-missing-or-has-expi","errorCode":null,"errorMessage":"template document tree plan is missing or has expired","messagePattern":"template document tree plan is missing or has expired","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":482,"sourceCode":"\t\treturn false, errors.New(\"template document tree plans cannot be attached to replay transactions\")\n\t}\n\tif 0 == len(target.DoOperations) || 0 == len(target.UndoOperations) {\n\t\treturn false, errors.New(\"template document tree plan requires reversible parent operations\")\n\t}\n\tif err = validateTemplateDocTreeParentOperations(target); nil != err {\n\t\treturn false, err\n\t}\n\tfor _, operation := range append(append([]*Operation{}, target.DoOperations...), target.UndoOperations...) {\n\t\tif nil != operation && (\"restoreCreatedDoc\" == operation.Action || \"removeCreatedDoc\" == operation.Action) {\n\t\t\treturn false, errors.New(\"template document tree transaction contains a reserved operation\")\n\t\t}\n\t}\n\n\tplanID := target.TemplateDocTreePlanID\n\ttarget.TemplateDocTreePlanID = \"\"\n\tvalue, loaded := templateDocTreePlans.LoadAndDelete(planID)\n\tif !loaded {\n\t\treturn false, errors.New(\"template document tree plan is missing or has expired\")\n\t}\n\tplan, ok := value.(*templateDocTreePlan)\n\tif !ok || plan.id != planID || time.Now().After(plan.expiresAt) {\n\t\treturn false, errors.New(\"template document tree plan is invalid or has expired\")\n\t}\n\tif !transactionTargetsTemplateRoot(target, plan.rootID, plan.boxID) {\n\t\treturn false, errors.New(\"template document tree plan does not match the edited document\")\n\t}\n\trootTree, loadErr := LoadTreeByBlockID(plan.rootID)\n\tif nil != loadErr || nil == rootTree || rootTree.Box != plan.boxID || rootTree.Path != plan.rootPath ||\n\t\trootTree.HPath != plan.rootHPath {\n\t\treturn false, errors.New(\"the document used to render the template has changed\")\n\t}\n\ttarget.templateDocTreeRootSnapshot = rootTree\n\tbox := Conf.Box(plan.boxID)\n\tif nil == box {\n\t\treturn false, ErrBoxNotFound\n\t}","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L464-L500","documentation":"Plans are stored in a temporary registry (templateDocTreePlans) between rendering and commit, with an expiry time. When the transaction carrying TemplateDocTreePlanID arrives, the plan is loaded-and-deleted from the registry; if no entry with that ID exists, the plan was never created, was already consumed, or expired and was evicted.","triggerScenarios":"Committing a transaction whose TemplateDocTreePlanID was never registered (render step skipped), committing the same plan twice (first commit consumed it via LoadAndDelete), or waiting past the plan expiry before committing.","commonSituations":"User leaves the rendered template pending longer than the plan TTL; a network retry resubmits a transaction that already succeeded; plugin attaches a fabricated plan ID.","solutions":["Re-render the template to get a fresh plan ID, then commit immediately","Do not reuse a TemplateDocTreePlanID across commits; a plan is single-use","Commit the plan transaction promptly after rendering to stay within the expiry window"],"exampleFix":"// before\nreplayOldTx(planID) // plan already consumed\n// after\nplanID := renderTemplateDocTree(...) // fresh render\ncommit(txWith(planID))","handlingStrategy":"retry","validationCode":"const plan = lookupPlan(planId); if (!plan) { planId = await renderTemplateDocTree(); }","typeGuard":"null","tryCatchPattern":"try { commit(txWith(planId)) } catch (e) { if (String(e).includes('missing or has expired')) { planId = await renderTemplateDocTree(); commit(txWith(planId)) } else { throw e } }","preventionTips":["Treat plan IDs as single-use; never commit the same plan twice","Commit immediately after rendering to avoid registry eviction","On retry after an ambiguous failure, re-render instead of replaying the old plan ID"],"tags":["transaction","expiry","template","single-use"],"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"}