siyuan-note/siyuan · error
invalid agent permission mode
Error message
invalid agent permission mode
What it means
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.
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
Example fix
// runtime JSON before
{"sessionID":"20240101...","permissionMode":"auto-yes"}
// after
{"sessionID":"20240101...","permissionMode":"allowSession"} Defensive patterns
Strategy: type-guard
Validate before calling
func validMode(m string) bool { return m == "" || m == "confirm" || m == "allowSession" } Type guard
func isKnownPermissionMode(m string) bool {
return m == agent.AgentPermissionConfirm || m == agent.AgentPermissionAllowSession
} Try / catch
if err != nil {
// fall back to defaults or surface a repair prompt for the session state
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- agent runtime turn changed
- agent runtime turn is not finalized
- agent session revision conflict
- capability ID collision
- capability model name collision
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/7b41f279d89b5642.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/agent/runtime.go:67
type sessionPermissionController struct {
allowSession atomic.Bool
}
var sessionPermissionControllers sync.Map
func validAgentPermissionMode(mode string) bool {
return mode == AgentPermissionConfirm || mode == AgentPermissionAllowSession
}
func resolveSessionPermissionModeLocked(sessionID string, session map[string]any) (string, error) {
runtime, err := loadRuntimeLocked(sessionID)
if err != nil {
return "", err
}
if runtime.PermissionMode != "" {
if !validAgentPermissionMode(runtime.PermissionMode) {
return "", fmt.Errorf("invalid agent permission mode")
}
return runtime.PermissionMode, nil
}
if runtime.AlwaysAllow {
return AgentPermissionAllowSession, nil
}
if session == nil {
data, readErr := os.ReadFile(filepath.Join(sessionsDir(), sessionID, "session.json"))
if readErr != nil {
return "", readErr
}
session = map[string]any{}
if unmarshalErr := gulu.JSON.UnmarshalJSON(data, &session); unmarshalErr != nil {
return "", unmarshalErr
}
}
if permissionMode, _ := session["permissionMode"].(string); permissionMode != "" {
if !validAgentPermissionMode(permissionMode) {View on GitHub (pinned to 9f775e8a12)