Skip to content

An open-source, faster Devin alternative

TypeScript

React: settle tool rows with their turn, keep the result a decoded value, test against documented logs

Igor Zalutski57161ef34bba
diff --git a/docs/agents/events.mdx b/docs/agents/events.mdx
index c4cd68ac..6403cfa2 100644
--- a/docs/agents/events.mdx
+++ b/docs/agents/events.mdx
@@ -99,9 +99,9 @@ no rule recognizes is `agent_failed`.
| Type | When | `data` |
| --- | --- | --- |
-| `tool.started` | The model called a tool | `tool`: its name; `callId`; `title`; `input` |
+| `tool.started` | The model called a tool | `tool`: its name; `callId`; `title`; `input`: the arguments as a JSON value |
| `tool.progress` | The tool reported progress | runtime-defined |
-| `tool.completed` | The tool returned | `tool`, `callId`, `title`, `output`; `result: true` when the output became the session's result |
+| `tool.completed` | The tool returned | `tool`, `callId`, `title`, `output`: what the tool returned as a JSON value; `result: true` when the output became the session's result |
| `tool.failed` | The tool raised an error | `tool`, `callId`, `message` |
The exact fields come from the runtime's tool record; read them as optional
@@ -109,11 +109,20 @@ and key a tool call on `callId` when it is present. The memory tools
(`memory_save`, `memory_read`, `memory_list`) appear here like any other
tool; the save itself is reported separately.
+`input` and `output` are JSON values, never JSON text: an object comes as an
+object, and a consumer reads it without parsing.
+
A successful call of the agent's [result tool](/agents/tools#the-session-result)
-is recorded with `result: true`; its `output` is the validated value as JSON
-text, the same value `GET /sessions/<id>` returns parsed as `result.data`.
-The session writes this event when it commits the result, before the model
-sees the call succeed, and there is one per call.
+is recorded with `result: true`; its `output` is the validated value, the
+same JSON value `GET /sessions/<id>` returns as `result.data`. The session
+writes this event when it commits the result, before the model sees the call
+succeed, and there is one per call.
+
+A terminal turn event, `turn.completed`, `turn.failed` or `turn.cancelled`,
+settles every tool call of the turn that has no completion of its own. The
+log records a `tool.completed` or `tool.failed` per call while the runtime is
+connected; a call without one ended with its turn, and the turn's outcome is
+the call's outcome.
### Memory
diff --git a/docs/agents/react.mdx b/docs/agents/react.mdx
index 16f95374..a08924ad 100644
--- a/docs/agents/react.mdx
+++ b/docs/agents/react.mdx
@@ -211,13 +211,16 @@ Each turn is:
| `status` | `queued`, `running`, `completed`, `failed` or `cancelled` |
| `input` | The text the turn was admitted with |
| `messages` | The turn's messages, the same objects as in `messages` |
-| `toolCalls` | `{ callId, tool, title, input?, output?, status }` in the order the calls started; `status` is `running`, `completed` or `failed` |
-| `result` | The output of the agent's result tool, when it reported one; a later call replaces it |
+| `toolCalls` | `{ callId, tool, title, input?, output?, status }` in the order the calls started; `input` and `output` are JSON values; `status` is `running`, `completed`, `failed` or `cancelled` |
+| `result` | The decoded output of the agent's result tool, the same JSON value the session's `result.data` holds, when it reported one; a later call replaces it. An ordinary tool's output never becomes `result` |
| `failure` | `{ code, message }` from `turn.failed` |
Tool calls are keyed on the runtime's `callId`, so a `tool.completed` updates
-the entry its `tool.started` created rather than adding one. An activity
-timeline renders `turns` directly:
+the entry its `tool.started` created rather than adding one. When a turn ends,
+every call still `running` is settled with the turn: `completed` when the turn
+completed, `failed` when it failed, `cancelled` when it was interrupted. A
+settled turn therefore never shows a running call. An activity timeline
+renders `turns` directly:
```tsx
{turns.map((turn) => (
diff --git a/react/src/events.test.ts b/react/src/events.test.ts
index 47a5d8ab..81334678 100644
--- a/react/src/events.test.ts
+++ b/react/src/events.test.ts
@@ -200,3 +200,67 @@ test("a tool event without a callId still gets a stable id from its position", (
assert.equal(turns[0]?.input, "");
assert.deepEqual(turns[0]?.toolCalls, [{ callId: "event:2", tool: "shell", title: "shell", status: "running" }]);
});
+
+// The review's case in the documented shape: the result tool committed an
+// object, a later shell call started and never reported a completion of its
+// own, and the turn completed. The turn's word is final: the row is settled
+// with the turn, the result is the decoded object, and an ordinary output
+// that looks like a result is not one.
+const unsettled: AgentEvent[] = [
+ { seq: 1, turnId: "t1", type: "message.received", data: { input: "Fix the login page", mode: "queue" } },
+ { seq: 2, turnId: "t1", type: "turn.started", data: {} },
+ { seq: 3, turnId: "t1", type: "tool.started", data: { tool: "shell", callId: "c1", title: "git status", input: { command: "git status" } } },
+ { seq: 4, turnId: "t1", type: "tool.completed", data: { tool: "shell", callId: "c1", title: "git status", output: { branch: "task/1", pr: { number: 7, url: "https://example.test/pr/7" } } } },
+ { seq: 5, turnId: "t1", type: "tool.started", data: { tool: "report", callId: "c2", title: "report", input: { branch: "task/1" } } },
+ { seq: 6, turnId: "t1", type: "tool.completed", data: { tool: "report", callId: "c2", title: "report", output: { branch: "task/1", pr: { number: 7, url: "https://example.test/pr/7" } }, result: true } },
+ { seq: 7, turnId: "t1", type: "tool.started", data: { tool: "shell", callId: "c3", title: "npm test", input: { command: "npm test" } } },
+ { seq: 8, turnId: "t1", type: "message.completed", data: { text: "Opened PR 7." } },
+ { seq: 9, turnId: "t1", type: "turn.completed", data: {} },
+];
+
+test("a terminal turn event settles every tool row without a completion, and the result is the decoded value", () => {
+ const timeline = applyEvents(emptyTimeline(), unsettled.slice(0, 7));
+ assert.deepEqual(timeline.turns.t1?.toolCalls.map((call) => [call.callId, call.status]), [
+ ["c1", "completed"],
+ ["c2", "completed"],
+ ["c3", "running"],
+ ]);
+ // The ordinary shell output equals the result object byte for byte and is
+ // still not the result: only `result: true` commits one.
+ const beforeReport = turnsOf(applyEvents(emptyTimeline(), unsettled.slice(0, 4)))[0];
+ assert.equal(beforeReport?.result, undefined);
+ assert.deepEqual(beforeReport?.toolCalls[0]?.output, { branch: "task/1", pr: { number: 7, url: "https://example.test/pr/7" } });
+
+ const [turn] = turnsOf(applyEvents(emptyTimeline(), unsettled)) as [Turn];
+ assert.equal(turn.status, "completed");
+ assert.deepEqual(turn.toolCalls.map((call) => [call.callId, call.status]), [
+ ["c1", "completed"],
+ ["c2", "completed"],
+ ["c3", "completed"],
+ ]);
+ assert.equal(typeof turn.result, "object");
+ assert.deepEqual(turn.result, { branch: "task/1", pr: { number: 7, url: "https://example.test/pr/7" } });
+ assert.deepEqual(turn.toolCalls[1]?.output, turn.result);
+
+ const failed = turnsOf(applyEvents(emptyTimeline(), [
+ ...unsettled.slice(0, 7),
+ { seq: 8, turnId: "t1", type: "turn.failed", data: { code: "runtime_lost", message: "The runtime was lost" } },
+ ]))[0];
+ assert.deepEqual(failed?.toolCalls.map((call) => [call.callId, call.status]), [
+ ["c1", "completed"],
+ ["c2", "completed"],
+ ["c3", "failed"],
+ ]);
+ assert.deepEqual(failed?.result, turn.result);
+
+ const cancelled = turnsOf(applyEvents(emptyTimeline(), [
+ ...unsettled.slice(0, 7),
+ { seq: 8, turnId: "t1", type: "turn.cancelled", data: { reason: "interrupted", operationsSettled: 1 } },
+ ]))[0];
+ assert.deepEqual(cancelled?.toolCalls.map((call) => [call.callId, call.status]), [
+ ["c1", "completed"],
+ ["c2", "completed"],
+ ["c3", "cancelled"],
+ ]);
+ assert.deepEqual(cancelled?.result, turn.result);
+});
diff --git a/react/src/events.ts b/react/src/events.ts
index 5f3f4792..fbe138f3 100644
--- a/react/src/events.ts
+++ b/react/src/events.ts
@@ -48,14 +48,24 @@ export type TurnStatus =
| "failed"
| "cancelled";
-export type ToolCallStatus = "running" | "completed" | "failed";
+/**
+ * `running` until the call's own `tool.completed` or `tool.failed`, or until
+ * its turn ends: a terminal turn event settles every call still running with
+ * the turn's outcome, so a settled turn never shows a running call.
+ */
+export type ToolCallStatus = "running" | "completed" | "failed" | "cancelled";
-/** One tool call of a turn, keyed on the runtime's `callId`. */
+/**
+ * One tool call of a turn, keyed on `callId`, reduced from the documented
+ * `tool.*` event fields: `tool`, `callId`, `title`, `input` and `output` as
+ * JSON values.
+ */
export interface ToolCall {
callId: string;
tool: string;
title: string;
input?: DataValue;
+ /** The tool's output as the log carries it: a JSON value, never JSON text. */
output?: DataValue;
status: ToolCallStatus;
}
@@ -76,7 +86,11 @@ export interface Turn {
messages: AgentMessage[];
/** Tool calls in the order they started. */
toolCalls: ToolCall[];
- /** The output of the result tool's call, from `tool.completed` with `data.result`. */
+ /**
+ * The decoded output of the result tool's latest committed call, from
+ * `tool.completed` with `data.result: true`; the same value the session's
+ * `result.data` holds. An ordinary tool's output never lands here.
+ */
result?: DataValue;
failure?: TurnFailure;
}
@@ -190,6 +204,18 @@ function toolCallId(event: AgentEvent): string {
return typeof callId === "string" && callId ? callId : `event:${String(event.seq)}`;
}
+/**
+ * Settles every call still running when its turn ends. The log records a
+ * completion per call while the runtime is connected; a call that never got
+ * one ended with the turn, and the turn's outcome is the only honest word on
+ * it: completed with the turn, failed with it, or stopped by the interrupt.
+ */
+function settleToolCalls(calls: ToolCall[], status: Exclude<ToolCallStatus, "running">): ToolCall[] {
+ return calls.some((call) => call.status === "running")
+ ? calls.map((call) => (call.status === "running" ? { ...call, status } : call))
+ : calls;
+}
+
/**
* Applies one event to the turn records: the turn it names is created on
* first sight and moved along its lifecycle; tool events attach to it. Pure,
@@ -221,17 +247,18 @@ export function applyTurnEvent(
next = { ...current, status: "running" };
break;
case "turn.completed":
- next = { ...current, status: "completed" };
+ next = { ...current, status: "completed", toolCalls: settleToolCalls(current.toolCalls, "completed") };
break;
case "turn.failed":
next = {
...current,
status: "failed",
+ toolCalls: settleToolCalls(current.toolCalls, "failed"),
failure: { code: text(fields.code) || "agent_failed", message: text(fields.message) },
};
break;
case "turn.cancelled":
- next = { ...current, status: "cancelled" };
+ next = { ...current, status: "cancelled", toolCalls: settleToolCalls(current.toolCalls, "cancelled") };
break;
case "tool.started": {
const tool = text(fields.tool);
diff --git a/react/src/fixtures.test.ts b/react/src/fixtures.test.ts
new file mode 100644
index 00000000..96549184
--- /dev/null
+++ b/react/src/fixtures.test.ts
@@ -0,0 +1,79 @@
+// Every fixture log under react/test/fixtures reduces through the same
+// reducer the hook uses. `documented/` holds logs authored to
+// docs/agents/events.mdx; `backend-emitted/` holds recordings of what the
+// platform actually returned, added once the platform emits the documented
+// shape on every runtime. The checks are the contract's invariants, so a
+// recording that disagrees with the docs fails here rather than in a page.
+
+import assert from "node:assert/strict";
+import { readdirSync, readFileSync } from "node:fs";
+import test from "node:test";
+
+import { applyEvents, emptyTimeline, turnsOf, type AgentEvent, type Turn } from "./events.js";
+
+// Tests run from dist/, one level below the package root, like src/.
+const root = new URL("../test/fixtures/", import.meta.url);
+
+interface Fixture {
+ events: AgentEvent[];
+ /** The turns the log must reduce to, when the fixture pins them. */
+ turns?: Turn[];
+}
+
+function fixturesIn(directory: string): Array<{ name: string; fixture: Fixture }> {
+ const url = new URL(`${directory}/`, root);
+ let names: string[];
+ try {
+ names = readdirSync(url).filter((name) => name.endsWith(".json")).sort();
+ } catch {
+ return [];
+ }
+ return names.map((name) => ({
+ name: `${directory}/${name}`,
+ fixture: JSON.parse(readFileSync(new URL(name, url), "utf8")) as Fixture,
+ }));
+}
+
+function check(name: string, fixture: Fixture): void {
+ assert.ok(Array.isArray(fixture.events) && fixture.events.length > 0, `${name}: no events`);
+ const whole = turnsOf(applyEvents(emptyTimeline(), fixture.events));
+ let paged = emptyTimeline();
+ for (let start = 0; start < fixture.events.length; start += 3) {
+ paged = applyEvents(paged, fixture.events.slice(start, start + 3));
+ }
+ assert.deepEqual(turnsOf(paged), whole, `${name}: replay in pages differs from replay whole`);
+ for (const turn of whole) {
+ const settled = turn.status === "completed" || turn.status === "failed" || turn.status === "cancelled";
+ if (settled) {
+ for (const call of turn.toolCalls) {
+ assert.notEqual(
+ call.status,
+ "running",
+ `${name}: turn ${turn.id} is ${turn.status} but its call ${call.callId} is still running`,
+ );
+ }
+ }
+ const ids = turn.toolCalls.map((call) => call.callId);
+ assert.equal(new Set(ids).size, ids.length, `${name}: turn ${turn.id} has duplicate tool rows`);
+ if (turn.result !== undefined) {
+ const pinned = fixture.turns?.find((candidate) => candidate.id === turn.id)?.result;
+ if (typeof pinned !== "string") {
+ assert.notEqual(typeof turn.result, "string", `${name}: turn ${turn.id} exposes its result as JSON text`);
+ }
+ }
+ }
+ if (fixture.turns) assert.deepEqual(whole, fixture.turns, `${name}: turns differ from the pinned turns`);
+}
+
+for (const directory of ["documented", "backend-emitted"]) {
+ test(`every ${directory} fixture reduces to settled turns, the same whole and in pages`, (t) => {
+ const files = fixturesIn(directory);
+ for (const { name, fixture } of files) check(name, fixture);
+ t.diagnostic(`${directory}: ${String(files.length)} fixture file(s) ran`);
+ });
+}
+
+test("the documented fixtures cover a result, an interrupt and a failure", () => {
+ const names = fixturesIn("documented").map(({ name }) => name);
+ assert.ok(names.length >= 3, `expected at least three documented fixtures, found ${String(names.length)}`);
+});
diff --git a/react/src/use-agent.test.ts b/react/src/use-agent.test.ts
index 59ff431f..b532f528 100644
--- a/react/src/use-agent.test.ts
+++ b/react/src/use-agent.test.ts
@@ -665,6 +665,13 @@ test("attach exposes turns with their tool activity and result, the same after a
await again.render();
const fresh = await again.until((result) => !result.isReplaying && result.turns.length === 2, "second replay");
assert.deepEqual(fresh.turns, live.turns);
+
+ // An interrupt settles the running call with the turn: the hook shows no
+ // running call on a cancelled turn, and stops counting the turn as running.
+ session.append({ turnId: "turn-1", type: "turn.cancelled", data: { reason: "interrupted", operationsSettled: 1 } });
+ const settled = await view.until((result) => result.turns[1]?.status === "cancelled", "cancelled turn");
+ assert.deepEqual(settled.turns[1]?.toolCalls, [{ callId: "c3", tool: "shell", title: "npm test", status: "cancelled" }]);
+ assert.equal(settled.isRunning, false);
await again.unmount();
await view.unmount();
});
diff --git a/react/test/fixtures/backend-emitted/README.md b/react/test/fixtures/backend-emitted/README.md
new file mode 100644
index 00000000..2f7a498a
--- /dev/null
+++ b/react/test/fixtures/backend-emitted/README.md
@@ -0,0 +1,22 @@
+# Backend-emitted event logs
+
+Recorded session logs from the platform go here, one JSON file per recorded
+session or turn, as `GET /sessions/<id>/events` returned them through the
+public API. Every `*.json` file in this directory is run by
+`react/src/fixtures.test.ts` on `npm test`: replayed whole and in pages, and
+checked for settled tool rows on settled turns, unique tool rows and a decoded
+result.
+
+The file shape is the one the authored fixtures in `../documented/` use:
+
+```json
+{ "events": [ ...events, in log order... ], "turns": [ ...expected turns, optional... ] }
+```
+
+`turns` is optional; when present it is compared for deep equality with what
+the reducer produces. Without it the invariants above are still checked.
+
+This directory holds only this README until the platform emits the documented
+event shape on every runtime (bluecode F2); recordings made before then would
+pin the wrong contract. Add recordings here once that ships, do not author
+them by hand.
diff --git a/react/test/fixtures/documented/completed-turn-with-result.json b/react/test/fixtures/documented/completed-turn-with-result.json
new file mode 100644
index 00000000..9aa23bbd
--- /dev/null
+++ b/react/test/fixtures/documented/completed-turn-with-result.json
@@ -0,0 +1,30 @@
+{
+ "events": [
+ { "id": "evt_1", "seq": 1, "timestamp": "2026-09-15T10:00:00.000Z", "sessionId": "ses_1", "turnId": "t1", "type": "message.received", "data": { "input": "Fix the login page", "mode": "queue", "payload": { "repo": "acme/web", "ref": "main" } } },
+ { "id": "evt_2", "seq": 2, "timestamp": "2026-09-15T10:00:00.100Z", "sessionId": "ses_1", "turnId": "t1", "type": "turn.started", "data": {} },
+ { "id": "evt_3", "seq": 3, "timestamp": "2026-09-15T10:00:01.000Z", "sessionId": "ses_1", "turnId": "t1", "type": "tool.started", "data": { "tool": "shell", "callId": "c1", "title": "git clone", "input": { "command": "git clone https://github.com/acme/web.git" } } },
+ { "id": "evt_4", "seq": 4, "timestamp": "2026-09-15T10:00:03.000Z", "sessionId": "ses_1", "turnId": "t1", "type": "tool.completed", "data": { "tool": "shell", "callId": "c1", "title": "git clone", "output": { "exitCode": 0, "stdout": "Cloning into 'web'...\n" } } },
+ { "id": "evt_5", "seq": 5, "timestamp": "2026-09-15T10:00:20.000Z", "sessionId": "ses_1", "turnId": "t1", "type": "tool.started", "data": { "tool": "report", "callId": "c2", "title": "report", "input": { "branch": "task/1", "pr": { "number": 7, "url": "https://github.com/acme/web/pull/7" } } } },
+ { "id": "evt_6", "seq": 6, "timestamp": "2026-09-15T10:00:20.500Z", "sessionId": "ses_1", "turnId": "t1", "type": "tool.completed", "data": { "tool": "report", "callId": "c2", "title": "report", "output": { "branch": "task/1", "pr": { "number": 7, "url": "https://github.com/acme/web/pull/7" } }, "result": true } },
+ { "id": "evt_7", "seq": 7, "timestamp": "2026-09-15T10:00:21.000Z", "sessionId": "ses_1", "turnId": "t1", "type": "message.delta", "data": { "text": "Opened " } },
+ { "id": "evt_8", "seq": 8, "timestamp": "2026-09-15T10:00:21.200Z", "sessionId": "ses_1", "turnId": "t1", "type": "message.delta", "data": { "text": "PR 7." } },
+ { "id": "evt_9", "seq": 9, "timestamp": "2026-09-15T10:00:21.400Z", "sessionId": "ses_1", "turnId": "t1", "type": "message.completed", "data": { "text": "Opened PR 7." } },
+ { "id": "evt_10", "seq": 10, "timestamp": "2026-09-15T10:00:21.500Z", "sessionId": "ses_1", "turnId": "t1", "type": "turn.completed", "data": {} }
+ ],
+ "turns": [
+ {
+ "id": "t1",
+ "status": "completed",
+ "input": "Fix the login page",
+ "toolCalls": [
+ { "callId": "c1", "tool": "shell", "title": "git clone", "input": { "command": "git clone https://github.com/acme/web.git" }, "output": { "exitCode": 0, "stdout": "Cloning into 'web'...\n" }, "status": "completed" },
+ { "callId": "c2", "tool": "report", "title": "report", "input": { "branch": "task/1", "pr": { "number": 7, "url": "https://github.com/acme/web/pull/7" } }, "output": { "branch": "task/1", "pr": { "number": 7, "url": "https://github.com/acme/web/pull/7" } }, "status": "completed" }
+ ],
+ "result": { "branch": "task/1", "pr": { "number": 7, "url": "https://github.com/acme/web/pull/7" } },
+ "messages": [
+ { "id": "turn:t1:input", "role": "user", "text": "Fix the login page", "turnId": "t1" },
+ { "id": "turn:t1:reply", "role": "assistant", "text": "Opened PR 7.", "turnId": "t1", "streaming": false }
+ ]
+ }
+ ]
+}
diff --git a/react/test/fixtures/documented/interrupted-turn-settled-by-cancel.json b/react/test/fixtures/documented/interrupted-turn-settled-by-cancel.json
new file mode 100644
index 00000000..37ce271c
--- /dev/null
+++ b/react/test/fixtures/documented/interrupted-turn-settled-by-cancel.json
@@ -0,0 +1,40 @@
+{
+ "events": [
+ { "id": "evt_1", "seq": 1, "timestamp": "2026-09-15T11:00:00.000Z", "sessionId": "ses_2", "turnId": "t1", "type": "message.received", "data": { "input": "Run the full suite", "mode": "queue" } },
+ { "id": "evt_2", "seq": 2, "timestamp": "2026-09-15T11:00:00.100Z", "sessionId": "ses_2", "turnId": "t1", "type": "turn.started", "data": {} },
+ { "id": "evt_3", "seq": 3, "timestamp": "2026-09-15T11:00:01.000Z", "sessionId": "ses_2", "turnId": "t1", "type": "tool.started", "data": { "tool": "shell", "callId": "c1", "title": "npm test", "input": { "command": "npm test", "timeoutSeconds": 600 } } },
+ { "id": "evt_4", "seq": 4, "timestamp": "2026-09-15T11:00:30.000Z", "sessionId": "ses_2", "turnId": "t2", "type": "message.received", "data": { "input": "Stop, run the fast suite instead", "mode": "interrupt" } },
+ { "id": "evt_5", "seq": 5, "timestamp": "2026-09-15T11:00:30.010Z", "sessionId": "ses_2", "turnId": "t2", "type": "turn.interrupted", "data": { "interruptedTurnIds": ["t1"] } },
+ { "id": "evt_6", "seq": 6, "timestamp": "2026-09-15T11:00:31.200Z", "sessionId": "ses_2", "turnId": "t1", "type": "turn.cancelled", "data": { "reason": "interrupted", "replacementTurnId": "t2", "settledAfterMs": 1190, "operationsSettled": 1, "computerTerminated": false } },
+ { "id": "evt_7", "seq": 7, "timestamp": "2026-09-15T11:00:31.300Z", "sessionId": "ses_2", "turnId": "t2", "type": "turn.started", "data": {} },
+ { "id": "evt_8", "seq": 8, "timestamp": "2026-09-15T11:00:32.000Z", "sessionId": "ses_2", "turnId": "t2", "type": "tool.started", "data": { "tool": "shell", "callId": "c2", "title": "npm test -- --fast", "input": { "command": "npm test -- --fast" } } },
+ { "id": "evt_9", "seq": 9, "timestamp": "2026-09-15T11:00:40.000Z", "sessionId": "ses_2", "turnId": "t2", "type": "tool.completed", "data": { "tool": "shell", "callId": "c2", "title": "npm test -- --fast", "output": { "exitCode": 0 } } },
+ { "id": "evt_10", "seq": 10, "timestamp": "2026-09-15T11:00:41.000Z", "sessionId": "ses_2", "turnId": "t2", "type": "message.completed", "data": { "text": "The fast suite passed." } },
+ { "id": "evt_11", "seq": 11, "timestamp": "2026-09-15T11:00:41.100Z", "sessionId": "ses_2", "turnId": "t2", "type": "turn.completed", "data": {} }
+ ],
+ "turns": [
+ {
+ "id": "t1",
+ "status": "cancelled",
+ "input": "Run the full suite",
+ "toolCalls": [
+ { "callId": "c1", "tool": "shell", "title": "npm test", "input": { "command": "npm test", "timeoutSeconds": 600 }, "status": "cancelled" }
+ ],
+ "messages": [
+ { "id": "turn:t1:input", "role": "user", "text": "Run the full suite", "turnId": "t1" }
+ ]
+ },
+ {
+ "id": "t2",
+ "status": "completed",
+ "input": "Stop, run the fast suite instead",
+ "toolCalls": [
+ { "callId": "c2", "tool": "shell", "title": "npm test -- --fast", "input": { "command": "npm test -- --fast" }, "output": { "exitCode": 0 }, "status": "completed" }
+ ],
+ "messages": [
+ { "id": "turn:t2:input", "role": "user", "text": "Stop, run the fast suite instead", "turnId": "t2" },
+ { "id": "turn:t2:reply", "role": "assistant", "text": "The fast suite passed.", "turnId": "t2", "streaming": false }
+ ]
+ }
+ ]
+}
diff --git a/react/test/fixtures/documented/running-call-settled-by-failure.json b/react/test/fixtures/documented/running-call-settled-by-failure.json
new file mode 100644
index 00000000..fd6caf4a
--- /dev/null
+++ b/react/test/fixtures/documented/running-call-settled-by-failure.json
@@ -0,0 +1,22 @@
+{
+ "events": [
+ { "id": "evt_1", "seq": 1, "timestamp": "2026-09-15T12:00:00.000Z", "sessionId": "ses_3", "turnId": "t1", "type": "message.received", "data": { "input": "Deploy the preview", "mode": "queue" } },
+ { "id": "evt_2", "seq": 2, "timestamp": "2026-09-15T12:00:00.100Z", "sessionId": "ses_3", "turnId": "t1", "type": "turn.started", "data": {} },
+ { "id": "evt_3", "seq": 3, "timestamp": "2026-09-15T12:00:01.000Z", "sessionId": "ses_3", "turnId": "t1", "type": "tool.started", "data": { "tool": "shell", "callId": "c1", "title": "npm run deploy", "input": { "command": "npm run deploy" } } },
+ { "id": "evt_4", "seq": 4, "timestamp": "2026-09-15T12:05:00.000Z", "sessionId": "ses_3", "turnId": "t1", "type": "turn.failed", "data": { "code": "runtime_lost", "message": "The runtime was lost" } }
+ ],
+ "turns": [
+ {
+ "id": "t1",
+ "status": "failed",
+ "input": "Deploy the preview",
+ "toolCalls": [
+ { "callId": "c1", "tool": "shell", "title": "npm run deploy", "input": { "command": "npm run deploy" }, "status": "failed" }
+ ],
+ "failure": { "code": "runtime_lost", "message": "The runtime was lost" },
+ "messages": [
+ { "id": "turn:t1:input", "role": "user", "text": "Deploy the preview", "turnId": "t1" }
+ ]
+ }
+ ]
+}