{"record":{"id":"9b4d5913dad8acd8","repo":"JuliusBrussee/caveman","slug":"compat-upstream-q-w-openaicompat","errorCode":null,"errorMessage":"compat upstream %q: %w","messagePattern":"compat upstream %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/providers/openaicompat/openaicompat.go","lineNumber":374,"sourceCode":"// on the mount. It changes two things and nothing else:\n//\n//   - USAGE ACCOUNTING parses with the Anthropic dialect (Base.UsageProvider):\n//     the usage block reports input_tokens EXCLUSIVE of cache reads/writes, so\n//     the OpenAI-shape contradiction check reads a warm cache as malformed and\n//     drops every such row from token accounting (issue #1026).\n//   - COMPRESSION ZONES follow the Anthropic Messages grammar on Messages-path\n//     requests and keep the OpenAI grammar on every other path (see\n//     anthropicWireZones): the Anthropic extractor keys the live/frozen\n//     boundary on the request's own cache_control breakpoints.\n//\n// Routing, header mapping, telemetry provider, and pricing keep the mount's\n// openai_compatible identity in every dialect.\nfunc NewNamedWithWireDialect(name, baseURL, wireDialect string, forwardHeaders ...string) (providers.Adapter, error) {\n\tif err := ValidateName(name); err != nil {\n\t\treturn nil, err\n\t}\n\tif err := ValidateWireDialect(wireDialect); err != nil {\n\t\treturn nil, fmt.Errorf(\"compat upstream %q: %w\", name, err)\n\t}\n\tbaseURL = strings.TrimSpace(baseURL)\n\tif err := ValidateBaseURL(baseURL); err != nil {\n\t\treturn nil, fmt.Errorf(\"compat upstream %q base_url: %w\", name, err)\n\t}\n\tif err := ValidateForwardHeaders(forwardHeaders); err != nil {\n\t\treturn nil, fmt.Errorf(\"compat upstream %q forward_headers: %w\", name, err)\n\t}\n\tprefix := \"/compat/\" + name\n\treturn namedAdapter{\n\t\tBase: providers.Base{\n\t\t\tProvider:      \"openai_compatible\",\n\t\t\tBaseURL:       baseURL,\n\t\t\tRoutes:        []string{prefix + \"/\"},\n\t\t\tUsageProvider: wireDialectUsageProvider[wireDialect],\n\t\t},\n\t\tprefix:         prefix,\n\t\tforwardHeaders: append([]string(nil), forwardHeaders...),","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/providers/openaicompat/openaicompat.go#L356-L392","documentation":"NewNamedWithWireDialect wraps ValidateWireDialect failures with the offending mount name: \"compat upstream %q: %w\". It is raised when creating a named compat mount whose wire_dialect is neither \"anthropic\" nor empty, so startup or the test harness cannot construct the adapter.","triggerScenarios":"Calling NewNamedWithWireDialect(name, baseURL, dialect, ...) or buildAdapters on config with an invalid dialect string; also exercised by the dialect stream/non-stream tests that pass an unknown dialect.","commonSituations":"Invalid wire_dialect in the mounts config loaded at startup; unit/integration tests constructing mounts with an intentionally bad dialect; config templating injecting a dialect variable that is empty-but-nonstandard (e.g. \"none\").","solutions":["Correct the wire_dialect for the named mount to \"anthropic\" or drop it (empty = OpenAI shape).","The wrapped message names the mount (name in %q) — fix that mount's entry in config.","If constructing programmatically, validate with providers.ValidateWireDialect (or openaicompat.ValidateWireDialect) before calling NewNamedWithWireDialect.","Run the config validation (validateCompat path) at startup to catch this before serving traffic."],"exampleFix":"// before\nadapter, err := openaicompat.NewNamedWithWireDialect(\"claude\", url, \"openai-shape\")\n// after\nadapter, err := openaicompat.NewNamedWithWireDialect(\"claude\", url, \"anthropic\")","handlingStrategy":"validation","validationCode":"if d := mount.WireDialect; d != \"\" && d != \"anthropic\" {\n    return fmt.Errorf(\"mount %q: wire_dialect %q not supported\", mount.Name, d)\n}","typeGuard":null,"tryCatchPattern":"adapter, err := openaicompat.NewNamedWithWireDialect(name, baseURL, dialect)\nif err != nil {\n    return nil, fmt.Errorf(\"constructing compat mount: %w\", err)\n}","preventionTips":["Validate dialects at config-load time, before constructing adapters.","Keep dialect strings in a small typed constant set.","Test mount construction in CI with the real config file."],"tags":["go","proxy","config","adapter-init"],"backgroundTag":"invalid-enum-value","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"}