siyuan-note/siyuan · error
template changed; reload it before saving, moving or…
Error message
template changed; reload it before saving, moving or deleting
What it means
ManageTemplateFiles implements optimistic concurrency: when the target template already exists, its current revision (a content hash) is compared with the Revision supplied in the request. If the client sends an empty Revision or a stale one, the write/move/remove is rejected so a user does not silently overwrite or delete changes made elsewhere. The caller must re-read the template to get the fresh revision before retrying.
Solutions
- Re-read the template (Action "read") to obtain the current revision, then resend the request with that Revision value
- If you intend to create a new file, ensure the path does not exist — new files with Revision=="" are allowed (stat must return ErrNotExist)
- Detect the conflict in UI: show 'template changed' and let the user merge/reload before saving
- Retry only after confirming with the user that overwriting the newer external change is acceptable
Example fix
// before
manage(TemplateFileRequest{Action: "write", Path: "t.md", Content: c, Revision: oldRev})
// after
read := manage(TemplateFileRequest{Action: "read", Path: "t.md"})
manage(TemplateFileRequest{Action: "write", Path: "t.md", Content: c, Revision: read["revision"]}) Defensive patterns
Strategy: retry
Validate before calling
// read current revision first
res, _ := manage(TemplateFileRequest{Action: "read", Path: p})
rev := res.(map[string]string)["revision"] Try / catch
if err != nil && strings.Contains(err.Error(), "template changed") {
fresh, _ := manage(TemplateFileRequest{Action: "read", Path: p})
req.Revision = fresh.(map[string]string)["revision"]
// retry after user confirms merge/overwrite
} Prevention
- Always carry the revision from the last read into write/move/remove
- Refresh the editor state on sync/push events that may change templates
- Surface revision conflicts in UI instead of auto-overwriting
- Never cache template revisions across long-running sessions
When it happens
Trigger: Calling ManageTemplateFiles with Action 'write', 'move', or 'remove' on an existing path while request.Revision is empty or differs from templateFileRevision(root, path) — i.e. the file's hash changed since the client last read it.
Common situations: Two windows or devices edit the same template and the second save carries an outdated hash; a sync operation updated the template between the client's read and write; a caller never fetched the revision (sent Revision: "") for an existing file; clocks/sync reordered saves.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- agent session revision conflict
- attribute view order changed; retry the drag
- OIDC configuration changed during validation
- skill changed; reload it before saving, renaming or deleting
- source changed during asset relink
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/1ec43a09f141161e.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_manage.go:274
if !strings.EqualFold(path.Ext(request.Path), ".md") {
return nil, errors.New("template source must use the .md extension")
}
}
if request.Action == "read" {
if info.IsDir() {
revision, readErr := templateFileRevision(root, request.Path)
return map[string]string{"content": "", "revision": revision}, readErr
}
content, readErr := readTemplateSource(root, request.Path)
return map[string]string{"content": content, "revision": fmt.Sprintf("%x", sha256.Sum256([]byte(content))), "path": filepath.Join(util.DataDir, "templates", filepath.FromSlash(request.Path))}, readErr
}
if info != nil {
revision, revisionErr := templateFileRevision(root, request.Path)
if revisionErr != nil {
return nil, revisionErr
}
if request.Revision == "" || request.Revision != revision {
return nil, errors.New("template changed; reload it before saving, moving or deleting")
}
}
switch request.Action {
case "write":
if info == nil {
if err = validateNewTemplateName(request.Path); err != nil {
return nil, err
}
}
if len(request.Content) > maxTemplateSourceSize {
return nil, errors.New("template source is too large")
}
if info != nil && info.IsDir() {
return nil, errors.New("cannot write a template directory")
}
err = writeTemplateSource(root, request.Path, request.Content, info == nil)
return map[string]string{"revision": fmt.Sprintf("%x", sha256.Sum256([]byte(request.Content)))}, err
case "move":View on GitHub (pinned to 9f775e8a12)