{"record":{"id":"15c95dce9a9d96a7","repo":"siyuan-note/siyuan","slug":"invalid-session-id","errorCode":null,"errorMessage":"invalid session id","messagePattern":"invalid session id","errorType":"http","errorClass":null,"httpStatus":200,"severity":"error","filePath":"kernel/agent/runtime.go","lineNumber":125,"sourceCode":"\tmode, err := resolveSessionPermissionModeLocked(sessionID, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcontroller.allowSession.Store(mode == AgentPermissionAllowSession)\n\tsessionPermissionControllers.Store(sessionID, controller)\n\treturn controller, nil\n}\n\nfunc unregisterSessionPermissionController(sessionID string, controller *sessionPermissionController) {\n\tif sessionID == \"\" || controller == nil {\n\t\treturn\n\t}\n\tsessionPermissionControllers.CompareAndDelete(sessionID, controller)\n}\n\nfunc SetSessionPermissionMode(sessionID, mode string) error {\n\tif sessionID == \"\" || !isValidSessionID(sessionID) {\n\t\treturn fmt.Errorf(\"invalid session id\")\n\t}\n\tif !validAgentPermissionMode(mode) {\n\t\treturn fmt.Errorf(\"invalid agent permission mode\")\n\t}\n\tlock := sessionLock(sessionID)\n\tlock.Lock()\n\tdefer lock.Unlock()\n\tif _, err := os.Stat(filepath.Join(sessionsDir(), sessionID, \"session.json\")); err != nil {\n\t\treturn err\n\t}\n\truntime, err := loadRuntimeLocked(sessionID)\n\tif err != nil {\n\t\treturn err\n\t}\n\truntime.PermissionMode = mode\n\truntime.AlwaysAllow = false\n\tif err = writeRuntimeLocked(sessionID, runtime); err != nil {\n\t\treturn err","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/agent/runtime.go#L107-L143","documentation":"gulu.JSON.UnmarshalJSON failed to decode the contents of ~/.config/siyuan/workspace.json into []string inside util.ReadWorkspacePaths. The file exists but is not valid JSON of the expected shape — typically a JSON array of workspace path strings. Corruption usually comes from manual edits, a truncated write (crash during save), or another tool rewriting the file.","triggerScenarios":"Hand-editing workspace.json and leaving a trailing comma/missing bracket; the process being killed mid-write leaving a partial file; replacing the file with an object {\"path\": ...} instead of an array; encoding issues (BOM, double UTF-8 encoding) from external editors.","commonSituations":"Users manually reordering or pruning workspace entries; power loss during workspace switching; sync tools (Dropbox etc.) conflict-merging the dotfile; scripts generating the file with a different schema.","solutions":["Open ~/.config/siyuan/workspace.json and validate it: it must be a plain JSON array of strings, e.g. [\"/home/me/SiYuan\"]","Fix the syntax error, or simply delete/rename the file — the app treats it as fresh state and re-registers the current workspace","If workspaces listed there matter, note the paths first, then recreate the file with those paths as a clean array","Exclude ~/.config/siyuan from sync/merge tools to avoid conflict-corrupted writes in the future"],"exampleFix":"// before (corrupt)\n[\"/home/me/SiYuan\", \"/data/ws\",]\n\n// after (valid)\n[\n  \"/home/me/SiYuan\",\n  \"/data/ws\"\n]","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(workspaceConf)\nif err == nil && !json.Valid(data) {\n    // refuse to hand corrupt config to the kernel; back it up and start fresh\n    _ = os.Rename(workspaceConf, workspaceConf+\".bak\")\n}","typeGuard":"func isValidWorkspaceConf(data []byte) bool {\n    var paths []string\n    return json.Unmarshal(data, &paths) == nil\n}","tryCatchPattern":"paths, err := util.ReadWorkspacePaths()\nif err != nil && strings.Contains(err.Error(), \"unmarshal workspace conf\") {\n    _ = os.Rename(workspaceConf, workspaceConf+\".corrupt\")\n    paths, err = util.ReadWorkspacePaths() // regenerates from fresh state\n}","preventionTips":["Never hand-edit workspace.json while the kernel is running; use the UI to switch workspaces","Validate with json.Valid before external tooling rewrites the file","Exclude ~/.config/siyuan from sync/merge tools that produce conflict artifacts"],"tags":["workspace","json","config-file","corruption"],"backgroundTag":"config-json-corrupt","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}