siyuan-note/siyuan · error

template document tree plan is missing or has expired

Error message

template document tree plan is missing or has expired

What it means

Plans are stored in a temporary registry (templateDocTreePlans) between rendering and commit, with an expiry time. When the transaction carrying TemplateDocTreePlanID arrives, the plan is loaded-and-deleted from the registry; if no entry with that ID exists, the plan was never created, was already consumed, or expired and was evicted.

Solutions

  1. Re-render the template to get a fresh plan ID, then commit immediately
  2. Do not reuse a TemplateDocTreePlanID across commits; a plan is single-use
  3. Commit the plan transaction promptly after rendering to stay within the expiry window

Example fix

// before
replayOldTx(planID) // plan already consumed
// after
planID := renderTemplateDocTree(...) // fresh render
commit(txWith(planID))
Defensive patterns

Strategy: retry

Validate before calling

const plan = lookupPlan(planId); if (!plan) { planId = await renderTemplateDocTree(); }

Type guard

null

Try / catch

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

Prevention

When it happens

Trigger: Committing a transaction whose TemplateDocTreePlanID was never registered (render step skipped), committing the same plan twice (first commit consumed it via LoadAndDelete), or waiting past the plan expiry before committing.

Common situations: User leaves the rendered template pending longer than the plan TTL; a network retry resubmits a transaction that already succeeded; plugin attaches a fabricated plan ID.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template_doc_tree.go:482

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

View on GitHub (pinned to 9f775e8a12)