{"record":{"id":"760f242020e98696","repo":"JuliusBrussee/caveman","slug":"read-experiment-id-w","errorCode":null,"errorMessage":"read experiment id: %w","messagePattern":"read experiment id: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/learn_experiment.go","lineNumber":103,"sourceCode":"}\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 {\n\t\treturn Experiment{}, fmt.Errorf(\"arm must be %q or %q\", experimentArmOn, experimentArmOff)\n\t}\n\texperiment, err := s.LoadExperiment(label)\n\tif err != nil {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/81536f57b3303b7de7f5bc5b564cc344f9112d68/proxy/internal/store/learn_experiment.go#L85-L121","documentation":"StartExperiment could not read the auto-increment id after inserting the experiment row (LastInsertId failed). The row may exist without its id being retrievable — a driver/store-level failure, not a validation problem.","triggerScenarios":"Thrown at proxy/internal/store/learn_experiment.go:103 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the experiment start; check whether the orphaned row was inserted and clean it up","Inspect the wrapped driver error for a closed or locked database","Query the experiments table by label to recover the id of an already-inserted row"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"81536f57b3303b7de7f5bc5b564cc344f9112d68","analyzedAt":"2026-08-27T02:25:50.681Z","contentChangedAt":"2026-08-27T02:25:50.681Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}