siyuan-note/siyuan · error

source ID [%s] is not in the current order

Error message

source ID [%s] is not in the current order

What it means

reorderIDSequence validates each source ID being moved against the set of currently known IDs in the sort sequence. If any sourceID is not present in the current order, the whole reorder is rejected with this error and the sequence is left untouched.

Source

Thrown at kernel/model/file.go:2793

	}
	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 = i
			break
		}
	}
	if "after" == position {
		targetIndex++

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Reload the current children list of the parent folder and filter the request's sourceIDs down to those actually present before calling the reorder.
  2. Confirm each source ID is a document root ID (matches the .sy filename) in the same notebook and parent directory.
  3. Remove deleted/nonexistent IDs from the request and retry with the remaining valid ones.
  4. Refresh the file tree in the client so selection state matches the server-side state.

Example fix

// before
sources := uiSelection // may contain stale IDs
reorder(parentPath, sources, target, "after")
// after
current := loadCurrentOrder(parentPath)
sources = filterIn(current, uiSelection)
reorder(parentPath, sources, target, "after")
Defensive patterns

Strategy: validation

Validate before calling

const current = new Set(await loadSortOrder(parentPath));
const valid = sourceIDs.filter(id => current.has(id));
if (valid.length !== sourceIDs.length) {
  console.warn("dropping stale source IDs", sourceIDs.filter(id => !current.has(id)));
}

Try / catch

try {
  await api.setFileTreeSort(payload);
} catch (e) {
  if (String(e).includes("source ID") && String(e).includes("not in the current order")) {
    const fresh = await loadSortOrder(parentPath);
    payload.sourceIDs = payload.sourceIDs.filter(id => fresh.includes(id));
    return api.setFileTreeSort(payload);
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing one or more sourceIDs (docs/notebooks being dragged) that are absent from currentIDs in the file-tree reorder API — e.g. IDs of items deleted concurrently, IDs belonging to another notebook/parent, or duplicated/stale selections from the UI.

Common situations: Multi-select drag where one selected document was deleted by sync between selection and drop; client caches IDs across a rename/copy; caller accidentally passes a target block ID (heading/child block) rather than the document root ID of the .sy file.

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


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/8486b50ca0eb781c. Report an issue: GitHub.