{"record":{"id":"1211bfb2604fb012","repo":"siyuan-note/siyuan","slug":"template-document-tree-plan-is-invalid-or-has-expi","errorCode":null,"errorMessage":"template document tree plan is invalid or has expired","messagePattern":"template document tree plan is invalid or has expired","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":486,"sourceCode":"\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}\n\tfor _, tree := range plan.trees {\n\t\tif nil == tree || nil == tree.Root || tree.ID != tree.Root.ID || tree.Box != plan.boxID || box.Exist(tree.Path) {\n\t\t\treturn false, errors.New(\"template document tree plan contains an invalid document snapshot\")\n\t\t}","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L468-L504","documentation":"After the plan record is found, its contents are validated: it must be a *templateDocTreePlan, its stored id must equal the requested plan ID, and the current time must be before plan.expiresAt. Any mismatch — corrupted registry value, forged ID, or expired plan — produces this error.","triggerScenarios":"Committing a transaction whose plan TTL elapsed between render and commit, or whose registry entry was replaced with a different object/id, or sending a mismatched plan ID.","commonSituations":"Slow network or user hesitation past the expiry window; multiple windows/devices sharing one workspace where another consumer deleted the entry; clock skew on the machine.","solutions":["Re-render the template to obtain a new, valid plan and commit right away","Check system clock skew if commits are made near the expiry boundary","Ensure only one client consumes the plan (single window/device per workspace while applying)"],"exampleFix":"// before\ncommitLater(tx, planID, hours(2)) // plan expired\n// after\nplanID := render(...); commit(txWith(planID)) // commit within TTL","handlingStrategy":"retry","validationCode":"if (Date.now() > planExpiresAtMs(planId)) { planId = await renderTemplateDocTree(); }","typeGuard":"null","tryCatchPattern":"try { commit(txWith(planId)) } catch (e) { if (String(e).includes('invalid or has expired')) { planId = await renderTemplateDocTree(); commit(txWith(planId)) } else { throw e } }","preventionTips":["Know the plan TTL and commit well within it","Keep the workspace clock accurate","Avoid committing stale plans after long idle periods"],"tags":["transaction","expiry","template"],"backgroundTag":"jwt-token-expired","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"}