{"record":{"id":"8486b50ca0eb781c","repo":"siyuan-note/siyuan","slug":"source-id-s-is-not-in-the-current-order","errorCode":null,"errorMessage":"source ID [%s] is not in the current order","messagePattern":"source ID \\[(.+?)\\] is not in the current order","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2817,"sourceCode":"\t}\n\treturn mergeRequestedIDOrder(currentIDs, requestedIDs)\n}\n\nfunc reorderIDSequence(currentIDs, sourceIDs []string, targetID, position string) (ret []string, changed bool, err error) {\n\tif err = validateReorderArgs(sourceIDs, targetID, position); nil != err {\n\t\treturn\n\t}\n\tcurrentSet := make(map[string]struct{}, len(currentIDs))\n\tfor _, id := range currentIDs {\n\t\tcurrentSet[id] = struct{}{}\n\t}\n\tif _, exists := currentSet[targetID]; !exists {\n\t\treturn nil, false, fmt.Errorf(\"target ID [%s] is not in the current order\", targetID)\n\t}\n\tsourceSet := make(map[string]struct{}, len(sourceIDs))\n\tfor _, sourceID := range sourceIDs {\n\t\tif _, exists := currentSet[sourceID]; !exists {\n\t\t\treturn nil, false, fmt.Errorf(\"source ID [%s] is not in the current order\", sourceID)\n\t\t}\n\t\tsourceSet[sourceID] = struct{}{}\n\t}\n\tremaining := make([]string, 0, len(currentIDs)-len(sourceIDs))\n\tfor _, id := range currentIDs {\n\t\tif _, source := sourceSet[id]; !source {\n\t\t\tremaining = append(remaining, id)\n\t\t}\n\t}\n\ttargetIndex := -1\n\tfor i, id := range remaining {\n\t\tif id == targetID {\n\t\t\ttargetIndex = i\n\t\t\tbreak\n\t\t}\n\t}\n\tif \"after\" == position {\n\t\ttargetIndex++","sourceCodeStart":2799,"sourceCodeEnd":2835,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L2799-L2835","documentation":"During custom-sort application, every sourceID being moved is checked against the current sibling order (currentSet). Any sourceID not present in currentIDs aborts the whole operation with \"source ID [%s] is not in the current order\". This is the symmetric check to error 1391 and protects order integrity when the source document has vanished or changed parents.","triggerScenarios":"Calling the sort-application API where sourceIDs contains an ID absent from currentIDs — deleted source document, source moved to another parent, duplicate/malformed client request listing a non-sibling ID.","commonSituations":"Multi-select drag where one of the selected docs was deleted by another window; batch operations built before a sync reconciled documents; client bug sending child-block IDs instead of document root IDs.","solutions":["Re-fetch the current sibling list and rebuild sourceIDs from documents that still exist under the parent","Filter out stale sourceIDs client-side before sending the sort request","Check that all sourceIDs are root document IDs of the same parent as targetID"],"exampleFix":"// before\nMoveDocsSort(sourceIDs, targetID, pos)\n// after: prune sources that no longer exist in the order\ncurrentIDs, _ := loadSiblingCustomOrder(boxID, parentPath, nil)\nvalid := make([]string, 0, len(sourceIDs))\nfor _, id := range sourceIDs {\n    if slices.Contains(currentIDs, id) {\n        valid = append(valid, id)\n    }\n}\nMoveDocsSort(valid, targetID, pos)","handlingStrategy":"validation","validationCode":"const currentIDs = await api.getChildDocs(parentID);\nconst bad = sourceIDs.filter(id => !currentIDs.includes(id));\nif (bad.length) sourceIDs = sourceIDs.filter(id => currentIDs.includes(id));","typeGuard":"const allValidSources = (ids, currentIDs) => Array.isArray(ids) && ids.every(id => currentIDs.includes(id));","tryCatchPattern":"try { await api.sortDocs(sourceIDs, targetID, pos); } catch (e) { if (String(e).match(/source ID .* not in the current order/)) { sourceIDs = await revalidateSources(); retry(); } else { throw e; } }","preventionTips":["Re-fetch siblings after any concurrent edit before multi-select sorts","Compact selection arrays so they contain only existing documents","Avoid batching sort operations across windows without reconciliation"],"tags":["go","validation","sorting","stale-state"],"backgroundTag":"resource-not-found","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}