{"record":{"id":"7f81d3821e33e53a","repo":"siyuan-note/siyuan","slug":"box-document-id-s-does-not-match-box-id-s","errorCode":null,"errorMessage":"box document ID [%s] does not match box ID [%s]","messagePattern":"box document ID \\[(.+?)\\] does not match box ID \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/box_doc.go","lineNumber":80,"sourceCode":"\tif err != nil {\n\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\terr = nil\n\t\t}\n\t\treturn\n\t}\n\n\tmeta := &boxDocMeta{}\n\tif err = gulu.JSON.UnmarshalJSON(data, meta); err != nil {\n\t\treturn \"\", fmt.Errorf(\"unmarshal box document metadata failed: %w\", err)\n\t}\n\tif boxDocMetaSpec != meta.Spec {\n\t\treturn \"\", fmt.Errorf(\"unsupported box document metadata spec [%d]\", meta.Spec)\n\t}\n\tif !ast.IsNodeIDPattern(meta.BoxDocID) {\n\t\treturn \"\", fmt.Errorf(\"invalid box document ID [%s]\", meta.BoxDocID)\n\t}\n\tif boxID != meta.BoxDocID {\n\t\treturn \"\", fmt.Errorf(\"box document ID [%s] does not match box ID [%s]\", meta.BoxDocID, boxID)\n\t}\n\treturn boxID, nil\n}\n\nfunc writeBoxDocID(boxID string) error {\n\tmeta := &boxDocMeta{Spec: boxDocMetaSpec, BoxDocID: boxID}\n\tdata, err := gulu.JSON.MarshalIndentJSON(meta, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal box document metadata failed: %w\", err)\n\t}\n\treturn filelock.WriteFile(boxDocMetaPath(boxID), data)\n}\n\nfunc IsBoxDocEnabled() bool {\n\treturn nil != Conf && nil != Conf.FileTree && nil != Conf.FileTree.BoxDocEnabled && *Conf.FileTree.BoxDocEnabled\n}\n\nfunc hiddenBoxDocRootIDs() (ret []string) {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/box_doc.go#L62-L98","documentation":"The boxDocID stored in boxDoc.json must equal the notebook (box) ID, because the box doc node is the notebook's own root document. A mismatch means the metadata file belongs to a different notebook — likely copied, renamed, or stale — and readBoxDocID refuses to return an inconsistent identity.","triggerScenarios":"readBoxDocID (via ensureBoxDoc0 or TestBoxDocMetadataMatchesBoxID) finds meta.BoxDocID != boxID — e.g. the whole .siyuan directory was copied between notebooks, or the notebook folder was renamed without regenerating boxDoc.json.","commonSituations":"Duplicating a notebook by copying its data directory (boxDoc.json still names the old ID); renaming the notebook folder manually; sync restoring a boxDoc.json from another notebook.","solutions":["Delete the stale .siyuan/boxDoc.json in the notebook so ensureBoxDoc0 rewrites it with the current box ID","Edit boxDoc.json so boxDocID matches the notebook's directory ID (if intentional)","When duplicating notebooks, use SiYuan's copy/import flow rather than copying raw data directories"],"exampleFix":"// before: copied from notebook 20240101120000-oldid01\n{\"spec\": 1, \"boxDocID\": \"20240101120000-oldid01\"}\n// after\n{\"spec\": 1, \"boxDocID\": \"20240101120000-newid01\"}","handlingStrategy":"try-catch","validationCode":"var probe struct{ BoxDocID string `json:\"boxDocID\"` }\nif json.Unmarshal(data, &probe) == nil && probe.BoxDocID != boxID {\n    // metadata from another notebook: delete and regenerate\n}","typeGuard":"func matchesBox(data []byte, boxID string) bool {\n    var m struct{ BoxDocID string `json:\"boxDocID\"` }\n    return json.Unmarshal(data, &m) == nil && m.BoxDocID == boxID\n}","tryCatchPattern":"if _, err := readBoxDocID(boxID); err != nil && strings.Contains(err.Error(), \"does not match box ID\") {\n    // stale/copied metadata: remove .siyuan/boxDoc.json and let ensureBoxDoc0 rewrite it\n}","preventionTips":["Duplicate notebooks via SiYuan's copy/import, not directory copies","Rename notebooks through the app, not the filesystem","After restoring from backup, confirm boxDoc.json matches the notebook folder ID"],"tags":["identifier","consistency","notebook","metadata"],"backgroundTag":"invalid-identifier-format","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"}