Skip to content

feat(server): add GET /api/kernel/status endpoint#9768

Merged
mscolnick merged 1 commit into
mainfrom
ms/feature/kernel-status-endpoint
Jun 2, 2026
Merged

feat(server): add GET /api/kernel/status endpoint#9768
mscolnick merged 1 commit into
mainfrom
ms/feature/kernel-status-endpoint

Conversation

@mscolnick
Copy link
Copy Markdown
Contributor

@mscolnick mscolnick commented Jun 2, 2026

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.

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.
Copilot AI review requested due to automatic review settings June 2, 2026 21:49
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jun 2, 2026 9:50pm

Request Review

@github-actions github-actions Bot added the bash-focus Area to focus on during release bug bash label Jun 2, 2026
@mscolnick mscolnick requested a review from mchav June 2, 2026 21:49
@mscolnick mscolnick added the enhancement New feature or request label Jun 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 from kernel_state() plus session_view.cell_notifications.
  • Introduce KernelStatusResponse server 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"

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Re-trigger cubic

@mscolnick mscolnick merged commit 8d6e540 into main Jun 2, 2026
57 of 59 checks passed
@mscolnick mscolnick deleted the ms/feature/kernel-status-endpoint branch June 2, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants