{"record":{"id":"010e786b555fcb84","repo":"siyuan-note/siyuan","slug":"template-document-tree-transaction-contains-a-rese","errorCode":null,"errorMessage":"template document tree transaction contains a reserved operation","messagePattern":"template document tree transaction contains a reserved operation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":474,"sourceCode":"\t\t\treturn false, errors.New(\"a document tree plan must be applied in a single transaction\")\n\t\t}\n\t\ttarget = transaction\n\t}\n\tif nil == target {\n\t\treturn false, nil\n\t}\n\tif target.isReplay {\n\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 ||","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L456-L492","documentation":"The action names \"restoreCreatedDoc\" and \"removeCreatedDoc\" are reserved for operations that AttachTemplateDocTreePlans itself injects when consuming a plan. If the incoming transaction already contains operations with these actions, the kernel rejects it to prevent duplicates or forged plan-side effects.","triggerScenarios":"A client crafts a transaction with hand-made restoreCreatedDoc/removeCreatedDoc operations and a TemplateDocTreePlanID; or replays a transaction that already had plan operations appended before being re-attached.","commonSituations":"Plugin reimplementing plan application by mimicking kernel operations; replaying a captured transaction payload that already contains the injected operations.","solutions":["Remove restoreCreatedDoc/removeCreatedDoc operations from the client-built transaction; let the kernel inject them from the plan","Do not re-attach a plan ID to a transaction whose operations were already augmented by a prior attach","Use standard insert/delete operations for custom document creation instead of the reserved actions"],"exampleFix":"// before\ntx.DoOperations = append(tx.DoOperations, &Operation{Action: \"restoreCreatedDoc\", ...})\n// after\n// rely on the plan: only send parent insert/delete ops + TemplateDocTreePlanID","handlingStrategy":"validation","validationCode":"const reserved = ['restoreCreatedDoc','removeCreatedDoc'];\nif (tx.operations.some(op => reserved.includes(op.action))) throw new Error('reserved plan operations must not be sent by clients')","typeGuard":"null","tryCatchPattern":"try { commit(tx) } catch (e) { if (String(e).includes('reserved operation')) { tx.operations = tx.operations.filter(op => !['restoreCreatedDoc','removeCreatedDoc'].includes(op.action)); commit(tx) } else { throw e } }","preventionTips":["Never hand-craft restoreCreatedDoc/removeCreatedDoc operations","Filter out plan-injected operations before re-submitting a previously augmented transaction","Let the kernel generate plan operations from the plan ID"],"tags":["transaction","reserved-operation","template"],"backgroundTag":"unsupported-operation","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"}