{"record":{"id":"7553591703fbc8d6","repo":"JuliusBrussee/caveman","slug":"session-value-artifact-schema-mismatch","errorCode":null,"errorMessage":"session-value artifact schema mismatch","messagePattern":"session-value artifact schema mismatch","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/routing/session_value.go","lineNumber":165,"sourceCode":"\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"marshal session-value artifact: %w\", err)\n\t}\n\tsum := sha256.Sum256(raw)\n\treturn \"sha256:\" + hex.EncodeToString(sum[:]), nil\n}\n\nfunc SealSessionValueArtifact(artifact SessionValuePolicyArtifact) (SessionValuePolicyArtifact, error) {\n\thash, err := ComputeSessionValueArtifactHash(artifact)\n\tif err != nil {\n\t\treturn SessionValuePolicyArtifact{}, err\n\t}\n\tartifact.ArtifactHash = hash\n\treturn artifact, nil\n}\n\nfunc ValidateSessionValueArtifact(artifact SessionValuePolicyArtifact, organizationID, projectID, candidatePoolHash string, now time.Time) error {\n\tif artifact.Schema != SessionValueArtifactSchema || artifact.StateSchemaVersion != SessionValueStateSchema {\n\t\treturn errors.New(\"session-value artifact schema mismatch\")\n\t}\n\tif strings.TrimSpace(artifact.OrganizationID) == \"\" || artifact.OrganizationID != strings.TrimSpace(organizationID) ||\n\t\tstrings.TrimSpace(artifact.ProjectID) == \"\" || artifact.ProjectID != strings.TrimSpace(projectID) {\n\t\treturn errors.New(\"session-value artifact tenant scope mismatch\")\n\t}\n\tif artifact.PolicyVersion <= 0 || artifact.RouterVersion != SessionValueRouterVersion || strings.TrimSpace(artifact.EstimatorVersion) == \"\" {\n\t\treturn errors.New(\"session-value artifact version identity invalid\")\n\t}\n\tif !validCompactPoolHash(artifact.CandidatePoolHash) || artifact.CandidatePoolHash != candidatePoolHash {\n\t\treturn errors.New(\"session-value artifact candidate pool mismatch\")\n\t}\n\tif !validSHA256Ref(artifact.TrainingManifestHash) || strings.TrimSpace(artifact.TrainingExtractor) == \"\" || strings.TrimSpace(artifact.OutcomeContractVersion) == \"\" {\n\t\treturn errors.New(\"session-value artifact training lineage invalid\")\n\t}\n\tif artifact.ValidFrom.IsZero() || artifact.ValidUntil.IsZero() || !artifact.ValidUntil.After(artifact.ValidFrom) || now.Before(artifact.ValidFrom) || !now.Before(artifact.ValidUntil) {\n\t\treturn errors.New(\"session-value artifact outside validity window\")\n\t}\n\tif artifact.RollbackParentHash != \"\" && (!validSHA256Ref(artifact.RollbackParentHash) || artifact.RollbackParentHash == artifact.ArtifactHash) {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/proxy/routing/session_value.go#L147-L183","documentation":"ValidateSessionValueArtifact first checks that the artifact declares the exact schema pair the evaluator understands: Schema == \"caveman.router.session-value-policy.v1\" and StateSchemaVersion == \"router-state-metadata-v1\". Any other pair is rejected before tenant, pool, lineage, or numeric checks run, because the evaluator cannot interpret fields from a different schema generation.","triggerScenarios":"Loading an artifact produced by an older or newer trainer where either constant was renamed or bumped; hand-edited JSON; mixing two artifact streams so the policy schema no longer matches the state-metadata schema the router persists.","commonSituations":"Router upgraded across a schema version change while old artifacts are still referenced by config; trainer and router released out of sync; artifact files copied between environments running different versions.","solutions":["Regenerate or re-ship the artifact with the current trainer so Schema and StateSchemaVersion match the deployed router constants.","When debugging, check these two fields first — all later validation (tenant, pool, lineage, window) only runs after this check passes.","Pin router and trainer versions together in the release pipeline so schema constants cannot skew."],"exampleFix":"// before\n{\n  \"schema\": \"caveman.router.session-value-policy.v0\",\n  \"state_schema_version\": \"router-state-metadata-v0\"\n}\n\n// after\n{\n  \"schema\": \"caveman.router.session-value-policy.v1\",\n  \"state_schema_version\": \"router-state-metadata-v1\"\n}","handlingStrategy":"validation","validationCode":"// Before full validation, compare against the exported constants.\nif artifact.Schema != routing.SessionValueArtifactSchema ||\n\tartifact.StateSchemaVersion != routing.SessionValueStateSchema {\n\treturn fmt.Errorf(\"artifact schema %q/%q not supported by this router (want %q/%q); regenerate with the matching trainer\",\n\t\tartifact.Schema, artifact.StateSchemaVersion,\n\t\trouting.SessionValueArtifactSchema, routing.SessionValueStateSchema)\n}","typeGuard":"func artifactSchemaCompatible(a routing.SessionValuePolicyArtifact) bool {\n\treturn a.Schema == routing.SessionValueArtifactSchema &&\n\t\ta.StateSchemaVersion == routing.SessionValueStateSchema\n}","tryCatchPattern":null,"preventionTips":["Check schema fields first when loading artifacts — they short-circuit every later diagnostic.","Ship trainer and router in lockstep so the constants cannot diverge.","Include the schema strings in artifact filenames or registry metadata for quick visual audits."],"tags":["routing","schema","versioning","artifact"],"backgroundTag":"artifact-schema-version-mismatch","analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}