{"record":{"id":"5e92cdd4bdc08e18","repo":"JuliusBrussee/caveman","slug":"encode-before-evidence-w","errorCode":null,"errorMessage":"encode before evidence: %w","messagePattern":"encode before evidence: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/learn_outcomes.go","lineNumber":93,"sourceCode":"\t}\n\tif fixKind == \"\" {\n\t\treturn AppliedFixRecord{}, fmt.Errorf(\"sink %q has no measurable fix kind; pass --fix-kind explicitly\", sinkID)\n\t}\n\tif len(fixKind) > 128 {\n\t\treturn AppliedFixRecord{}, fmt.Errorf(\"fix kind exceeds 128 bytes\")\n\t}\n\tif len(note) > 4096 {\n\t\treturn AppliedFixRecord{}, fmt.Errorf(\"note exceeds 4096 bytes\")\n\t}\n\tappliedAt := appliedAtTime.Format(time.RFC3339)\n\tbeforeEvidence := make(map[string]any, len(sink.Evidence)+1)\n\tfor key, value := range sink.Evidence {\n\t\tbeforeEvidence[key] = value\n\t}\n\tbeforeEvidence[\"before_source\"] = beforeSource\n\tevidence, err := json.Marshal(beforeEvidence)\n\tif err != nil {\n\t\treturn AppliedFixRecord{}, fmt.Errorf(\"encode before evidence: %w\", err)\n\t}\n\t// Fingerprint the edited artifact as it stands NOW — which at\n\t// `caveman learn applied` time is immediately after the approved edit. This\n\t// is the provenance anchor: a later scan re-hashes the same path and can\n\t// state whether the change we proposed is still the change that is there.\n\ttarget := fingerprintFixTarget(*sink)\n\ttargetJSON := \"\"\n\tif target != nil {\n\t\tif encoded, encodeErr := json.Marshal(target); encodeErr == nil {\n\t\t\ttargetJSON = string(encoded)\n\t\t}\n\t}\n\tresult, err := s.db.Exec(`INSERT INTO applied_fixes\n\t\t(sink_id, practice_id, fix_kind, applied_at, before_tokens_per_turn, before_evidence_json, note, target_json)\n\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?)`, sink.SinkID, sink.PracticeID, fixKind, appliedAt, sink.TokensPerTurn, string(evidence), note, targetJSON)\n\tif err != nil {\n\t\treturn AppliedFixRecord{}, fmt.Errorf(\"record applied fix: %w\", err)\n\t}","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/81536f57b3303b7de7f5bc5b564cc344f9112d68/proxy/internal/store/learn_outcomes.go#L75-L111","documentation":"json.Marshal of the before-evidence map failed in RecordAppliedFix, before any database write. The map copies the sink's evidence and adds before_source; marshaling fails only if evidence contains values JSON cannot encode (channels, funcs, cyclic data).","triggerScenarios":"Thrown at proxy/internal/store/learn_outcomes.go:93 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the sink evidence map for non-JSON-serializable values","Sanitize or drop unsupported evidence values before recording the fix","Log the wrapped json error to identify the offending key"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"81536f57b3303b7de7f5bc5b564cc344f9112d68","analyzedAt":"2026-08-27T02:25:50.681Z","contentChangedAt":"2026-08-27T02:25:50.681Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}