---
title: Compare runs step by step
description: 'Line up two or more runs in Studio step by step, a replay on the source steps it replays: the /compare page, the GET /api/diff route behind it, what each column compares, and why a cell reads kept, "differs · not counted" or "not comparable" instead of "same".'
url: https://weftgo.dev/docs/observe/studio/compare/
type: how-to
sources:
  - 'weft/studio/diff.go:17-64 (GET /api/diff: aligned by the source''s step ordinal under a forked_from lineage, else by each run''s own; kept rows; siblings and kept_by; differs for a 0-token side; each step assembled as the step route does; marks never change a row; scoping; N-way is N−1 calls), 66 (maxDiffSteps 500), 70-77 (the change names), 79-162 (diffAlign, diffDoc, diffSummary.kept, diffRow: a_step, b_step, kept, kept_by, differs), 164-201 (diffSide, diffToolCall, diffToolResult), 204-275 (serveDiff: a and b required; the fork chain, a panel token reads depth 1; a from_step past the source''s last is a gap hole), 372-374 (maxForkDepth 8); diffSteps, diffSideOf, derivedSide, compareSides, canonicalJSON'
  - weft/studio/testdata/api/diff-replay.golden.json (TestDiffAlignsAReplayOnItsSource); weft/studio/testdata/api/diff-siblings.golden.json (TestDiffSiblingsCompareAgainstTheSource)
  - weft/studio/routes.go:163 (GET /api/diff, capability diff)
  - 'weft/studio/web/src/lib/stepdiff.ts (ARRIVAL, rowNote, CELL_WORDS, CELL_REASONS, ROW_WORDS, SOURCE_ROW, rowState, cellText, systemHidden, markerWords, summaryWords: kept (not re-run), usage differs (0 tokens), nWayView)'
  - 'weft/studio/web/src/components/studio/step-diff.tsx (changed only, on by default when a step differs; show all steps; the usage line per run against the base; the cost column: the first 50 steps; no step changed)'
  - 'weft/studio/web/src/routes/compare.tsx (the page: a, b as a comma list, step; This Studio does not serve the step compare.; the add box and the picker)'
  - 'weft/studio/web/src/lib/compare-picker.ts (PICK_BASE, PICK_OTHER, WHY_SOURCE, WHY_PUBLIC, WHY_AGENT, PICK_FIND; splitRuns: a comma list or a JSON array)'
  - weft/studio/web/src/components/studio/run-header.tsx (compare with source, compare with…)
  - weft/studio/web/src/lib/run-tree.ts (the drawer's compare…)
  - weft/studio/web/src/components/studio/replay-drawer.tsx (open the step compare)
  - weft/studio/web/src/routes/playground.tsx (open the compare page)
  - weft/studio/web/src/routes/experiments.$id.tsx (compare the two cells)
  - weft/studio/web/src/lib/links.ts (runsParam, compareLink)
  - weft/studio/README.md (the step compare; a replay is compared on its source; the panel's 2-way result pane; parity.test.ts)
  - 'weft/AGENTS.md (block 7: diff?a=&b=, the reduced columns, changes and unknown, compaction and subagent are marks, system hidden to a read token, the step cap, capability diff, /compare N-way)'
  - 'weft/CHANGELOG.md:144-145 (0.19.0: the row words, the arrival retry), 158-159 (0.19.0 breaking: alignment on the shared run, differs), 49 (0.20.0: compare N from the runs list, changed only, the usage line), 100 (0.20.0 fixed: /compare drops a repeated b and a b equal to a)'
  - 'docs-site/examples/studio/compare_test.go: TestDiffAlignsSteps (passes against ../weft-rc020 through a scratch go.work)'
  - 'observed: weft studio v0.17.0, /compare and GET /api/diff over two scripted support-bot runs that differ in their final reply (outputs below; summary gains kept: 0 at 0.19.0)'
---

# Compare runs step by step

Studio's compare page lines up a base run and the runs you compare with it step by step: step 0 against step 0, step 1 against step 1. A replay lines up on the source steps it replays, so a replay from step 1 sets its own step 0 beside its source's step 1 and marks the source's step 0 kept. For each step it compares five columns (the system prompt, the tool calls, the tool results, the assistant text and the usage) and marks each cell `same`, `changed`, `not comparable` or `missing`. Open it from a run's header with **compare with…**, or go to `/compare?a=<base run>&b=<run>,<run>`. Behind it is one route, `GET /api/diff?a=&b=`, which compares two runs.

The same comparison from a terminal, for two runs of a support agent whose final replies differ, against `weft studio` with its dev token in `$TOKEN`:

```sh
curl -s -H "Authorization: Bearer $TOKEN" \
  'http://127.0.0.1:7331/api/diff?a=c17b44940f21af67c33a6b68daa3c40d&b=557fbdca810b6e4f7a76e2d3285cbf13' \
  | jq -c '.summary, (.steps[] | {step, changes, unknown, a: .a.text, b: .b.text})'
```

```text
{"changed_steps":[1],"first_changed":1,"kept":0}
{"step":0,"changes":[],"unknown":[],"a":"","b":""}
{"step":1,"changes":["text"],"unknown":[],"a":"Order 1234 has shipped.","b":"Order 1234 shipped on Monday."}
```

Step 0 (the `lookup_order` call and its result) is the same in both. Step 1 changed in one column, `text`.

## The compare page

`/compare` takes three URL keys:

| Key | Meaning |
|---|---|
| `a` | The base run, drawn in the first column |
| `b` | The runs compared with it, as one comma list (`b=r_2,r_3`); the base and repeats are dropped. A JSON array, as older links wrote it, still reads |
| `step` | A step ordinal to scroll to and highlight |

Opened without `a`, the page asks for a base run: type or paste an id into the box and press **add**, or pick one of the newest runs under "pick a base run — or paste an id above". With a base named, the picker reads "compare with — or paste an id above" and offers the base's replay source first ("its replay source"), then runs of the same conversation ("same conversation"), then the same agent's newest runs ("same agent"). Its find box ("find a run by id prefix or agent") reaches past the newest 50 runs, by id prefix or agent name. One click adds a run to the URL.

![The compare page for a turn and its replay under another system prompt: changed at step 0 in system, tool calls, tool results and text, step 1 only in the base run, the two runs side by side by step](https://weftgo.dev/docs/_astro/studio-compare.light.D2drgA3x.webp)

*A turn compared with its replay under another system prompt: changed at step 0 in system, tool calls, tool results and text; step 1 only in the base run.*

You also reach the page from:

- the runs list: pick runs with `x`, then **compare N**;
- a run's header: **compare with…** (this run as the base), and **compare with source** on a replayed run, which puts the source first;
- the run page's drawer: **compare…**, landing on the selected step;
- the playground's replay drawer, once a replay finished: **open the step compare**;
- the playground's variants: **open the compare page**; and a saved experiment: **compare the two cells**.

### Read the table

Above the table, one line sums the compare: "1 of 2 steps changed · first at step 1", or "no step changed of 1", followed by "· 1 kept (not re-run)" when the base's earlier steps were kept by a replay, "· usage differs (0 tokens)" when a scripted side billed nothing, and the count of cells not comparable. One line per changed step links to it: "changed at step 1 · text". A compared run with no change reads "`<run>`: no step changed", and adds "among the columns both runs recorded" when some cells were not comparable. A usage line per run gives its tokens against the base.

When a step differs, the table opens on **changed only**: the changed steps and columns. **show all steps** brings the rest back.

The table has a column group per run, the base first ("· base"). Each compared run's row reads in one word: **kept** (the source's step, which the replay did not re-run), **same**, **changed** or **missing** (one run has no such step). Each group has the columns **marks**, **system**, **tool calls**, **tool results**, **text**, **usage** and, under the `pricing` and `steps` capabilities, **cost**. The base's cells hold its values: the system prompt, `name(args)` per call, each result (an error result prefixed `error:`), the text, and the usage as `in→out`. A compared run's cells hold its state against the base, and the value only where it changed:

| Cell | Means |
|---|---|
| `same` | Both runs recorded this column and it is the same |
| `changed` | Both runs recorded this column and it differs; the cell shows the compared run's value |
| `not comparable` | A side did not record this column, so the two were not compared. Never read it as same |
| `missing` | One run has no such step |
| `kept` | The row is a source step the replay did not re-run: nothing was compared |
| `differs · not counted` | The usage differs where a side billed no tokens (the scripted engine's 0 → 0): drawn greyed, never a change |

In the base column a value it did not record reads `—`, and an empty one `(none)` (or `(empty)` for a system prompt). A system prompt known only by its hash shows `#` and the hash's first 8 characters. Each cell's value is cut at 160 characters. The table scrolls inside its own frame, never the page.

The cost column shows each step's own model call, priced at read time, for the first 50 steps of each run. It is informational: a different cost never marks a step changed, since cost follows usage, which is compared already. An unknown cost on either side reads `not comparable` ([See what a run cost](https://weftgo.dev/docs/observe/studio/cost/)).

Without the `diff` capability the page says "This Studio does not serve the step compare." with the reason.

## Replays align on their source

A replay numbers its own steps from 0: its step 0 is the fresh step `from_step` of its source. When one side's run row carries `weft.forked_from = "<other side>#<n>"`, the diff aligns that side's step k with the other side's step n+k, and the rows are the source's ordinals. The source's steps before n are rows marked `kept`: the replay side is null, nothing is compared, and a kept row is never a change. More generally the diff follows each side's `forked_from` chain, at most 8 links, adding the offsets, and aligns the two on the nearest run both chains hold: a replay of a replay against the root aligns on the root, two replays of one run on that run. A panel token reads only the sides' own `forked_from`.

Weft's own golden for a scripted replay from step 1 that changed nothing (`testdata/api/diff-replay.golden.json`), cut to the alignment, the summary and each row's flags:

```json
{"aligned": {"replay": "b", "source": "r_src", "a_from": 0, "b_from": 1},
 "summary": {"changed_steps": [], "first_changed": null, "kept": 1}}
{"step": 0, "a_step": 0, "b_step": null, "kept": true,  "changed": false, "changes": [], "unknown": [], "differs": []}
{"step": 1, "a_step": 1, "b_step": 0,    "kept": false, "changed": false, "changes": [], "unknown": [], "differs": ["usage"]}
```

Studio draws it "no step changed of 1 · 1 kept (not re-run) · usage differs (0 tokens)": step 0 kept, step 1 the same, its usage greyed. Before 0.19.0 the same replay read "changed at every step", its fresh step compared with the source's step 0.

**Two replays of one run** (siblings, maybe from different steps) align on that run, `aligned.replay` `both`, offset by their difference. Steps neither side ran have no row. Between their two `from_step`s one side kept the shared run's step and the other re-ran it: the row's `kept_by` names the keeping side (`"a"` or `"b"`), whose column is the shared run's own step, and the re-run side is compared with it. A change there counts in `changed_steps` and `first_changed`, never in `summary.kept`. Studio and the panel read such a row "changed · vs source" or "same · vs source", with the note "b kept the source's step; a vs source: changed". When Studio cannot read the shared run (another public id, a run that is gone), those rows are not compared: every column is in `unknown`.

A `forked_from` that names a step past the source side's last is no alignment: the two align by their own ordinals and a `gap` hole in the response's `holes` names the mismatch. Runs with no lineage align by their own ordinals.

## Compare right after a replay

The replay drawer shows the step compare of a finished replay against its source. The command's finish can arrive before Studio holds the replay's run row, so a 404 there reads "recording the run… the step compare follows once Studio has it" and is retried three times, one second apart. If the run is still absent, the pane says "`<run>` has not reached Studio yet (still absent after 3 more reads, 1 s apart)" with **read the compare again**. Anywhere else a 404 is not retried.

## Step diff

`GET /api/diff?a=<run>&b=<run>` (capability `diff`) assembles each step of both runs the way `GET /api/runs/{id}/steps/{n}` does, reduces it to the compared columns, and aligns the two lists by step ordinal: the shared source's under a lineage ([above](#replays-align-on-their-source)), else each run's own. A step one run has and the other lacks is changed, with `changes: ["missing"]`.

| Column | Compared as |
|---|---|
| `system` | The system prompt by its hash when both sides have one, by its text when neither has one. When one side has only a hash and the other only the text, the cell reads changed |
| `tool_calls` | Each call as its name and its arguments, the arguments canonicalised (object keys sorted, no insignificant space), in call order |
| `tool_results` | Each result's content and `is_error`, in call order. A parked or running call has none |
| `text` | The step's assistant text, exactly: the text parts of its assistant messages, joined by a newline |
| `usage` | The step's token numbers |

Each row of `steps` carries:

| Field | Means |
|---|---|
| `step` | the aligned ordinal: the shared source's under a lineage, else the runs' own |
| `a_step`, `b_step` | each side's own ordinal, null where that side has no step; link to a run's step by its own |
| `kept` | a source step before the replay's `from_step`: not re-run, nothing compared |
| `kept_by` | between two siblings' `from_step`s, the side that kept the shared run's step |
| `changed`, `changes` | whether the row changed, and the columns that differ |
| `unknown` | the columns that could not be compared |
| `differs` | the columns that differ but do not count: `usage` when a side reported no tokens |
| `a`, `b` | the two sides, null where a run lacks the step |

The response's `aligned` is `{replay, source, a_from, b_from}`, null without a lineage. `summary` names `changed_steps`, `first_changed` and `kept`, the count of kept rows. One side of a step looks like this:

```text
{"status":"ok","system_hash":"","system":"","tool_calls":[{"name":"lookup_order","args":{"order_id":"1234"}}],"tool_results":[{"call_id":"c1","name":"lookup_order","content":"order 1234: shipped","is_error":false}],"text":"","usage":{"input_tokens":10,"output_tokens":5},"marks":[],"holes":[]}
```

### Why a cell is not comparable

A column one side did not record is listed in `unknown`, never compared, and never read as the same. The side's `holes` say why, with [badges](https://weftgo.dev/docs/reference/glossary/#badge) from the one [hole](https://weftgo.dev/docs/reference/glossary/#hole) table ([Badges and holes](https://weftgo.dev/docs/reference/badges/)):

- **`system`**: a side has neither a hash nor the text, for example a run recorded before the request record, or one whose request record was dropped. Content-off runs and read tokens keep the hash, so they still compare.
- **`tool_calls`, `tool_results`, `usage`**: a side's events were not all stored. When a side's calls were recorded with content off, `tool_calls` compares by name alone (a name change is still a change) and `tool_results` is not comparable.
- **`text`**: a side's text is null for a hole: no messages record of the step was stored, or one did not parse.
- **Every column**: a side is a [derived run](https://weftgo.dev/docs/reference/glossary/#derived-run), built from stock spans, so none of its columns was recorded.

A read-scoped panel token reads every column but the system prompt: `system` is `null` under the `hidden` hole, the side says so explicitly with `system_hidden: true`, and the page draws the `hidden` badge in that cell beside the state the hashes gave. A side's `hidden` hole can also carry a `count`: the child runs left out because they lie outside the token's scope. Read `system_hidden`, not a count-less `hidden` hole, for "the system prompt is hidden".

### Marks

A side's `marks` say what its step was, beside what it said: `compacted` (the request carried a compaction view), `subagent` (the step called a subagent), `max_tokens`, `parked`, `running`, `interrupted` and `error`. Marks are never a change by themselves. A compaction or a subagent call does not shift the alignment either: the child run's steps are its own and are not aligned. The page draws a mark that is also a hole (`compacted`, `max_tokens`, `interrupted`) once, as that hole's badge.

### Limits and errors

The diff compares at most 500 steps of each run. A longer run is compared that far, and the response's own `holes` carries `truncated` with cause `response_cap`. Both runs must be inside a panel token's public id (else 403); an unknown run is a 404, and a missing `a` or `b` is a 400:

```sh
curl -s -H "Authorization: Bearer $TOKEN" \
  'http://127.0.0.1:7331/api/diff?a=c17b44940f21af67c33a6b68daa3c40d' | jq -c .
```

```text
{"error":{"code":"bad_request","message":"a and b must both name a run: /api/diff?a=<run id>&b=<run id>"}}
```

The route is two-way. The page's N-way table is N−1 calls of it against the same base, laid side by side. The devtools panel's experiment result pane draws the two-way table (the replayed run against its source) from the same module, `src/lib/stepdiff.ts`, and a parity test holds both surfaces to the same rows, markers and badges.

`TestDiffAlignsSteps` in `docs-site/examples/studio/compare_test.go` records the two runs above into a temporary database and asserts the same rows. Run it from `docs-site/examples`:

```sh
go test -v -run 'Diff' ./studio
```

```text
--- PASS: TestDiffAlignsSteps (0.02s)
PASS
ok  	weftgo.dev/docs/examples/studio	0.049s
```

## Best practices & gotchas

- **Open a replay's compare from its header.** On a replayed run, **compare with source** opens the compare with the source as the base, landing on the step the replay started from. (Source: `run-header.tsx` "compare with source"; `lib/links.ts` `compareLink`)
- **"no step changed" covers only what both runs recorded.** Check the `unknown` lists, or the "among the columns both runs recorded" note, before you call two runs identical. (Source: `studio/diff.go` `compareSides`; `lib/stepdiff.ts` `summaryWords`)
- **Record with content on to compare results.** A content-off run compares tool calls by name only and its results not at all. (Source: `studio/diff.go` `compareSides`)
- **Compare a replay with its own source.** Only a `forked_from` lineage aligns a replay on its source. Two unrelated runs align by their own ordinals, by position, not by meaning: one extra step early shifts every later step against the base, so each later row reads changed. (Source: `studio/diff.go:17-38`)
- **Read `a_step` and `b_step` to link a side.** Under a lineage, `step` is the source's ordinal; a link to the replay's own step uses its own ordinal. (Source: `studio/diff.go` `diffRow`)
- **Do not count a scripted replay's usage as a change.** Its 0 tokens differ from the source's real usage by design: the diff lists it in `differs`, not `changes`. (Source: `studio/diff.go:46-48`)

## See also

- [Read a run in Studio](https://weftgo.dev/docs/observe/studio/run-page/)
- [Replay a run from any step, with edits](https://weftgo.dev/docs/observe/playground/replay/)
- [Run experiments with the option lab](https://weftgo.dev/docs/observe/playground/experiments/)
- [Badges and holes](https://weftgo.dev/docs/reference/badges/)
- [Studio HTTP API](https://weftgo.dev/docs/reference/studio-api/)
