{"record":{"id":"e7d865c88101ad1f","repo":"siyuan-note/siyuan","slug":"failed-to-save-agent-session","errorCode":null,"errorMessage":"Failed to save agent session","messagePattern":"Failed to save agent session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/layout/dock/agent/SessionStore.ts","lineNumber":187,"sourceCode":"        }\n        // 连续写入期间若三次读取都落后于本地已知版本，则不返回旧数据覆盖界面。\n        return null;\n    },\n\n    async save(session: AgentSession): Promise<SessionSaveResult> {\n        const snapshot = JSON.parse(JSON.stringify(session)) as AgentSession;\n        snapshot.updatedAt = Date.now();\n        const baseRevision = snapshot.expectedRevision ?? sessionRevisions.get(snapshot.id) ?? snapshot.revision ?? 0;\n        const previous = sessionSaveQueues.get(snapshot.id);\n        const persist = async (expectedRevision: number) => {\n            snapshot.expectedRevision = expectedRevision;\n            const resp = await fetchSyncPost(API + \"/saveSession\", snapshot, APP_HEADER) as {\n                code: number;\n                msg?: string;\n                data?: {revision?: number; session?: AgentSession};\n            };\n            if (!resp || resp.code !== 0) {\n                throw new Error(resp?.msg || \"Failed to save agent session\");\n            }\n            const revision = resp.data?.revision ?? expectedRevision;\n            sessionRevisions.set(snapshot.id, revision);\n            if (snapshot.commitTurnID || snapshot.recoveryTurnID) {\n                sessionRuntimeRevisions.set(snapshot.id, 0);\n            }\n            return {revision, session: resp.data?.session};\n        };\n        const save = previous ? previous.then((result) => persist(result.revision)) : persist(baseRevision);\n        sessionSaveQueues.set(snapshot.id, save);\n        try {\n            return await save;\n        } finally {\n            if (sessionSaveQueues.get(snapshot.id) === save) {\n                sessionSaveQueues.delete(snapshot.id);\n            }\n        }\n    },","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/layout/dock/agent/SessionStore.ts#L169-L205","documentation":"Thrown by the agent SessionStore persist path when saving a session snapshot to the kernel fails after queued retries: the write returned an error or an expected-revision conflict could not be resolved, so the session was not durably stored.","triggerScenarios":"Thrown at app/src/layout/dock/agent/SessionStore.ts:187 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry saving the session","Reload the agent panel to resync session state from the server","Check kernel storage availability and logs"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}