JuliusBrussee/caveman · error

note exceeds 4096 bytes

Error message

note exceeds 4096 bytes

What it means

Validation error in StartExperiment: the note attached to the learn experiment exceeds the 4096-byte ceiling enforced by the store. The note is persisted with the experiment record, so oversized free text is rejected rather than truncated silently.

Solutions

  1. Truncate the note to 4096 bytes before calling StartExperiment
  2. Move long content to an external artifact and reference it in the note
  3. Enforce the limit at the input UI/form layer
  4. Summarize or compress diagnostics before storing

Example fix

// before
store.StartExperiment(label, sinkID, fixKind, fullLog) // >4096 bytes
// after
note := fullLog
if len(note) > 4096 { note = note[:4096] }
store.StartExperiment(label, sinkID, fixKind, note)
Defensive patterns

Strategy: validation

Validate before calling

if len(note) > 4096 { return errors.New("note exceeds 4096 bytes; truncate before calling StartExperiment") }

Try / catch

_, err := store.StartExperiment(label, sinkID, fixKind, note)
if err != nil && strings.Contains(err.Error(), "note exceeds 4096 bytes") {
    return fmt.Errorf("trim note from %d to <=4096 bytes", len(note))
}

Prevention

When it happens

Trigger: Calling StartExperiment with a note string whose UTF-8 length exceeds 4096 bytes.

Common situations: Pasting stack traces, logs, or long markdown documents into the note field; programmatic notes built by concatenating diagnostic output.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


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

Appendix: source

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

	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)
	}
	return s.LoadExperiment(label)
}

View on GitHub (pinned to 3ee70a1026)