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: move cell back to idle on error (#1824)

Akshay Agrawal032773ca4672
diff --git a/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap b/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
index d09ac3ee39..a8d7ab71cc 100644
--- a/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
+++ b/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
@@ -1089,3 +1089,122 @@ import numpy",
"stopped": false,
}
`;
+
+exports[`cell reducer > errors reset status to idle 1`] = `
+{
+ "code": "",
+ "config": {
+ "disabled": false,
+ "hide_code": false,
+ },
+ "consoleOutputs": [],
+ "debuggerActive": false,
+ "edited": false,
+ "errored": false,
+ "id": "0",
+ "interrupted": false,
+ "lastCodeRun": null,
+ "lastExecutionTime": null,
+ "name": "__",
+ "outline": null,
+ "output": null,
+ "runElapsedTimeMs": null,
+ "runStartTimestamp": null,
+ "serializedEditorState": null,
+ "staleInputs": false,
+ "status": "idle",
+ "stopped": false,
+}
+`;
+
+exports[`cell reducer > errors reset status to idle 2`] = `
+{
+ "code": "import marimo as mo",
+ "config": {
+ "disabled": false,
+ "hide_code": false,
+ },
+ "consoleOutputs": [],
+ "debuggerActive": false,
+ "edited": true,
+ "errored": false,
+ "id": "0",
+ "interrupted": false,
+ "lastCodeRun": null,
+ "lastExecutionTime": null,
+ "name": "__",
+ "outline": null,
+ "output": null,
+ "runElapsedTimeMs": null,
+ "runStartTimestamp": null,
+ "serializedEditorState": null,
+ "staleInputs": false,
+ "status": "idle",
+ "stopped": false,
+}
+`;
+
+exports[`cell reducer > errors reset status to idle 3`] = `
+{
+ "code": "import marimo as mo",
+ "config": {
+ "disabled": false,
+ "hide_code": false,
+ },
+ "consoleOutputs": [],
+ "debuggerActive": false,
+ "edited": false,
+ "errored": false,
+ "id": "0",
+ "interrupted": false,
+ "lastCodeRun": "import marimo as mo",
+ "lastExecutionTime": null,
+ "name": "__",
+ "outline": null,
+ "output": null,
+ "runElapsedTimeMs": null,
+ "runStartTimestamp": null,
+ "serializedEditorState": null,
+ "staleInputs": false,
+ "status": "queued",
+ "stopped": false,
+}
+`;
+
+exports[`cell reducer > errors reset status to idle 4`] = `
+{
+ "code": "import marimo as mo",
+ "config": {
+ "disabled": false,
+ "hide_code": false,
+ },
+ "consoleOutputs": [],
+ "debuggerActive": false,
+ "edited": false,
+ "errored": true,
+ "id": "0",
+ "interrupted": false,
+ "lastCodeRun": "import marimo as mo",
+ "lastExecutionTime": null,
+ "name": "__",
+ "outline": null,
+ "output": {
+ "channel": "marimo-error",
+ "data": [
+ {
+ "exception_type": "SyntaxError",
+ "msg": "Oh no!",
+ "type": "exception",
+ },
+ ],
+ "mimetype": "application/vnd.marimo+error",
+ "timestamp": 0,
+ },
+ "runElapsedTimeMs": null,
+ "runStartTimestamp": null,
+ "serializedEditorState": null,
+ "staleInputs": false,
+ "status": "idle",
+ "stopped": false,
+}
+`;
diff --git a/frontend/src/core/cells/__tests__/cells.test.ts b/frontend/src/core/cells/__tests__/cells.test.ts
index 3bce285e00..5c79cbd477 100644
--- a/frontend/src/core/cells/__tests__/cells.test.ts
+++ b/frontend/src/core/cells/__tests__/cells.test.ts
@@ -495,6 +495,69 @@ describe("cell reducer", () => {
expect(cell).toMatchSnapshot(); // snapshot everything as a catch all
});
+ it("errors reset status to idle", () => {
+ // Initial state
+ let cell = cells[0];
+ expect(cell.status).toBe("idle");
+ expect(cell.lastCodeRun).toBe(null);
+ expect(cell.edited).toBe(false);
+ expect(cell).toMatchSnapshot(); // snapshot everything as a catch all
+
+ // Update code
+ actions.updateCellCode({
+ cellId: firstCellId,
+ code: "import marimo as mo",
+ formattingChange: false,
+ });
+ cell = cells[0];
+ expect(cell.status).toBe("idle");
+ expect(cell.lastCodeRun).toBe(null);
+ expect(cell.edited).toBe(true);
+ expect(cell).toMatchSnapshot(); // snapshot everything as a catch all
+
+ // Prepare for run
+ actions.prepareForRun({
+ cellId: firstCellId,
+ });
+ cell = cells[0];
+ expect(cell.status).toBe("queued");
+ expect(cell.lastCodeRun).toBe("import marimo as mo");
+ expect(cell.edited).toBe(false);
+ expect(cell).toMatchSnapshot(); // snapshot everything as a catch all
+
+ // ERROR RESPONSE
+ //
+ // should reset status to idle
+ /////////////////
+ // Prepare for run
+ actions.prepareForRun({
+ cellId: firstCellId,
+ });
+ cell = cells[0];
+ // Receive error
+ actions.handleCellMessage({
+ cell_id: firstCellId,
+ output: {
+ channel: "marimo-error",
+ mimetype: "application/vnd.marimo+error",
+ data: [
+ { type: "exception", exception_type: "SyntaxError", msg: "Oh no!" },
+ ],
+ timestamp: 0,
+ },
+ console: null,
+ stale_inputs: null,
+ timestamp: new Date(61).getTime() as Seconds,
+ });
+ cell = cells[0];
+ expect(cell.status).toBe("idle");
+ expect(cell.lastCodeRun).toBe("import marimo as mo");
+ expect(cell.edited).toBe(false);
+ expect(cell.runElapsedTimeMs).toBe(null);
+ expect(cell.runStartTimestamp).toBe(null);
+ expect(cell).toMatchSnapshot(); // snapshot everything as a catch all
+ });
+
it("can run a stale cell", () => {
// Update code of first cell
actions.updateCellCode({
diff --git a/frontend/src/core/cells/cell.ts b/frontend/src/core/cells/cell.ts
index a497971d07..8075f7090c 100644
--- a/frontend/src/core/cells/cell.ts
+++ b/frontend/src/core/cells/cell.ts
@@ -73,6 +73,14 @@ export function transitionCell(
message.output != null &&
message.output.mimetype === "application/vnd.marimo+error"
) {
+ // The frontend manually sets status to queued when a user runs a cell,
+ // to give immediate feedback, but the kernel doesn't know that.
+ //
+ // TODO(akshayka): Move all status management to the backend.
+ if (nextCell.status === "queued" || nextCell.status === "running") {
+ nextCell.status = "idle";
+ }
+
invariant(
Array.isArray(message.output.data),
"Expected error output data to be an array",
@@ -142,7 +150,11 @@ export function prepareCellForExecution(
): CellRuntimeState {
const nextCell = { ...cell };
- nextCell.status = "queued";
+ if (cell.status !== "disabled-transitively") {
+ // TODO(akshayka): Move this to the backend. It's in the FE right now
+ // to give the user immediate feedback.
+ nextCell.status = "queued";
+ }
nextCell.interrupted = false;
nextCell.errored = false;
nextCell.runElapsedTimeMs = null;