siyuan-note/siyuan · error
template document tree plans cannot be attached to replay…
Error message
template document tree plans cannot be attached to replay transactions
What it means
Template document tree plans cannot be attached to transactions that are being replayed (isReplay). Replay transactions are kernel-internal redrives of earlier commits; attaching a plan there would create documents twice and corrupt undo history, so the kernel refuses.
Solutions
- Resubmit the transaction as a normal (non-replay) commit so the plan attaches and is consumed
- Clear TemplateDocTreePlanID before feeding a transaction into the replay path
- Regenerate the plan if it expired and commit once through the standard flow
Example fix
// before tx.isReplay = true; tx.TemplateDocTreePlanID = planID // after tx.isReplay = false; tx.TemplateDocTreePlanID = planID; CommitTx(tx)
Defensive patterns
Strategy: validation
Validate before calling
if (tx.isReplay && tx.templateDocTreePlanID) { delete tx.templateDocTreePlanID } Type guard
null
Try / catch
try { commit(tx) } catch (e) { if (String(e).includes('replay transactions')) { tx.templateDocTreePlanID = ''; commit(tx) } else { throw e } } Prevention
- Clear TemplateDocTreePlanID before any undo/redo replay of captured transactions
- Only attach plans at initial render-and-commit time
- Treat replay transactions as kernel-internal and never enrich them
When it happens
Trigger: A transaction carrying TemplateDocTreePlanID is passed through the replay/rollback machinery instead of a normal commit — e.g. the plan ID survived into a transaction reconstructed during undo/redo replay.
Common situations: Undo/redo of a commit whose payload still contains the plan ID because AttachTemplateDocTreePlans was never allowed to consume it; custom client code re-submitting an old transaction payload.
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/152dafca90255f38.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:464
}
// AttachTemplateDocTreePlans 将一次性计划转换为内核事务操作,父文档内容与全部子文档共用一条撤销记录。
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")View on GitHub (pinned to 9f775e8a12)