Skip to content

Index

routes

Dashboard API routes.

All routes are prefixed with /api for clear API namespace separation.

Attributes

Classes

ActiveWorkSelection

Bases: BaseModel

Selected active or blocked-in-place sheet for cockpit surfaces.

ArtifactState

Bases: BaseModel

Artifact/workspace state derived from concrete workspace files.

LogState

Bases: BaseModel

Compact log availability state for cockpit rows.

SheetSummary

Bases: BaseModel

Summarized sheet information for list views.

JobSummary

Bases: BaseModel

Summarized job information for list views.

Methods:
from_checkpoint classmethod
from_checkpoint(state, *, data_source='checkpoint', is_partial=False)

Create from CheckpointState.

Source code in src/marianne/dashboard/routes/__init__.py
@classmethod
def from_checkpoint(
    cls,
    state: CheckpointState,
    *,
    data_source: str = "checkpoint",
    is_partial: bool = False,
) -> "JobSummary":
    """Create from CheckpointState."""
    completed, total = state.get_progress()
    active = resolve_active_work(state)
    validation_state, failed_count, failed_validations, pass_percent = (
        _validation_summary(state)
    )
    return cls(
        job_id=state.job_id,
        job_name=state.job_name,
        status=state.status,
        total_sheets=total,
        completed_sheets=completed,
        progress_percent=state.get_progress_percent(),
        created_at=state.created_at,
        updated_at=state.updated_at,
        current_sheet=state.current_sheet,
        active_sheet=active.sheet_num,
        active_sheet_status=active.status,
        active_reason=active.reason,
        active_selected_by=active.selected_by,
        dispatch_blocked_reason=active.dispatch_blocked_reason,
        dispatch_blocked_details=active.dispatch_blocked_details,
        retry_resume_metadata=_retry_resume_metadata(state, active),
        validation_state=validation_state,
        validation_failed_count=failed_count,
        failed_validations=failed_validations[:5],
        validation_pass_percent=pass_percent,
        artifact_state=_artifact_state_from_checkpoint(state),
        log_state=_log_state_from_checkpoint(state),
        total_estimated_cost=round(state.total_estimated_cost or 0.0, 4),
        cost_uncertain=any(sheet.cost_uncertain for sheet in state.sheets.values()),
        data_source=data_source,
        last_updated=state.updated_at,
        is_partial=is_partial,
    )

JobDetail

Bases: BaseModel

Full job details including sheet information.

Methods:
from_checkpoint classmethod
from_checkpoint(state)

Create from CheckpointState.

Source code in src/marianne/dashboard/routes/__init__.py
@classmethod
def from_checkpoint(cls, state: CheckpointState) -> "JobDetail":
    """Create from CheckpointState."""
    sheets = [
        SheetSummary(
            sheet_num=s.sheet_num,
            status=s.status,
            attempt_count=s.attempt_count,
            validation_passed=s.validation_passed,
            failed_validations=s.failed_validations,
            last_pass_percentage=s.last_pass_percentage,
            execution_mode=s.execution_mode,
            dispatch_blocked_reason=s.dispatch_blocked_reason,
        )
        for s in sorted(state.sheets.values(), key=lambda x: x.sheet_num)
    ]
    return cls(
        job_id=state.job_id,
        job_name=state.job_name,
        status=state.status,
        total_sheets=state.total_sheets,
        last_completed_sheet=state.last_completed_sheet,
        current_sheet=state.current_sheet,
        progress_percent=state.get_progress_percent(),
        created_at=state.created_at,
        updated_at=state.updated_at,
        started_at=state.started_at,
        completed_at=state.completed_at,
        error_message=state.error_message,
        total_retry_count=state.total_retry_count,
        rate_limit_waits=state.rate_limit_waits,
        sheets=sheets,
    )

JobStatusResponse

Bases: BaseModel

Focused status information for job monitoring.

Methods:
from_checkpoint classmethod
from_checkpoint(state)

Create from CheckpointState.

Source code in src/marianne/dashboard/routes/__init__.py
@classmethod
def from_checkpoint(cls, state: CheckpointState) -> "JobStatusResponse":
    """Create from CheckpointState."""
    completed, total = state.get_progress()
    return cls(
        job_id=state.job_id,
        status=state.status,
        progress_percent=state.get_progress_percent(),
        completed_sheets=completed,
        total_sheets=total,
        current_sheet=state.current_sheet,
        error_message=state.error_message,
        updated_at=state.updated_at,
    )

JobListResponse

