siyuan-note/siyuan · error
a document tree plan must be applied in a single transaction
Error message
a document tree plan must be applied in a single transaction
What it means
AttachTemplateDocTreePlans is invoked when transactions are committed and only accepts a batch containing exactly one transaction that carries a TemplateDocTreePlanID. If more than one transaction is present and one of them carries a plan, or multiple carry plans, the kernel rejects the commit because a document tree plan must be atomic in a single transaction to keep undo/redo consistent.
Solutions
- Send the plan-bearing transaction alone in its own request (transactions array length must be 1)
- Split batched operations into separate commit requests so the plan transaction is isolated
- Ensure the frontend does not attach TemplateDocTreePlanID to more than one transaction
Example fix
// before
POST /api/transactions {"transactions": [txWithPlan, otherTx]}
// after
POST /api/transactions {"transactions": [txWithPlan]}
POST /api/transactions {"transactions": [otherTx]} Defensive patterns
Strategy: validation
Validate before calling
if (transactions.length !== 1 || !transactions[0].templateDocTreePlanID) throw new Error('plan must be its own single transaction') Type guard
null
Try / catch
try { await commitTransactions(txs) } catch (e) { if (String(e).includes('single transaction')) { for (const tx of txs) await commitTransactions([tx]) } else { throw e } } Prevention
- Always send plan-bearing transactions in a dedicated request with exactly one transaction
- Do not batch template plan commits with unrelated operations
- Guard client code so TemplateDocTreePlanID is set on at most one transaction per request
When it happens
Trigger: Calling the transaction-commit path (e.g. /api/transactions) with multiple transactions in one request where at least one has a templateDocTreePlanID, or batching two plan-bearing transactions together.
Common situations: Plugin or integration code batches transactions; a frontend retry accumulates several plan transactions in one payload.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- load template document tree parent snapshot failed
- template document tree parent snapshot is invalid
- template document tree plan contains an invalid document…
- template document tree plan does not match the edited…
- template document tree plan is invalid or has expired
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/1c50221bf35550a2.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:456
"title": node.Title,
"id": node.ID,
"parentID": node.ParentID,
"rootID": node.RootID,
"hPath": node.HPath,
"name": "",
"alias": "",
}
}
// 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")View on GitHub (pinned to 9f775e8a12)