@marimo-team/islands 0.25.3-dev388 → 0.25.3-dev391

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 (101) hide show
  1. package/dist/{ErrorBoundary-_mFP3LkM.js → ErrorBoundary-DNRG0xHi.js} +1 -1
  2. package/dist/{chat-ui-BKSYhGMh.js → chat-ui-CWVNPm2l.js} +769 -769
  3. package/dist/{code-visibility-DkMNjdNe.js → code-visibility-Ca8sDptK.js} +10 -10
  4. package/dist/{common-Ces9ooG_.js → common-B3NYpak4.js} +4910 -4902
  5. package/dist/{data-grid-overlay-editor-uNMslVKY.js → data-grid-overlay-editor-Cz7uMmtm.js} +1 -1
  6. package/dist/{error-entries-rtPWQkJk.js → error-entries-CnXf4kpP.js} +821 -686
  7. package/dist/{feedback-button-i960qUnq.js → feedback-button-BQbnZsf5.js} +7 -7
  8. package/dist/{glide-data-editor-_EEhlGzS.js → glide-data-editor-Bxc30klU.js} +3 -3
  9. package/dist/{globals-DKkjIolp.js → globals-CDatnx0Y.js} +1 -1
  10. package/dist/{html-to-image-B5nTOeMI.js → html-to-image-Bu_-vH_Y.js} +4782 -4765
  11. package/dist/main.js +6233 -6172
  12. package/dist/{number-overlay-editor-D5U7jbrh.js → number-overlay-editor-ChGu5C-s.js} +1 -1
  13. package/dist/{process-output-DNxpsd4n.js → process-output-Rbqr1aYD.js} +2 -2
  14. package/dist/{reveal-component-BM9TozVQ.js → reveal-component-CSxWJFAP.js} +32 -32
  15. package/dist/style.css +1 -1
  16. package/package.json +1 -1
  17. package/src/__mocks__/executions.ts +48 -8
  18. package/src/__mocks__/notebook.ts +20 -42
  19. package/src/components/app-config/__tests__/add-model-discovery.test.tsx +255 -0
  20. package/src/components/app-config/__tests__/model-discovery.test.tsx +183 -0
  21. package/src/components/app-config/ai-config.tsx +20 -24
  22. package/src/components/app-config/model-discovery.tsx +118 -184
  23. package/src/components/app-config/model-provider-config.ts +25 -0
  24. package/src/components/editor/Output.tsx +5 -4
  25. package/src/components/editor/__tests__/data-attributes.test.tsx +1 -6
  26. package/src/components/editor/__tests__/dynamic-favicon.test.tsx +11 -16
  27. package/src/components/editor/__tests__/output-persistence.test.tsx +6 -24
  28. package/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts +6 -8
  29. package/src/components/editor/actions/useSetOutputsExpanded.ts +12 -4
  30. package/src/components/editor/cell/cell-context-menu.tsx +3 -2
  31. package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +89 -72
  32. package/src/components/editor/notebook-cell.tsx +15 -10
  33. package/src/components/editor/output/console/process-output.ts +4 -2
  34. package/src/components/editor/renderers/cells-renderer.tsx +3 -1
  35. package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +5 -11
  36. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +9 -8
  37. package/src/components/editor/renderers/types.ts +2 -2
  38. package/src/components/editor/renderers/vertical-layout/utils.ts +4 -4
  39. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +5 -8
  40. package/src/components/scratchpad/scratchpad.tsx +6 -2
  41. package/src/components/slides/__tests__/cell-output-block.test.tsx +7 -8
  42. package/src/components/slides/__tests__/minimap-actions.test.tsx +3 -3
  43. package/src/components/slides/__tests__/slide-cell-view.test.tsx +1 -0
  44. package/src/components/slides/slide-cell-view.tsx +1 -3
  45. package/src/components/slides/slide.tsx +3 -3
  46. package/src/core/ai/context/__tests__/registry.test.ts +7 -11
  47. package/src/core/ai/context/providers/__tests__/cell-output.test.ts +113 -35
  48. package/src/core/ai/context/providers/__tests__/error.test.ts +74 -191
  49. package/src/core/ai/context/providers/cell-output.ts +11 -6
  50. package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +8 -103
  51. package/src/core/cells/__tests__/cells.test.ts +40 -292
  52. package/src/core/cells/__tests__/clear-outputs.test.ts +151 -0
  53. package/src/core/cells/__tests__/harness.ts +14 -12
  54. package/src/core/cells/__tests__/layout.test.ts +20 -26
  55. package/src/core/cells/__tests__/notebook-outline.test.ts +49 -43
  56. package/src/core/cells/__tests__/session.test.ts +26 -146
  57. package/src/core/cells/actions.ts +49 -9
  58. package/src/core/cells/cell.ts +0 -13
  59. package/src/core/cells/cells.ts +53 -62
  60. package/src/core/cells/focus.ts +6 -1
  61. package/src/core/cells/layout.ts +2 -3
  62. package/src/core/cells/outputs.ts +2 -2
  63. package/src/core/cells/session.ts +3 -38
  64. package/src/core/cells/types.ts +6 -8
  65. package/src/core/cells/utils.ts +4 -3
  66. package/src/core/codemirror/ai/__tests__/resources.test.ts +7 -11
  67. package/src/core/errors/__tests__/error-entries.test.ts +52 -18
  68. package/src/core/errors/error-entries.ts +21 -11
  69. package/src/core/executions/__tests__/freshness.test.ts +7 -4
  70. package/src/core/executions/__tests__/hooks.test.tsx +5 -1
  71. package/src/core/executions/__tests__/interrupt.test.ts +2 -0
  72. package/src/core/executions/__tests__/output-lifecycle.test.ts +201 -0
  73. package/src/core/executions/__tests__/output.test.ts +87 -3
  74. package/src/core/executions/__tests__/select.test.ts +17 -10
  75. package/src/core/executions/atoms.ts +73 -15
  76. package/src/core/executions/freshness.ts +1 -1
  77. package/src/core/executions/hooks.ts +18 -8
  78. package/src/core/executions/index.ts +6 -0
  79. package/src/core/executions/output.ts +122 -38
  80. package/src/core/executions/select.ts +2 -2
  81. package/src/core/export/__tests__/hooks.test.ts +20 -29
  82. package/src/core/export/hooks.ts +7 -9
  83. package/src/core/islands/__tests__/iframe-resizer.test.ts +91 -0
  84. package/src/core/islands/__tests__/main.test.ts +17 -0
  85. package/src/core/islands/components/__tests__/web-components.test.tsx +13 -15
  86. package/src/core/islands/components/output-wrapper.tsx +15 -20
  87. package/src/core/islands/iframe-resizer.ts +38 -0
  88. package/src/core/islands/main.ts +3 -0
  89. package/src/core/lifecycle/render-policy.ts +7 -4
  90. package/src/core/network/__tests__/ai.test.ts +41 -0
  91. package/src/core/network/ai.ts +12 -0
  92. package/src/core/notebook/document/__tests__/codemirror.test.ts +2 -0
  93. package/src/core/notebook/replica/__tests__/replica.test.ts +19 -0
  94. package/src/core/notebook/replica/__tests__/results.test.ts +45 -16
  95. package/src/core/notebook/replica/index.ts +1 -1
  96. package/src/core/notebook/replica/replica.ts +19 -4
  97. package/src/core/notebook/replica/resources/executions.ts +100 -9
  98. package/src/core/notebook/replica/resources/results.ts +46 -31
  99. package/src/core/transports/__tests__/static.test.ts +5 -3
  100. package/src/stories/cell.stories.tsx +40 -30
  101. package/src/stories/layout/vertical/one-column.stories.tsx +15 -7
