{"record":{"id":"1b668b2e9a8445d3","repo":"JuliusBrussee/caveman","slug":"start-experiment-q-w","errorCode":null,"errorMessage":"start experiment %q: %w","messagePattern":"start experiment %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/learn_experiment.go","lineNumber":99,"sourceCode":"\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}\n\treturn s.LoadExperiment(label)\n}\n\n// SwitchExperimentArm closes the open arm and opens the other one. Switching to\n// the arm already running is a no-op rather than an error: it keeps a repeated\n// call from fragmenting the interval history.\nfunc (s *Store) SwitchExperimentArm(label, arm string) (Experiment, error) {\n\tarm = strings.ToLower(strings.TrimSpace(arm))\n\tif arm != experimentArmOn && arm != experimentArmOff {","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/learn_experiment.go#L81-L117","documentation":"This wraps a failure of the INSERT INTO experiments SQL statement inside StartExperiment. Any SQLite/driver error (constraint violation, locked database, schema mismatch) is reported under this prefix with the experiment label for context.","triggerScenarios":"Calling StartExperiment when the experiments table is missing or has an incompatible schema, a UNIQUE constraint on label collides with an existing experiment, or the database file is locked/corrupt.","commonSituations":"Old database files from a previous schema version, starting two experiments with the same label, or concurrent writers holding the SQLite lock.","solutions":["Read the wrapped error (%w) for the exact SQL failure cause","Check for an existing experiment with the same label (UNIQUE collision) and reuse or rename it","Run schema migrations if the database predates the experiments table","Retry on SQLITE_BUSY or ensure connections close to release locks"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check label uniqueness if schema enforces UNIQUE\nvar count int\nerr := db.QueryRow(`SELECT COUNT(*) FROM experiments WHERE label = ?`, label).Scan(&count)\nif err == nil && count > 0 { return errors.New(\"experiment label already exists\") }","typeGuard":null,"tryCatchPattern":"exp, err := store.StartExperiment(label, sinkID, fixKind, note)\nif err != nil {\n    if strings.Contains(err.Error(), \"UNIQUE constraint\") { /* reuse or rename */ }\n    var busy bool\n    if strings.Contains(err.Error(), \"SQLITE_BUSY\") { busy = true /* retry with backoff */ }\n    return fmt.Errorf(\"start experiment failed: %w\", err)\n}","preventionTips":["Run schema migrations before starting experiments","Use unique or pre-checked labels","Serialize writers or set a busy_timeout on SQLite","Back up and integrity-check the database file"],"tags":["database","sqlite","insert"],"backgroundTag":"database-write-failed","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"}