siyuan-note/siyuan · error
Failed to update agent session permission
Error message
Failed to update agent session permission
What it means
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.
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
Example fix
// before await store.setPermission(id, "unknown-mode"); // after if (VALID_MODES.includes(mode)) await store.setPermission(id, mode);
Defensive patterns
Strategy: try-catch
Validate before calling
const valid = ["default", "ask", "auto"].includes(mode) && sessions.some(s => s.id === id);
Type guard
const isPermissionMode = (v: unknown): v is AgentPermissionMode => ["default","ask","auto"].includes(v as string);
Try / catch
try { await store.setPermission(id, mode); } catch (e) { revertToggle(); showMessage(e.message); } Prevention
- Validate the mode against supported values before calling
- Re-fetch session state before mutating a possibly stale id
- Revert UI toggles on failure
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to remove agent session
- Access to encrypted notebook data is not supported via this…
- AI editor action must not be empty
- AI editor action not found
- [/api/av/batchSetAttributeViewBlockAttrs] parameter [rowID]…
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/9c7470f0c63bd0fc.
Report an issue: GitHub.
Appendix: source
Thrown at app/src/layout/dock/agent/SessionStore.ts:231
sessionRevisions.delete(id);
sessionRuntimeRevisions.delete(id);
},
async rename(id: string, newTitle: string): Promise<void> {
const session = await this.load(id);
if (!session) { return; }
session.title = newTitle;
await this.save(session);
},
async setPermission(id: string, permissionMode: AgentPermissionMode): Promise<AgentPermissionMode> {
await waitForPendingSave(id);
const resp = await fetchSyncPost(API + "/setPermission", {
sessionID: id,
permissionMode,
}, APP_HEADER) as {code: number; msg?: string; data?: {permissionMode?: AgentPermissionMode}};
if (!resp || resp.code !== 0) {
throw new Error(resp?.msg || "Failed to update agent session permission");
}
return resp.data?.permissionMode || permissionMode;
},
getRevision(id: string): number {
return sessionRevisions.get(id) ?? 0;
},
newSessionId,
};
View on GitHub (pinned to 9f775e8a12)