@@ -0,0 +1,91 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
+ import { registerIframeResizer } from "../iframe-resizer";
5
+
6
+ const observe = vi.fn();
7
+ let notifyResize: () => void = vi.fn();
8
+
9
+ beforeEach(() => {
10
+ delete window.__resizeIframe;
11
+ document.body.replaceChildren();
12
+ vi.stubGlobal(
13
+ "ResizeObserver",
14
+ class {
15
+ public constructor(callback: () => void) {
16
+ notifyResize = callback;
17
+ }
18
+ public observe = observe;
19
+ },
20
+ );
21
+ registerIframeResizer();
22
+ });
23
+
24
+ afterEach(() => {
25
+ delete window.__resizeIframe;
26
+ vi.unstubAllGlobals();
27
+ });
28
+
29
+ function createIframe() {
30
+ const iframe = document.createElement("iframe");
31
+ document.body.append(iframe);
32
+ const element = iframe.contentDocument!.documentElement;
33
+ Object.defineProperties(element, {
34
+ scrollHeight: { configurable: true, value: 600 },
35
+ clientHeight: { configurable: true, value: 150 },
36
+ scrollWidth: { configurable: true, value: 300 },
37
+ clientWidth: { configurable: true, value: 300 },
38
+ });
39
+ return { iframe, element };
40
+ }
41
+
42
+ describe("islands iframe resizing", () => {
43
+ it("resizes overflowing content and observes subsequent height changes", () => {
44
+ const { iframe, element } = createIframe();
45
+
46
+ window.__resizeIframe!(iframe);
47
+
48
+ expect(iframe.style.height).toBe("600px");
49
+ expect(observe).toHaveBeenCalledExactlyOnceWith(
50
+ iframe.contentDocument!.body,
51
+ );
52
+
53
+ Object.defineProperty(element, "scrollHeight", { value: 900 });
54
+ notifyResize();
55
+ expect(iframe.style.height).toBe("900px");
56
+ });
57
+
58
+ it("allows space for a horizontal scrollbar", () => {
59
+ const { iframe, element } = createIframe();
60
+ Object.defineProperty(element, "scrollWidth", { value: 500 });
61
+
62
+ window.__resizeIframe!(iframe);
63
+
64
+ expect(iframe.style.height).toBe("620px");
65
+ });
66
+
67
+ it("preserves the height when there is no vertical overflow", () => {
68
+ const { iframe, element } = createIframe();
69
+ Object.defineProperty(element, "scrollHeight", { value: 150 });
70
+ iframe.style.height = "150px";
71
+
72
+ window.__resizeIframe!(iframe);
73
+
74
+ expect(iframe.style.height).toBe("150px");
75
+ });
76
+
77
+ it("ignores an iframe whose content window is not ready", () => {
78
+ const iframe = document.createElement("iframe");
79
+
80
+ expect(() => window.__resizeIframe!(iframe)).not.toThrow();
81
+ expect(observe).not.toHaveBeenCalled();
82
+ });
83
+
84
+ it("keeps the same handler across repeated registration", () => {
85
+ const handler = window.__resizeIframe;
86
+
87
+ registerIframeResizer();
88
+
89
+ expect(window.__resizeIframe).toBe(handler);
90
+ });
91
+ });
@@ -38,6 +38,7 @@ async function importMain(): Promise<typeof MainModule> {
38
38
  }
