Skip to content

Compare runs step by step

View as Markdown

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:

Terminal window
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})'
{"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.

/compare takes three URL keys:

KeyMeaning
aThe base run, drawn in the first column
bThe 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
stepA 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 stepThe 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
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.

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:

CellMeans
sameBoth runs recorded this column and it is the same
changedBoth runs recorded this column and it differs; the cell shows the compared run’s value
not comparableA side did not record this column, so the two were not compared. Never read it as same
missingOne run has no such step
keptThe row is a source step the replay did not re-run: nothing was compared
differs · not countedThe 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).

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

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:

{"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_steps 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.

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.

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), else each run’s own. A step one run has and the other lacks is changed, with changes: ["missing"].

ColumnCompared as
systemThe 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_callsEach call as its name and its arguments, the arguments canonicalised (object keys sorted, no insignificant space), in call order
tool_resultsEach result’s content and is_error, in call order. A parked or running call has none
textThe step’s assistant text, exactly: the text parts of its assistant messages, joined by a newline
usageThe step’s token numbers

Each row of steps carries:

FieldMeans
stepthe aligned ordinal: the shared source’s under a lineage, else the runs’ own
a_step, b_stepeach side’s own ordinal, null where that side has no step; link to a run’s step by its own
kepta source step before the replay’s from_step: not re-run, nothing compared
kept_bybetween two siblings’ from_steps, the side that kept the shared run’s step
changed, changeswhether the row changed, and the columns that differ
unknownthe columns that could not be compared
differsthe columns that differ but do not count: usage when a side reported no tokens
a, bthe 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:

{"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":[]}

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 from the one hole table (Badges and holes):

  • 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, 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”.

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.

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:

Terminal window
curl -s -H "Authorization: Bearer $TOKEN" \
'http://127.0.0.1:7331/api/diff?a=c17b44940f21af67c33a6b68daa3c40d' | jq -c .
{"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:

Terminal window
go test -v -run 'Diff' ./studio
--- PASS: TestDiffAlignsSteps (0.02s)
PASS
ok weftgo.dev/docs/examples/studio 0.049s
  • 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)