feat(server): add GET /api/kernel/status endpoint#9768
Merged
Conversation
Returns {"state": "running" | "idle" | "stopped"} for the current
session's kernel. State is derived from existing session state:
`kernel_state()` for process liveness and the per-cell statuses in
`session_view.cell_notifications` (queued/running => running), the same
source of truth the frontend uses. Gated with @requires("edit").
Adds KernelStatusResponse model, registers it for OpenAPI codegen,
regenerates the API client, and adds endpoint tests.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new server API endpoint to report the current session kernel’s execution status, exposing it via OpenAPI and the generated TypeScript client.
Changes:
- Add
GET /api/kernel/status(edit-mode only) returning{"state": "running" | "idle" | "stopped"}derived fromkernel_state()plussession_view.cell_notifications. - Introduce
KernelStatusResponseserver model and register it for OpenAPI schema/codegen. - Regenerate OpenAPI artifacts and add endpoint tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
marimo/_server/api/endpoints/execution.py |
Implements GET /status under the /api/kernel router and derives running/idle/stopped from session state. |
marimo/_server/models/models.py |
Adds KernelStatusResponse msgspec model used by the new endpoint and OpenAPI schema generation. |
marimo/_cli/development/commands.py |
Registers KernelStatusResponse so it’s included in the generated server OpenAPI schema. |
packages/openapi/api.yaml |
Adds the KernelStatusResponse schema and the /api/kernel/status path definition. |
packages/openapi/src/api.ts |
Updates the generated TypeScript types/paths for the new endpoint and schema. |
tests/_server/api/endpoints/test_execution.py |
Adds tests covering authorization plus running and idle status derivation. |
Comment on lines
+148
to
+157
| @staticmethod | ||
| @with_session(SESSION_ID) | ||
| def test_kernel_status_idle(client: TestClient) -> None: | ||
| session = get_session_manager(client).get_session(SESSION_ID) | ||
| assert session is not None | ||
| session.session_view.cell_notifications.clear() | ||
| response = client.get("/api/kernel/status", headers=HEADERS) | ||
| assert response.status_code == 200, response.text | ||
| assert response.json()["state"] == "idle" | ||
|
|
mchav
approved these changes
Jun 2, 2026
Contributor
There was a problem hiding this comment.
No issues found across 6 files
Architecture diagram
sequenceDiagram
participant Client as API Client (frontend/other)
participant Router as API Router
participant AppState as AppState
participant Session as Session
participant SessionView as SessionView
participant Kernel as Kernel Process
Note over Client,Kernel: GET /api/kernel/status – Happy Path
Client->>Router: GET /api/kernel/status<br/>Header: Marimo-Session-Id
Router->>Router: @requires("edit") permission check
alt Permission denied (read-only session)
Router-->>Client: 401 Unauthorized
else Permission granted
Router->>AppState: require_current_session()
AppState-->>Router: Session object
Router->>Session: kernel_state()
Session->>Kernel: Check process liveness
Kernel-->>Session: KernelState value
Session-->>Router: KernelState enum
alt Kernel stopped or not started
Router->>Router: Return state="stopped"
else Kernel alive
Router->>SessionView: Iterate cell_notifications
SessionView-->>Router: Cell notification statuses
alt Any cell queued or running
Router->>Router: Return state="running"
else All cells idle/completed
Router->>Router: Return state="idle"
end
end
Router-->>Client: 200 OK<br/>{"state": "running"|"idle"|"stopped"}
end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Returns {"state": "running" | "idle" | "stopped"} for the current
session's kernel. State is derived from existing session state:
kernel_state()for process liveness and the per-cell statuses insession_view.cell_notifications(queued/running => running), the samesource of truth the frontend uses. Gated with
@requires("edit").Adds KernelStatusResponse model, registers it for OpenAPI codegen,
regenerates the API client, and adds endpoint tests.