39
39
 
40
40
  beforeEach(() => {
41
+ delete window.__resizeIframe;
41
42
  document.body.replaceChildren();
42
43
  mockInitializeApps.mockClear();
43
44
  mockStopSession.mockClear();
@@ -47,6 +48,22 @@ beforeEach(() => {
47
48
  });
48
49
 
49
50
  describe("islands public API surface", () => {
51
+ it("registers the iframe load handler even without interactive islands", async () => {
52
+ await importMain();
53
+
54
+ expect(window.__resizeIframe).toBeTypeOf("function");
55
+ expect(mockInitializeIslands).not.toHaveBeenCalled();
56
+ });
57
+
58
+ it("preserves a host-provided iframe load handler", async () => {
59
+ const hostResizeIframe = vi.fn();
60
+ window.__resizeIframe = hostResizeIframe;
61
+
62
+ await importMain();
63
+
64
+ expect(window.__resizeIframe).toBe(hostResizeIframe);
65
+ });
66
+
50
67
  it("exposes a stable set of exports and signatures", async () => {
51
68
  const mod = await importMain();
52
69
  const surface = Object.fromEntries(
@@ -12,6 +12,7 @@ import {
12
12
  vi,
13
13
  } from "vitest";
14
14
  import { cellId } from "@/__tests__/branded";
15
+ import { MockExecutions } from "@/__mocks__/executions";
15
16
  import { MockNotebook } from "@/__mocks__/notebook";
16
17
  import { MockRequestClient } from "@/__mocks__/requests";
17
18
  import { notebookAtom } from "@/core/cells/cells";
@@ -249,21 +250,18 @@ function setNotebook(id: string, output?: string): void {
249
250
  const runtimeCellId = cellId(id);
250
251
  store.set(
251
252
  notebookAtom,
252
- MockNotebook.notebookState({
253
- cellData: { [runtimeCellId]: {} },
254
- cellRuntime: output
255
- ? {
256
- [runtimeCellId]: {
257
- output: {
258
- channel: "output",
259
- data: `<div>${output}</div>`,
260
- mimetype: "text/html",
261
- timestamp: 0,
262
- },
263
- },
264
- }
265
- : undefined,
266
- }),
253
+ MockNotebook.notebookState({ cellData: { [runtimeCellId]: {} } }),
254
+ );
255
+ MockExecutions.seed(
256
+ store,
257
+ output === undefined
258
+ ? []
259
+ : [
260
+ MockExecutions.shown(runtimeCellId, {
261
+ mimetype: "text/html",
262
+ data: `<div>${output}</div>`,
263
+ }),
264
+ ],
267
265
  );
268
266
  }
269
267
 
@@ -1,19 +1,17 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { useAtomValue } from "jotai";
4
- import { selectAtom } from "jotai/utils";
5
4
  import { Loader2Icon } from "lucide-react";
6
- import React, {
7
- type PropsWithChildren,
8
- useCallback,
9
- useEffect,
10
- useRef,
11
- } from "react";
5
+ import React, { type PropsWithChildren, useEffect, useRef } from "react";
12
6
  import { OutputRenderer } from "@/components/editor/Output";
13
- import { type NotebookState, notebookAtom } from "@/core/cells/cells";
14
7
  import type { CellId } from "@/core/cells/ids";
15
8
  import { isOutputEmpty } from "@/core/cells/outputs";
16
- import { type CellRunStatus, useCellExecution } from "@/core/executions";
9
+ import {
10
+ type CellRunStatus,
11
+ useCellExecution,
12
+ useCellHasResult,
13
+ useCellOutput,
14
+ } from "@/core/executions";
17
15
  import { ISLAND_TAG_NAMES } from "../constants";
18
16
  import { islandsHydratedAtom } from "../state";
19
17
  import { IslandControls } from "./IslandControls";
@@ -60,11 +58,8 @@ export const MarimoOutputWrapper: React.FC<MarimoOutputWrapperProps> = ({
60
58
  }) => {
61
59
  const controlsVisible = useIslandControls(alwaysShowRun);
62
60
  const wrapperRef = useRef<HTMLDivElement>(null);
63
- const selector = useCallback(
64
- (s: NotebookState) => s.cellRuntime[cellId],
65
- [cellId],
66
- );
67
- const runtime = useAtomValue(selectAtom(notebookAtom, selector));
61
+ const output = useCellOutput(cellId);
62
+ const hasResult = useCellHasResult(cellId);
68
63
  const isHydrated = useAtomValue(islandsHydratedAtom);
69
64
 
70
65
  // Sync cell status to the host <marimo-island> element as a data attribute
@@ -72,9 +67,9 @@ export const MarimoOutputWrapper: React.FC<MarimoOutputWrapperProps> = ({
72
67
  const { status } = useCellExecution(cellId);
73
68
  useSyncStatusToIsland(wrapperRef, status);
74
69
 
75
- // If no runtime yet, show static content
76
- // Keep static content mounted while the initial run is pending.
77
- if (!isHydrated || !runtime?.output) {
70
+ // Show the static content until the cell has run here. Keep it mounted
71
+ // while the initial run is pending.
72
+ if (!isHydrated || (output === null && !hasResult)) {
78
73
  return (
79
74
  <div ref={wrapperRef} className="relative min-h-6 empty:hidden">
80
75
  {children}
@@ -82,14 +77,14 @@ export const MarimoOutputWrapper: React.FC<MarimoOutputWrapperProps> = ({
82
77
  );
83
78
  }
84
79
 
85
- // No output to display
86
- if (isOutputEmpty(runtime.output)) {
80
+ // The cell ran and shows nothing, so the static content is out of date.
81
+ if (output === null || isOutputEmpty(output)) {
87
82
  return <div ref={wrapperRef} />;
88
83
  }
89
84
 
90
85
  return (
91
86
  <div ref={wrapperRef} className="relative min-h-6">
92
- <OutputRenderer message={runtime.output} />
87
+ <OutputRenderer message={output} />
93
88
  <RunningIndicator status={status} />
94
89
  <IslandControls
95
90
  cellId={cellId}
@@ -0,0 +1,38 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ declare global {
4
+ interface Window {
5
+ __resizeIframe?: (iframe: HTMLIFrameElement) => void;
6
+ }
7
+ }
8
+
9
+ // Match the inline helper in frontend/index.html, which islands do not load.
10
+ function resizeIframe(iframe: HTMLIFrameElement): void {
11
+ const scrollbarHeight = 20;
12
+
13
+ function setHeight() {
14
+ const element = iframe.contentWindow?.document?.documentElement;
15
+ if (!element || element.scrollHeight === element.clientHeight) {
16
+ return;
17
+ }
18
+
19
+ const hasHorizontalScrollbar = element.scrollWidth > element.clientWidth;
20
+ const newHeight =
21
+ element.scrollHeight + (hasHorizontalScrollbar ? scrollbarHeight : 0);
22
+ if (iframe.style.height !== `${newHeight}px`) {
23
+ iframe.style.height = `${newHeight}px`;
24
+ }
25
+ }
26
+
27
+ setHeight();
28
+
29
+ const resizeObserver = new ResizeObserver(setHeight);
30
+ const body = iframe.contentWindow?.document?.body;
31
+ if (body) {
32
+ resizeObserver.observe(body);
33
+ }
34
+ }
35
+
36
+ export function registerIframeResizer(): void {
37
+ window.__resizeIframe ??= resizeIframe;
38
+ }
@@ -16,8 +16,11 @@ import { Logger } from "@/utils/Logger";
16
16
  import { initializeIslands } from "./bootstrap";
17
17
  import { getGlobalBridge } from "./bridge";
18
18
  import { ISLAND_CSS_CLASSES, ISLAND_TAG_NAMES } from "./constants";
19
+ import { registerIframeResizer } from "./iframe-resizer";
19
20
  import { parseMarimoIslandApps } from "./parse";
20
21
 
22
+ registerIframeResizer();
23
+
21
24
  const bridge = getGlobalBridge();
22
25
  let bootstrapPromise: Promise<void> | undefined;
23
26
 
@@ -1,9 +1,12 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { atom } from "jotai";
4
- import { hasCellsAtom, notebookAtom } from "../cells/cells";
4
+ import { cellIdsAtom, hasCellsAtom } from "../cells/cells";
5
5
  import { isOutputEmpty } from "../cells/outputs";
6
- import { notebookQueuedOrRunningCountAtom } from "../executions";
6
+ import {
7
+ cellOutputAtom,
8
+ notebookQueuedOrRunningCountAtom,
9
+ } from "../executions";
7
10
  import { KnownQueryParams } from "../constants";
8
11
  import { showCodeInRunModeAtom } from "../meta/state";
9
12
  import { type AppMode, initialModeAtom } from "../mode";
@@ -80,8 +83,8 @@ function computeRenderPolicy(input: {
80
83
  * update.
81
84
  */
82
85
  const hasCachedOutputsAtom = atom((get) =>
83
- Object.values(get(notebookAtom).cellRuntime).some(
84
- (runtime) => !isOutputEmpty(runtime.output),
86
+ get(cellIdsAtom).some(
87
+ (cellId) => !isOutputEmpty(get(cellOutputAtom(cellId))),
85
88
  ),
86
89
  );
87
90
 
@@ -0,0 +1,41 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { afterEach, expect, it, vi } from "vitest";
4
+ import { listProviderModels } from "../ai";
5
+
6
+ vi.mock("@/core/runtime/config", () => ({
7
+ getRuntimeManager: () => ({
8
+ httpURL: new URL("https://notebook.example.com/nested/"),
9
+ headers: () => ({ "Marimo-Session-Id": "session" }),
10
+ }),
11
+ }));
12
+
13
+ afterEach(() => vi.unstubAllGlobals());
14
+
15
+ it.each([
16
+ ["gateway", "gateway"],
17
+ ["gateway?tenant", "gateway%3Ftenant"],
18
+ ["gateway#tenant", "gateway%23tenant"],
19
+ ])(
20
+ "encodes %s while preserving runtime URL prefix and session headers",
21
+ async (provider, encodedProvider) => {
22
+ const catalog = { models: [{ id: "model", name: "Model" }] };
23
+ const fetch = vi
24
+ .fn<(request: Request) => Promise<Response>>()
25
+ .mockResolvedValue(Response.json(catalog));
26
+ vi.stubGlobal("fetch", fetch);
27
+
28
+ await expect(listProviderModels(provider)).resolves.toEqual(catalog);
29
+ expect(fetch).toHaveBeenCalledOnce();
30
+ const [request] = fetch.mock.calls[0];
31
+ expect({
32
+ method: request.method,
33
+ url: request.url,
34
+ session: request.headers.get("Marimo-Session-Id"),
35
+ }).toEqual({
36
+ method: "GET",
37
+ url: `https://notebook.example.com/nested/api/ai/models/${encodedProvider}`,
38
+ session: "session",
39
+ });
40
+ },
41
+ );
@@ -0,0 +1,12 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { getRuntimeManager } from "../runtime/config";
4
+ import { API, createClientWithRuntimeManager } from "./api";
5
+
6
+ export function listProviderModels(provider: string) {
7
+ return createClientWithRuntimeManager(getRuntimeManager())
8
+ .GET("/api/ai/models/{provider_name}", {
9
+ params: { path: { provider_name: encodeURIComponent(provider) } },
10
+ })
11
+ .then(API.handleResponse);
12
+ }
@@ -82,6 +82,8 @@ function languages(id: CellId) {
82
82
  expandCell: vi.fn(),
83
83
  collapseAllCells: vi.fn(),
84
84
  expandAllCells: vi.fn(),
85
+ clearCellOutput: vi.fn(),
86
+ clearAllCellOutputs: vi.fn(),
85
87
  showCellIfHidden: vi.fn(),
86
88
  moveCell: vi.fn(),
87
89
  moveCellToIndex: vi.fn(),
@@ -188,6 +188,25 @@ describe("NotebookReplica lifetime", () => {
188
188
  expect(store.get(client.notebookAtom)?.id).toBe("n2");
189
189
  });
190
190
 
191
+ it("preserves output revisions across an unchanged replacement snapshot", async () => {
192
+ const { connect, opened, client, store } = setup();
193
+ connect(lifetime().signal);
194
+ const { receive } = await opened();
195
+ const snapshot = fixtureMessages("notebook-events.sse");
196
+ snapshot.forEach(receive);
197
+ const before = store.get(client.executionsAtom);
198
+ expect(
199
+ [...before.executions.values()].some(
200
+ (execution) => execution.outputVersion > 0,
201
+ ),
202
+ ).toBe(true);
203
+
204
+ receive({ event: "reset", data: {} });
205
+ snapshot.filter((event) => event.event !== "ready").forEach(receive);
206
+ receive({ event: "ready", id: "98", data: {} });
207
+ expect(store.get(client.executionsAtom)).toEqual(before);
208
+ });
209
+
191
210
  it("keeps what is on show when the snapshot replacing it is interrupted", async () => {
192
211
  vi.useFakeTimers();
193
212
  const { connect, opened, client, store } = setup();
@@ -2,11 +2,11 @@
2
2
 
3
3
  import { describe, expect, it } from "vitest";
4
4
  import * as Protocol from "@marimo-team/client/protocol";
5
- import { results } from "../resources/results";
5
+ import { executions } from "../resources/executions";
6
6
  import { createNotebookReducer } from "@marimo-team/client";
7
7
  import { fixtureEvents } from "./fixtures";
8
8
 
9
- const reducer = createNotebookReducer({ results });
9
+ const reducer = createNotebookReducer({ executions });
10
10
  const snapshot = fixtureEvents("notebook-events.sse");
11
11
  const runCells = fixtureEvents("run-cells.sse");
12
12
  const time = "2026-10-01T09:30:00Z";
@@ -18,7 +18,8 @@ function replay(
18
18
  return events.reduce(reducer.reduce, from);
19
19
  }
20
20
 
21
- const resource = (state: ReturnType<typeof replay>) => state.resources.results;
21
+ const resource = (state: ReturnType<typeof replay>) =>
22
+ state.resources.executions.results;
22
23
 
23
24
  /** Build one event as the stream would deliver it. */
24
25
  const event = (message: unknown) => Protocol.Event.parse(message);
@@ -47,7 +48,7 @@ const restored = {
47
48
  completed_at: "2026-09-30T09:20:02Z",
48
49
  };
49
50
 
50
- describe("results resource", () => {
51
+ describe("retained results", () => {
51
52
  it("has an entry per document cell, filled by a restored result", () => {
52
53
  const ready = snapshot.findIndex((item) => item.event === "ready");
53
54
  const opening = resource(replay(snapshot.slice(0, ready + 1)));
@@ -64,8 +65,8 @@ describe("results resource", () => {
64
65
  ...snapshot.slice(ready),
65
66
  ]),
66
67
  );
67
- expect(opened.get("c3")?.id).toBe("e-restored");
68
- expect(opened.get("c3")?.run_id).toBeNull();
68
+ expect(opened.get("c3")?.record.id).toBe("e-restored");
69
+ expect(opened.get("c3")?.record.run_id).toBeNull();
69
70
  });
70
71
 
71
72
  it("records a cell's result when its execution completes", () => {
@@ -75,14 +76,42 @@ describe("results resource", () => {
75
76
  expect(running.get("k7f2")).toBeNull();
76
77
 
77
78
  const done = resource(replay(runCells, start));
78
- expect(done.get("c3")?.id).toBe("e12");
79
- expect(done.get("c3")?.status).toBe("completed");
80
- expect(done.get("k7f2")?.depends_on).toEqual({
79
+ 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
82
  x: { execution: "e12", update: 0 },
82
83
  });
83
84
  expect(done.get("c1")).toBeNull();
84
85
  });
85
86
 
87
+ it("keeps a result when the attempt that replaced it was superseded", () => {
88
+ const done = replay(runCells, replay(snapshot));
89
+ const result = resource(done).get("c3")!;
90
+ const superseded = reducer.reduce(
91
+ replay(retire("e12", "e12-x"), done),
92
+ event({
93
+ event: "execution",
94
+ id: "113",
95
+ data: {
96
+ execution: {
97
+ ...result.record,
98
+ id: "e14",
99
+ 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: [],
107
+ },
108
+ },
109
+ },
110
+ }),
111
+ );
112
+ expect(resource(superseded).get("c3")).toBe(result);
113
+ });
114
+
86
115
  it("keeps a result while the host replaces it", () => {
87
116
  const done = replay(runCells, replay(snapshot));
88
117
  const result = resource(done).get("c3")!;
@@ -90,7 +119,7 @@ describe("results resource", () => {
90
119
  expect(resource(retired).get("c3")).toBe(result);
91
120
 
92
121
  const again = {
93
- ...result,
122
+ ...result.record,
94
123
  id: "e14",
95
124
  run_id: "run-again",
96
125
  status: "queued",
@@ -120,14 +149,14 @@ describe("results resource", () => {
120
149
  },
121
150
  }),
122
151
  );
123
- expect(resource(completed).get("c3")?.id).toBe("e14");
152
+ expect(resource(completed).get("c3")?.record.id).toBe("e14");
124
153
  });
125
154
 
126
155
  it("replaces a result with an execution interrupted before it started", () => {
127
156
  const done = replay(runCells, replay(snapshot));
128
157
  const result = resource(done).get("c3")!;
129
158
  const interrupted = {
130
- ...result,
159
+ ...result.record,
131
160
  id: "e14",
132
161
  run_id: "run-again",
133
162
  status: "completed",
@@ -158,7 +187,7 @@ describe("results resource", () => {
158
187
  ],
159
188
  done,
160
189
  );
161
- expect(resource(cancelled).get("c3")?.outcome).toEqual({
190
+ expect(resource(cancelled).get("c3")?.record.outcome).toEqual({
162
191
  kind: "interrupted",
163
192
  });
164
193
  });
@@ -170,7 +199,7 @@ describe("results resource", () => {
170
199
 
171
200
  const finished = replay(runCells.slice(5), deleted);
172
201
  expect(resource(finished).has("c3")).toBe(false);
173
- expect(resource(finished).get("k7f2")?.id).toBe("e13");
202
+ expect(resource(finished).get("k7f2")?.record.id).toBe("e13");
174
203
  });
175
204
 
176
205
  it("ignores cells it has not seen and clears on reset", () => {
@@ -183,11 +212,11 @@ describe("results resource", () => {
183
212
  data: { execution: { ...restored, id: "e-zz", cell_id: "zz" } },
184
213
  }),
185
214
  );
186
- expect(unknown.resources).toBe(start.resources);
215
+ expect(resource(unknown)).toBe(resource(start));
187
216
  const reset = reducer.reduce(replay(runCells, start), {
188
217
  event: "reset",
189
218
  data: {},
190
219
  });
191
- expect(resource(reset)).toBe(results.initial);
220
+ expect(resource(reset)).toBe(executions.initial.results);
192
221
  });
193
222
  });
@@ -17,4 +17,4 @@ export {
17
17
  type Item,
18
18
  itemsInOrder,
19
19
  } from "./resources/executions";
20
- export type { Results } from "./resources/results";
20
+ export type { Result, Results } from "./resources/results";
@@ -24,8 +24,12 @@ import {
24
24
  } from "./connection";
25
25
  import { attachments } from "./resources/attachments";
26
26
  import { type Document, document } from "./resources/document";
27
- import { type Executions, executions } from "./resources/executions";
28
- import { type Results, results } from "./resources/results";
27
+ import {
28
+ type Executions,
29
+ executions,
30
+ resumeResults,
31
+ } from "./resources/executions";
32
+ import type { Results } from "./resources/results";
29
33
  import { runtime } from "./resources/runtime";
30
34
 
31
35
  /**
@@ -162,7 +166,6 @@ export function createNotebookReplica(
162
166
  attachments,
163
167
  runtime,
164
168
  executions,
165
- results,
166
169
  });
167
170
  type Stream = typeof reducer.initial;
168
171
  /**
@@ -205,7 +208,7 @@ export function createNotebookReplica(
205
208
  get(presentAtom) ? get(streamAtom).resources.runtime : null,
206
209
  );
207
210
  const executionsAtom = atom((get) => get(shownAtom).resources.executions);
208
- const resultsAtom = atom((get) => get(shownAtom).resources.results);
211
+ const resultsAtom = atom((get) => get(executionsAtom).results);
209
212
  const backendAtom = atom<NotebookBackend | null>(null);
210
213
  /** The connection this replica follows. Connecting again ends it. */
211
214
  let current: { end(): void; reconnect(): Promise<void> } | undefined;
@@ -218,6 +221,18 @@ export function createNotebookReplica(
218
221
  return followed;
219
222
  }
220
223
  if (next.phase !== "snapshot") {
224
+ if (retained !== null && retained.notebook?.id === next.notebook?.id) {
225
+ next = {
226
+ ...next,
227
+ resources: {
228
+ ...next.resources,
229
+ executions: resumeResults(
230
+ next.resources.executions,
231
+ retained.resources.executions,
232
+ ),
233
+ },
234
+ };
235
+ }
221
236
  return { stream: next, retained: null };
222
237
  }
223
238
  return {