siyuan-note/siyuan · error
agent runtime session id mismatch
Error message
agent runtime session id mismatch
What it means
loadRuntimeLocked checks that the runtime file's embedded SessionID matches the sessionID being loaded. A non-empty mismatch means the runtime file belongs to a different session — the directory contents and file contents have diverged. This is treated as a corruption/invariant violation rather than silently remapping the data.
Solutions
- Ensure you are addressing the correct session ID; the runtime file's SessionID field tells you which session the file actually belongs to
- If the file was misplaced, move it back to sessions/<embeddedSessionID>/ rather than editing it
- If the runtime is genuinely corrupt, remove that session's runtime state so it can be regenerated, preserving other session data
Defensive patterns
Strategy: validation
Validate before calling
const runtime = JSON.parse(readRuntimeFile(sessionDir));
if (runtime.sessionID && runtime.sessionID !== sessionID) throw new Error(`runtime file belongs to ${runtime.sessionID}, not ${sessionID}`); Prevention
- Never copy or rename session directories by hand
- Restore backups as whole session folders, not mixed files
- Treat the runtime file's embedded sessionID as authoritative when locating files
When it happens
Trigger: Calling any loadRuntimeLocked-backed API for session X while the runtime JSON inside sessions/<X>/ was written for session Y; copying or renaming session directories by hand; a restore that mixed files across session folders.
Common situations: Manual file moves/copies between session directories; a botched backup restore; a script that rewrites session IDs without updating the embedded runtime SessionID field.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- decode existing session data failed
- invalid session id
- agent compaction summary is empty
- agent context cannot be compacted enough
- agent context cannot be compacted enough: build runtime…
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/c3eba555c4cf280d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/agent/runtime.go:207
}
func loadRuntimeLocked(sessionID string) (*agentRuntime, error) {
data, err := os.ReadFile(runtimePath(sessionID))
if err != nil {
if os.IsNotExist(err) {
return &agentRuntime{SchemaVersion: 1, SessionID: sessionID}, nil
}
return nil, err
}
var runtime agentRuntime
if err := gulu.JSON.UnmarshalJSON(data, &runtime); err != nil {
return nil, err
}
if runtime.SchemaVersion > 1 {
return nil, fmt.Errorf("unsupported agent runtime schema version: %d", runtime.SchemaVersion)
}
if runtime.SessionID != "" && runtime.SessionID != sessionID {
return nil, fmt.Errorf("agent runtime session id mismatch")
}
if runtime.Revision < 0 {
return nil, fmt.Errorf("invalid agent runtime revision")
}
if runtime.ActiveTurn != nil {
if runtime.ActiveTurn.TurnID == "" {
return nil, fmt.Errorf("invalid agent runtime turn id")
}
switch runtime.ActiveTurn.State {
case "running", "finished", "interrupted":
default:
return nil, fmt.Errorf("invalid agent runtime turn state")
}
}
if runtime.SchemaVersion == 0 {
runtime.SchemaVersion = 1
}
if runtime.SessionID == "" {View on GitHub (pinned to 9f775e8a12)