{"record":{"id":"0456fe785f76093d","repo":"JuliusBrussee/caveman","slug":"native-runtime-invalid-decision-record","errorCode":null,"errorMessage":"native runtime: invalid decision record","messagePattern":"native runtime: invalid decision record","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/nativeruntime/explain.go","lineNumber":58,"sourceCode":"\t}\n\tvar record struct {\n\t\tSchema               string         `json:\"schema\"`\n\t\tDecisionID           string         `json:\"decision_id\"`\n\t\tTimestampMS          int64          `json:\"timestamp_ms\"`\n\t\tAction               string         `json:\"action\"`\n\t\tReason               string         `json:\"reason\"`\n\t\tInputBasis           map[string]any `json:\"input_basis\"`\n\t\tAlternativesRejected []string       `json:\"alternatives_rejected\"`\n\t\tTaskStateBefore      string         `json:\"task_state_before\"`\n\t\tTaskStateAfter       string         `json:\"task_state_after\"`\n\t\tCurrentness          string         `json:\"currentness\"`\n\t\tRecoveryRef          string         `json:\"recovery_ref\"`\n\t}\n\tif err := json.Unmarshal(object.Data, &record); err != nil {\n\t\treturn DecisionExplanation{}, fmt.Errorf(\"native runtime: decode decision: %w\", err)\n\t}\n\tif record.Schema != \"caveman.native.decision.v1\" || record.DecisionID != decisionID || record.Action == \"\" || record.Reason == \"\" {\n\t\treturn DecisionExplanation{}, errors.New(\"native runtime: invalid decision record\")\n\t}\n\treturn DecisionExplanation{\n\t\tSchema:               WhySchema,\n\t\tDecisionID:           record.DecisionID,\n\t\tSessionID:            object.SessionID,\n\t\tTimestampMS:          record.TimestampMS,\n\t\tAction:               record.Action,\n\t\tReason:               record.Reason,\n\t\tInputBasis:           record.InputBasis,\n\t\tAlternativesRejected: record.AlternativesRejected,\n\t\tTaskStateBefore:      record.TaskStateBefore,\n\t\tTaskStateAfter:       record.TaskStateAfter,\n\t\tCurrentness:          record.Currentness,\n\t\tRecoveryRef:          record.RecoveryRef,\n\t}, nil\n}\n","sourceCodeStart":40,"sourceCodeEnd":75,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/nativeruntime/explain.go#L40-L75","documentation":"After decoding the stored decision record, ExplainDecision enforces the record's invariants: schema must be caveman.native.decision.v1, the embedded DecisionID must match the requested id, and Action and Reason must be non-empty. Any violation returns this error instead of emitting a partially-populated explanation.","triggerScenarios":"store.FindTaskDecision(decisionID) returns a task-decision object whose JSON data fails one of: wrong record.Schema, record.DecisionID != requested decisionID, empty record.Action, or empty record.Reason.","commonSituations":"Records written by an older runtime version with a different schema string; corrupted or hand-edited SQLite rows; a record inserted by a test/external tool missing Action/Reason; a store row keyed by one id but containing another's payload after a bad migration or id collision.","solutions":["Delete/re-write the offending record with the current runtime so it is serialized under caveman.native.decision.v1 with Action and Reason populated.","Upgrade the runtime that wrote the record so schema versions match, or add a migration for old schema values.","Verify no duplicate/colliding decision ids exist in the ccr store.","Catch this error in runNativeWhy and report the decision as unexplainable rather than crashing the why flow."],"exampleFix":"// before\n// record written with schema \"caveman.native.decision\" (v0)\n// after\nrecord.Schema = \"caveman.native.decision.v1\" // re-persist the decision with the v1 schema before explaining","handlingStrategy":"try-catch","validationCode":"// after fetching the record, check invariants yourself\nvar rec struct{ Schema, DecisionID, Action, Reason string }\nif json.Unmarshal(data, &rec) == nil &&\n   rec.Schema == \"caveman.native.decision.v1\" && rec.Action != \"\" && rec.Reason != \"\" {\n    // safe to explain\n}","typeGuard":"func isV1Decision(data []byte, id string) bool {\n    var r struct{ Schema, DecisionID, Action, Reason string }\n    return json.Unmarshal(data, &r) == nil &&\n        r.Schema == \"caveman.native.decision.v1\" && r.DecisionID == id && r.Action != \"\" && r.Reason != \"\"\n}","tryCatchPattern":"exp, err := nativeruntime.ExplainDecision(store, id)\nif err != nil && strings.Contains(err.Error(), \"invalid decision record\") {\n    return fmt.Errorf(\"decision %s stored in an incompatible schema; re-record it\", id)\n}","preventionTips":["Always write decisions through the current runtime API","Migrate old schema versions before explaining historical records","Refuse manual edits to the ccr SQLite store"],"tags":["schema","validation","native-runtime"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}