@marimo-team/islands 0.25.3-dev458 → 0.25.3-dev460

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/{ErrorBoundary-CwkGSYmm.js → ErrorBoundary-D2YXxE_x.js} +1 -1
  2. package/dist/{chat-ui-6d75EmD5.js → chat-ui-wWHUzOrx.js} +3 -3
  3. package/dist/{code-visibility-Xv_t4WwT.js → code-visibility-BPWgfZVa.js} +2 -2
  4. package/dist/{common-BlMwQJMs.js → common-_2RH91nQ.js} +3 -3
  5. package/dist/{data-grid-overlay-editor-Bd8kunYq.js → data-grid-overlay-editor-yh1wqygW.js} +1 -1
  6. package/dist/{error-entries-Y2oBe6wK.js → error-entries-3nytC8-z.js} +527 -504
  7. package/dist/{feedback-button-nET4jF-9.js → feedback-button-Ctc_u2JY.js} +3 -3
  8. package/dist/{glide-data-editor-DzQRP0yA.js → glide-data-editor-DJikF-sp.js} +3 -3
  9. package/dist/{globals-IFL15lCt.js → globals-D8_0qvIC.js} +1 -1
  10. package/dist/{html-to-image-BMB3OKAk.js → html-to-image-C3Nb90uM.js} +1 -1
  11. package/dist/main.js +8493 -8478
  12. package/dist/{number-overlay-editor-BtYxGlC3.js → number-overlay-editor-BUXorcPD.js} +1 -1
  13. package/dist/{process-output-lVSjjNuD.js → process-output-BiLaCBoX.js} +2 -2
  14. package/dist/{reveal-component-BtbTYMke.js → reveal-component-B54ZJYk8.js} +2 -2
  15. package/package.json +1 -1
  16. package/src/__mocks__/executions.ts +54 -52
  17. package/src/components/editor/__tests__/output-persistence.test.tsx +1 -1
  18. package/src/components/editor/cell/__tests__/useRunCells.test.tsx +5 -8
  19. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +7 -5
  20. package/src/components/editor/stdin-blocking-alert.tsx +1 -1
  21. package/src/core/cells/__tests__/clear-outputs.test.ts +8 -9
  22. package/src/core/cells/__tests__/runs.test.ts +18 -18
  23. package/src/core/cells/__tests__/session.test.ts +13 -11
  24. package/src/core/cells/execution-console.ts +6 -8
  25. package/src/core/cells/runs.ts +10 -10
  26. package/src/core/cells/session.ts +7 -5
  27. package/src/core/cells/utils.ts +1 -1
  28. package/src/core/errors/__tests__/error-entries.test.ts +1 -1
  29. package/src/core/executions/__tests__/atoms.test.ts +12 -5
  30. package/src/core/executions/__tests__/freshness.test.ts +53 -37
  31. package/src/core/executions/__tests__/hooks.test.tsx +8 -9
  32. package/src/core/executions/__tests__/interrupt.test.ts +12 -5
  33. package/src/core/executions/__tests__/output-lifecycle.test.ts +39 -38
  34. package/src/core/executions/__tests__/output.test.ts +62 -72
  35. package/src/core/executions/__tests__/run.test.ts +1 -4
  36. package/src/core/executions/__tests__/select.test.ts +44 -30
  37. package/src/core/executions/atoms.ts +2 -1
  38. package/src/core/executions/freshness.ts +7 -5
  39. package/src/core/executions/output.ts +8 -6
  40. package/src/core/executions/select.ts +23 -18
  41. package/src/core/islands/__tests__/bridge.test.ts +2 -10
  42. package/src/core/notebook/replica/__tests__/executions.test.ts +20 -11
  43. package/src/core/notebook/replica/__tests__/results.test.ts +42 -33
  44. package/src/core/notebook/replica/execution-state.ts +35 -0
  45. package/src/core/notebook/replica/index.ts +6 -0
  46. package/src/core/notebook/replica/replica.ts +1 -1
  47. package/src/core/notebook/replica/resources/executions.ts +9 -8
  48. package/src/core/notebook/replica/resources/results.ts +6 -5
  49. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +20 -22
  50. package/src/core/session/useNotebookSession.tsx +11 -4
  51. package/src/core/static/virtual-file-tracker.ts +3 -2
  52. package/src/core/transports/__tests__/static.test.ts +13 -8
  53. package/src/core/wasm/__tests__/bridge.test.ts +7 -16
  54. package/src/core/wasm/bridge.ts +6 -5
  55. package/src/stories/cell.stories.tsx +24 -19