Bases: BaseModel

Response for job list endpoint.

Functions:

resolve_active_work

resolve_active_work(state)

Resolve active or blocked-in-place work for a job.

The resolver is intentionally narrower than SheetStatus.is_active: it prefers CheckpointState.current_sheet for non-terminal jobs, then falls back only to executing or blocked-in-place statuses. Ordinary pending and ready sheets remain queued future work.

Source code in src/marianne/dashboard/routes/__init__.py
def resolve_active_work(state: CheckpointState) -> ActiveWorkSelection:
    """Resolve active or blocked-in-place work for a job.

    The resolver is intentionally narrower than ``SheetStatus.is_active``:
    it prefers ``CheckpointState.current_sheet`` for non-terminal jobs, then
    falls back only to executing or blocked-in-place statuses. Ordinary
    ``pending`` and ``ready`` sheets remain queued future work.
    """

    if state.status in TERMINAL_JOB_STATUSES:
        return ActiveWorkSelection(
            reason="Terminal job has no active sheet",
            selected_by="terminal_job",
        )

    if state.current_sheet is not None:
        sheet = state.sheets.get(state.current_sheet)
        if sheet is None:
            return ActiveWorkSelection(
                sheet_num=state.current_sheet,
                reason=f"Sheet {state.current_sheet} reported as current without sheet state",
                selected_by="current_sheet_missing_state",
            )
        return ActiveWorkSelection(
            sheet_num=sheet.sheet_num,
            status=sheet.status,
            reason=_active_reason_for_sheet(sheet, selected_by="current_sheet"),
            selected_by="current_sheet",
            dispatch_blocked_reason=sheet.dispatch_blocked_reason,
            dispatch_blocked_details=sheet.dispatch_blocked_details,
        )

    for sheet in sorted(state.sheets.values(), key=lambda s: s.sheet_num):
        if sheet.status in ACTIVE_OR_BLOCKED_SHEET_STATUSES:
            return ActiveWorkSelection(
                sheet_num=sheet.sheet_num,
                status=sheet.status,
                reason=_active_reason_for_sheet(sheet, selected_by="fallback_status"),
                selected_by="fallback_status",
                dispatch_blocked_reason=sheet.dispatch_blocked_reason,
                dispatch_blocked_details=sheet.dispatch_blocked_details,
            )

    queued = [
        sheet.sheet_num
        for sheet in state.sheets.values()
        if sheet.status in QUEUED_SHEET_STATUSES
    ]
    if queued:
        noun = "sheets" if len(queued) != 1 else "sheet"
        return ActiveWorkSelection(
            reason=f"{len(queued)} queued {noun}; no active sheet reported",
            selected_by="queued_only",
        )

    return ActiveWorkSelection(
        reason="No current sheet reported",
        selected_by="no_current_sheet_reported",
    )

resolve_job_workspace

resolve_job_workspace(state, job_id)

Resolve workspace path from job state's worktree path.

Only works for worktree-isolated jobs. Non-isolated jobs do not store a workspace path in state, so this function will raise 404 for them.

Parameters:

Name Type Description Default
state CheckpointState

Loaded checkpoint state (must have worktree_path set).

required
job_id str

Job identifier (for error messages).

required

Returns:

Type Description
Path

Resolved workspace Path.

Raises:

Type Description
HTTPException

404 if no worktree_path is set on the state.

Source code in src/marianne/dashboard/routes/__init__.py
def resolve_job_workspace(state: CheckpointState, job_id: str) -> Path:
    """Resolve workspace path from job state's worktree path.

    Only works for worktree-isolated jobs. Non-isolated jobs do not store
    a workspace path in state, so this function will raise 404 for them.

    Args:
        state: Loaded checkpoint state (must have worktree_path set).
        job_id: Job identifier (for error messages).

    Returns:
        Resolved workspace Path.

    Raises:
        HTTPException: 404 if no worktree_path is set on the state.
    """
    if state.worktree_path:
        return Path(state.worktree_path)
    raise HTTPException(
        status_code=404,
        detail=f"No accessible workspace found for job {job_id}. "
               f"Job may not be using worktree isolation.",
    )

get_job_or_404 async

get_job_or_404(backend, job_id)

Load job state or raise 404 if not found.

Consolidates the repeated load→check→raise pattern used across multiple route handlers.

Parameters:

Name Type Description Default
backend StateBackend

State backend to load from.

required
job_id str

Job identifier.

required

Returns:

Type Description
CheckpointState

Loaded CheckpointState.

