Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: Persist stale cells on session resume (#1625)

Wasim Sandhucf30a9c02c35
diff --git a/frontend/src/components/editor/Cell.tsx b/frontend/src/components/editor/Cell.tsx
index 2969a2bd52..c86344fe58 100644
--- a/frontend/src/components/editor/Cell.tsx
+++ b/frontend/src/components/editor/Cell.tsx
@@ -160,6 +160,7 @@ const CellComponent = (
const needsRun =
edited || interrupted || (staleInputs && !disabledOrAncestorDisabled);
const loading = status === "running" || status === "queued";
+
const outputStale = outputIsStale(
{ status, output, runStartTimestamp, interrupted, staleInputs },
edited,
@@ -385,6 +386,9 @@ const CellComponent = (
const hasOutput = !isOutputEmpty(output);
+ const uninstantiated =
+ !userConfig.runtime.auto_instantiate && !runElapsedTimeMs;
+
return (
<CellActionsContextMenu
cellId={cellId}
@@ -451,6 +455,7 @@ const CellComponent = (
disabled={cellConfig.disabled ?? false}
elapsedTime={runElapsedTimeMs}
runStartTimestamp={runStartTimestamp}
+ uninstantiated={uninstantiated}
/>
<div className="flex align-bottom">
<RunButton
diff --git a/frontend/src/components/editor/cell/CellStatus.tsx b/frontend/src/components/editor/cell/CellStatus.tsx
index c3cd09f7dc..fda5b9909f 100644
--- a/frontend/src/components/editor/cell/CellStatus.tsx
+++ b/frontend/src/components/editor/cell/CellStatus.tsx
@@ -24,6 +24,7 @@ export interface CellStatusComponentProps
disabled: boolean;
staleInputs: boolean;
elapsedTime: number | null;
+ uninstantiated: boolean;
}
export const CellStatusComponent: React.FC<CellStatusComponentProps> = ({
@@ -35,6 +36,7 @@ export const CellStatusComponent: React.FC<CellStatusComponentProps> = ({
interrupted,
elapsedTime,
runStartTimestamp,
+ uninstantiated,
}) => {
if (!editing) {
return null;
@@ -158,13 +160,15 @@ export const CellStatusComponent: React.FC<CellStatusComponentProps> = ({
}
// outdated: cell needs to be re-run
- if (edited || interrupted || staleInputs) {
+ if (edited || interrupted || staleInputs || uninstantiated) {
const elapsedTimeStr = formatElapsedTime(elapsedTime);
// Customize tooltips based on why the cell needs to be re-run
let title = "";
let timerTitle = "";
- if (interrupted) {
+ if (uninstantiated) {
+ title = "This cell has not yet been run";
+ } else if (interrupted) {
title = "This cell was interrupted when it was last run";
timerTitle = `This cell ran for ${elapsedTimeStr} before being interrupted`;
} else if (edited) {
@@ -172,7 +176,7 @@ export const CellStatusComponent: React.FC<CellStatusComponentProps> = ({
timerTitle = `This cell took ${elapsedTimeStr} to run`;
} else {
// staleInputs
- title = "This cell has not been run with the latest inputs.";
+ title = "This cell has not been run with the latest inputs";
timerTitle = `This cell took ${elapsedTimeStr} to run`;
}
diff --git a/frontend/src/core/cells/cells.ts b/frontend/src/core/cells/cells.ts
index 38af95e937..ef09f8127c 100644
--- a/frontend/src/core/cells/cells.ts
+++ b/frontend/src/core/cells/cells.ts
@@ -498,16 +498,25 @@ const {
});
},
setCells: (state, cells: CellData[]) => {
+ const cellData = Object.fromEntries(cells.map((cell) => [cell.id, cell]));
+
+ const cellRuntime = Object.fromEntries(
+ cells.map((cell) => [
+ cell.id,
+ createCellRuntimeState({
+ staleInputs: !cellData[cell.id].lastExecutionTime,
+ }),
+ ]),
+ );
+
return {
...state,
cellIds: cells.map((cell) => cell.id),
- cellData: Object.fromEntries(cells.map((cell) => [cell.id, cell])),
+ cellData: cellData,
+ cellRuntime: cellRuntime,
cellHandles: Object.fromEntries(
cells.map((cell) => [cell.id, createRef()]),
),
- cellRuntime: Object.fromEntries(
- cells.map((cell) => [cell.id, createCellRuntimeState()]),
- ),
};
},
/**
diff --git a/frontend/src/core/cells/types.ts b/frontend/src/core/cells/types.ts
index 27bf46e579..817ca493ec 100644
--- a/frontend/src/core/cells/types.ts
+++ b/frontend/src/core/cells/types.ts
@@ -5,6 +5,7 @@ import { Outline } from "./outline";
import { CellId } from "./ids";
import { DEFAULT_CELL_NAME } from "./names";
import { Milliseconds, Seconds } from "@/utils/time";
+import { getUserConfig } from "../config/config";
/**
* The status of a cell.
@@ -45,19 +46,23 @@ export function createCell({
};
}
-export function createCellRuntimeState(): CellRuntimeState {
+export function createCellRuntimeState(
+ state?: Partial<CellRuntimeState>,
+): CellRuntimeState {
+ const auto_instantiate = getUserConfig().runtime.auto_instantiate;
return {
outline: null,
output: null,
consoleOutputs: [],
- status: "idle",
- staleInputs: false,
+ status: "idle" as CellStatus,
+ staleInputs: !auto_instantiate,
interrupted: false,
errored: false,
stopped: false,
runElapsedTimeMs: null,
runStartTimestamp: null,
debuggerActive: false,
+ ...state,
};
}