siyuan-note/siyuan · error

template document tree transaction contains a reserved…

Error message

template document tree transaction contains a reserved operation

What it means

The action names "restoreCreatedDoc" and "removeCreatedDoc" are reserved for operations that AttachTemplateDocTreePlans itself injects when consuming a plan. If the incoming transaction already contains operations with these actions, the kernel rejects it to prevent duplicates or forged plan-side effects.

Solutions

  1. Remove restoreCreatedDoc/removeCreatedDoc operations from the client-built transaction; let the kernel inject them from the plan
  2. Do not re-attach a plan ID to a transaction whose operations were already augmented by a prior attach
  3. Use standard insert/delete operations for custom document creation instead of the reserved actions

Example fix

// before
tx.DoOperations = append(tx.DoOperations, &Operation{Action: "restoreCreatedDoc", ...})
// after
// rely on the plan: only send parent insert/delete ops + TemplateDocTreePlanID
Defensive patterns

Strategy: validation

Validate before calling

const reserved = ['restoreCreatedDoc','removeCreatedDoc'];
if (tx.operations.some(op => reserved.includes(op.action))) throw new Error('reserved plan operations must not be sent by clients')

Type guard

null

Try / catch

try { commit(tx) } catch (e) { if (String(e).includes('reserved operation')) { tx.operations = tx.operations.filter(op => !['restoreCreatedDoc','removeCreatedDoc'].includes(op.action)); commit(tx) } else { throw e } }

Prevention

When it happens

Trigger: A client crafts a transaction with hand-made restoreCreatedDoc/removeCreatedDoc operations and a TemplateDocTreePlanID; or replays a transaction that already had plan operations appended before being re-attached.

Common situations: Plugin reimplementing plan application by mimicking kernel operations; replaying a captured transaction payload that already contains the injected operations.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template_doc_tree.go:474

			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) {
		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 ||

View on GitHub (pinned to 9f775e8a12)