siyuan-note/siyuan · error
invalid session id
Error message
invalid session id
What it means
registerSessionPermissionController validates the session ID format before locking session state. Session IDs must match the SiYuan node-ID pattern (ast.IsNodeIDPattern); an empty ID returns a no-op controller, but a non-empty malformed ID is rejected with this error.
Solutions
- Use the session ID exactly as issued by the agent runtime (a valid SiYuan node ID, e.g. '20240101120000-abcdefgh') rather than a custom string
- Verify the ID matches the node-ID pattern: 14 digits timestamp, hyphen, then alphanumeric suffix
- Check for truncation or URL-encoding artifacts when passing IDs between systems
Example fix
// before
registerSessionPermissionController("session-1")
// after
registerSessionPermissionController("20240918103000-1a2b3c4") Defensive patterns
Strategy: validation
Validate before calling
if sessionID != "" && !ast.IsNodeIDPattern(sessionID) {
return fmt.Errorf("session id %q is not a valid node ID", sessionID)
} Type guard
func isNodeID(s string) bool { return ast.IsNodeIDPattern(s) } Try / catch
controller, err := registerSessionPermissionController(id)
if err != nil { /* reject the ID before touching session state */ } Prevention
- Always obtain session IDs from the runtime, never construct them by hand
- Sanitize IDs taken from paths or URLs before passing them into agent APIs
- Add a node-ID-pattern check at the boundary of any external input
When it happens
Trigger: Calling registerSessionPermissionController (directly or via session setup paths) with a hand-made or truncated ID such as 'abc', a filename stem without the full node-ID format, or an ID containing invalid characters.
Common situations: Custom tooling constructing session IDs instead of using IDs issued by the agent runtime; IDs copied from paths/URLs and mangled; tests passing fake IDs.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- frontend capability description is required
- invalid session data
- invalid session id
- agent runtime turn changed
- agent runtime turn is not finalized
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/15c95dce9a9d96a7.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/agent/runtime.go:102
if permissionMode, _ := session["permissionMode"].(string); permissionMode != "" {
if !validAgentPermissionMode(permissionMode) {
return "", fmt.Errorf("invalid agent permission mode")
}
return permissionMode, nil
}
if alwaysAllow, _ := session["alwaysAllow"].(bool); alwaysAllow {
return AgentPermissionAllowSession, nil
}
return AgentPermissionConfirm, nil
}
func registerSessionPermissionController(sessionID string) (*sessionPermissionController, error) {
controller := &sessionPermissionController{}
if sessionID == "" {
return controller, nil
}
if !isValidSessionID(sessionID) {
return nil, fmt.Errorf("invalid session id")
}
lock := sessionLock(sessionID)
lock.Lock()
defer lock.Unlock()
mode, err := resolveSessionPermissionModeLocked(sessionID, nil)
if err != nil {
return nil, err
}
controller.allowSession.Store(mode == AgentPermissionAllowSession)
sessionPermissionControllers.Store(sessionID, controller)
return controller, nil
}
func unregisterSessionPermissionController(sessionID string, controller *sessionPermissionController) {
if sessionID == "" || controller == nil {
return
}
sessionPermissionControllers.CompareAndDelete(sessionID, controller)View on GitHub (pinned to 9f775e8a12)