Raises:

Type Description
HTTPException

404 if job not found.

Source code in src/marianne/dashboard/routes/__init__.py
async def get_job_or_404(
    backend: StateBackend, job_id: str
) -> CheckpointState:
    """Load job state or raise 404 if not found.

    Consolidates the repeated load→check→raise pattern used
    across multiple route handlers.

    Args:
        backend: State backend to load from.
        job_id: Job identifier.

    Returns:
        Loaded CheckpointState.

    Raises:
        HTTPException: 404 if job not found.
    """
    state = await backend.load(job_id)
    if state is None:
        raise HTTPException(status_code=404, detail=f"Score not found: {job_id}")
    return state

list_jobs async

list_jobs(status=None, limit=50, backend=Depends(get_state_backend))

List all jobs with optional status filter.

Parameters:

Name Type Description Default
status JobStatus | None

Filter by job status (optional)

None
limit int

Maximum number of jobs to return

50
backend StateBackend

State backend (injected)

Depends(get_state_backend)

Returns:

Type Description
JobListResponse

List of job summaries

Source code in src/marianne/dashboard/routes/__init__.py
@router.get("/jobs", response_model=JobListResponse)
async def list_jobs(
    status: JobStatus | None = None,
    limit: int = 50,
    backend: StateBackend = Depends(get_state_backend),
) -> JobListResponse:
    """List all jobs with optional status filter.

    Args:
        status: Filter by job status (optional)
        limit: Maximum number of jobs to return
        backend: State backend (injected)

    Returns:
        List of job summaries
    """
    all_jobs = await backend.list_jobs()

    # Apply status filter
    if status is not None:
        all_jobs = [j for j in all_jobs if j.status == status]

    # Apply limit
    limited_jobs = all_jobs[:limit]
    summaries: list[JobSummary] = []
    is_partial = False
    data_sources: set[str] = set()
    for job in limited_jobs:
        metadata = _backend_dashboard_metadata(backend, job.job_id)
        job_is_partial = bool(metadata.get("is_partial", False))
        data_source = str(metadata.get("data_source") or "checkpoint")
        summaries.append(
            JobSummary.from_checkpoint(
                job,
                data_source=data_source,
                is_partial=job_is_partial,
            )
        )
        is_partial = is_partial or job_is_partial
        data_sources.add(data_source)

    return JobListResponse(
        jobs=summaries,
        total=len(all_jobs),
        is_partial=is_partial,
        data_source="mixed" if len(data_sources) > 1 else next(iter(data_sources), "checkpoint"),
    )

get_job async

get_job(job_id, backend=Depends(get_state_backend))

Get detailed information about a specific job.

Parameters:

Name Type Description Default
job_id str

Unique job identifier

required
backend StateBackend

State backend (injected)

Depends(get_state_backend)

Returns:

Type Description
JobDetail

Full job details

Raises:

Type Description
HTTPException

404 if job not found

Source code in src/marianne/dashboard/routes/__init__.py
@router.get("/jobs/{job_id}", response_model=JobDetail)
async def get_job(
    job_id: str,
    backend: StateBackend = Depends(get_state_backend),
) -> JobDetail:
    """Get detailed information about a specific job.

    Args:
        job_id: Unique job identifier
        backend: State backend (injected)

    Returns:
        Full job details

    Raises:
        HTTPException: 404 if job not found
    """
    state = await get_job_or_404(backend, job_id)
    return JobDetail.from_checkpoint(state)

get_job_status async

get_job_status(job_id, backend=Depends(get_state_backend))

Get focused status information for a job.

Lightweight endpoint for polling job progress.

Parameters:

Name Type Description Default
job_id str

Unique job identifier

required
backend StateBackend

State backend (injected)

Depends(get_state_backend)

Returns:

Type Description
JobStatusResponse

Job status summary

Raises:

Type Description
HTTPException

404 if job not found

Source code in src/marianne/dashboard/routes/__init__.py
@router.get("/jobs/{job_id}/status", response_model=JobStatusResponse)
async def get_job_status(
    job_id: str,
    backend: StateBackend = Depends(get_state_backend),
) -> JobStatusResponse:
    """Get focused status information for a job.

    Lightweight endpoint for polling job progress.

    Args:
        job_id: Unique job identifier
        backend: State backend (injected)

    Returns:
        Job status summary

    Raises:
        HTTPException: 404 if job not found
    """
    state = await get_job_or_404(backend, job_id)
    return JobStatusResponse.from_checkpoint(state)