---
name: improve-baseline
description: "Open an issue for each failure mode the owner picked, cut one branch from the deployed commit, and set the baseline: the existing one, or up to three new approved cases per mode, each measured once. Use after improve-classify."
metadata:
  min-cli-version: "0.93.0"
  next: "improve-propose"
---

# Improve: baseline

Record each chosen failure mode as an issue, start one branch from the exact commit that produced the evidence, and make sure a baseline shows each failure before anything is changed. You need the chosen modes from `improve-classify` and `runs/improve/version.json` from `improve-select`.

It writes issues, a branch, cases and a baseline, and never changes the Recipe, merges, deploys or changes a runtime.

## 1. Open the issues

The chosen modes, up to four, go through this step and `improve-propose` together, in one pass: one issue per mode, one branch, one review of every case, one baseline, one fix. Open each issue as `platform-issues` says. In a platform task it belongs to that task:

```sh
introspection issues create --title "<the mode's name>" --priority <low|medium|high|urgent> --tags '["improve"]' \
  --description "<the definition, the signals, the number of conversations, the version and its commit>" \
  -o json --query '{id: id, key: display_key}' > runs/improve/issue.json
```

Its key is the platform's `display_key` (`I-4`). `$I` is the first mode's key and names the branch (`pr/improve-I-4`); use each key wherever the owner sees that issue.

## 2. Cut the branch

Work in the build folder's checkout of the Recipe's repository, cloning it if there is none:

```sh
introspection recipes get "$(jq -r .recipe_id runs/improve/version.json)" -o json   # repository_id, sub_path, git_commit_sha
introspection repositories list -o json                                             # the repository's clone URL
```

Branch from the version's commit, push, and name the branch on each issue:

```sh
git fetch origin && git switch -c pr/improve-$I <git_commit_sha> && git push -u origin pr/improve-$I
introspection issues update <issue-id> --description "<the description, then: Branch: pr/improve-$I>"
```

## 3. A mode from the baseline

A mode from failing baseline cases needs no new cases: those cases and the committed baseline are its baseline. When every mode is one, go on with `improve-propose`.

## 4. A new mode: draft the cases

For each new mode, pick at most three of its conversations from `modes.md`, each showing the mode differently, never two near-copies of one turn. All of them must be what one fix would address: a turn whose mistake needs a fix of its own belongs to another mode. Read each as a trajectory, never the span export, and get its link:

```sh
C=<conversation-id>; F=runs/conversations/$C.json
test -s $F || { mkdir -p runs/conversations && introspection conversations get $C --format trajectory --output-file $F; }
introspection open --conversation $C --print   # its link in the dashboard
jq -r 'to_entries[] | select(.value.role == "user") | "\(.key)\t\(.value.content[0:200])"' $F
```

Turn `n` is the `n`th `user` record, not counting any holding the agent's system prompt; read it to the next request with `jq '.[<from>:<to>]'`.

Draft one case per turn, in the format `eval-case`'s case file reference shows, with `issue:` set to the issue's id. Its body opens with the conversation's link and turn, then the title, the situation, a suggested good result and the bad result the agent gave. Write them to the outputs folder, one file each, never to the repository yet. For each, decide:

- **Its runner.** Vitest, unless the failure depends on the deployed environment: its connections, its image, its network, or uploads that must be kept as they were. Only then is it Harbor.
- **Its request.** When the failure is a wrong value or rule the Recipe holds (a term, a name, a policy), the case is a fresh request, one turn that asks for it in the user's words. Replay the production turn only when the failure depends on what came earlier in that conversation: a replayed history repeats the agent's old answers, and they pull a fixed agent back to the old value.

A case for a changed value requires the new one. It fails a reply that uses the old value as current, not one that names it as replaced, unless the owner asks for that.

A changed value revises only the case that states it, or adds one; other cases test logic and stay as they are. When the good result changes a rule existing cases expect, draft each such case's changed body as a revision; find them with `git grep -n "<the old value>" -- evals/`.

Then ask for the review with `review_artifacts`, one item per case and per revision across every mode, each labelled with its mode and title. Per item the owner approves it, asks for changes, or leaves it out:

- **Changes:** write them in the owner's words, and review that item again.
- **Left out:** delete its file.

Link each kept case's conversation on its issue, as `platform-issues` says:

```sh
introspection issues update <issue-id> --links '[{"url":"<link>","title":"<case title>"}, ...]'
```

## 5. Write the approved cases

Write each approved case with its approved body, and record the approval at once: the owner approved it in the review, and its verifier comes after.

- **A fresh request:** write `evals/cases/<id>.md` as `eval-case` says, with the next free id.
- **A replayed turn on Vitest:** `introspection eval add <suite> --runner vitest --from-conversation <conversation-id> --turn <n> --case-id <id>`, its suite named as the eval author brief says.
- **A Harbor case:** as [the Harbor case reference](references/harbor-case.md) says.
- **A revision:** put its approved body in its existing case file.

```sh
introspection eval approve <id> ... --by "<owner>" --in "review_artifacts <time>"
```

Then have eval authors write the checks, all started at once for every mode, as [agents/eval-author-brief.md](../../agents/eval-author-brief.md) says: one per new case, and one for all the revisions together, which edits their rows' `expected` to the approved values. Fetch each conversation's outputs first, as `SYSTEM.md` says. Brief each new case's author with its trajectory, turn and records from step 4, and the turn's reply and output files, all known-bad.

## 6. Measure the baseline

Read each run as `eval-run` says. Commit and push the cases, so each run measures that commit:

```sh
git add evals && git commit -q -m "test(evals): cases for $I" && git push -q && S=$(git rev-parse HEAD)
```

Agree the remedy and start the proposer, as `improve-propose` steps 1 and 2 say, then measure the baseline while it works: the proposer never sees the cases. Run only the new and revised cases yourself, locally, one trial each on the unchanged Recipe, and note each run's id:

```sh
introspection eval run -p evals/vitest/<case>.eval.ts   # once per new or revised case
```

When the fix's result could depend on the Runtime's environment but no case needs Harbor, run it as a cloud trial of `$S` instead, adding `-r <slug> --commit-sha "$S"`; the fix then goes the same path. A Harbor case is measured as [the Harbor case reference](references/harbor-case.md) says.

They should fail. A new case that passes doesn't show the failure: tell the owner, and redraft it. These runs are the fix's baseline; the committed `baseline.json` stays as it is until a full-suite run replaces it.

## Done when

- The issue exists, its key `I-…` is set, and it names the branch `pr/improve-I-…`, which starts at the version's commit.
- Each issue names the branch. For a mode from the baseline, its failing cases are named; for a new mode, at most three approved cases, and any revised ones, fail on the unchanged Recipe.

Then go straight on with `improve-propose`.
