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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: uninstantiated logic (#1632)
Akshay Agrawal5b542e4cbfd0
diff --git a/frontend/src/components/editor/Cell.tsx b/frontend/src/components/editor/Cell.tsxindex b01489ec2d..c9d0687de2 100644--- a/frontend/src/components/editor/Cell.tsx+++ b/frontend/src/components/editor/Cell.tsx@@ -15,7 +15,7 @@ import { saveCellConfig, sendRun, sendStdin } from "@/core/network/requests";import { autocompletionKeymap } from "@/core/codemirror/cm";import { UserConfig } from "../../core/config/config-schema";import { CellData, CellRuntimeState } from "../../core/cells/types";-import { CellActions } from "../../core/cells/cells";+import { CellActions, isUninstantiated } from "../../core/cells/cells";import { derefNotNull } from "../../utils/dereference";import { OutputArea } from "./Output";import { ConsoleOutput } from "./output/ConsoleOutput";@@ -157,8 +157,21 @@ const CellComponent = (const disabledOrAncestorDisabled =cellConfig.disabled || status === "disabled-transitively";++ const uninstantiated = isUninstantiated(+ userConfig.runtime.auto_instantiate,+ runElapsedTimeMs,+ status,+ errored,+ interrupted,+ stopped,+ );+const needsRun =- edited || interrupted || (staleInputs && !disabledOrAncestorDisabled);+ uninstantiated ||+ edited ||+ interrupted ||+ (staleInputs && !disabledOrAncestorDisabled);const loading = status === "running" || status === "queued";const outputStale = outputIsStale(@@ -388,9 +401,6 @@ const CellComponent = (const hasOutput = !isOutputEmpty(output);- const uninstantiated =- !userConfig.runtime.auto_instantiate && !runElapsedTimeMs;-return (<CellActionsContextMenucellId={cellId}diff --git a/frontend/src/core/cells/cells.ts b/frontend/src/core/cells/cells.tsindex 6ab991f4f7..f53b7722dc 100644--- a/frontend/src/core/cells/cells.ts+++ b/frontend/src/core/cells/cells.ts@@ -37,7 +37,8 @@ import {updateEditorCodeFromPython,} from "../codemirror/language/utils";import { invariant } from "@/utils/invariant";-import { CellConfig } from "../network/types";+import { CellConfig, CellStatus } from "../network/types";+import { getUserConfig } from "@/core/config/config";/*** The state of the notebook.@@ -502,12 +503,7 @@ const {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,- }),- ]),+ cells.map((cell) => [cell.id, createCellRuntimeState()]),);return {@@ -867,13 +863,44 @@ export const getCellEditorView = (cellId: CellId) => {return cellHandles[cellId].current?.editorView;};+export function isUninstantiated(+ autoInstantiate: boolean,+ executionTime: number | null,+ status: CellStatus,+ errored: boolean,+ interrupted: boolean,+ stopped: boolean,+) {+ return (+ // autorun on startup is off ...+ !autoInstantiate &&+ // hasn't run ...+ executionTime === null &&+ // isn't currently queued/running &&+ status !== "queued" &&+ status !== "running" &&+ // and isn't in an error state.+ !(errored || interrupted || stopped)+ );+}+/*** Cells that are stale and can be run.*/export function staleCellIds(state: NotebookState) {+ const autoInstantiate = getUserConfig().runtime.auto_instantiate;+const { cellIds, cellData, cellRuntime } = state;return cellIds.filter((cellId) =>+ isUninstantiated(+ autoInstantiate,+ cellData[cellId].lastExecutionTime,+ cellRuntime[cellId].status,+ cellRuntime[cellId].errored,+ cellRuntime[cellId].interrupted,+ cellRuntime[cellId].stopped,+ ) ||cellData[cellId].edited ||cellRuntime[cellId].interrupted ||(cellRuntime[cellId].staleInputs &&diff --git a/frontend/src/core/cells/types.ts b/frontend/src/core/cells/types.tsindex 3133f07383..30a0125f01 100644--- a/frontend/src/core/cells/types.ts+++ b/frontend/src/core/cells/types.ts@@ -5,7 +5,6 @@ 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";import { CellConfig, CellStatus } from "../network/types";/**@@ -39,13 +38,12 @@ export function createCell({export function createCellRuntimeState(state?: Partial<CellRuntimeState>,): CellRuntimeState {- const auto_instantiate = getUserConfig().runtime.auto_instantiate;return {outline: null,output: null,consoleOutputs: [],status: "idle" as CellStatus,- staleInputs: !auto_instantiate,+ staleInputs: false,interrupted: false,errored: false,stopped: false,