{"record":{"id":"eba822c9a5eb8dc9","repo":"JuliusBrussee/caveman","slug":"experiment-label-must-be-1-128-bytes","errorCode":null,"errorMessage":"experiment label must be 1-128 bytes","messagePattern":"experiment label must be 1-128 bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/learn_experiment.go","lineNumber":90,"sourceCode":"type ExperimentReport struct {\n\tSchema     string                `json:\"schema\"`\n\tBasis      string                `json:\"basis\"`\n\tLabel      string                `json:\"label\"`\n\tSinkID     string                `json:\"sink_id,omitempty\"`\n\tFixKind    string                `json:\"fix_kind,omitempty\"`\n\tArms       []ExperimentArmResult `json:\"arms\"`\n\tVerdict    string                `json:\"verdict\"`\n\tDeltaPct   *float64              `json:\"median_session_tokens_delta_pct,omitempty\"`\n\tSavedUSD   *float64              `json:\"saved_usd_per_session,omitempty\"`\n\tCurrency   string                `json:\"currency,omitempty\"`\n\tAttributed LearnAttribution      `json:\"attribution\"`\n\tCaveats    []string              `json:\"caveats\"`\n}\n\nfunc (s *Store) StartExperiment(label, sinkID, fixKind, note string) (Experiment, error) {\n\tlabel = strings.TrimSpace(label)\n\tif label == \"\" || len(label) > 128 {\n\t\treturn Experiment{}, fmt.Errorf(\"experiment label must be 1-128 bytes\")\n\t}\n\tif len(note) > 4096 {\n\t\treturn Experiment{}, fmt.Errorf(\"note exceeds 4096 bytes\")\n\t}\n\tnow := learnOutcomeClock().UTC().Format(time.RFC3339)\n\tresult, err := s.db.Exec(`INSERT INTO experiments (label, sink_id, fix_kind, note, created_at)\n\t\tVALUES (?, ?, ?, ?, ?)`, label, sinkID, fixKind, note, now)\n\tif err != nil {\n\t\treturn Experiment{}, fmt.Errorf(\"start experiment %q: %w\", label, err)\n\t}\n\tid, err := result.LastInsertId()\n\tif err != nil {\n\t\treturn Experiment{}, fmt.Errorf(\"read experiment id: %w\", err)\n\t}\n\tif _, err := s.db.Exec(`INSERT INTO experiment_arms (experiment_id, arm, started_at)\n\t\tVALUES (?, ?, ?)`, id, experimentArmOn, now); err != nil {\n\t\treturn Experiment{}, fmt.Errorf(\"open first arm: %w\", err)\n\t}","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/learn_experiment.go#L72-L108","documentation":"StartExperiment validates the experiment label after trimming whitespace and rejects empty labels or labels longer than 128 bytes with this fixed message. The limit is on bytes, not runes, so multibyte UTF-8 characters count more heavily.","triggerScenarios":"Calling StartExperiment with an empty or whitespace-only label, or a label whose UTF-8 encoding exceeds 128 bytes.","commonSituations":"Auto-generated labels including long prefixes/timestamps, labels built from user input without truncation, or non-ASCII labels that blow past 128 bytes quickly (e.g. CJK text at 3 bytes/char).","solutions":["Trim and non-empty-check the label before calling StartExperiment","Truncate the label to at most 128 bytes on a rune boundary","Use ASCII characters to maximize effective character count within 128 bytes","Move long descriptive text into the note field, keeping the label short"],"exampleFix":"// before\nexp, err := store.StartExperiment(rawUserInput, sinkID, fixKind, note)\n// after\nlabel := strings.TrimSpace(rawUserInput)\nif len(label) > 128 { label = string([]rune(label)[:42]) }\nexp, err := store.StartExperiment(label, sinkID, fixKind, note)","handlingStrategy":"validation","validationCode":"func validExperimentLabel(label string) bool {\n    l := strings.TrimSpace(label)\n    return len(l) >= 1 && len(l) <= 128\n}","typeGuard":null,"tryCatchPattern":"exp, err := store.StartExperiment(label, sinkID, fixKind, note)\nif err != nil && strings.Contains(err.Error(), \"experiment label must be 1-128 bytes\") {\n    return fmt.Errorf(\"shorten experiment label %q to <=128 bytes\", label)\n}","preventionTips":["Truncate labels to 128 bytes on a rune boundary at input time","Keep labels ASCII and short; put detail in note","Reject empty/whitespace labels in UI/forms","Add a unit test for a 128-byte boundary label"],"tags":["validation","input-length"],"backgroundTag":"invalid-argument-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"}