siyuan-note/siyuan · error
template document tree plan requires reversible parent…
Error message
template document tree plan requires reversible parent operations
What it means
A transaction carrying a template document tree plan must have both non-empty DoOperations and UndoOperations, because the plan's created documents are appended to these lists and the parent operations define reversibility. If either list is empty the kernel cannot fold the plan into a reversible transaction and rejects it.
Solutions
- Attach the plan ID to the transaction that actually modifies the parent document (it must have both do and undo operations)
- Verify the transaction payload still contains operations after serialization before committing
- Regenerate the plan and re-render the template if the parent transaction was lost
Example fix
// before
{"transactions":[{"templateDocTreePlanID":"p1","doOps":[],"undoOps":[]}]}
// after
{"transactions":[{"templateDocTreePlanID":"p1","doOps":[insertOps],"undoOps":[deleteOps]}]} Defensive patterns
Strategy: validation
Validate before calling
if (!tx.doOperations.length || !tx.undoOperations.length) throw new Error('plan transaction needs reversible parent operations') Type guard
null
Try / catch
try { commit(tx) } catch (e) { if (String(e).includes('reversible parent operations')) { rebuildParentOps(tx); commit(tx) } else { throw e } } Prevention
- Attach the plan ID to the parent-document editing transaction, not to an empty one
- Verify do/undo operations survive your serialization layer
- Build transactions through the standard kernel API instead of hand-rolling
When it happens
Trigger: Committing a transaction whose only payload is a TemplateDocTreePlanID with no parent document operations (empty DoOperations or UndoOperations), e.g. the client sent the plan ID without the corresponding document-update operations.
Common situations: Frontend bug where the plan ID is attached to a bare transaction; operations were stripped by serialization; plugin constructed the transaction manually and forgot the undo operations.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- a document tree plan must be applied in a single transaction
- invalid database binding replay
- load template document tree parent snapshot failed
- template document tree parent snapshot is invalid
- template document tree plan contains an invalid document…
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/43a964ddc5837c2f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:467
func AttachTemplateDocTreePlans(transactions []*Transaction) (attached bool, err error) {
var target *Transaction
for _, transaction := range transactions {
if nil == transaction || "" == transaction.TemplateDocTreePlanID {
continue
}
if nil != target || 1 != len(transactions) {
return false, errors.New("a document tree plan must be applied in a single transaction")
}
target = transaction
}
if nil == target {
return false, nil
}
if target.isReplay {
return false, errors.New("template document tree plans cannot be attached to replay transactions")
}
if 0 == len(target.DoOperations) || 0 == len(target.UndoOperations) {
return false, errors.New("template document tree plan requires reversible parent operations")
}
if err = validateTemplateDocTreeParentOperations(target); nil != err {
return false, err
}
for _, operation := range append(append([]*Operation{}, target.DoOperations...), target.UndoOperations...) {
if nil != operation && ("restoreCreatedDoc" == operation.Action || "removeCreatedDoc" == operation.Action) {
return false, errors.New("template document tree transaction contains a reserved operation")
}
}
planID := target.TemplateDocTreePlanID
target.TemplateDocTreePlanID = ""
value, loaded := templateDocTreePlans.LoadAndDelete(planID)
if !loaded {
return false, errors.New("template document tree plan is missing or has expired")
}
plan, ok := value.(*templateDocTreePlan)
if !ok || plan.id != planID || time.Now().After(plan.expiresAt) {View on GitHub (pinned to 9f775e8a12)