@marimo-team/islands 0.25.3-dev463 → 0.25.3-dev464

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 (38) hide show
  1. package/dist/{ErrorBoundary-LEY4eR-u.js → ErrorBoundary-BUp3s8bW.js} +1 -1
  2. package/dist/{chat-ui-Ow2U38zW.js → chat-ui-DFoH-uxc.js} +3 -3
  3. package/dist/{code-visibility-B6vd-MS9.js → code-visibility-JyOG3ytM.js} +2 -2
  4. package/dist/{common-CmFmwC3k.js → common-DsPeHITU.js} +4 -4
  5. package/dist/{data-grid-overlay-editor-DLAyzP8s.js → data-grid-overlay-editor-D6RpA9b2.js} +1 -1
  6. package/dist/{error-entries-DEV4YOvI.js → error-entries-C9OKfJKe.js} +265 -257
  7. package/dist/{feedback-button-ln7KZEYq.js → feedback-button-w5jJOd6o.js} +3 -3
  8. package/dist/{glide-data-editor-DwVqbx2W.js → glide-data-editor-lWcwB0Si.js} +3 -3
  9. package/dist/{globals-DqKjaSau.js → globals-BFICoaLo.js} +1 -1
  10. package/dist/{html-to-image-BdgBPfgg.js → html-to-image-BiWLL4Tu.js} +1 -1
  11. package/dist/main.js +4467 -4464
  12. package/dist/{number-overlay-editor-D9vaIlf5.js → number-overlay-editor-BDYmg8YM.js} +1 -1
  13. package/dist/{process-output-C_EHwiTn.js → process-output-ClyiXL-f.js} +2 -2
  14. package/dist/{reveal-component-BrnL8w_N.js → reveal-component-B63xZtLQ.js} +2 -2
  15. package/package.json +1 -1
  16. package/src/__mocks__/executions.ts +2 -2
  17. package/src/components/dependency-graph/minimap-content.tsx +1 -1
  18. package/src/components/editor/notebook-cell.tsx +6 -6
  19. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +2 -2
  20. package/src/components/slides/slide-cell-view.tsx +2 -2
  21. package/src/core/ai/context/providers/__tests__/error.test.ts +0 -4
  22. package/src/core/cells/__tests__/cell.test.ts +8 -8
  23. package/src/core/cells/__tests__/runs.test.ts +1 -1
  24. package/src/core/cells/__tests__/session.test.ts +2 -2
  25. package/src/core/cells/__tests__/utils.test.ts +2 -2
  26. package/src/core/cells/cell.ts +2 -2
  27. package/src/core/cells/runs.ts +10 -2
  28. package/src/core/cells/session.ts +1 -1
  29. package/src/core/cells/utils.ts +2 -2
  30. package/src/core/executions/__tests__/atoms.test.ts +1 -1
  31. package/src/core/executions/__tests__/interrupt.test.ts +1 -1
  32. package/src/core/executions/__tests__/output.test.ts +26 -5
  33. package/src/core/executions/__tests__/select.test.ts +4 -4
  34. package/src/core/executions/output.ts +16 -4
  35. package/src/core/notebook/replica/__tests__/executions.test.ts +57 -3
  36. package/src/core/notebook/replica/__tests__/results.test.ts +2 -2
  37. package/src/core/notebook/replica/resources/executions.ts +27 -0
  38. package/src/core/session/useNotebookSession.tsx +1 -1
@@ -1,6 +1,6 @@
1
1
  import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { t } from "./react-Bgs_wQh3.js";
3
- import { a as n } from "./glide-data-editor-DwVqbx2W.js";
3
+ import { a as n } from "./glide-data-editor-lWcwB0Si.js";
4
4
  //#region ../node_modules/.pnpm/@glideapps+glide-data-grid@6.0.4-alpha24_lodash@4.17.21_marked@15.0.12_react-dom@19.3.1_57c124ac5a994dbbf13fd11838cf9ba9/node_modules/@glideapps/glide-data-grid/dist/esm/internal/data-grid-overlay-editor/private/number-overlay-editor-style.js
