# Run an experiment

> Compare two ways of working on real tickets: define arms, limit which tickets take part, read the report, and stop or promote the winner.

An experiment gives some of your tickets one setting or prompt and the rest another, then compares what happened. Use it to answer "does a higher retry limit help?" or "does this reviewer prompt catch more?" with your own tickets, not a guess.

Nothing changes until you add an experiment. A ticket keeps its arm for life, retries included, and an arm changes only that ticket's runs.

## Define one

An experiment has a name and two or more arms. The first arm is the control: every other arm is compared with it. An arm can do any of three things:

- `set`: config keys (dot paths) and the values to use for that ticket's runs.
- `roles`: a role file to use instead of the role's own.
- `prompt`: exact text in a role's prompt, and what replaces it.

```sh
dobby experiment add '{"name":"retries","arms":[{"name":"base"},{"name":"more","set":{"retryLimit":5}}],"scope":{"percent":50}}'
```

Dobby checks the keys and values like the config would and saves the experiment to your private config. You can also write it under `experiments` in the config file by hand.

Keys that guard the sandbox, safety rules, secrets and merge rules are refused unless you add `--allow-protected`. A command in a checked-in config file is ignored.

## Scope it

`scope` limits which tickets take part. Every part is optional:

- `projects`, `sizes`, `kinds` (`ticket` or `fix`): only tickets that match.
- `roles`: the `set` overrides apply only to runs of these roles (build, check, design, review).
- `percent`: the share of the matching tickets that take part. The rest run unchanged.

A ticket joins one arm of each running experiment whose scope fits, as long as the experiments' `scope.roles` do not overlap (an experiment with no `scope.roles` reaches every role, so it overlaps all): for example one with roles build and one with roles review both take the same ticket, and each run uses the arm whose roles include its role. Otherwise the first in the list whose scope fits wins. Arms stay balanced, so their ticket counts never differ by more than one.

## See what is running

`dobby experiment list` shows each experiment, its state and the tickets in each arm.

The dashboard's Home page has an Experiments card for each running experiment: its arms, the tickets in each, and one headline number, the difference from the first arm. On Mondays the summary adds one line per running experiment.

Both use one built-in metric. It is `cost` unless the experiment sets `headline` to another name from the report below.

## Read the report

```sh
dobby experiment report retries
```

```text
experiment retries  tickets: base 21, more 20
Value = mean per ticket; ±range = 95% error range. Rates are 0 to 1. A difference whose range includes 0 is not a clear result.

metric                base (control)  more           more − base
cost (% of week)      0.42 ±0.08      0.55 ±0.1      +0.13 ±0.13
first-review pass     0.67 ±0.2       0.8 ±0.18      +0.13 ±0.27
```

Each row is a mean per ticket for each arm, plus the later arm's difference from the control. A difference whose range includes 0 (like both above) is not a clear result yet: wait for more tickets.

The built-in metrics are cost, turns, ceiling hits, first-review pass, review rounds, shipped, reverted and time to merge. Add your own under `metrics`, each a read-only SQL query using `:ticket` or a command with an argument list, that prints one number per ticket.

## Stop it

- `dobby experiment stop retries` ends it: no new tickets join, and the ones in it run unchanged from their next run.
- Dobby also stops an arm by itself when it is clearly worse than the control. After `expStopAfter` tickets (20 by default) on the arm and the control, an arm that is `expStopMargin` points or more behind on first-review pass or shipped, or that far ahead on reverted, stops. Its tickets then run the control, and you are told. Both keys can be set per experiment as `stopAfter` and `stopMargin`.

## Promote the winner

```sh
dobby experiment promote retries more
```

This writes the arm's `set` keys into your private config as ordinary settings, after saving a backup copy next to it. Role files and prompt edits are not config keys, so copy those by hand. Only you promote: a report or a stop never does. Stop the experiment afterwards.

## Watch a config change (no arms)

When you change a setting yourself and only want to know what it did, a watch compares the days before the change with the days after it. It has no arms and takes no tickets: every ticket runs as normal.

```sh
dobby experiment watch retry-five --keys retryLimit --metrics cost,first-review-pass,runs-fix --days 7
```

```text
experiment retry-five watching: keys retryLimit, metrics cost, first-review-pass, runs-fix, 7 days. Baseline saved (last 7 days). Config backup ~/.config/dobby/config.json.bak-2026-11-28T09-00-00-000Z. Decide by 2026-12-05: dobby experiment report retry-five
```

Start it just before you make the change. Dobby copies your private config to the backup file and saves the last `--days` days of each metric as the baseline. After that it saves one row of numbers for every finished day (UTC dates). The keys you name must be real config keys. They are shown in `dobby experiment list`, which lists the watch with kind watch. If you leave `--days` out, the default below is used and the start line says so.

Metrics come from numbers Dobby already tracks, as a daily value (a day with no runs has none):

| Metric | Daily value | Better when |
| --- | --- | --- |
| `plan-usage` | % of the week Dobby's plan runs used | lower |
| `api-credit` | $ spent on the plan's API credits | lower |
| `cost` | $ of all runs | lower |
| `runs-build`, `runs-fix` | runs of that kind | higher for build, lower for fix |
| `runs-review`, `runs-check` | runs of that kind | neither, never flagged |
| `first-review-pass` | share of PRs whose first review passed | higher |
| `fix-rounds` | reviews after a PR's first | lower |

```sh
dobby experiment report retry-five
```

```text
experiment retry-five (watch)  before: 2026-11-21–2026-11-27  after: 2026-11-29–2026-12-04 (6 days so far)
Value = daily mean; worse = moved the wrong way by more than 10%.

metric                    before  after  change
cost ($)                  4.1     5.2    +1.1    ⚠ worse
first-review-pass (rate)  0.7     0.74   +0.04
runs-fix                  3       2.5    -0.5

Keep: dobby experiment keep retry-five   Roll back: dobby experiment rollback retry-five (restores ~/.config/dobby/config.json.bak-2026-11-28T09-00-00-000Z)
```

Before the decide-by date the report says `Not ready` instead of the Keep line, and its numbers are partial. A metric that moved the wrong way by more than the threshold gets `⚠ worse`. The word is always there, so nothing depends on the symbol.

- `dobby experiment keep retry-five` leaves your config as it is.
- `dobby experiment rollback retry-five` puts the watched keys back to their value in the backup and leaves your other settings alone (the current file is saved first as `.bak-rollback-<time>`). If the backup file is gone, nothing is restored and the command says so.

Running either twice says it was already done. Neither one changes anything else, and a watch never touches the dashboard card or the Monday line.

| Key | Default | What it does |
| --- | --- | --- |
| `watchExperiment.days` | 7 | Days a watch runs when `--days` is left out (2 to 90). The baseline is the same number of days before the start. |
| `watchExperiment.threshold` | 10 | A metric is flagged worse when it moved the wrong way by more than this many percent of its before value. |

## Example

You want to know if letting the builder retry five times instead of the default pays off on small tickets.

1. Add the experiment above, with `"scope":{"sizes":["S"],"percent":50}` to try it on half of the small tickets.
2. Let it run for a week or two. Watch the Experiments card on Home, and the Monday line.
3. Run the report. If `more` shows a clearly higher first-review pass and the cost difference is small, promote it. If its range includes 0, let it run longer or stop it.

All the keys are in the [configuration reference](/docs/config.md) under `experiments`.
