{"record":{"id":"7aec418c847b7b18","repo":"siyuan-note/siyuan","slug":"read-session-file-failed-w","errorCode":null,"errorMessage":"read session file failed: %w","messagePattern":"read session file failed: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"kernel/agent/session.go","lineNumber":380,"sourceCode":"\t\t\t\t}\n\t\t\t\treturn currentRevision, existingData, nil\n\t\t\t}\n\t\t\tif meta.ExpectedRevision != nil && *meta.ExpectedRevision != currentRevision {\n\t\t\t\treturn currentRevision, nil, ErrSessionConflict\n\t\t\t}\n\t\t\tfor k, v := range existingData {\n\t\t\t\tif _, ok := newData[k]; !ok {\n\t\t\t\t\t// messages 是已废弃的旧会话字段，不再带入新格式；其他未知字段原样保留，\n\t\t\t\t\t// 避免前后端版本不一致时擦除较新版本写入的数据。\n\t\t\t\t\tif k != \"messages\" && k != \"expectedRevision\" && k != \"commitTurnID\" &&\n\t\t\t\t\t\tk != \"recoveryTurnID\" && k != \"recoveryState\" && k != \"recoveryRevision\" && k != \"agentRunning\" {\n\t\t\t\t\t\tnewData[k] = v\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else if err != nil && !os.IsNotExist(err) {\n\t\treturn 0, nil, fmt.Errorf(\"read session file failed: %w\", err)\n\t} else if meta.ExpectedRevision != nil && *meta.ExpectedRevision != 0 {\n\t\treturn 0, nil, ErrSessionConflict\n\t}\n\tif commitTurnID != \"\" {\n\t\truntime, err := loadRuntimeLocked(meta.ID)\n\t\tif err != nil {\n\t\t\treturn currentRevision, nil, fmt.Errorf(\"read agent runtime failed: %w\", err)\n\t\t}\n\t\tif runtime.ActiveTurn != nil {\n\t\t\tif runtime.ActiveTurn.TurnID != commitTurnID {\n\t\t\t\treturn currentRevision, nil, ErrSessionConflict\n\t\t\t}\n\t\t\tif !isRuntimeTurnTerminal(runtime.ActiveTurn) {\n\t\t\t\treturn currentRevision, nil, ErrRuntimeNotFinalized\n\t\t\t}\n\t\t\tif err := applyRuntimeTurnToSessionLocked(newData, runtime.ActiveTurn); err != nil {\n\t\t\t\treturn currentRevision, nil, err\n\t\t\t}","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/agent/session.go#L362-L398","documentation":"While loading the current session for a save, os.ReadFile(path) failed with an error other than os.IsNotExist — i.e. the file is probably there (or the directory is inaccessible) but the kernel cannot read it (kernel/agent/session.go:379-380). The raw OS error is wrapped with %w, so the cause (permission, I/O, path length) is visible in the message.","triggerScenarios":"POST /api/ai/agent/saveSession when data/storage/ai/agent/sessions/<id>/session.json or a parent directory has wrong ownership/permissions (EACCES), the workspace is on an unmounted/network volume (EIO, ENOTCONN), or the path exceeds OS limits. Distinct from a first-time save: file-not-exist is expected and handled, everything else is fatal.","commonSituations":"Workspace copied between machines with different UIDs; running the kernel under a service account without read access; antivirus or backup software holding an exclusive lock on Windows; a removable/network drive dropping out mid-session.","solutions":["Read the wrapped errno in the message: EACCES/EPERM → fix ownership (chown/chmod) on workspace/data/storage/ai/agent; EIO/ENOTCONN → remount the workspace volume","Verify the kernel process user can cat the session.json file","On Windows, exclude the workspace from antivirus real-time scanning or wait for the backup lock to release","Retry the save only after the underlying access problem is fixed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight: kernel process must be able to read the session dir\n// (run as the same user the kernel runs under)\n// ls -la <workspace>/data/storage/ai/agent/sessions/<id>/session.json","typeGuard":"null","tryCatchPattern":"catch (e) {\n  if (/read session file failed/.test(e?.data?.msg ?? '')) {\n    // inspect wrapped errno; fix ownership/mount, then retry once\n  }\n}","preventionTips":["Run the kernel under a user that owns the workspace tree","Avoid network-mounted workspaces for live agent sessions","On Windows, exclude the workspace from antivirus locks"],"tags":["agent","session","filesystem","permissions"],"backgroundTag":"file-read-permission-denied","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}