{"record":{"id":"9c7470f0c63bd0fc","repo":"siyuan-note/siyuan","slug":"failed-to-update-agent-session-permission","errorCode":null,"errorMessage":"Failed to update agent session permission","messagePattern":"Failed to update agent session permission","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/layout/dock/agent/SessionStore.ts","lineNumber":231,"sourceCode":"        sessionRevisions.delete(id);\n        sessionRuntimeRevisions.delete(id);\n    },\n\n    async rename(id: string, newTitle: string): Promise<void> {\n        const session = await this.load(id);\n        if (!session) { return; }\n        session.title = newTitle;\n        await this.save(session);\n    },\n\n    async setPermission(id: string, permissionMode: AgentPermissionMode): Promise<AgentPermissionMode> {\n        await waitForPendingSave(id);\n        const resp = await fetchSyncPost(API + \"/setPermission\", {\n            sessionID: id,\n            permissionMode,\n        }, APP_HEADER) as {code: number; msg?: string; data?: {permissionMode?: AgentPermissionMode}};\n        if (!resp || resp.code !== 0) {\n            throw new Error(resp?.msg || \"Failed to update agent session permission\");\n        }\n        return resp.data?.permissionMode || permissionMode;\n    },\n\n    getRevision(id: string): number {\n        return sessionRevisions.get(id) ?? 0;\n    },\n\n    newSessionId,\n};\n","sourceCodeStart":213,"sourceCodeEnd":242,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/layout/dock/agent/SessionStore.ts#L213-L242","documentation":"setPermission() posts to /api/agent/setPermission and expects code===0 plus the resulting permissionMode. It throws the kernel msg or this fallback when the response is missing or reports failure, so callers never observe a half-applied permission change.","triggerScenarios":"Calling setPermission(id, permissionMode) on a nonexistent session, with an invalid permissionMode value, or when the kernel request fails and returns non-zero code / undefined response.","commonSituations":"Session closed or deleted by another window while toggling permissions; stale UI bound to a removed session id; kernel rejecting an unsupported permission mode; transient API failure.","solutions":["Verify the session id is still valid and re-fetch the session before retrying","Check the permissionMode value is one the kernel accepts","Inspect kernel logs for the setPermission rejection reason","Retry after confirming API connectivity"],"exampleFix":"// before\nawait store.setPermission(id, \"unknown-mode\");\n// after\nif (VALID_MODES.includes(mode)) await store.setPermission(id, mode);","handlingStrategy":"try-catch","validationCode":"const valid = [\"default\", \"ask\", \"auto\"].includes(mode) && sessions.some(s => s.id === id);","typeGuard":"const isPermissionMode = (v: unknown): v is AgentPermissionMode => [\"default\",\"ask\",\"auto\"].includes(v as string);","tryCatchPattern":"try { await store.setPermission(id, mode); } catch (e) { revertToggle(); showMessage(e.message); }","preventionTips":["Validate the mode against supported values before calling","Re-fetch session state before mutating a possibly stale id","Revert UI toggles on failure"],"tags":["api","permissions","agent-sessions"],"backgroundTag":"api-error-response","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"}