siyuan-note/siyuan · error
template document tree plan parent operations are not…
Error message
template document tree plan parent operations are not reversible
What it means
For every do-operation the validator looks up undoOperations[inverseAction\x00ID]; if no matching undo operation exists (count below 1), the transaction is not reversible and the plan cannot be attached. The plan machinery appends restoreCreatedDoc/removeCreatedDoc pairs and assumes the surrounding parent transaction can itself be undone operation-by-operation.
Solutions
- For each do operation, add the inverse undo operation (insert->delete, delete->insert, update->update, foldHeading<->unfoldHeading, setAttrs->setAttrs) with the same operation ID
- Keep do/undo construction in a single helper so IDs always match
- Verify pairing by checking each do op's ID appears in an undo op before calling AttachTemplateDocTreePlans
Example fix
// before: insert without undo
ops.DoOperations = []*Operation{{Action: "insert", ID: id}}
// after
ops.DoOperations = []*Operation{{Action: "insert", ID: id}}
ops.UndoOperations = []*Operation{{Action: "delete", ID: id}} Defensive patterns
Strategy: validation
Validate before calling
undoByID := map[string]string{}
for _, op := range tx.UndoOperations {
undoByID[op.Action+"\x00"+op.ID] = op.Action
}
for _, op := range tx.DoOperations {
inv := inverseOf(op.Action)
if _, ok := undoByID[inv+"\x00"+op.ID]; !ok {
return fmt.Errorf("do op %s (%s) has no inverse undo", op.ID, op.Action)
}
} Prevention
- Create do/undo pairs together with shared IDs
- Verify inverse pairing before attaching plans
- Avoid incrementally building undo stacks across retries
When it happens
Trigger: Attaching a plan to a transaction whose DoOperations include an operation whose matching inverse (per inverseActions) is absent from UndoOperations, e.g. a do 'insert' with no undo 'delete' carrying the same ID, or the undo entry uses a different action pairing than the map expects.
Common situations: Hand-built transactions where undo entries were generated with mismatched IDs; partially recorded undo stacks after an earlier failure; plugin code appending do operations without adding the inverse undo entries.
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
- block position changed since conversion
- block swap ID already exists
- block swap insertion position has changed
- template document tree plan contains an invalid document…
- template document tree plan contains an invalid parent undo…
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/87b2323f4eb96261.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:561
}
undoOperations[operation.Action+"\x00"+operation.ID]++
}
hasContentMutation := false
for _, operation := range transaction.DoOperations {
if nil == operation || "" == operation.ID {
return errors.New("template document tree plan contains an invalid parent operation")
}
inverseAction, supported := inverseActions[operation.Action]
if !supported || "" != operation.RootID {
return errors.New("template document tree plan contains an unsupported parent operation")
}
if "insert" == operation.Action || "delete" == operation.Action || "update" == operation.Action {
hasContentMutation = true
}
key := inverseAction + "\x00" + operation.ID
if 1 > undoOperations[key] {
return errors.New("template document tree plan parent operations are not reversible")
}
undoOperations[key]--
}
if !hasContentMutation {
return errors.New("template document tree plan requires a parent content operation")
}
for _, count := range undoOperations {
if 0 != count {
return errors.New("template document tree plan parent operations are not reversible")
}
}
return nil
}
func transactionTargetsTemplateRoot(transaction *Transaction, rootID, boxID string) bool {
matched := false
for operationSetIndex, operations := range [][]*Operation{transaction.DoOperations, transaction.UndoOperations} {
for _, operation := range operations {View on GitHub (pinned to 9f775e8a12)