Skip to content

remote_termination

Normalized job-termination classification: value set and rendering.

When a remote job dies, why it died (Spot reclamation, OOM, timeout, node failure, ...) is a fact the backend knows with varying certainty. snakesee does not classify terminations itself — that happens upstream (the executor, which has the cloud context) and arrives on the event as a structured triple:

termination_category   — what kind of death (this module's TERM_* values)
termination_source     — where the classification came from (provenance)
termination_confidence — how sure the producer was (high / low)

snakesee's only job is to render that classification honestly: a high-confidence classification is stated firmly, a low-confidence (heuristic) one is phrased tentatively, so the UI never asserts something a lower layer merely guessed.

This module is the reader-side half of the contract; the executor defines the same value strings independently (the two packages can't share code).

Functions:

format_termination_marker

format_termination_marker(category: str | None, confidence: str | None) -> str | None

Render a one-line termination marker, phrased by confidence.

Parameters:

Name Type Description Default
category str | None

The termination category (a TERM_* value, or a forward-compat string). None or TERM_UNKNOWN yields no marker.

required
confidence str | None

CONFIDENCE_HIGH renders a firm marker; anything else (including None) renders a tentative one.

required

Returns:

Type Description
str | None

A marker string, or None when there is nothing meaningful to assert.

Source code in snakesee/remote_termination.py
def format_termination_marker(category: str | None, confidence: str | None) -> str | None:
    """Render a one-line termination marker, phrased by confidence.

    Args:
        category: The termination category (a TERM_* value, or a forward-compat
            string). None or TERM_UNKNOWN yields no marker.
        confidence: CONFIDENCE_HIGH renders a firm marker; anything else
            (including None) renders a tentative one.

    Returns:
        A marker string, or None when there is nothing meaningful to assert.
    """
    if not category or category == TERM_UNKNOWN:
        return None
    label = _CATEGORY_LABELS.get(category, category.replace("_", " "))
    if confidence == CONFIDENCE_HIGH:
        return f"⚠ {label}"
    return f"possibly {label}"

format_termination_source

format_termination_source(source: str | None) -> str | None

Render the provenance of a termination classification as a "via ..." phrase.

Parameters:

Name Type Description Default
source str | None

The classification provenance (a SOURCE_* value, or a forward-compat string). None or empty yields no phrase, so a missing source can't render a dangling "via ".

required

Returns:

Type Description
str | None

A "via " string, or None when there is no source to attribute.

Source code in snakesee/remote_termination.py
def format_termination_source(source: str | None) -> str | None:
    """Render the provenance of a termination classification as a "via ..." phrase.

    Args:
        source: The classification provenance (a SOURCE_* value, or a
            forward-compat string). None or empty yields no phrase, so a
            missing source can't render a dangling "via ".

    Returns:
        A "via <source label>" string, or None when there is no source to attribute.
    """
    if not source:
        return None
    return f"via {_SOURCE_LABELS.get(source, source.replace('_', ' '))}"