{"record":{"id":"53a888deb5e0cc24","repo":"JuliusBrussee/caveman","slug":"native-runtime-invalid-decision-id","errorCode":null,"errorMessage":"native runtime: invalid decision id","messagePattern":"native runtime: invalid decision id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/nativeruntime/explain.go","lineNumber":35,"sourceCode":"// Ledger record. It contains decision basis, never raw prompt or tool output.\ntype DecisionExplanation struct {\n\tSchema               string         `json:\"schema\"`\n\tDecisionID           string         `json:\"decision_id\"`\n\tSessionID            string         `json:\"session_id\"`\n\tTimestampMS          int64          `json:\"timestamp_ms\"`\n\tAction               string         `json:\"action\"`\n\tReason               string         `json:\"reason\"`\n\tInputBasis           map[string]any `json:\"input_basis\"`\n\tAlternativesRejected []string       `json:\"alternatives_rejected\"`\n\tTaskStateBefore      string         `json:\"task_state_before\"`\n\tTaskStateAfter       string         `json:\"task_state_after\"`\n\tCurrentness          string         `json:\"currentness\"`\n\tRecoveryRef          string         `json:\"recovery_ref,omitempty\"`\n}\n\nfunc ExplainDecision(store *ccr.Store, decisionID string) (DecisionExplanation, error) {\n\tif !decisionIDPattern.MatchString(decisionID) {\n\t\treturn DecisionExplanation{}, errors.New(\"native runtime: invalid decision id\")\n\t}\n\tobject, err := store.FindTaskDecision(decisionID)\n\tif err != nil {\n\t\treturn DecisionExplanation{}, err\n\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}","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/nativeruntime/explain.go#L17-L53","documentation":"ExplainDecision validates the decisionID against a strict decisionIDPattern before touching the store, returning this error for malformed ids. This keeps arbitrary strings from becoming store lookups and gives callers a deterministic, cheap validation failure.","triggerScenarios":"runNativeWhy (native runtime why handler) or tests call ExplainDecision(store, decisionID) with an id that does not match decisionIDPattern — e.g. empty string, path separators, uuid with wrong format, or a truncated id from a client.","commonSituations":"A client tool passes a human-typed or copy-pasted decision reference; an older stored id format predating the pattern; passing a session id where a decision id was expected.","solutions":["Check the id against the same decisionIDPattern client-side before calling ExplainDecision and return a better message.","Retrieve the decision id programmatically from the store (FindTaskDecision/list) instead of accepting user-typed input.","If valid legacy ids fail, migrate them to the current id format.","Log the offending id (safely) to spot the client sending malformed values."],"exampleFix":"// before\nexp, err := nativeruntime.ExplainDecision(store, req.DecisionID)\n// after\nif !isValidDecisionID(req.DecisionID) {\n    return errorf(\"decision id must match format ...\")\n}\nexp, err := nativeruntime.ExplainDecision(store, req.DecisionID)","handlingStrategy":"validation","validationCode":"var decisionIDPattern = regexp.MustCompile(`^[0-9a-f-]{36}$`) // match the library's pattern\nif !decisionIDPattern.MatchString(id) {\n    return fmt.Errorf(\"malformed decision id %q\", id)\n}","typeGuard":"func validDecisionID(s string) bool { return decisionIDPattern.MatchString(s) }","tryCatchPattern":"exp, err := nativeruntime.ExplainDecision(store, id)\nif err != nil && strings.Contains(err.Error(), \"invalid decision id\") {\n    return fmt.Errorf(\"decision id %q is malformed; fetch ids from the store instead\", id)\n}","preventionTips":["Never accept hand-typed decision ids; list them from the store","Keep client-side id format validation in sync with the runtime","Log rejected ids to find misbehaving clients"],"tags":["validation","identifier","native-runtime"],"backgroundTag":"invalid-identifier-format","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"}