5
5
  var r = /* @__PURE__ */ e(t()), i = /*#__PURE__*/ n("div")({
6
6
  name: "NumberOverlayEditorStyle",
@@ -1,6 +1,6 @@
1
- import { T as e } from "./html-to-image-BdgBPfgg.js";
1
+ import { T as e } from "./html-to-image-BiWLL4Tu.js";
2
2
  import { h as t } from "./tooltip-CiJ919pg.js";
3
- import { Tt as n, wt as r } from "./error-entries-DEV4YOvI.js";
3
+ import { Tt as n, wt as r } from "./error-entries-C9OKfJKe.js";
4
4
  import { r as i } from "./assertNever-DOTNJ2Y4.js";
5
5
  var a = t("file", [["path", {
6
6
  d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",
@@ -3,14 +3,14 @@ import { g as t, h as n, i as r, m as i, t as a } from "./button-qQhINE7z.js";
3
3
  import { t as o } from "./react-Bgs_wQh3.js";
4
4
  import { t as s } from "./compiler-runtime-C5KHtL5D.js";
5
5
  import { h as c, t as l } from "./tooltip-CiJ919pg.js";
6
- import { Cn as u, En as d, Sn as f, dn as p, et as m, f as h, i as g, l as _, n as v, nt as y, r as b, t as x, tt as S, u as C } from "./common-CmFmwC3k.js";
6
+ import { Cn as u, En as d, Sn as f, dn as p, et as m, f as h, i as g, l as _, n as v, nt as y, r as b, t as x, tt as S, u as C } from "./common-DsPeHITU.js";
7
7
  import { M as w } from "./select-PQHWLm64.js";
8
8
  import { X as T } from "./dropdown-menu-B12Nf3Zf.js";
9
9
  import { t as E } from "./jsx-runtime-D8btoEHk.js";
10
10
  import { Rt as D, Vt as O, f as k, i as ee } from "./use-restore-focus-BLj45Ibw.js";
11
11
  import { t as A } from "./useEvent-BoN7U38T.js";
12
12
  import { o as te } from "./static-state-CWXd6dYX.js";
13
- import { n as ne, t as re } from "./code-visibility-B6vd-MS9.js";
13
+ import { n as ne, t as re } from "./code-visibility-JyOG3ytM.js";
14
14
  /* empty css */
15
15
  var j = c("sticky-note", [["path", {
16
16
  d: "M21 9a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2z",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.25.3-dev463",
3
+ "version": "0.25.3-dev464",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -180,7 +180,7 @@ export const MockExecutions = {
180
180
  error: Partial<Protocol.Error> = {},
181
181
  ): Protocol.Execution {
182
182
  return completed(cellId, {
183
- kind: "error",
183
+ kind: "failed",
184
184
  error: {
185
185
  kind: "exception",
186
186
  message: "boom",
@@ -200,7 +200,7 @@ export const MockExecutions = {
200
200
  },
201
201
 
202
202
  interrupted(cellId: string | null): Protocol.Execution {
203
- return completed(cellId, { kind: "interrupted" });
203
+ return completed(cellId, { kind: "cancelled" });
204
204
  },
205
205
 
206
206
  skipped(cellId: string): Protocol.Execution {
@@ -33,7 +33,7 @@ const MinimapCell: React.FC<MinimapCellProps> = (props) => {
33
33
  id: props.cellId,
34
34
  graph: graphs[props.cellId],
35
35
  code: useCellData(props.cellId).code,
36
- hasError: useCellExecution(props.cellId).outcome === "error",
36
+ hasError: useCellExecution(props.cellId).outcome === "failed",
37
37
  };
38
38
 
39
39
  let selectedCell: undefined | { id: CellId; graph: CellGraph };
@@ -327,8 +327,8 @@ const ReadonlyCellComponent = forwardRef(
327
327
  const cellData = useCellData(cellId);
328
328
  const output = useCellOutput(cellId);
329
329
  const { execution, freshness } = useCellPresentation(cellId);
330
- const errored = execution.outcome === "error";
331
- const interrupted = execution.outcome === "interrupted";
330
+ const errored = execution.outcome === "failed";
331
+ const interrupted = execution.outcome === "cancelled";
332
332
  const stopped = execution.outcome === "skipped";
333
333
 
334
334
  const className = clsx("marimo-cell", "hover-actions-parent z-10", {
@@ -392,8 +392,8 @@ const EditableCellComponent = ({
392
392
  const output = useCellOutput(cellId);
393
393
  const outline = useCellOutline(cellId);
394
394
  const { execution, freshness } = useCellPresentation(cellId);
395
- const errored = execution.outcome === "error";
396
- const interrupted = execution.outcome === "interrupted";
395
+ const errored = execution.outcome === "failed";
396
+ const interrupted = execution.outcome === "cancelled";
397
397
  const stopped = execution.outcome === "skipped";
398
398
  const cellActionDropdownRef = useRef<CellActionsDropdownHandle>(null);
399
399
  // DOM node where the editorView will be mounted
@@ -859,7 +859,7 @@ const CellRightSideActions = memo(
859
859
  <CellStatusComponent
860
860
  status={execution.status}
861
861
  freshness={freshness}
862
- interrupted={execution.outcome === "interrupted"}
862
+ interrupted={execution.outcome === "cancelled"}
863
863
  editing={true}
864
864
  disabled={disabled}
865
865
  elapsedTime={execution.duration}
@@ -1038,7 +1038,7 @@ const SetupCellComponent = ({
1038
1038
  const cellRuntime = useCellRuntime(cellId);
1039
1039
  const output = useCellOutput(cellId);
1040
1040
  const { execution, freshness } = useCellPresentation(cellId);
1041
- const errored = execution.outcome === "error";
1041
+ const errored = execution.outcome === "failed";
1042
1042
  const stopped = execution.outcome === "skipped";
1043
1043
  const cellActionDropdownRef = useRef<CellActionsDropdownHandle>(null);
1044
1044
  // DOM node where the editorView will be mounted
@@ -328,7 +328,7 @@ const VerticalCell = memo(
328
328
  const cellRef = useRef<HTMLDivElement>(null);
329
329
  const output = useCellOutput(cellId);
330
330
  const { execution, freshness } = useCellPresentation(cellId);
331
- const errored = execution.outcome === "error";
331
+ const errored = execution.outcome === "failed";
332
332
  const stopped = execution.outcome === "skipped";
333
333
 
334
334
  const outputStale = outputIsStale(execution, freshness, false);
@@ -402,7 +402,7 @@ const VerticalCell = memo(
402
402
  // instead of hiding them
403
403
  const hidden = shouldHidePublishedCell({
404
404
  errored,
405
- interrupted: execution.outcome === "interrupted",
405
+ interrupted: execution.outcome === "cancelled",
406
406
  stopped,
407
407
  output,
408
408
  showErrorTracebacks,
@@ -62,8 +62,8 @@ export const SlideCellView = ({ cell }: { cell: RuntimeCell }) => {
62
62
  const cellOutputPosition = userConfig.display.cell_output;
63
63
  const hasOutput = cell.output != null;
64
64
  const { execution, freshness } = useCellPresentation(cell.id);
65
- const errored = execution.outcome === "error";
66
- const interrupted = execution.outcome === "interrupted";
65
+ const errored = execution.outcome === "failed";
66
+ const interrupted = execution.outcome === "cancelled";
67
67
  const stopped = execution.outcome === "skipped";
68
68
 
69
69
  const uninstantiated = isUninstantiated(execution);
@@ -341,10 +341,6 @@ describe("ErrorContextProvider", () => {
341
341
  error: { kind: "invalid-syntax", message: "Syntax error" },
342
342
  expected: "Syntax error",
343
343
  },
344
- {
345
- error: { kind: "interrupted", message: "" },
346
- expected: "This cell was interrupted and needs to be re-run",
347
- },
348
344
  {
349
345
  error: { kind: "internal", message: "Unknown error" },
350
346
  expected: "Unknown error",
@@ -46,9 +46,9 @@ describe("outputIsStale", () => {
46
46
  });
47
47
 
48
48
  it("should return false if the cell is interrupted", () => {
49
- expect(
50
- outputIsStale(view({ outcome: "interrupted" }), CURRENT, false),
51
- ).toBe(false);
49
+ expect(outputIsStale(view({ outcome: "cancelled" }), CURRENT, false)).toBe(
50
+ false,
51
+ );
52
52
  });
53
53
 
54
54
  it("should return false if the cell is idle and not edited", () => {
@@ -64,7 +64,7 @@ describe("outputIsStale", () => {
64
64
  });
65
65
 
66
66
  it("should return true if the cell is interrupted and edited since", () => {
67
- expect(outputIsStale(view({ outcome: "interrupted" }), EDITED, true)).toBe(
67
+ expect(outputIsStale(view({ outcome: "cancelled" }), EDITED, true)).toBe(
68
68
  true,
69
69
  );
70
70
  });
@@ -94,14 +94,14 @@ describe("consoleOutputIsStale", () => {
94
94
  });
95
95
 
96
96
  it("is not stale after an interruption", () => {
97
- expect(consoleOutputIsStale(view({ outcome: "interrupted" }), EDITED)).toBe(
97
+ expect(consoleOutputIsStale(view({ outcome: "cancelled" }), EDITED)).toBe(
98
98
  false,
99
99
  );
100
100
  });
101
101
 
102
102
  it("should return false if the cell is interrupted but has stale inputs", () => {
103
- expect(
104
- outputIsStale(view({ outcome: "interrupted" }), REPLACED, false),
105
- ).toBe(false);
103
+ expect(outputIsStale(view({ outcome: "cancelled" }), REPLACED, false)).toBe(
104
+ false,
105
+ );
106
106
  });
107
107
  });
@@ -42,7 +42,7 @@ describe("execution traces", () => {
42
42
  started_at,
43
43
  completed_at: "1970-01-01T00:01:42Z",
44
44
  status: "completed",
45
- outcome: { kind: "interrupted" },
45
+ outcome: { kind: "cancelled" },
46
46
  } satisfies Execution["state"];
47
47
  const runId = "r1" as RunId;
48
48
  const running = observe(observe(initialState()), {
@@ -171,7 +171,7 @@ describe("readExport", () => {
171
171
  expect(result.snapshot.results?.[0]?.execution.state).toHaveProperty(
172
172
  "outcome",
173
173
  {
174
- kind: "error",
174
+ kind: "failed",
175
175
  error: expect.objectContaining({
176
176
  kind: "exception",
177
177
  name: "ValueError",
@@ -325,7 +325,7 @@ describe("readExport", () => {
325
325
  expect(result.snapshot?.results[0]?.execution.state).toHaveProperty(
326
326
  "outcome",
327
327
  {
328
- kind: "error",
328
+ kind: "failed",
329
329
  error: expect.objectContaining({
330
330
  kind: "exception",
331
331
  name: "ValueError",
@@ -204,10 +204,10 @@ describe("isUninstantiated", () => {
204
204
 
205
205
  it("should return false if the cell ended without a value", () => {
206
206
  expect(
207
- isUninstantiated({ status: "idle", outcome: "error", live: true }),
207
+ isUninstantiated({ status: "idle", outcome: "failed", live: true }),
208
208
  ).toBe(false);
209
209
  expect(
210
- isUninstantiated({ status: "idle", outcome: "interrupted", live: true }),
210
+ isUninstantiated({ status: "idle", outcome: "cancelled", live: true }),
211
211
  ).toBe(false);
212
212
  expect(
213
213
  isUninstantiated({ status: "idle", outcome: "skipped", live: true }),
@@ -32,7 +32,7 @@ export function outputIsStale(
32
32
  return true;
33
33
  }
34
34
  // An interrupted run's partial output stands as the record of that run.
35
- if (outcome === "interrupted") {
35
+ if (outcome === "cancelled") {
36
36
  return false;
37
37
  }
38
38
  return freshness.inputsChanged;
@@ -46,7 +46,7 @@ export function consoleOutputIsStale(
46
46
  freshness: CellFreshness,
47
47
  ): boolean {
48
48
  const { status, outcome } = execution;
49
- if (outcome === "interrupted") {
49
+ if (outcome === "cancelled") {
50
50
  return false;
51
51
  }
52
52
  if (outputIsLoading(status)) {
@@ -46,8 +46,16 @@ function traceStatus(record: Execution): CellRun["status"] {
46
46
  if (record.state.status !== "completed") {
47
47
  return record.state.status;
48
48
  }
49
- const outcome = record.state.outcome.kind;
50
- return outcome === "succeeded" ? "success" : outcome;
49
+ switch (record.state.outcome.kind) {
50
+ case "succeeded":
51
+ return "success";
52
+ case "failed":
53
+ return "error";
54
+ case "cancelled":
55
+ return "interrupted";
56
+ case "skipped":
57
+ return "skipped";
58
+ }
51
59
  }
52
60
 
53
61
  const {
@@ -226,7 +226,7 @@ function resultRecord(
226
226
  } else if (primary.type === "error") {
227
227
  const traceback = normalizeTraceback(primary.traceback);
228
228
  outcome = {
229
- kind: "error",
229
+ kind: "failed",
230
230
  error: {
231
231
  kind: "exception",
232
232
  name: primary.ename,
@@ -84,7 +84,7 @@ export function getDescendantsStatus(
84
84
  const stale = descendants.some(
85
85
  (id) => freshness(id).sourceChanged || freshness(id).inputsChanged,
86
86
  );
87
- const errored = views.some((view) => view.outcome === "error");
87
+ const errored = views.some((view) => view.outcome === "failed");
88
88
  const runningOrQueued = views.some(
89
89
  (view) => view.status === "running" || view.status === "queued",
90
90
  );
@@ -112,7 +112,7 @@ export function cellRunReason(
112
112
  if (freshness.sourceChanged) {
113
113
  return "source";
114
114
  }
115
- if (execution.outcome === "interrupted") {
115
+ if (execution.outcome === "cancelled") {
116
116
  return "interrupted";
117
117
  }
118
118
  return freshness.inputsChanged && !cell.config.disabled && !execution.blocked
@@ -42,7 +42,7 @@ function run(
42
42
  status,
43
43
  started_at: null,
44
44
  completed_at: "2026-10-01T09:20:02Z",
45
- outcome: "succeeded",
45
+ outcome: { kind: "succeeded" },
46
46
  }
47
47
  : status === "running"
48
48
  ? { status, started_at: "2026-10-01T09:20:01Z" }
@@ -35,7 +35,7 @@ function run(
35
35
  status,
36
36
  started_at: MockExecutions.T0,
37
37
  completed_at: MockExecutions.T1,
38
- outcome: "succeeded",
38
+ outcome: { kind: "succeeded" },
39
39
  }
40
40
  : status === "running"
41
41
  ? { status, started_at: MockExecutions.T0 }
@@ -63,7 +63,7 @@ describe("cellOutputView", () => {
63
63
  const view = cellOutputView(
64
64
  inputs([
65
65
  MockExecutions.completed(C1, {
66
- kind: "error",
66
+ kind: "failed",
67
67
  error: hostError({
68
68
  traceback: { mimetype: "text/plain", data: "Traceback..." },
69
69
  related: [{ cell_id: C2, range: null, message: "Raised it" }],
@@ -242,9 +242,6 @@ describe("cellError", () => {
242
242
  expect(
243
243
  cellError(hostError({ kind: "internal", name: "abc", message: "oops" })),
244
244
  ).toEqual({ type: "unknown", msg: "oops", error_type: "abc" });
245
- expect(
246
- cellError(hostError({ kind: "interrupted", name: null, message: "" })),
247
- ).toEqual({ type: "interruption" });
248
245
  });
249
246
 
250
247
  it("shows any other kind as a diagnostic with the cells involved", () => {
@@ -305,11 +302,35 @@ describe("scratchOutputView", () => {
305
302
  status: "completed",
306
303
  started_at: null,
307
304
  completed_at: LATER,
308
- outcome: { kind: "interrupted" },
305
+ outcome: { kind: "cancelled" },
309
306
  depends_on: {},
310
307
  });
311
308
  expect(
312
309
  scratchOutputView(inputs([done, interrupted]).executions)?.data,
313
310
  ).toEqual([{ type: "interruption" }]);
314
311
  });
312
+
313
+ it("shows why a run failed when it has no execution to show", () => {
314
+ const done = MockExecutions.shown(null, HTML);
315
+ const { executions } = inputs([done]);
316
+ const failure = { message: "Kernel channel closed", completedAt: LATER };
317
+
318
+ // The run never reached the kernel, so only the run says what happened.
319
+ expect(
320
+ scratchOutputView({
321
+ ...executions,
322
+ scratchFailure: { ...failure, runId: "run-2" },
323
+ })?.data,
324
+ ).toEqual([
325
+ { type: "unknown", msg: "Kernel channel closed", error_type: null },
326
+ ]);
327
+
328
+ // Its own execution already shows the error.
329
+ expect(
330
+ scratchOutputView({
331
+ ...executions,
332
+ scratchFailure: { ...failure, runId: done[0].run_id! },
333
+ })?.data,
334
+ ).toBe("<b>1</b>");
335
+ });
315
336
  });
@@ -69,7 +69,7 @@ function run(
69
69
  status,
70
70
  started_at: null,
71
71
  completed_at: "2026-10-01T09:20:02Z",
72
- outcome: "succeeded",
72
+ outcome: { kind: "succeeded" },
73
73
  }
74
74
  : status === "running"
75
75
  ? { status, started_at: "2026-10-01T09:20:01Z" }
@@ -210,7 +210,7 @@ describe("cellExecutionView", () => {
210
210
  live: true,
211
211
  });
212
212
  const error = (kind: string): Protocol.Outcome => ({
213
- kind: "error",
213
+ kind: "failed",
214
214
  error: {
215
215
  kind,
216
216
  message: "",
@@ -222,7 +222,7 @@ describe("cellExecutionView", () => {
222
222
  related: [],
223
223
  },
224
224
  });
225
- expect(ended(error("exception")).outcome).toBe("error");
225
+ expect(ended(error("exception")).outcome).toBe("failed");
226
226
  const skipped: Protocol.Outcome = {
227
227
  kind: "skipped",
228
228
  reason: "ancestor-stopped",
@@ -230,7 +230,7 @@ describe("cellExecutionView", () => {
230
230
  related: [],
231
231
  };
232
232
  expect(ended(skipped).outcome).toBe("skipped");
233
- expect(ended({ kind: "interrupted" }).outcome).toBe("interrupted");
233
+ expect(ended({ kind: "cancelled" }).outcome).toBe("cancelled");
234
234
  });
235
235
 
236
236
  it("reads as queued from a request the stream has not shown a run for", () => {
@@ -130,8 +130,6 @@ export function cellError(error: Protocol.Error): CellError {
130
130
  };
131
131
  case "internal":
132
132
  return { type: "unknown", msg: error.message, error_type: error.name };
133
- case "interrupted":
134
- return { type: "interruption" };
135
133
  default:
136
134
  return {
137
135
  type: "diagnostic",
@@ -221,9 +219,9 @@ function resultDisplay(result: Result): CellOutput | null {
221
219
  switch (showing.kind) {
222
220
  case "output":
223
221
  return showing.media === null ? null : valueOutput(record, showing.media);
224
- case "error":
222
+ case "failed":
225
223
  return errorOutput(record, [cellError(showing.error)]);
226
- case "interrupted":
224
+ case "cancelled":
227
225
  return errorOutput(record, [{ type: "interruption" }]);
228
226
  case "skipped":
229
227
  return skippedOutput(record, showing);
@@ -321,5 +319,19 @@ export function cellOutputsView(
321
319
  * The latest scratch display, retained until a newer execution shows one.
322
320
  */
323
321
  export function scratchOutputView(executions: Executions): CellOutput | null {
322
+ const failure = executions.scratchFailure;
323
+ // A run that failed before the kernel saw its code has no execution to
324
+ // show, so its own reason stands in for the result.
325
+ if (
326
+ failure !== undefined &&
327
+ executions.scratch?.record.run_id !== failure.runId
328
+ ) {
329
+ return {
330
+ channel: "marimo-error",
331
+ mimetype: ERROR_MIMETYPE,
332
+ data: [{ type: "unknown", msg: failure.message, error_type: null }],
333
+ timestamp: seconds(failure.completedAt),
334
+ };
335
+ }
324
336
  return executions.scratch === null ? null : resultOutput(executions.scratch);
325
337
  }
@@ -52,7 +52,7 @@ describe("executions resource", () => {
52
52
  const done = resource(replay(snapshot));
53
53
  expect(done.executions.get("e7")?.record.state.status).toBe("completed");
54
54
  expect(done.runs.get("run-scratch")?.state).toMatchObject({
55
- outcome: "succeeded",
55
+ outcome: { kind: "succeeded" },
56
56
  });
57
57
  const released = reducer.reduce(
58
58
  replay(snapshot),
@@ -80,7 +80,7 @@ describe("executions resource", () => {
80
80
  },
81
81
  );
82
82
  expect(resource(done).runs.get("run-cells")?.state).toMatchObject({
83
- outcome: "succeeded",
83
+ outcome: { kind: "succeeded" },
84
84
  });
85
85
 
86
86
  const retired = replay(retire("e12", "e12-x"), done);
@@ -173,7 +173,7 @@ describe("executions resource", () => {
173
173
  const gone = resource(replay(inputs, start));
174
174
  expect(gone.executions.has("e-input")).toBe(false);
175
175
  expect(gone.runs.get("run-input")?.state).toMatchObject({
176
- outcome: "interrupted",
176
+ outcome: { kind: "cancelled" },
177
177
  });
178
178
 
179
179
  const orphan = reducer.reduce(
@@ -208,4 +208,58 @@ describe("executions resource", () => {
208
208
  const reset = reducer.reduce(done, { event: "reset", data: {} });
209
209
  expect(resource(reset)).toBe(executions.initial);
210
210
  });
211
+
212
+ it("remembers why the latest scratch run failed until a newer one arrives", () => {
213
+ const run = (
214
+ id: string,
215
+ origin: Protocol.RunOrigin,
216
+ state: Protocol.RunState,
217
+ cursor: string,
218
+ ) =>
219
+ event({
220
+ event: "run",
221
+ id: cursor,
222
+ data: {
223
+ run: { id, notebook_id: "n1", runtime_id: "r1", origin, state },
224
+ time,
225
+ },
226
+ });
227
+ const code: Protocol.RunOrigin = { kind: "code", code: "1" };
228
+ const failed: Protocol.RunState = {
229
+ status: "completed",
230
+ started_at: null,
231
+ completed_at: time,
232
+ outcome: { kind: "failed", message: "Kernel channel closed" },
233
+ };
234
+
235
+ const afterFailure = replay(
236
+ [run("run-9", code, failed, "200")],
237
+ replay(snapshot),
238
+ );
239
+ expect(resource(afterFailure).scratchFailure).toEqual({
240
+ runId: "run-9",
241
+ message: "Kernel channel closed",
242
+ completedAt: time,
243
+ });
244
+
245
+ // Cell runs say nothing about the scratchpad.
246
+ const afterCells = replay(
247
+ [
248
+ run(
249
+ "run-10",
250
+ { kind: "cells", cell_ids: ["c1"] },
251
+ { status: "queued" },
252
+ "201",
253
+ ),
254
+ ],
255
+ afterFailure,
256
+ );
257
+ expect(resource(afterCells).scratchFailure?.runId).toBe("run-9");
258
+
259
+ const afterNext = replay(
260
+ [run("run-11", code, { status: "queued" }, "202")],
261
+ afterCells,
262
+ );
263
+ expect(resource(afterNext).scratchFailure).toBeUndefined();
264
+ });
211
265
  });
@@ -168,7 +168,7 @@ describe("retained results", () => {
168
168
  status: "completed",
169
169
  started_at: null,
170
170
  completed_at: time,
171
- outcome: { kind: "interrupted" },
171
+ outcome: { kind: "cancelled" },
172
172
  depends_on: {},
173
173
  },
174
174
  };
@@ -196,7 +196,7 @@ describe("retained results", () => {
196
196
  expect(resource(cancelled).get("c3")?.record.state).toHaveProperty(
197
197
  "outcome",
198
198
  {
199
- kind: "interrupted",
199
+ kind: "cancelled",
200
200
  },
201
201
  );
202
202
  });
@@ -45,6 +45,28 @@ export interface Executions {
45
45
  readonly scratch: Result | null;
46
46
  /** The latest scratch execution to start, including one that printed nothing. */
47
47
  readonly scratchConsole?: Execution;
48
+ /** The latest scratch run, if the host could not finish it and says why. */
49
+ readonly scratchFailure?: RunFailure;
50
+ }
51
+
52
+ /** A run the host could not finish, with its reason. */
53
+ export interface RunFailure {
54
+ readonly runId: Protocol.RunId;
55
+ readonly message: string;
56
+ readonly completedAt: string;
57
+ }
58
+
59
+ function hostFailure(run: Protocol.Run): RunFailure | undefined {
60
+ const { state } = run;
61
+ return state.status === "completed" &&
62
+ state.outcome.kind === "failed" &&
63
+ state.outcome.message !== null
64
+ ? {
65
+ runId: run.id,
66
+ message: state.outcome.message,
67
+ completedAt: state.completed_at,
68
+ }
69
+ : undefined;
48
70
  }
49
71
 
50
72
  type Kind =
@@ -275,6 +297,11 @@ export const executions: NotebookResource<Executions, Kind> = {
275
297
  run: (state, { data }) => ({
276
298
  ...state,
277
299
  runs: new Map(state.runs).set(data.run.id, data.run),
300
+ // A newer scratch run replaces what the last one reported.
301
+ scratchFailure:
302
+ data.run.origin.kind === "code"
303
+ ? hostFailure(data.run)
304
+ : state.scratchFailure,
278
305
  }),
279
306
  "run.removed": (state, { data }) =>
280
307
  state.runs.has(data.id)
@@ -443,7 +443,7 @@ export function useNotebookSession(opts: { sessionId: SessionId }) {
443
443
  time === null ? Date.now() / 1000 : Date.parse(time) / 1000;
444
444
  if (
445
445
  record.state.status === "completed" &&
446
- record.state.outcome?.kind === "error"
446
+ record.state.outcome.kind === "failed"
447
447
  ) {
448
448
  getCellLogsForMessage({
449
449
  cell_id: cellId,