JuliusBrussee/caveman · error

experiment %q is stopped

Error message

experiment %q is stopped

What it means

Guard in SwitchExperimentArm: the named experiment already has a stopped_at timestamp, so its arm history is closed and no further arm switches are permitted. It fires when switching arms on a stopped experiment rather than silently reopening it.

Source

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

		return Experiment{}, fmt.Errorf("open first arm: %w", err)
	}
	return s.LoadExperiment(label)
}

// SwitchExperimentArm closes the open arm and opens the other one. Switching to
// the arm already running is a no-op rather than an error: it keeps a repeated
// call from fragmenting the interval history.
func (s *Store) SwitchExperimentArm(label, arm string) (Experiment, error) {
	arm = strings.ToLower(strings.TrimSpace(arm))
	if arm != experimentArmOn && arm != experimentArmOff {
		return Experiment{}, fmt.Errorf("arm must be %q or %q", experimentArmOn, experimentArmOff)
	}
	experiment, err := s.LoadExperiment(label)
	if err != nil {
		return Experiment{}, err
	}
	if experiment.StoppedAt != "" {
		return Experiment{}, fmt.Errorf("experiment %q is stopped", experiment.Label)
	}
	for _, existing := range experiment.Arms {
		if existing.EndedAt == "" && existing.Arm == arm {
			return experiment, nil
		}
	}
	now := learnOutcomeClock().UTC().Format(time.RFC3339)
	if _, err := s.db.Exec(`UPDATE experiment_arms SET ended_at = ?
		WHERE experiment_id = ? AND ended_at IS NULL`, now, experiment.id); err != nil {
		return Experiment{}, fmt.Errorf("close open arm: %w", err)
	}
	if _, err := s.db.Exec(`INSERT INTO experiment_arms (experiment_id, arm, started_at)
		VALUES (?, ?, ?)`, experiment.id, arm, now); err != nil {
		return Experiment{}, fmt.Errorf("open arm %q: %w", arm, err)
	}
	return s.LoadExperiment(label)
}

View on GitHub (pinned to 81536f57b3)

Solutions

  1. Start a new experiment with StartExperiment instead of switching the stopped one
  2. Remove or clear the stopped_at value only if intentionally reusing the experiment label
  3. Confirm the experiment label refers to the experiment you meant to switch
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at proxy/internal/store/learn_experiment.go:125 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@81536f57b3 (2026-08-27). Data as JSON: /api/errors/33fdee6461f65b9c. Report an issue: GitHub.