---
title: Replay a run from any step, with edits
description: Re-run a recorded run from step N with the steps before it kept as the model saw them, on the scripted engine (free, the recorded answers) or live, after editing a prompt, a reply, a tool result or a call's arguments, with the target and the exact request checked before Run.
url: https://weftgo.dev/docs/observe/playground/replay/
type: how-to
sources:
  - 'W11-auditB2-fix, v0.20.2: weft/studio/web/src/lib/edits.ts:457-472 (replayViewWords)'
  - 'weft/docs/adr/0029-replay-input.md (decision 1: the prefix is step N''s request messages; from_step 0; from_step at the step count; the PrepareStep limit; decision 2: weft.replay.view; decision 3: transcript?step=N; decision 4: edits inside a compacted range; decision 5: a child run is its own source; decision 6: weft.forked_from; decision 8: the edit kinds, weft.edits, substitution on the edited pairs, the scripted refusal, the preview)'
  - 'weft/studio/playground.go (runRequest: the command body, Engine, CrossAgent; checkCommandWarn: edits need a source and from_step > 0, engine "" and live alike, the scripted refusals'' sentences, the fork rules; checkSource; checkTargetNamed and unnamedSourceMsg; checkTarget and crossAgentMsg; refuseDerivedSource)'
  - 'weft/studio/edits.go (validateTranscriptEdits, editKindOf: the kinds and the fields each takes)'
  - 'weft/studio/runtime/runtime.go (TranscriptEdit, SourceSpec; CommandStatus: reason)'
  - 'weft/studio/runtime/reason.go (Reason, ReasonScriptedMiss, ReasonOf, ScriptedMissReason: missClause, the sentence, ", or replay from an earlier step" for unanswered)'
  - 'weft/runtime/scripted.go (the miss components tools, thinking, tool_choice, sequential, messages, unanswered, exhausted; the error text "weft/runtime: no recorded turn for …")'
  - 'weft/runtime/executor.go (prepareSource: WARN weft/runtime: source transcript unresolved; running on the input alone; runPrefix; keptSteps and runOptions: core.KeptSteps(from_step); the replay''s error "weft: run failed at step N (the source''s step ordinal; this run''s step M)")'
  - 'weft/core/run.go (KeptSteps: MaxSteps budgets the whole turn, DetectLoops'' streak, the usage limit and MaxModelRetries count this run only, own steps indexed from 0)'
  - weft/obsdb/args.go (CheckToolArgs); weft/obsdb/args_test.go (ExampleCheckToolArgs)
  - 'weft/studio/preview.go (POST /api/playground/preview: will_send, was_sent, diff, compacted_at, warnings, unchecked, scripted_hit, scripted_key_match); weft/studio/preview_scripted.go (scriptedStep, scriptedMatch, checkScripted)'
  - weft/studio/web/src/lib/engine.ts (engineChoice, scriptedBlock, factsOf, ENGINE_WORDS, runLabel, modelLabel, COST_STEPS, liveEstimate)
  - weft/studio/web/src/lib/target.ts (TARGET_WORDS, targetCheck, targetKey, agentOptions, SCRIPT_NOTE, SCRIPT_EXHAUSTED, MISS_FROM_ZERO, MISS_SAVE)
  - weft/studio/web/src/components/studio/target-check.tsx (the miss line's three ways on)
  - weft/studio/web/src/lib/drawer-spec.ts (DRAWER_ORDER, DRAWER_TITLES, WRITE_TO)
  - weft/studio/web/src/lib/replay.ts (VERB_TITLES, REPLAY_OPEN, REPLAY_WORDS, replayVerdicts, prefixLine, REPLAY_OFF, REPLAY_MARK)
  - 'weft/studio/web/src/lib/run-tree.ts (the drawer''s verbs: replay from here ▸, edit…, edit result…, replay the child ▸)'
  - weft/studio/web/src/lib/run-row.ts (↻ the replay glyph); weft/studio/web/src/components/studio/run-header.tsx (REPLAY_WORDS.of)
  - weft/studio/web/src/components/studio/transcript-editor.tsx (insert a message before step N)
  - 'weft/studio/README.md (The playground: a child run as source; the prefix includes the compaction view; from_step at the step count; the transcript editor; the target facts and the target check before Run; Wire: the scripted miss)'
  - 'weft/CHANGELOG.md:118-123, 132, 138-143 (0.19.0: the preview''s scripted check, the command reason, the typed ack, wefttest, target_check, KeptSteps, the engine per command, the drawer order, the target check, the refusal sentences, the scripted miss), 156-157, 163-164 (0.19.0 breaking: cross-agent, the engine default, the replay is the same turn, the error''s step ordinals)'
  - docs-site/examples/playground/main_test.go:TestReplayFromStep (forked_from <src>#1, weft.replay.view transcript, no session id, 409 on reuse)
  - 'observed: POST /api/playground/runs, /api/playground/preview and GET /api/runs/{id}/transcript?step=1 against the example program (go run ./playground) at v0.17.0; the responses below are verbatim'
  - docs-site/factcheck/playground.md (findings 3, 18-23)
---

# Replay a run from any step, with edits

A playground replay re-runs a recorded run from step N: steps 0 to N−1 are kept exactly as the model saw them, and step N onwards runs fresh in your process. It runs on the **scripted** engine, which answers each step with the recorded model output and costs nothing, or **live**, which calls the model. Before it runs you can edit what it keeps: the turn's prompt, a reply, a tool result or a call's arguments, or a message inserted between steps. Studio checks the target agent and previews the exact request before Run.

The smallest replay is one command naming the source run, the step and the agent. Against the example program from [How does the playground work?](https://weftgo.dev/docs/observe/playground/overview/#complete-example), keep step 0 (the `lookup_order` call and its result) and re-run step 1 under a new system prompt:

```sh
curl -s -X POST http://127.0.0.1:8080/studio/api/playground/runs -d '{
  "command_id": "cmd_docs_1",
  "runtime": "rt_6ea843dccc7741ff",
  "agent": "acme-support",
  "source": {"run_id": "dd66354adfaac2b44848f0c1ed75516f", "from_step": 1},
  "overrides": {"instructions": "You are Acme'"'"'s support agent. Always include the tracking link.",
                "options": {"temperature": 0.2}},
  "engine": "live", "side_effects": "substitute", "thread": "ephemeral",
  "experiment_id": "tracking-link"
}'
```

```json
{"command_id":"cmd_docs_1","state":"queued"}
```

`runtime` is an id from `GET /api/runtimes` ([See your runtimes](https://weftgo.dev/docs/observe/playground/runtimes/)). The command's row then names the replay, a `pg_` run:

```json
{"command_id":"cmd_docs_1","state":"finished","run_id":"pg_01M5780D5BYHQNGQDWRXR84HAZ","status":"succeeded","error":null,"created":"2026-10-18T12:13:07.369713696+02:00","updated":"2026-10-18T12:13:07.376531416+02:00"}
```

The replay's run row carries `"forked_from":"dd66354adfaac2b44848f0c1ed75516f#1"`, `"playground":true` and `"experiment_id":"tracking-link"`, and its `meta` carries `"weft.playground.command":"cmd_docs_1"` and `"weft.replay.view":"transcript"`; the `weft.playground` attribute is what the row's `playground` reads. Its run header reads "replay of `<source>` · step 1" and its runs-table row "↻ replay of `<source>` · step 1", both linking the source step. The same command, as the [experiments](https://weftgo.dev/docs/observe/playground/experiments/) page's variant b, files it under `tracking-link`.

## How it works

The command's `source` is `{run_id, from_step}`, and `from_step` counts the source run's own steps (the step ordinal Studio shows). The input the turn was given is context, not a step. The replay's input is what step `from_step`'s model call carried, its request record's messages ([ADR 0029](https://github.com/weftgo/weft/blob/v0.20.2/docs/adr/0029-replay-input.md) decision 1):

- **`from_step` N > 0** keeps steps 0 to N−1 and runs from N. When that request carried a `PrepareStep` compaction view, the replay is fed the view, the model's exact input there, on every source path (the local sink, Studio, thread storage); the scripted engine keys its recorded turns over the compacted prefix too.
- **`from_step` 0** re-runs the whole turn from what it was fed: its step-0 `PrepareStep` runs again over the original input, and nothing is kept. With no `input` the replay reuses the source's user message; `input` replaces it, and the conversation before the turn stays. That needs the source transcript: when the runtime cannot resolve it, the replay runs on the `input` alone ([gotcha](#best-practices--gotchas)).
- **`from_step` equal to the step count** is accepted when the source's last step ended in answered tool calls, as a run that failed or hit its budget does: the replay's first model call answers those results. After a call-free reply it is refused.

`GET /api/runs/{id}/transcript?step=N` serves that prefix: `step`, `messages` (what step N's model call carried) and `compacted_at`, the view it carried or `null`. For the example's source, `?step=1` is the prompt, the call and its result:

```sh
curl -s 'http://127.0.0.1:8080/studio/api/runs/dd66354adfaac2b44848f0c1ed75516f/transcript?step=1' | jq '{step, messages, compacted_at}'
```

```json
{
  "step": 1,
  "messages": [
    {"role": "user", "content": [{"type": "text", "text": "Where is my order #4411?"}]},
    {"role": "assistant", "content": [{"type": "tool_call", "id": "c1", "name": "lookup_order", "args": {"order_id": "4411"}}]},
    {"role": "tool", "content": [{"type": "tool_result", "call_id": "c1", "name": "lookup_order", "content": "{\"order_id\":\"4411\",\"status\":\"shipped\"}", "is_error": false}]}
  ],
  "compacted_at": null
}
```

A step past the run's last is 404; records that do not rebuild the step are 409 with their hole (`gap`, `stripped`). The runtime splits every source the same way, into the turn's input and the run's own steps, whether it reads thread storage, the local sink or Studio. A thread-stored source whose records cannot rebuild the step (content off) replays on the thread's messages with a warning; a turn that ran over a summarized context is refused on the thread path, and the runtime then reads the source from the local sink, else from Studio. The scripted engine replays reasoning and tool-call signatures as recorded. A run derived from stock OTel spans has no transcript to replay, and the run and preview routes refuse it 400 with the `derived` badge.

The replay carries `weft.forked_from = "<source run>#<from_step>"` and, from step N > 0, `weft.replay.view`: how its prefix knew what the model saw.

| `weft.replay.view` | Means |
|---|---|
| `transcript` | step N's request record placed the plain transcript |
| `compacted:<index>` | it named the run-scope compaction view at that record index, spliced in |
| `derived` | no request record placed N's messages: the `from_step` cut rule applied |
| `unknown` | the records could not be read (a thread source with Studio unreachable or content off, a Studio older than `?step=`) |

The last two are the replay's `derived` [hole](https://weftgo.dev/docs/reference/glossary/#hole) on its run page, its reason naming the mark and the source step, so a fallback is never silent. The replay's header says the mark in words beside that badge: "fed the compacted view #7" for `compacted:7`, "prefix derived" for `derived` and "prefix view unknown" for `unknown`; `transcript` adds nothing. A replay is ephemeral by default: it never carries `weft.session.id`. To continue a conversation instead, send `"thread": "fork"` with an `input` and `from_step` 0 ([Engines and threads](https://weftgo.dev/docs/observe/playground/overview/#engines-and-threads)).

**A subagent's child run is its own source.** Send the child's id (`<parent>/<step>/<call>`) as `source.run_id` and the child's agent, registered on the runtime by that name, as `agent`. The child replays as its own run, with `weft.forked_from = "<child id>#<from_step>"` and no parent linkage. A replay of the parent from the step that called the child substitutes or parks that `Subagent` call like any never-class call; the child is not re-run.

**The limit:** your agent's own `PrepareStep` runs over the replay's prefix. The model's input is exact when that `PrepareStep` is idempotent over its own output. One keyed on a count or an index re-shapes the replay's input.

## A replay continues the turn

A replay from step N > 0 is the same turn, not a new one. The runtime runs it with [`weft.KeptSteps(N)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#KeptSteps), on the live engine and the scripted one alike, so the kept steps count toward the agent's guards as if the replay had made them:

- **`MaxSteps` budgets the whole turn.** The replay makes at most `MaxSteps` − N model calls, and none when N reaches it.
- **`DetectLoops`' streak starts from the kept steps' tool calls.**
- **The usage limit, `MaxModelRetries` and `StopWhen` see the replay's own spend and steps.** The kept steps' usage is not in its input.

An unchanged replay of a turn that a guard stopped therefore stops the same way at the same step, with the same `max_steps` or `loop_detected` end, and the [compare](https://weftgo.dev/docs/observe/studio/compare/) reads its rows kept · same. A decision on a parked replay resumes with a fresh budget, as any resume does.

The replay's own record numbers its steps from 0. A command's error names the step in the source's ordinals and says so. For a replay from step 2 that fails at its own step 1:

```text
weft: run failed at step 3 (the source's step ordinal; this run's step 1): …
```

## Replay from the run page

You rarely type the command. On Studio's [run page](https://weftgo.dev/docs/observe/studio/run-page/#the-drawer), the verbs open the replay drawer pre-filled. Each step card carries "replay from this step (step N)", "edit the prompt and replay (step N)", "re-run the whole turn" and, on a session's top-level turn, "continue here with a new message". The run tree's drawer has its own shorter labels for the selected row:

| Drawer verb | The replay drawer's title | What it pre-fills |
|---|---|---|
| replay from here ▸ | Replay from this step | `from_step` N |
| edit result… | Edit this result and replay | `from_step` N+1, an empty edit field for the call's result with the recording beside it |
| edit… | Edit the prompt and replay | the step's own system prompt from its request record |
| replay the child ▸ | Re-run | the child run as its own source, under its own agent |

![The replay drawer on a run page: Replay from this step, continuing from step 1, the target's Runs in line naming the acme-app runtime, the engine (scripted or live), the recorded tool result open to edit, the system prompt, the tools with refund marked needs approval, the model and thinking, and Run on scripted](https://weftgo.dev/docs/_astro/studio-replay-drawer.light.MGV2P23T.webp)

*The replay drawer from &quot;replay from here&quot; on step 1: step 0 kept, its recorded tool result offered as a transcript edit, then the prompt, tools, model and modes.*

The step cards' "re-run the whole turn" and "continue here with a new message" open the drawer as **Re-run** and **Continue here with a new message** (a fork). In the devtools panel, a turn's **✎ Replay…** button opens it with no verb, titled **Replay**. With the drawer open, the story rings the step it replays from ("replaying from here") and draws the steps before it faint, marked "kept". The replay's result head in the devtools panel reads "Replay 1 of t3 · scripted · finished" (its number among the turn's replays, the engine and the run's status word), and its chip "replay of t3 · step 0". A run that is still running reads "replay after the run ends"; a read token reads "a read token cannot replay: it needs the dev token or a playground panel token".

### The replay drawer

The drawer reads top to bottom in the order a command is decided, the same in Studio and in the [devtools panel](https://weftgo.dev/docs/observe/devtools/replay/):

1. **source** and **target**: the run and step it replays, and the agent it replays them on ([The target check](#the-target-check)).
2. **engine**: scripted or live, with what each costs ([Choose the engine](#choose-the-engine)).
3. **1 what changes**, **2 will be sent** ([Preview](#preview)) and **3 tools during the replay**.
4. **advanced: side effects · where it writes · options**, folded: the side-effect mode, **Write to** ("nowhere (ephemeral)" or "a new session (fork)") and the option lab.
5. Run, in a footer that stays in view, naming its engine.

Under "tools during the replay" the drawer lists each tool of the step's catalog and what its calls would do:

| The drawer says | When |
|---|---|
| replay safe · runs | the tool is `weft.Replay(weft.ReplaySafe)` |
| replay never (unannotated) · substituted from the recorded result when the call repeats, else parked | an unannotated tool under `substitute` |
| … · parks (side effects: park) | a never-class tool under `park` |
| … · not registered on the runtime · … | a tool in the step's catalog that the runtime's registration of the agent lacks |
| opted in by AllowSideEffects · runs for real | an opted-in tool under `allow` |
| … · not opted in by AllowSideEffects: side effects allow is refused while it is on | `allow` with a tool that would refuse the command |
| breakpoint · parks | a runtime-wide [breakpoint](https://weftgo.dev/docs/observe/playground/runtimes/#breakpoints) on the tool |
| requires approval · substituted from the recorded result when the call repeats, else parked | a `weft.RequireApproval` tool under `substitute` |
| requires approval · parks at the approval boundary | a `weft.RequireApproval` tool under `park` or `allow` |
| structured output · runs | an `Output` agent's `submit_output` |
| off | the command turns the tool off |

A `weft.RequireApproval` tool also reads "needs approval" beside its ⚠: its side-effect class `never` is the replay class, not "no side effects". The drawer names the kept prefix too: "nothing kept · the whole turn runs again", "step 0 kept", "steps 0–2 kept", or "steps 0–2 kept · the compacted prefix (what the model saw at step 3)". Run is held while any refusal shows: the target check, a scripted pick that cannot answer, `allow` that would be refused, an option-lab refusal, a preview that is pending or refused, an edit inside a compacted range or with invalid args, edits on a fork, or a fork with no input. Breakpoints are not a per-replay setting: the drawer points to [Runtimes](https://weftgo.dev/docs/observe/playground/runtimes/#breakpoints), where they apply to every run of the runtime.

## Choose the engine

Studio's replay drawer, its playground and the panel's drawer choose the engine per command. They open on **scripted** when it can answer, and on **live** otherwise. Scripted can answer when all of these hold:

- the command has a source run;
- nothing changes the request the recording answered: no transcript edit, no system prompt or model override, no new input at step 0, no fork, and no change to the tools, the thinking level or the tool choice;
- parallelism is not 1, which asks for sequential tool calls;
- `from_step` is a step the source answered;
- the preview's `scripted_key_match` is not a miss ([Preview](#preview)).

An override equal to the agent's own setting is no change and is not sent: a model equal to the source's own, a tool choice or thinking level equal to the agent's default, an input equal to the source's, an edit equal to the recording.

The engine is two radios, each with one line:

| Radio | Its line |
|---|---|
| scripted | `scripted · 0 tokens · replays the recorded answers`, or why it cannot answer, such as "a changed prompt: the recording answered the original" or "the source never answered step 3" |
| live | `live · calls <model> · ~1.2k tokens ≈ $0.0004 for steps 1–2`: the source's recorded usage from `from_step` to its last step at the price table's rate |

The live estimate reads at most 20 steps. When some are not read it adds "· later steps also run live", and Run's figure becomes "≥". When the usage or the price is unknown it reads `cost unknown: <why>` (for example "step 2 recorded no usage", or "the steps were priced on `<model>`" under a model override), never $0. A model the source never ran on reads "· live call" in the model choice. When the registered agent's model is a `wefttest` script (its `model_provider` in `GET /api/runtimes` reads `wefttest`, [The runtimes API](https://weftgo.dev/docs/observe/playground/runtimes/#the-runtimes-api)), the drawer adds "live calls this agent's wefttest script, which runs out: scripted replays the recording", and a run that exhausted the script reads "the wefttest script ran out".

Run names the engine: **Run on scripted · 0 tokens**, or **Run live on `<model>` · ≈ $0.0004**. On the playground it names the variant too: **Run A on scripted · 0 tokens**.

The engine is never switched behind you. A scripted pick that cannot answer holds Run with `scripted is refused: <why> — pick live`. A saved experiment keeps the engine it was saved with, live included, and a matrix saved before 0.19.0, which saved no engine, keeps the engine its runs ran on.

Over the API, `engine` is `"scripted"` or `"live"`, and a body without it runs live. Studio's clients always send the engine they show.

## The target check

A command names the agent it replays the source on, and Studio never picks one for you. A body with no `agent` is refused, naming the source's:

```json
{"error":{"code":"bad_request","message":"a run needs an agent: source run dd66354adfaac2b44848f0c1ed75516f is agent acme-support (send agent: \"acme-support\" to replay it on that agent)"}}
```

A source recorded by another agent than the target is refused too, because a replay is the target's prompt and tools over the source's transcript:

```json
{"error":{"code":"bad_request","message":"source run r_orders is agent orders; this command targets agent acme-support: send agent \"orders\" to replay it as recorded, or cross_agent: true to replay it as acme-support anyway"}}
```

`"cross_agent": true` in the body opts in. Studio checks it; it never reaches the runtime. A source that recorded no agent name runs on the agent the command names. The preview still assembles a cross-agent replay, with its `agent` warning.

In the drawers the same check runs before Run, from the source run's row, the registrations in `GET /api/runtimes` and the preview (capability `target_check`):

| The drawer says | What holds Run | How to go on |
|---|---|---|
| the source run names no agent: pick one | the source recorded no agent name | pick an agent; the picker lists the agents whose tools match the recorded ones first |
| the source run is agent orders; no runtime registers it: pick one, or start its app | no connected runtime registers the source's agent | pick another agent, or start the app that registers it |
| the source run is agent orders; this replays it as acme-support | you picked another agent | **replay as acme-support anyway** sends `cross_agent: true` |
| recorded by researcher@9b5997a3 · registered now researcher@a59ce89e · tools differ: search_docs → web_search · scripted will miss at step 2 | the source was recorded by another build of the agent and its tools differ | **replay on today's build anyway** |

The build line compares the source run's `manifest_hash` with the registration's ([The manifest hash](https://weftgo.dev/docs/guides/manifest/#the-manifest-hash)). When only the hash differs, the line is shown and Run is not held. An escape holds only for what it was taken for: a new source run or step, another target, another runtime or a new build of the target asks again. The drawer's **Runs in** line names the runtime the command goes to ([Runs in](https://weftgo.dev/docs/observe/playground/runtimes/#runs-in)).

## Edits

A command's `transcript_edits` is one list of edits to the kept prefix, applied before the replay runs. Each edit's `kind` picks what it changes, and each kind takes its own fields, no others:

| `kind` | Fields | Changes |
|---|---|---|
| `tool_result` | `step`, `call_id`, `tool_result` | a kept call's result |
| `reply` | `step`, `content` | a kept step's call-free assistant reply |
| `user` | `step`, `content`, `index` | a kept step's user message: step 0's is the turn's prompt, a later one a delivered steer; `index` (0 by default) picks among a step's several |
| `tool_args` | `step`, `call_id`, `args` | a kept call's arguments, a JSON object checked against the tool's schema ([below](#edit-tool-arguments)) |
| `insert` | `step`, `content` | a user message added at the boundary before step `step`'s model call, `0..from_step`: where a steer delivered after the previous step's tool batch would land |

An edit without `kind` reads as before the kinds existed: `tool_result` when it carries `tool_result`, `reply` when it carries `content`. Patch a result with `from_step` past it, in the example's source:

```sh
curl -s -X POST http://127.0.0.1:8080/studio/api/playground/runs -d '{
  "command_id": "cmd_docs_2",
  "runtime": "rt_6ea843dccc7741ff",
  "agent": "acme-support",
  "source": {"run_id": "dd66354adfaac2b44848f0c1ed75516f", "from_step": 1},
  "transcript_edits": [
    {"kind": "tool_result", "step": 0, "call_id": "c1",
     "tool_result": "{\"order_id\":\"4411\",\"status\":\"lost in transit\"}"}
  ]
}'
```

```json
{"command_id":"cmd_docs_2","state":"queued"}
```

The replay's model sees the counterfactual result, and its run row's `meta` carries the edit:

```json
"meta":{"weft.edits":"0:c1:result","weft.playground.actor":"local","weft.playground.command":"cmd_docs_2","weft.replay.view":"transcript"}
```

**`weft.edits`** names every edit, one token each in the command's order: `<step>:<call_id>:args` (the "args edited" mark), `<step>:<call_id>:result`, `<step>:reply`, `<step>:user` (`<step>:user:<index>` past the first) and `<step>:insert`. The tokens are in the source's coordinates, its step ordinals and call ids. A child run the replay starts inherits the value with the rest of the run's metadata, so it names the parent's edits.

The rules, checked by Studio (400) and again by the runtime before the ack, in one wording:

- **An edit needs a kept prefix.** `from_step` 0 keeps nothing:

  ```json
  {"error":{"code":"bad_request","message":"transcript_edits need from_step > 0 (0 re-runs the whole turn, nothing is kept)"}}
  ```

- **An edit names something in the kept prefix**: an edit of step N needs `from_step` N+1 or more, an insert at boundary N needs `from_step` N or more. A tool-result patch names a kept call, and a rewrite cannot drop a step's calls.
- **The prefix ends at a step boundary with every kept call answered**, so the loop never has to invent a result.
- **`input` beside `from_step` > 0 is refused.** Edit step 0's user message instead:

  ```json
  {"error":{"code":"bad_request","message":"input replaces the turn's user message only when from_step is 0: with from_step > 0, edit step 0's user message instead (a transcript edit of kind \"user\")"}}
  ```

- **The scripted engine takes no edits.** Its recorded answers answered the original request ([When scripted cannot answer](#when-scripted-cannot-answer)).
- **An edit inside a compacted range is refused.** When `from_step`'s request carried a compaction view, a message that view replaced is one the model never saw there: `call "c_1" of step 0 was compacted away before step 3's request (messages [1, 3) replaced by 1): the model never saw it there; edit from an earlier from_step`. An insert strictly inside the range is refused the same way. Edits outside it apply, then the view is spliced in.
- **A fork never carries edits.**

**Substitution keys on the edited pairs.** Under `substitute`, a kept call the model re-issues is answered from what the model saw answered. A call re-issued with its edited arguments gets the kept (or patched) result; one re-issued with its original arguments no longer matches and parks, or runs if it is replay-safe.

## Edit tool arguments

A `tool_args` edit rewrites a kept call's `args`, which must be a JSON object. It is checked against the tool's input schema with [`obsdb.CheckToolArgs`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CheckToolArgs), and refused in the loop's own `INVALID_INPUT` words. Writing the example's `order_id` as a number:

```sh
curl -s -X POST http://127.0.0.1:8080/studio/api/playground/runs -d '{
  "runtime": "rt_6ea843dccc7741ff", "agent": "acme-support",
  "source": {"run_id": "dd66354adfaac2b44848f0c1ed75516f", "from_step": 1},
  "transcript_edits": [{"kind": "tool_args", "step": 0, "call_id": "c1", "args": {"order_id": 4411}}]
}'
```

```json
{"error":{"code":"bad_request","message":"INVALID_INPUT: tool \"lookup_order\": field \"order_id\": expected string, got number"}}
```

The check covers `type` (one or a list), `properties`, `required`, `additionalProperties`, `items` and `enum`; a null field reads as absent, and an integer must be written as one (`3.0` is refused, as the loop refuses it). [`ExampleCheckToolArgs`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#example-CheckToolArgs) shows both answers.

The call keeps its id, name and signature, and its result stays unless a `tool_result` edit rewrites it too. `args` empty or `null` is absent. The runtime checks against its agent's current tool. Studio checks against the registered agent's manifest when a runtime holds it, else against the catalog the edited step recorded (the run's latest for a step without one). Without a registration the two can differ when the schema changed since the recording, and the runtime, the authority, decides before the ack. A read-scoped panel token's preview checks the object shape only, so no refusal names a hidden schema.

## Transcript editor

On the run page's story, and the devtools panel's Story tab, a run that is over is editable in place. Step 0's prompt, a steer, a call's args, a tool result and a call-free reply turn into a textarea when you click them, or press Enter on the pencil, with revert and a red "edited" chip. Every step boundary up to the highest `from_step` the run accepts takes an inserted message ("insert a message before step N").

The first edit opens the replay drawer as "Edit the transcript and replay". The drawer lists the edits by kind, each droppable, keeps `from_step` at what they imply, and opens on live, with the scripted radio saying why it cannot answer. An edit field starts empty with the recording beside it, and a value typed back to the recording is no edit: it is never sent and never a reason for live. An args edit is checked in the editor against the tool's schema with `CheckToolArgs`' rules; a refusal is said on the field in the `INVALID_INPUT` words and holds Run. On the playground page, the kept steps' **Transcript edits** fields show the recorded value as a muted "recorded: …" line, with **start from recorded** and **reset to recorded**.

A replay whose row carries `weft.edits` opens its story with "kept prefix edited": one chip per token, "args edited", "result edited", "edited" (a user message or a reply) or "inserted", at its source coordinates. A child run inherits the mark and draws none.

## Preview

`POST /api/playground/preview` takes the same body Run would post and answers the replay's first request beside the request step `from_step` recorded, with their diff. It is assembly in Studio from the records: no model, no tool and no runtime is needed. The capability is `preview`. For the tool-result edit above:

```sh
curl -s -X POST http://127.0.0.1:8080/studio/api/playground/preview -d '{
  "runtime": "rt_6ea843dccc7741ff", "agent": "acme-support",
  "source": {"run_id": "dd66354adfaac2b44848f0c1ed75516f", "from_step": 1},
  "transcript_edits": [{"kind": "tool_result", "step": 0, "call_id": "c1",
    "tool_result": "{\"order_id\":\"4411\",\"status\":\"lost in transit\"}"}]
}' | jq '{diff, warnings, unchecked}'
```

```json
{
  "diff": {
    "system": "same",
    "messages": [
      {"op": "same", "was": 0, "will": 0},
      {"op": "same", "was": 1, "will": 1},
      {"op": "changed", "was": 2, "will": 2}
    ],
    "tools": {"added": [], "removed": []},
    "model": "same",
    "params": "same",
    "thinking": "same",
    "tool_choice": "same"
  },
  "warnings": [],
  "unchecked": []
}
```

The answer's keys are `source`, `agent`, `engine`, `runtime`, `will_send`, `was_sent`, `diff`, `compacted_at`, `warnings`, `unchecked`, `scripted_hit` and `scripted_key_match`. `will_send` is the request: `system`, `messages`, `tools`, `model`, `params`, `thinking` and `tool_choice`, with `system_source`, `tools_source` and `params_source` saying where each came from (here `recorded`, `agent` and `agent`). Messages are aligned `same`, `changed`, `added` or `removed`.

The warnings name what the preview cannot promise: `prepare_step` when a request record of the source names what a `PrepareStep` changed, or none was recorded; `catalog` when the registered tools differ from the recorded step's; `agent` when the replay's agent is not the source run's; and `compacted`, `derived`, `scripted` and `instructions`. The scripted engine's refusals are warnings here, in the run route's words. `unchecked` lists the overrides only a registration could check, when no runtime holds the agent. A read-scoped panel token gets the system prompt and the catalog hidden.

**The scripted check.** Whatever the engine, the preview says whether the scripted engine holds a recorded answer for each step the replay would ask, before any model is called:

- `scripted_hit` is one entry per step from `from_step` through the first miss, `{step, hit, because}`. `because` lists the key components that differ: `tools`, `thinking`, `tool_choice`, `sequential`, `messages`, or `unanswered` for a step the source never answered.
- `scripted_key_match` sums it up as `{ok, because, step, message}`: `ok` when every step the replay reaches hits, else the first miss and its sentence, the one the run would fail with ([When scripted cannot answer](#when-scripted-cannot-answer)).

The check keys each step as the scripted engine does. A narrowed tool list, a thinking level, a tool choice, sequential tool calls or other messages miss at the step they change. A recorded call to a tool the registered agent lacks misses at the next step. A source that ended on a tool call (a failure, a cancel) asks the step it never answered, `unanswered`. When a step's request record names a `PrepareStep` change, that step is keyed from its record. Only component names are returned, never content.

The replay drawer draws the preview as "2 will be sent · step N's request", re-read 300 ms after the form rests: the system's state, one row per message with its op (a changed row shows was struck through above will, and each run of unchanged messages folds as "N same"), tools added and removed, the changed knobs and every badge. Its 400 is the command's own sentence, shown verbatim, and holds Run. A fork gets no preview.

## When scripted cannot answer

The scripted engine answers only what the source recorded. Studio refuses a scripted command it knows cannot answer, before any runtime sees it, with a 400 that says what differs and the two ways on:

| The command | The refusal |
|---|---|
| a system prompt override | `scripted cannot try a changed system prompt: the recorded answers ignore the prompt, so it would replay the old answer — run on live, or drop the prompt change` |
| a model override | `scripted cannot try another model: it replays the answers the source's own model recorded — run on live, or drop the model override` |
| no source run | `scripted replays a recorded run's answers: pick a source run, or run on live` |
| a transcript edit | `your edit changes step 1's request, and scripted holds only the recorded answer to the original — run on live, or drop the edit` |
| `from_step` at the step count | `scripted has no recorded answer for step 3: the source never answered it — run on live, or replay from an earlier step` |

The preview returns the same sentences as `warnings` instead of refusing, except the missing source run, which it refuses as the run route does.

Anything else that changes the request misses when the runtime asks for the step. The run fails, and the runtime's error names the source step whose recorded turn was nearest, the components that differ and the remedy:

```text
weft/runtime: no recorded turn for step 2 (scripted engine, key …): the tool list differs from the recording [tools]; the scripted engine answers only what the source recorded: run on live
```

| Component | Means |
|---|---|
| `tools` | the offered tool list is not the recorded one, or a recorded call names a tool the agent no longer has |
| `thinking` | the request sets a thinking level the recording does not hold |
| `tool_choice` | the request sets a tool choice the recording does not hold |
| `sequential` | the request asks for sequential tool calls (parallelism 1) |
| `messages` | the messages differ from the recording (a changed input or tool result) |
| `unanswered` | the source never answered the step |
| `exhausted` | the recording answered this request fewer times than the replay asks |

`GET /api/playground/commands/{id}` reads that failure into `reason`, beside `error`, which stays the runtime's text:

```json
"reason": {"kind": "scripted_miss", "step": 2, "components": ["tools"],
           "message": "scripted has no recorded answer for step 2: the tool list differs from the recording — run on live"}
```

The message ends ", or replay from an earlier step" when the source never answered the step. When the source recorded no turn at all, `step` is −1 and the sentence reads `scripted has no recorded answer for this request: …`.

The runtime sends the miss typed on its finished ack, `reason {kind: "scripted_miss", step, components}` beside the error text (which it cuts at 4 KiB), its components kept to the closed list above, and `reason` is built from it. Only for a runtime older than that field is the error text read instead. The preview, the refusal and the run agree on the step, the components and the sentence. [`ReasonOf`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio/runtime#ReasonOf) and [`ScriptedMissReason`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio/runtime#ScriptedMissReason) in `studio/runtime` are the mapping.

After a miss, the result shows that sentence with the ways on: **run again on live**, which puts the form on live with its estimate and posts nothing; **replay from step 0 with the recorded agent**; and, in Studio, **save the recording as a test**.

## Save a replay as a test

`POST /api/playground/fixtures` turns a run's records into `wefttest` replay fixtures, and the result card's **save as test** downloads the run as a replay test. For a replay from step N > 0 the test keeps the source's steps 0 to N−1 and replays the turn from its start. Both are on [Turn Studio runs into tests](https://weftgo.dev/docs/testing/studio-runs-as-tests/).

## Complete example

Start the example program from [How does the playground work?](https://weftgo.dev/docs/observe/playground/overview/#complete-example), then replay its source run with the commands above:

```sh
go run ./playground
```

```text
playground: http://127.0.0.1:8080/studio/playground
source run: dd66354adfaac2b44848f0c1ed75516f
```

Read the runtime id from `GET /api/runtimes` and the source run id from the output. The test `TestReplayFromStep` in [`main_test.go`](https://github.com/weftgo/weftgo.dev/blob/main/docs-site/examples/playground/main_test.go) sends the first command offline and checks the replay's `forked_from`, `playground`, `experiment_id`, `weft.replay.view` and empty `session_id`, then the 409 on a reused command id.

## Best practices & gotchas

- **Count `from_step` in the source's own steps.** The turn's input is context, not step 0's prefix, and a compaction changes no step count. (Source: ADR 0029 decision 1)
- **Re-check an unchanged change on scripted first.** It costs nothing and replays the recorded answers, so a step that differs points at your change, not at the model. (Source: `lib/engine.ts`, `runtime/scripted.go`)
- **Send `engine` and `agent` in your own clients.** A body without `engine` runs live, a real model call, and one without `agent` is refused. (Source: `studio/playground.go` `checkCommandWarn`, `checkTargetNamed`)
- **Expect a replay to stop where the source stopped.** It is the same turn: with `MaxSteps(10)` a replay from step 6 makes at most 4 model calls, and a loop streak carries over. (Source: `core/run.go` `KeptSteps`, `runtime/executor.go` `keptSteps`)
- **Edit step 0's user message instead of sending `input` past step 0.** `input` replaces the turn's message only when `from_step` is 0. (Source: `studio/playground.go` `checkSource`)
- **Check that a step-0 replay with `input` kept the conversation.** When the runtime cannot resolve the source transcript, because the source was recorded with content off, Studio is unreachable or the source run was swept, an ephemeral `from_step` 0 command with `input` runs on the input alone. The earlier turns are dropped and the command still finishes `succeeded`. The only signal is a WARN in the app's log: `weft/runtime: source transcript unresolved; running on the input alone`. Every other shape is refused instead: `from_step` above 0, edits, the scripted engine, or no `input`. (Source: `runtime/executor.go` `prepareSource`, `runPrefix`)
- **Edit from a step whose request the edited message reached.** Inside a compaction view the edit is refused: the model never saw that message there. (Source: ADR 0029 decision 4)
- **Make `PrepareStep` idempotent if you replay mid-run.** A count- or index-keyed one re-shapes the replay's input. (Source: ADR 0029 decision 1, `TestReplayRerunsTheAgentsPrepareStep`)
- **Re-issued calls with edited arguments are substituted from the kept result.** The original arguments no longer match and park. (Source: ADR 0029 decision 8)

## See also

- [See your runtimes and where a command runs](https://weftgo.dev/docs/observe/playground/runtimes/)
- [Run experiments with the option lab](https://weftgo.dev/docs/observe/playground/experiments/)
- [Compare runs step by step](https://weftgo.dev/docs/observe/studio/compare/)
- [Turn Studio runs into tests](https://weftgo.dev/docs/testing/studio-runs-as-tests/)
- [How does the playground work?](https://weftgo.dev/docs/observe/playground/overview/)

Symbols used: [`weft.KeptSteps`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#KeptSteps) · [`obsdb.CheckToolArgs`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#CheckToolArgs) · [`runtime.ReasonOf`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio/runtime#ReasonOf) · [`runtime.ScriptedMissReason`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio/runtime#ScriptedMissReason) · [`weft.Replay`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Replay) · [`weft.ReplaySafe`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#ReplaySafe) · [`weft.RequireApproval`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#RequireApproval) · [`weft.Subagent`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Subagent) · [`weft.PrepareStep`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#PrepareStep)
