{"record":{"id":"8d8909136b3e3b7d","repo":"siyuan-note/siyuan","slug":"invalid-agent-runtime-revision","errorCode":null,"errorMessage":"invalid agent runtime revision","messagePattern":"invalid agent runtime revision","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/runtime.go","lineNumber":210,"sourceCode":"\tdata, err := os.ReadFile(runtimePath(sessionID))\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn &agentRuntime{SchemaVersion: 1, SessionID: sessionID}, nil\n\t\t}\n\t\treturn nil, err\n\t}\n\tvar runtime agentRuntime\n\tif err := gulu.JSON.UnmarshalJSON(data, &runtime); err != nil {\n\t\treturn nil, err\n\t}\n\tif runtime.SchemaVersion > 1 {\n\t\treturn nil, fmt.Errorf(\"unsupported agent runtime schema version: %d\", runtime.SchemaVersion)\n\t}\n\tif runtime.SessionID != \"\" && runtime.SessionID != sessionID {\n\t\treturn nil, fmt.Errorf(\"agent runtime session id mismatch\")\n\t}\n\tif runtime.Revision < 0 {\n\t\treturn nil, fmt.Errorf(\"invalid agent runtime revision\")\n\t}\n\tif runtime.ActiveTurn != nil {\n\t\tif runtime.ActiveTurn.TurnID == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"invalid agent runtime turn id\")\n\t\t}\n\t\tswitch runtime.ActiveTurn.State {\n\t\tcase \"running\", \"finished\", \"interrupted\":\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"invalid agent runtime turn state\")\n\t\t}\n\t}\n\tif runtime.SchemaVersion == 0 {\n\t\truntime.SchemaVersion = 1\n\t}\n\tif runtime.SessionID == \"\" {\n\t\truntime.SessionID = sessionID\n\t}\n\treturn &runtime, nil","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/agent/runtime.go#L192-L228","documentation":"loadRuntimeLocked validates the persisted Revision counter and rejects negative values. The revision is a monotonically increasing version used for optimistic concurrency (compared against turn.BaseRevision elsewhere), so a negative revision is structurally meaningless and indicates a corrupted or hand-edited runtime file.","triggerScenarios":"Loading any session whose runtime JSON contains \"revision\": -N; hand-editing sessions/<id>/ runtime file; a partial/failed write that left a sentinel or garbage value in the field.","commonSituations":"Manual editing of the runtime JSON; an external tool rewriting session state; disk corruption in the workspace data directory.","solutions":["Inspect the runtime JSON and restore revision to a correct non-negative value from a backup","If no backup exists, delete the runtime state for that session so the kernel rebuilds it","Avoid editing session runtime files directly; always mutate them through the kernel APIs that bump the revision"],"exampleFix":"// before (runtime JSON)\n\"revision\": -3\n// after\n\"revision\": 3","handlingStrategy":"validation","validationCode":"const runtime = JSON.parse(readRuntimeFile(sessionDir));\nif (typeof runtime.revision !== \"number\" || runtime.revision < 0) throw new Error(\"runtime revision corrupt\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not hand-edit session runtime files; use kernel APIs that manage revision","Keep workspace backups so a corrupt revision can be restored","Only run one kernel instance per workspace to avoid concurrent conflicting writes"],"tags":["agent","validation","revision"],"backgroundTag":"value-out-of-range","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"}