siyuan-note/siyuan · error

template document tree plan is invalid or has expired

Error message

template document tree plan is invalid or has expired

What it means

After the plan record is found, its contents are validated: it must be a *templateDocTreePlan, its stored id must equal the requested plan ID, and the current time must be before plan.expiresAt. Any mismatch — corrupted registry value, forged ID, or expired plan — produces this error.

Solutions

  1. Re-render the template to obtain a new, valid plan and commit right away
  2. Check system clock skew if commits are made near the expiry boundary
  3. Ensure only one client consumes the plan (single window/device per workspace while applying)

Example fix

// before
commitLater(tx, planID, hours(2)) // plan expired
// after
planID := render(...); commit(txWith(planID)) // commit within TTL
Defensive patterns

Strategy: retry

Validate before calling

if (Date.now() > planExpiresAtMs(planId)) { planId = await renderTemplateDocTree(); }

Type guard

null

Try / catch

try { commit(txWith(planId)) } catch (e) { if (String(e).includes('invalid or has expired')) { planId = await renderTemplateDocTree(); commit(txWith(planId)) } else { throw e } }

Prevention

When it happens

Trigger: Committing a transaction whose plan TTL elapsed between render and commit, or whose registry entry was replaced with a different object/id, or sending a mismatched plan ID.

Common situations: Slow network or user hesitation past the expiry window; multiple windows/devices sharing one workspace where another consumer deleted the entry; clock skew on the machine.

Related errors


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

Appendix: source

Thrown at kernel/model/template_doc_tree.go:486

	}
	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 ||
		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")
		}

View on GitHub (pinned to 9f775e8a12)