{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/agent/runtime.go#L49-L85","documentation":"resolveSessionPermissionModeLocked reads the persisted agent runtime for a session and validates its permissionMode against the known modes ('confirm', 'allowSession'). An empty mode falls back to AlwaysAllow/confirm defaults, but a non-empty unrecognized value is rejected with this error.","triggerScenarios":"A runtime file for the session contains a permissionMode string outside the valid set — e.g. from a newer/older schema version, manual edit of the runtime JSON, or corrupted storage under data/storage/ai/agent.","commonSituations":"Downgrading SiYuan after a new permission mode was written; hand-editing runtime files; partial writes or corruption of runtime JSON; tests seeding unknown mode values.","solutions":["Open the session's runtime file and set permissionMode to \"confirm\" or \"allowSession\" (or remove the field to use defaults)","Delete the runtime state file for that session so it is rebuilt with defaults (loses per-session permission state)","Check for version mismatch: if runtime files were written by a newer build, return to that build or migrate the mode value"],"exampleFix":"// runtime JSON before\n{\"sessionID\":\"20240101...\",\"permissionMode\":\"auto-yes\"}\n// after\n{\"sessionID\":\"20240101...\",\"permissionMode\":\"allowSession\"}","handlingStrategy":"type-guard","validationCode":"func validMode(m string) bool { return m == \"\" || m == \"confirm\" || m == \"allowSession\" }","typeGuard":"func isKnownPermissionMode(m string) bool {\n    return m == agent.AgentPermissionConfirm || m == agent.AgentPermissionAllowSession\n}","tryCatchPattern":"if err != nil {\n    // fall back to defaults or surface a repair prompt for the session state\n}","preventionTips":["Only write mode values from the exported constants","Never hand-edit runtime files under data/storage/ai/agent","When downgrading versions, clear agent runtime state written by newer builds"],"tags":["go","agent","permissions","config"],"backgroundTag":"invalid-enum-value","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"}