siyuan-note/siyuan · error

template document tree plan does not match the edited…

Error message

template document tree plan does not match the edited document

What it means

The plan records the root document (rootID and boxID) it was rendered against. On attach, transactionTargetsTemplateRoot checks that the transaction's operations actually target that same root document in that notebook. If the transaction edits a different document or notebook, the plan cannot be applied and this error is thrown.

Solutions

  1. Attach the plan ID only to the transaction that modifies the root document it was rendered from
  2. Re-render the template after switching documents so the plan matches the new target
  3. Verify the transaction's operation IDs reference blocks under plan.rootID/plan.boxID before commit

Example fix

// before
renderIn(docA); commit(planID, txTargeting(docB))
// after
renderIn(docA); commit(planID, txTargeting(docA))
Defensive patterns

Strategy: validation

Validate before calling

assert(tx.operations.every(op => op.box === plan.boxId && belongsToDoc(op.id, plan.rootId)), 'transaction must target the plan root document')

Type guard

null

Try / catch

try { commit(txWith(planId)) } catch (e) { if (String(e).includes('does not match the edited document')) { rebindPlanToCurrentDoc(); commit(txWith(planId)) } else { throw e } }

Prevention

When it happens

Trigger: The client renders a template in document A but attaches the plan ID to a transaction whose operations touch document B, or moves the operations to another notebook before committing.

Common situations: Frontend loses track of which document initiated the template; user switches documents while a template plan is pending; plugin sends a generic transaction with a stale plan ID.

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/2950596a0d500c38. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template_doc_tree.go:489

	}
	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) {
		return false, errors.New("template document tree plan is invalid or has expired")
	}
	if !transactionTargetsTemplateRoot(target, plan.rootID, plan.boxID) {
		return false, errors.New("template document tree plan does not match the edited document")
	}
	rootTree, loadErr := LoadTreeByBlockID(plan.rootID)
	if nil != loadErr || nil == rootTree || rootTree.Box != plan.boxID || rootTree.Path != plan.rootPath ||
		rootTree.HPath != plan.rootHPath {
		return false, errors.New("the document used to render the template has changed")
	}
	target.templateDocTreeRootSnapshot = rootTree
	box := Conf.Box(plan.boxID)
	if nil == box {
		return false, ErrBoxNotFound
	}
	for _, tree := range plan.trees {
		if nil == tree || nil == tree.Root || tree.ID != tree.Root.ID || tree.Box != plan.boxID || box.Exist(tree.Path) {
			return false, errors.New("template document tree plan contains an invalid document snapshot")
		}
	}

	for _, tree := range plan.trees {

View on GitHub (pinned to 9f775e8a12)