siyuan-note/siyuan · error
load template document tree parent snapshot failed
Error message
load template document tree parent snapshot failed: %w
What it means
During transaction commit, an operation that renders a template document requires the parent document tree snapshot to be loaded via LoadTreeByBlockID. If that load fails (indexing error, missing database entry, corrupted tree), the transaction aborts with this wrapped error preserving the underlying cause.
Solutions
- Read the wrapped cause (%w) to identify the load failure
- Verify the template document still exists (check data/<box>/.sy files)
- Rebuild the index (Settings - Rebuild index) to restore LoadTreeByBlockID coverage
- Retry the transaction after the document tree is restored
Defensive patterns
Strategy: try-catch
Validate before calling
snapshot, err := LoadTreeByBlockID(templateDocTreeRootID)
if err != nil || snapshot == nil { /* abort before building the tx operation */ } Try / catch
if err := tx.Commit(); err != nil {
var wrapped error
if errors.As(err, &wrapped) && strings.Contains(err.Error(), "load template document tree parent snapshot failed") {
// rebuild index / verify doc exists, then retry
}
} Prevention
- Do not delete the template's parent document while template operations are pending
- Keep the SQL index healthy; rebuild after crashes
- Unwrap the %w cause to diagnose the underlying load failure
- Retry the transaction after the document tree is restored
When it happens
Trigger: Committing a transaction whose operation carries templateDocTreeRootID but LoadTreeByBlockID returns an error — the template's root block ID is no longer in blocktree/SQL index, or the underlying storage read failed.
Common situations: The template document was deleted between rendering and commit; the SQL index is out of sync or being rebuilt; a corrupted .sy file removed the root block; concurrent transaction deleted the parent doc.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- a document tree plan must be applied in a single transaction
- 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/6bffef72ce95538e.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/transaction.go:2697
if "restoreCreatedDoc" == operation.Action && "" != operation.templateDocTreeRootID &&
nil != operation.Tree && nil != operation.Tree.Root &&
operation.ID == operation.Tree.Root.ID {
if existingBox, exists := tx.restoredCreatedDocBoxes[operation.ID]; exists {
if existingBox != operation.Tree.Box {
tx.restoredCreatedDocBoxes[operation.ID] = ""
}
} else {
tx.restoredCreatedDocBoxes[operation.ID] = operation.Tree.Box
}
}
if ("restoreCreatedDoc" != operation.Action && "removeCreatedDoc" != operation.Action) ||
"" == operation.templateDocTreeRootID || nil == operation.Tree {
continue
}
if nil == tx.templateDocTreeRootSnapshot {
snapshot, loadErr := LoadTreeByBlockID(operation.templateDocTreeRootID)
if nil != loadErr {
return fmt.Errorf("load template document tree parent snapshot failed: %w", loadErr)
}
if nil == snapshot {
return errors.New("template document tree parent snapshot is invalid")
}
if nil != expectedTemplateDocTreeRoot &&
(expectedTemplateDocTreeRoot.ID != snapshot.ID || expectedTemplateDocTreeRoot.Box != snapshot.Box ||
expectedTemplateDocTreeRoot.Path != snapshot.Path || expectedTemplateDocTreeRoot.HPath != snapshot.HPath) {
return errors.New("the document used to render the template has changed")
}
tx.templateDocTreeRootSnapshot = snapshot
}
if nil == tx.templateDocTreeRootSnapshot || tx.templateDocTreeRootSnapshot.ID != operation.templateDocTreeRootID ||
tx.templateDocTreeRootSnapshot.Box != operation.Tree.Box {
return errors.New("template document tree parent snapshot is invalid")
}
}
tx.listItemFoldCandidates = nil
tx.listItemFoldCandidateIDs = map[string]struct{}{}View on GitHub (pinned to 9f775e8a12)