{"record":{"id":"7b41f279d89b5642","repo":"siyuan-note/siyuan","slug":"invalid-agent-permission-mode","errorCode":null,"errorMessage":"invalid agent permission mode","messagePattern":"invalid agent permission mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/runtime.go","lineNumber":67,"sourceCode":"\ntype sessionPermissionController struct {\n\tallowSession atomic.Bool\n}\n\nvar sessionPermissionControllers sync.Map\n\nfunc validAgentPermissionMode(mode string) bool {\n\treturn mode == AgentPermissionConfirm || mode == AgentPermissionAllowSession\n}\n\nfunc resolveSessionPermissionModeLocked(sessionID string, session map[string]any) (string, error) {\n\truntime, err := loadRuntimeLocked(sessionID)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif runtime.PermissionMode != \"\" {\n\t\tif !validAgentPermissionMode(runtime.PermissionMode) {\n\t\t\treturn \"\", fmt.Errorf(\"invalid agent permission mode\")\n\t\t}\n\t\treturn runtime.PermissionMode, nil\n\t}\n\tif runtime.AlwaysAllow {\n\t\treturn AgentPermissionAllowSession, nil\n\t}\n\tif session == nil {\n\t\tdata, readErr := os.ReadFile(filepath.Join(sessionsDir(), sessionID, \"session.json\"))\n\t\tif readErr != nil {\n\t\t\treturn \"\", readErr\n\t\t}\n\t\tsession = map[string]any{}\n\t\tif unmarshalErr := gulu.JSON.UnmarshalJSON(data, &session); unmarshalErr != nil {\n\t\t\treturn \"\", unmarshalErr\n\t\t}\n\t}\n\tif permissionMode, _ := session[\"permissionMode\"].(string); permissionMode != \"\" {\n\t\tif !validAgentPermissionMode(permissionMode) {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/agent/runtime.go#L49-L85","documentation":"resolveSessionPermissionModeLoaded reads the persisted agent runtime (runtime.json) and, when it contains a permissionMode, validates it against the allowed modes \"confirm\" and \"allowSession\". This error means runtime.json holds a permissionMode string outside that set, so the kernel cannot decide how to gate the session's tool calls. It is a data-integrity guard against a corrupted or hand-edited runtime file.","triggerScenarios":"Calling GetSessionState or registering a session permission controller (e.g. when opening/running an agent session) where the session's runtime.json has permissionMode set to a string other than \"confirm\" or \"allowSession\".","commonSituations":"Hand-editing or script-modifying data/storage/ai/agent/sessions/<id>/runtime.json with an unsupported mode like \"allow\", \"always\", or \"auto\"; a downgrade from a newer version that had extra modes; truncated/corrupted JSON producing a stale field value.","solutions":["Open data/storage/ai/agent/sessions/<sessionID>/runtime.json and change permissionMode to \"confirm\" or \"allowSession\"","Or remove the permissionMode field entirely so the resolver falls back to legacy alwaysAllow/session.json defaults","If the file is corrupt, delete runtime.json for that session; it will be recreated with the default \"confirm\" mode","Verify the kernel version is not a downgrade that lacks the mode value stored in the file"],"exampleFix":"// before (runtime.json)\n\"permissionMode\": \"allow\"\n// after\n\"permissionMode\": \"confirm\"","handlingStrategy":"validation","validationCode":"func validAgentPermissionMode(mode string) bool { return mode == \"confirm\" || mode == \"allowSession\" }\n// before resolving: if mode := runtime.PermissionMode; mode != \"\" && !validAgentPermissionMode(mode) { return fmt.Errorf(\"...\") }","typeGuard":"func isAgentPermissionMode(v any) bool { s, ok := v.(string); return ok && (s == \"confirm\" || s == \"allowSession\") }","tryCatchPattern":"mode, err := resolveSessionPermissionMode(sessionID)\nif err != nil {\n    log.Warnf(\"falling back to default permission mode: %v\", err)\n    mode = \"confirm\"\n}","preventionTips":["Only write \"confirm\"/\"allowSession\" into runtime.json permissionMode","Prefer the SetSessionPermissionMode API over manual file edits","Back up the sessions directory before version changes"],"tags":["agent","config","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}