JuliusBrussee/caveman · error

experiment label must be 1-128 bytes

Error message

experiment label must be 1-128 bytes

What it means

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.

Solutions

  1. Trim and non-empty-check the label before calling StartExperiment
  2. Truncate the label to at most 128 bytes on a rune boundary
  3. Use ASCII characters to maximize effective character count within 128 bytes
  4. Move long descriptive text into the note field, keeping the label short

Example fix

// before
exp, err := store.StartExperiment(rawUserInput, sinkID, fixKind, note)
// after
label := strings.TrimSpace(rawUserInput)
if len(label) > 128 { label = string([]rune(label)[:42]) }
exp, err := store.StartExperiment(label, sinkID, fixKind, note)
Defensive patterns

Strategy: validation

Validate before calling

func validExperimentLabel(label string) bool {
    l := strings.TrimSpace(label)
    return len(l) >= 1 && len(l) <= 128
}

Try / catch

exp, err := store.StartExperiment(label, sinkID, fixKind, note)
if err != nil && strings.Contains(err.Error(), "experiment label must be 1-128 bytes") {
    return fmt.Errorf("shorten experiment label %q to <=128 bytes", label)
}

Prevention

When it happens

Trigger: Calling StartExperiment with an empty or whitespace-only label, or a label whose UTF-8 encoding exceeds 128 bytes.

Common situations: 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).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/eba822c9a5eb8dc9. Report an issue: GitHub.

Appendix: source

Thrown at proxy/internal/store/learn_experiment.go:90

type ExperimentReport struct {
	Schema     string                `json:"schema"`
	Basis      string                `json:"basis"`
	Label      string                `json:"label"`
	SinkID     string                `json:"sink_id,omitempty"`
	FixKind    string                `json:"fix_kind,omitempty"`
	Arms       []ExperimentArmResult `json:"arms"`
	Verdict    string                `json:"verdict"`
	DeltaPct   *float64              `json:"median_session_tokens_delta_pct,omitempty"`
	SavedUSD   *float64              `json:"saved_usd_per_session,omitempty"`
	Currency   string                `json:"currency,omitempty"`
	Attributed LearnAttribution      `json:"attribution"`
	Caveats    []string              `json:"caveats"`
}

func (s *Store) StartExperiment(label, sinkID, fixKind, note string) (Experiment, error) {
	label = strings.TrimSpace(label)
	if label == "" || len(label) > 128 {
		return Experiment{}, fmt.Errorf("experiment label must be 1-128 bytes")
	}
	if len(note) > 4096 {
		return Experiment{}, fmt.Errorf("note exceeds 4096 bytes")
	}
	now := learnOutcomeClock().UTC().Format(time.RFC3339)
	result, err := s.db.Exec(`INSERT INTO experiments (label, sink_id, fix_kind, note, created_at)
		VALUES (?, ?, ?, ?, ?)`, label, sinkID, fixKind, note, now)
	if err != nil {
		return Experiment{}, fmt.Errorf("start experiment %q: %w", label, err)
	}
	id, err := result.LastInsertId()
	if err != nil {
		return Experiment{}, fmt.Errorf("read experiment id: %w", err)
	}
	if _, err := s.db.Exec(`INSERT INTO experiment_arms (experiment_id, arm, started_at)
		VALUES (?, ?, ?)`, id, experimentArmOn, now); err != nil {
		return Experiment{}, fmt.Errorf("open first arm: %w", err)
	}

View on GitHub (pinned to 3ee70a1026)