siyuan-note/siyuan · error
target ID [%s] is not in the current order
Error message
target ID [%s] is not in the current order
What it means
reorderIDSequence in kernel/model/file.go validates a drag-and-drop reorder of a file-tree sort sequence. Before moving source items, it builds a set of the currently known IDs and checks that the target (drop anchor) ID is one of them. If the target ID is absent from the current order, the reorder is aborted with this error and nothing is changed.
Source
Thrown at kernel/model/file.go:2788
func mergeRequestedSortOrder(currentIDs, requestedPaths []string) (ret []string) {
requestedIDs := make([]string, 0, len(requestedPaths))
for _, requestedPath := range requestedPaths {
requestedIDs = append(requestedIDs, util.GetTreeID(requestedPath))
}
return mergeRequestedIDOrder(currentIDs, requestedIDs)
}
func reorderIDSequence(currentIDs, sourceIDs []string, targetID, position string) (ret []string, changed bool, err error) {
if err = validateReorderArgs(sourceIDs, targetID, position); nil != err {
return
}
currentSet := make(map[string]struct{}, len(currentIDs))
for _, id := range currentIDs {
currentSet[id] = struct{}{}
}
if _, exists := currentSet[targetID]; !exists {
return nil, false, fmt.Errorf("target ID [%s] is not in the current order", targetID)
}
sourceSet := make(map[string]struct{}, len(sourceIDs))
for _, sourceID := range sourceIDs {
if _, exists := currentSet[sourceID]; !exists {
return nil, false, fmt.Errorf("source ID [%s] is not in the current order", sourceID)
}
sourceSet[sourceID] = struct{}{}
}
remaining := make([]string, 0, len(currentIDs)-len(sourceIDs))
for _, id := range currentIDs {
if _, source := sourceSet[id]; !source {
remaining = append(remaining, id)
}
}
targetIndex := -1
for i, id := range remaining {
if id == targetID {
targetIndex = iView on GitHub (pinned to 8641553a1f)
Solutions
- Refresh the current sort sequence (re-list the parent's children) and re-read the target ID from the fresh data before retrying the reorder.
- Verify the target ID exists on disk (data/<boxID>/<path>/<id>.sy) and belongs to the same parent folder as the reorder operation.
- If the target was intentionally deleted, remove it from the request instead of retrying — the sequence cannot anchor to a non-existent item.
- Check that the request does not confuse notebook-level and document-level sort sequences.
Example fix
// before
err := reorder(&req) // targetID from stale UI state
// after
ids := loadCurrentOrder(parentPath)
if !contains(ids, req.TargetID) {
req.TargetID = ids[len(ids)-1] // re-anchor to a valid item from fresh data
}
err := reorder(&req) Defensive patterns
Strategy: validation
Validate before calling
const current = await loadSortOrder(parentPath);
if (!current.includes(targetID)) {
throw new Error(`target ${targetID} absent from current order; refresh before sorting`);
} Try / catch
try {
await api.setFileTreeSort(payload);
} catch (e) {
if (String(e).includes("is not in the current order")) {
await refreshFileTree();
return retryOnceWithFreshOrder();
}
throw e;
} Prevention
- Always re-fetch the current order immediately before issuing a reorder request
- Never reuse target IDs cached from a previous render of the file tree
- Keep notebook-level and document-level IDs in separate sort payloads
When it happens
Trigger: Calling the file-tree sort API (reorderIDSequence path, e.g. via SetFileTreeSort / drag sort) with a targetID that does not appear in currentIDs — typically a stale ID of a document or notebook that was deleted or renamed, or an ID from a different parent folder than the one being reordered.
Common situations: Frontend sent a drop anchor from an outdated tree snapshot (the doc was deleted by another client/device between render and drop); caller passes a notebook ID where the sequence only contains document IDs or vice versa; target doc lives under a different parent than the sources.
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
- source ID [%s] is not in the current order
- invalid sort position [%s]
- sort target document [%s] is not a sibling of the new docume
- notebook sort item must not be nil
- duplicate notebook ID [%s]
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/c3a426fe8802cda1.
Report an issue: GitHub.