@@ -17,6 +17,13 @@ const T0 = "2026-10-01T09:20:11Z";
17
17
  const T1 = "2026-10-01T09:20:12.500Z";
18
18
  const T2 = "2026-10-01T09:20:20Z";
19
19
 
20
+ const QUEUED: Protocol.ExecutionState = { status: "queued" };
21
+ const RUNNING: Protocol.ExecutionState = {
22
+ status: "running",
23
+ started_at: T0,
24
+ value: null,
25
+ };
26
+
20
27
  function record(
21
28
  overrides: Partial<Protocol.Execution> & { id: string },
22
29
  ): Protocol.Execution {
@@ -26,11 +33,13 @@ function record(
26
33
  caused_by: null,
27
34
  cell_id: "c1",
28
35
  code_fingerprint: "0f71456db2ea83f4",
29
- depends_on: {},
30
- status: "completed",
31
- outcome: { kind: "value", display: null },
32
- started_at: T0,
33
- completed_at: T1,
36
+ state: {
37
+ status: "completed",
38
+ started_at: T0,
39
+ completed_at: T1,
40
+ outcome: { kind: "value", display: null },
41
+ depends_on: {},
42
+ },
34
43
  ...overrides,
35
44
  };
36
45
  }
@@ -46,7 +55,7 @@ function execution(overrides: Partial<Protocol.Execution> & { id: string }) {
46
55
 
47
56
  function run(
48
57
  cells: string[],
49
- status: Protocol.Run["status"],
58
+ status: Protocol.RunState["status"],
50
59
  id = "run-1",
51
60
  ): Protocol.Run {
52
61
  return {
@@ -54,10 +63,17 @@ function run(
54
63
  notebook_id: "n1",
55
64
  runtime_id: "r1",
56
65
  origin: { kind: "cells", cell_ids: cells },
57
- status,
58
- outcome: status === "completed" ? "succeeded" : null,
59
- started_at: null,
60
- completed_at: null,
66
+ state:
67
+ status === "completed"
68
+ ? {
69
+ status,
70
+ started_at: null,
71
+ completed_at: "2026-10-01T09:20:02Z",
72
+ outcome: "succeeded",
73
+ }
74
+ : status === "running"
75
+ ? { status, started_at: "2026-10-01T09:20:01Z" }
76
+ : { status },
61
77
  };
62
78
  }
63
79
 
@@ -118,10 +134,7 @@ describe("cellExecutionView", () => {
118
134
  executions: [
119
135
  execution({
120
136
  id: "e1",
121
- status: "queued",
122
- outcome: null,
123
- started_at: null,
124
- completed_at: null,
137
+ state: QUEUED,
125
138
  }),
126
139
  ],
127
140
  });
@@ -130,10 +143,7 @@ describe("cellExecutionView", () => {
130
143
  executions: [
131
144
  execution({
132
145
  id: "e1",
133
- status: "running",
134
- outcome: null,
135
- started_at: T2,
136
- completed_at: null,
146
+ state: { status: "running", started_at: T2, value: null },
137
147
  }),
138
148
  ],
139
149
  results: new Map([["c1", execution({ id: "e0" })]]),
@@ -173,11 +183,20 @@ describe("cellExecutionView", () => {
173
183
  });
174
184
 
175
185
  it("reports how the last completed execution ended, with its timing", () => {
186
+ const completedWith = (outcome: Protocol.Outcome) => ({
187
+ status: "completed" as const,
188
+ started_at: T0,
189
+ completed_at: T1,
190
+ outcome,
191
+ depends_on: {},
192
+ });
176
193
  const ended = (outcome: Protocol.Outcome) =>
177
194
  cellExecutionView(
178
195
  inputs({
179
- executions: [execution({ id: "e1", outcome })],
180
- results: new Map([["c1", execution({ id: "e1", outcome })]]),
196
+ executions: [execution({ id: "e1", state: completedWith(outcome) })],
197
+ results: new Map([
198
+ ["c1", execution({ id: "e1", state: completedWith(outcome) })],
199
+ ]),
181
200
  }),
182
201
  "c1",
183
202
  );
@@ -244,8 +263,7 @@ describe("cellExecutionView", () => {
244
263
  execution({
245
264
  id: "e2",
246
265
  run_id: "run-2",
247
- status: "running",
248
- completed_at: null,
266
+ state: RUNNING,
249
267
  }),
250
268
  ],
251
269
  results: result,
@@ -314,20 +332,17 @@ describe("cellExecutionView", () => {
314
332
  describe("notebook-level views", () => {
315
333
  const stream = inputs({
316
334
  executions: [
317
- execution({ id: "e1", status: "running", completed_at: null }),
335
+ execution({ id: "e1", state: RUNNING }),
318
336
  execution({
319
337
  id: "e2",
320
338
  cell_id: "c2",
321
- status: "queued",
322
- started_at: null,
323
- completed_at: null,
339
+ state: QUEUED,
324
340
  }),
325
341
  execution({ id: "e3", cell_id: "c3" }),
326
342
  execution({
327
343
  id: "s1",
328
344
  cell_id: null,
329
- status: "running",
330
- completed_at: null,
345
+ state: RUNNING,
331
346
  }),
332
347
  ],
333
348
  runs: [run(["c1", "c2", "c5"], "running"), run(["c5"], "queued", "run-2")],
@@ -348,8 +363,7 @@ describe("notebook-level views", () => {
348
363
  execution({
349
364
  id: "s1",
350
365
  cell_id: null,
351
- status: "running",
352
- completed_at: null,
366
+ state: RUNNING,
353
367
  }),
354
368
  execution({ id: "e3", cell_id: "c3" }),
355
369
  ],
@@ -29,6 +29,7 @@ import {
29
29
  type CellExecutionInputs,
30
30
  queuedOrRunningCount,
31
31
  } from "./select";
32
+ import { shownOutcome } from "@/core/notebook/replica";
32
33
 
33
34
  type Store = ReturnType<typeof createStore>;
34
35
 
@@ -237,7 +238,7 @@ export function clearCellOutputs(
237
238
  const next = new Map(inputs.cleared);
238
239
  for (const cellId of cellIds) {
239
240
  const shown = shownExecution(inputs, cellId);
240
- if (shown?.record.outcome != null) {
241
+ if (shown != null && shownOutcome(shown.record) !== null) {
241
242
  next.set(cellId, {
242
243
  execution: shown.record.id,
243
244
  version: shown.outputVersion,
@@ -19,6 +19,7 @@
19
19
 
20
20
  import type * as Protocol from "@marimo-team/client/protocol";
21
21
  import type { Executions, Results } from "@/core/notebook/replica";
22
+ import { completedAt, dependsOn, startedAt } from "@/core/notebook/replica";
22
23
 
23
24
  export interface CellFreshness {
24
25
  /** This cell's source differs from its pending execution, or its last result. */
@@ -84,7 +85,7 @@ export function freshnessOf(inputs: CellFreshnessInputs): CellFreshnessLookup {
84
85
  visiting: ReadonlySet<Protocol.ExecutionId>,
85
86
  ): boolean {
86
87
  const path = new Set(visiting).add(record.id);
87
- for (const [name, revision] of Object.entries(record.depends_on)) {
88
+ for (const [name, revision] of Object.entries(dependsOn(record))) {
88
89
  const variables = bound.get(name) ?? [];
89
90
  if (revision === null) {
90
91
  // Older runtimes bind nothing here, but a later binding invalidates
@@ -98,11 +99,12 @@ export function freshnessOf(inputs: CellFreshnessInputs): CellFreshnessLookup {
98
99
  if (binder.runtime_id === record.runtime_id) {
99
100
  return true;
100
101
  }
101
- const boundAt = binder.completed_at ?? binder.started_at;
102
+ const boundAt = completedAt(binder) ?? startedAt(binder);
103
+ const readAt = completedAt(record);
102
104
  return (
103
105
  boundAt !== null &&
104
- record.completed_at !== null &&
105
- Date.parse(boundAt) > Date.parse(record.completed_at)
106
+ readAt !== null &&
107
+ Date.parse(boundAt) > Date.parse(readAt)
106
108
  );
107
109
  })
108
110
  ) {
@@ -138,7 +140,7 @@ export function freshnessOf(inputs: CellFreshnessInputs): CellFreshnessLookup {
138
140
  const latest = inputs.executions.latest.get(cell.id);
139
141
  const pending = latest === undefined ? undefined : recordOf(latest);
140
142
  const source =
141
- pending !== undefined && pending.status !== "completed"
143
+ pending !== undefined && pending.state.status !== "completed"
142
144
  ? pending
143
145
  : result;
144
146
  return cell.code_fingerprint !== source.code_fingerprint;
@@ -13,6 +13,7 @@ import type * as Protocol from "@marimo-team/client/protocol";
13
13
  import type { CellId } from "@/core/cells/ids";
14
14
  import type { MarimoError, OutputMessage } from "@/core/kernel/messages";
15
15
  import type { Executions, Result, Results } from "@/core/notebook/replica";
16
+ import { completedAt, shownOutcome, startedAt } from "@/core/notebook/replica";
16
17
 
17
18
  /** A host error shown as its message and the cells involved. */
18
19
  export interface HostDiagnostic {
@@ -71,7 +72,7 @@ function seconds(iso: string | null): number {
71
72
  }
72
73
 
73
74
  function endedAt(record: Protocol.Execution): number {
74
- return seconds(record.completed_at ?? record.started_at);
75
+ return seconds(completedAt(record) ?? startedAt(record));
75
76
  }
76
77
 
77
78
  function valueOutput(
@@ -212,7 +213,7 @@ export function outcomeOutput(
212
213
  }
213
214
 
214
215
  function outcomeDisplay(record: Protocol.Execution): CellOutput | null {
215
- const outcome = record.outcome;
216
+ const outcome = shownOutcome(record);
216
217
  if (outcome === null) {
217
218
  return null;
218
219
  }
@@ -250,15 +251,16 @@ export function shownExecution(
250
251
  : inputs.executions.executions.get(latestId);
251
252
  if (
252
253
  latest !== undefined &&
253
- latest.record.outcome !== null &&
254
- latest.record.status !== "completed"
254
+ shownOutcome(latest.record) !== null &&
255
+ latest.record.state.status !== "completed"
255
256
  ) {
256
257
  return latest;
257
258
  }
258
259
  const result = inputs.results.get(id) ?? null;
259
260
  if (
260
- latest?.record.status === "running" &&
261
- result?.record.outcome?.kind === "skipped"
261
+ latest?.record.state.status === "running" &&
262
+ result !== null &&
263
+ shownOutcome(result.record)?.kind === "skipped"
262
264
  ) {
263
265
  return null;
264
266
  }
@@ -5,6 +5,11 @@
5
5
  import type * as Protocol from "@marimo-team/client/protocol";
6
6
  import type { Execution, Executions, Results } from "@/core/notebook/replica";
7
7
  import { type Milliseconds, Time } from "@/utils/time";
8
+ import {
9
+ completedAt,
10
+ shownOutcome,
11
+ startedAt as startedAtOf,
12
+ } from "@/core/notebook/replica";
8
13
 
9
14
  /** Where a cell is in its run. */
10
15
  export type CellRunStatus = "idle" | "queued" | "running";
@@ -54,7 +59,7 @@ export interface CellExecutionInputs {
54
59
  }
55
60
 
56
61
  export function outcomeOf(record: Protocol.Execution): CellOutcome | null {
57
- const outcome = record.outcome;
62
+ const outcome = shownOutcome(record);
58
63
  if (outcome === null) {
59
64
  return null;
60
65
  }
@@ -108,7 +113,7 @@ function awaited(inputs: CellExecutionInputs, id: Protocol.CellId): boolean {
108
113
  inputs.results.get(id)?.record.run_id;
109
114
  for (const run of inputs.executions.runs.values()) {
110
115
  if (
111
- run.status !== "completed" &&
116
+ run.state.status !== "completed" &&
112
117
  run.id !== planned &&
113
118
  run.origin.kind === "cells" &&
114
119
  run.origin.cell_ids.includes(id)
@@ -126,20 +131,19 @@ export function cellExecutionView(
126
131
  const latest = latestOf(inputs.executions, id);
127
132
  const result = inputs.results.get(id)?.record ?? null;
128
133
  let status: CellRunStatus = "idle";
129
- let startedAt = result === null ? null : millis(result.started_at);
130
- if (latest !== null && latest.record.status !== "completed") {
131
- status = latest.record.status;
132
- startedAt = millis(latest.record.started_at) ?? startedAt;
134
+ const began = result === null ? null : startedAtOf(result);
135
+ const ended = result === null ? null : completedAt(result);
136
+ let startedAt = millis(began);
137
+ if (latest !== null && latest.record.state.status !== "completed") {
138
+ status = latest.record.state.status;
139
+ startedAt = millis(startedAtOf(latest.record)) ?? startedAt;
133
140
  } else if (awaited(inputs, id)) {
134
141
  status = "queued";
135
142
  }
136
143
  const settled = status === "idle";
137
144
  const duration =
138
- settled &&
139
- result !== null &&
140
- result.started_at !== null &&
141
- result.completed_at !== null
142
- ? Time.parse(result.completed_at).since(Time.parse(result.started_at))
145
+ settled && began !== null && ended !== null
146
+ ? Time.parse(ended).since(Time.parse(began))
143
147
  : null;
144
148
  return {
145
149
  status,
@@ -157,13 +161,13 @@ export function cellExecutionView(
157
161
  /** Executions the host has not completed, cells and scratch alike. */
158
162
  function unfinished(executions: Executions): Execution[] {
159
163
  return [...executions.executions.values()].filter(
160
- (execution) => execution.record.status !== "completed",
164
+ (execution) => execution.record.state.status !== "completed",
161
165
  );
162
166
  }
163
167
 
164
168
  export function anyRunning(executions: Executions): boolean {
165
169
  return unfinished(executions).some(
166
- (execution) => execution.record.status === "running",
170
+ (execution) => execution.record.state.status === "running",
167
171
  );
168
172
  }
169
173
 
@@ -177,7 +181,7 @@ export function queuedOrRunningCount(inputs: CellExecutionInputs): number {
177
181
  );
178
182
  const named = new Set<Protocol.CellId>(inputs.requested);
179
183
  for (const run of inputs.executions.runs.values()) {
180
- if (run.status !== "completed" && run.origin.kind === "cells") {
184
+ if (run.state.status !== "completed" && run.origin.kind === "cells") {
181
185
  for (const cellId of run.origin.cell_ids) {
182
186
  named.add(cellId);
183
187
  }
@@ -195,7 +199,7 @@ export function queuedOrRunningCount(inputs: CellExecutionInputs): number {
195
199
  export function onlyScratchRunning(executions: Executions): boolean {
196
200
  return unfinished(executions).every(
197
201
  (execution) =>
198
- execution.record.status !== "running" ||
202
+ execution.record.state.status !== "running" ||
199
203
  execution.record.cell_id === null,
200
204
  );
201
205
  }
@@ -205,16 +209,17 @@ export function scratchStatus(executions: Executions): CellRunStatus {
205
209
  const scratch = unfinished(executions).find(
206
210
  (execution) => execution.record.cell_id === null,
207
211
  );
208
- if (scratch === undefined || scratch.record.status === "completed") {
212
+ if (scratch === undefined || scratch.record.state.status === "completed") {
209
213
  return "idle";
210
214
  }
211
- return scratch.record.status;
215
+ return scratch.record.state.status;
212
216
  }
213
217
 
214
218
  /** Cells with a running execution, in the order the host reported them. */
215
219
  export function runningCellIds(executions: Executions): Protocol.CellId[] {
216
220
  return unfinished(executions).flatMap((execution) =>
217
- execution.record.status === "running" && execution.record.cell_id !== null
221
+ execution.record.state.status === "running" &&
222
+ execution.record.cell_id !== null
218
223
  ? [execution.record.cell_id]
219
224
  : [],
220
225
  );
@@ -413,12 +413,7 @@ describe("IslandsPyodideBridge", () => {
413
413
  const record = {
414
414
  event: "execution",
415
415
  data: {
416
- execution: MockExecutions.completed("c2", {
417
- id: "e1",
418
- status: "running",
419
- outcome: null,
420
- completed_at: null,
421
- }),
416
+ execution: { ...MockExecutions.running("c2"), id: "e1" },
422
417
  },
423
418
  };
424
419
  const write = (name: "stdout" | "stderr", text: string, seq = 0) => ({
@@ -819,10 +814,7 @@ describe("IslandsPyodideBridge", () => {
819
814
  notebook_id: "n1",
820
815
  runtime_id: "r1",
821
816
  origin: { kind: "cells", cell_ids: ["c1"] },
822
- status: "queued",
823
- outcome: null,
824
- started_at: null,
825
- completed_at: null,
817
+ state: { status: "queued" },
826
818
  },
827
819
  });
828
820
 
@@ -42,16 +42,18 @@ describe("executions resource", () => {
42
42
  const ready = snapshot.findIndex((item) => item.event === "ready");
43
43
  const opening = resource(replay(snapshot.slice(0, ready + 1)));
44
44
  const scratch = opening.executions.get("e7");
45
- expect(scratch?.record.status).toBe("running");
45
+ expect(scratch?.record.state.status).toBe("running");
46
46
  expect(itemsInOrder(scratch!).map((item) => item.kind)).toEqual([
47
47
  "console",
48
48
  ]);
49
- expect(opening.runs.get("run-scratch")?.status).toBe("running");
49
+ expect(opening.runs.get("run-scratch")?.state.status).toBe("running");
50
50
  expect(opening.latest.size).toBe(0);
51
51
 
52
52
  const done = resource(replay(snapshot));
53
- expect(done.executions.get("e7")?.record.status).toBe("completed");
54
- expect(done.runs.get("run-scratch")?.outcome).toBe("succeeded");
53
+ expect(done.executions.get("e7")?.record.state.status).toBe("completed");
54
+ expect(done.runs.get("run-scratch")?.state).toMatchObject({
55
+ outcome: "succeeded",
56
+ });
55
57
  const released = reducer.reduce(
56
58
  replay(snapshot),
57
59
  removed("run", "run-scratch", "98"),
@@ -63,18 +65,23 @@ describe("executions resource", () => {
63
65
  const start = replay(snapshot);
64
66
  const running = resource(replay(runCells.slice(0, 5), start));
65
67
  expect(running.latest.get("c3")).toBe("e12");
66
- expect(running.executions.get("e12")?.record.status).toBe("running");
68
+ expect(running.executions.get("e12")?.record.state.status).toBe("running");
67
69
  expect(running.latest.get("k7f2")).toBe("e13");
68
- expect(running.runs.get("run-cells")?.status).toBe("running");
70
+ expect(running.runs.get("run-cells")?.state.status).toBe("running");
69
71
 
70
72
  const done = replay(runCells, start);
71
73
  const e12 = resource(done).executions.get("e12");
72
- expect(e12?.record.status).toBe("completed");
74
+ expect(e12?.record.state.status).toBe("completed");
73
75
  expect([...e12!.variables.values()].map((v) => v.name)).toEqual(["x"]);
74
- expect(resource(done).executions.get("e13")?.record.depends_on).toEqual({
75
- x: { execution: "e12", update: 0 },
76
+ expect(resource(done).executions.get("e13")?.record.state).toHaveProperty(
77
+ "depends_on",
78
+ {
79
+ x: { execution: "e12", update: 0 },
80
+ },
81
+ );
82
+ expect(resource(done).runs.get("run-cells")?.state).toMatchObject({
83
+ outcome: "succeeded",
76
84
  });
77
- expect(resource(done).runs.get("run-cells")?.outcome).toBe("succeeded");
78
85
 
79
86
  const retired = replay(retire("e12", "e12-x"), done);
80
87
  expect(resource(retired).executions.has("e12")).toBe(false);
@@ -163,7 +170,9 @@ describe("executions resource", () => {
163
170
  expect(prompted.latest.size).toBe(0);
164
171
  const gone = resource(replay(inputs, start));
165
172
  expect(gone.executions.has("e-input")).toBe(false);
166
- expect(gone.runs.get("run-input")?.outcome).toBe("interrupted");
173
+ expect(gone.runs.get("run-input")?.state).toMatchObject({
174
+ outcome: "interrupted",
175
+ });
167
176
 
168
177
  const orphan = reducer.reduce(
169
178
  start,
@@ -39,13 +39,14 @@ const restored = {
39
39
  runtime_id: null,
40
40
  caused_by: null,
41
41
  cell_id: "c3",
42
- code: null,
43
42
  code_fingerprint: "0f71456db2ea83f4",
44
- depends_on: {},
45
- status: "completed",
46
- outcome: { kind: "value", display: null },
47
- started_at: "2026-09-30T09:20:01Z",
48
- completed_at: "2026-09-30T09:20:02Z",
43
+ state: {
44
+ status: "completed",
45
+ started_at: "2026-09-30T09:20:01Z",
46
+ completed_at: "2026-09-30T09:20:02Z",
47
+ outcome: { kind: "value", display: null },
48
+ depends_on: {},
49
+ },
49
50
  };
50
51
 
51
52
  describe("retained results", () => {
@@ -77,8 +78,8 @@ describe("retained results", () => {
77
78
 
78
79
  const done = resource(replay(runCells, start));
79
80
  expect(done.get("c3")?.record.id).toBe("e12");
80
- expect(done.get("c3")?.record.status).toBe("completed");
81
- expect(done.get("k7f2")?.record.depends_on).toEqual({
81
+ expect(done.get("c3")?.record.state.status).toBe("completed");
82
+ expect(done.get("k7f2")?.record.state).toHaveProperty("depends_on", {
82
83
  x: { execution: "e12", update: 0 },
83
84
  });
84
85
  expect(done.get("c1")).toBeNull();
@@ -97,13 +98,17 @@ describe("retained results", () => {
97
98
  ...result.record,
98
99
  id: "e14",
99
100
  run_id: "run-again",
100
- started_at: null,
101
- completed_at: time,
102
- outcome: {
103
- kind: "skipped",
104
- reason: "superseded",
105
- message: "Replaced by a newer execution",
106
- related: [],
101
+ state: {
102
+ status: "completed",
103
+ started_at: null,
104
+ completed_at: time,
105
+ outcome: {
106
+ kind: "skipped",
107
+ reason: "superseded",
108
+ message: "Replaced by a newer execution",
109
+ related: [],
110
+ },
111
+ depends_on: {},
107
112
  },
108
113
  },
109
114
  },
@@ -122,10 +127,7 @@ describe("retained results", () => {
122
127
  ...result.record,
123
128
  id: "e14",
124
129
  run_id: "run-again",
125
- status: "queued",
126
- outcome: null,
127
- started_at: null,
128
- completed_at: null,
130
+ state: { status: "queued" },
129
131
  };
130
132
  const queued = reducer.reduce(
131
133
  retired,
@@ -141,10 +143,13 @@ describe("retained results", () => {
141
143
  data: {
142
144
  execution: {
143
145
  ...again,
144
- status: "completed",
145
- outcome: { kind: "value", display: null },
146
- started_at: time,
147
- completed_at: time,
146
+ state: {
147
+ status: "completed",
148
+ started_at: time,
149
+ completed_at: time,
150
+ outcome: { kind: "value", display: null },
151
+ depends_on: {},
152
+ },
148
153
  },
149
154
  },
150
155
  }),
@@ -159,10 +164,13 @@ describe("retained results", () => {
159
164
  ...result.record,
160
165
  id: "e14",
161
166
  run_id: "run-again",
162
- status: "completed",
163
- outcome: { kind: "interrupted" },
164
- started_at: null,
165
- completed_at: time,
167
+ state: {
168
+ status: "completed",
169
+ started_at: null,
170
+ completed_at: time,
171
+ outcome: { kind: "interrupted" },
172
+ depends_on: {},
173
+ },
166
174
  };
167
175
  const cancelled = replay(
168
176
  [
@@ -173,9 +181,7 @@ describe("retained results", () => {
173
181
  data: {
174
182
  execution: {
175
183
  ...interrupted,
176
- status: "queued",
177
- outcome: null,
178
- completed_at: null,
184
+ state: { status: "queued" },
179
185
  },
180
186
  },
181
187
  }),
@@ -187,9 +193,12 @@ describe("retained results", () => {
187
193
  ],
188
194
  done,
189
195
  );
190
- expect(resource(cancelled).get("c3")?.record.outcome).toEqual({
191
- kind: "interrupted",
192
- });
196
+ expect(resource(cancelled).get("c3")?.record.state).toHaveProperty(
197
+ "outcome",
198
+ {
199
+ kind: "interrupted",
200
+ },
201
+ );
193
202
  });
194
203
 
195
204
  it("drops a cell deleted while its execution runs", () => {
@@ -0,0 +1,35 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ /** Reads of an execution's state that hold whatever its status is. */
4
+
5
+ import type * as Protocol from "@marimo-team/client/protocol";
6
+
7
+ /** The final outcome once completed, or the value so far while running. */
8
+ export function shownOutcome(
9
+ record: Protocol.Execution,
10
+ ): Protocol.Outcome | null {
11
+ const state = record.state;
12
+ switch (state.status) {
13
+ case "queued":
14
+ return null;
15
+ case "running":
16
+ return state.value;
17
+ case "completed":
18
+ return state.outcome;
19
+ }
20
+ }
21
+
22
+ export function startedAt(record: Protocol.Execution): string | null {
23
+ return record.state.status === "queued" ? null : record.state.started_at;
24
+ }
25
+
26
+ export function completedAt(record: Protocol.Execution): string | null {
27
+ return record.state.status === "completed" ? record.state.completed_at : null;
28
+ }
29
+
30
+ /** The revisions a completed execution read. Empty until it completes. */
31
+ export function dependsOn(
32
+ record: Protocol.Execution,
33
+ ): Protocol.ExecutionCompleted["depends_on"] {
34
+ return record.state.status === "completed" ? record.state.depends_on : {};
35
+ }
@@ -22,3 +22,9 @@ export {
22
22
  itemsInOrder,
23
23
  } from "./resources/executions";
24
24
  export type { Result, Results } from "./resources/results";
25
+ export {
26
+ completedAt,
27
+ dependsOn,
28
+ shownOutcome,
29
+ startedAt,
30
+ } from "./execution-state";
@@ -429,7 +429,7 @@ export function createNotebookReplica(
429
429
  switch (event.event) {
430
430
  case "execution": {
431
431
  const record = event.data.execution;
432
- const changed = previous?.record.status !== record.status;
432
+ const changed = previous?.record.state.status !== record.state.status;
433
433
  observeExecution(record, changed);
434
434
  return;
435
435
  }