Skip to content

The cause document and the beat

gitlab.com/phpboyscout/go/dispatch/appcause holds the two things a launcher inside the job, such as go/launch, writes for the adapter to read: the cause document dispatch.app-cause.v1, which says why the payload ended, and the beat launch.beat.v1, which says it is still alive. It has their types, strict decoders and writers, and Refine, the one rule by which a document refines the scheduler's cause. It imports the standard library and model only, so the writer and the readers share one definition.

Both schemas are fixed from this release: a change to their members is a new schema name.

The document

One JSON object, at most appcause.MaxSize (2048) bytes encoded:

{
  "schema": "dispatch.app-cause.v1",
  "phase": "ended",
  "kind": "collective-failed",
  "class": "collective-failed",
  "summary": "rank 13 on gpu03: ncclRemoteError … (first of 16 ranks to fail)",
  "at": "2026-11-02T03:12:44Z",
  "attempt": "3.48121.1",
  "epoch": "3000001",
  "node": "gpu03",
  "nodeRank": 1,
  "exitCode": 1,
  "lastStep": 4180,
  "heartbeat": "on",
  "gpu": "nvml",
  "evidence": [{"source": "nccl", "rank": 13, "line": "…ncclRemoteError: A call failed …"}],
  "faults": [{"gpu": "GPU-6c1e…", "xid": [79]}]
}
Member Type and bound Required
schema dispatch.app-cause.v1 always
phase started, signalled, ended always
kind none, non-zero-exit, hung, collective-failed, gpu-fault, gpu-out-of-memory at ended; optional before
class non-zero-exit takes exception, signalled, launch-error or unclassified; each of the other four kinds takes its own name; none takes none with kind, except none
summary at most 384 bytes, no control characters no
at RFC 3339: when the finding was first seen, or when the phase was written always
attempt the execution's DISPATCH_ATTEMPT: 1 to 64 bytes, no control characters always
epoch the execution's DISPATCH_EPOCH: 1 to 20 decimal digits, as a string always
node 1 to 255 bytes, no control characters no
nodeRank ≥ 0 no
exitCode 0 to 255, torchrun's exit status at ended
lastStep ≥ 0 no
lastPhase, lastBeatAt the beat's phase, and RFC 3339 both or neither, and only with class hung
heartbeat on, or off without a heartbeat section always
gpu nvml, absent, not-built, or off for gpu.health: off always
signal at RFC 3339, checkpointStep ≥ 0 at signalled, and with class signalled
evidence at most 3 entries, oldest first; source one of error-json, nccl, stderr, nvml; line at most 256 bytes, no control characters; rank ≥ 0 no
faults at most 2 entries; gpu 1 to 64 bytes, no control characters; xid at most 8, each ≥ 0 no

Document.Kind is an appcause.Kind, a string, never a dispatch.CauseKind, so a kind this build's model doesn't name still decodes and re-encodes. Document.Cause() maps the kind to the CauseKind this build defines: none and non-zero-exit today. It returns false for the other four, and never returns a kind for which Valid is false. A document left at started or signalled means the launcher itself was killed before it finished.

Decode

appcause.Decode(b) reads one document in five steps, each refusal wrapping dispatch.ErrInvalid:

  1. Size. Over 2048 bytes is ErrTooLarge, before any parse. Exactly 2048 decodes.
  2. Schema. schema is read alone. Any other value, a non-string or none is ErrSchema, naming what it found.
  3. Strict decode. An unknown member at any level, a case-folded name, a duplicate, trailing data or invalid UTF-8 is ErrMalformed.
  4. Values. A member outside its bound or enumeration is ErrMalformed, naming the member. A control character in any string member is outside its bound, because summary reaches Cause.Detail and from there a terminal. A control character here means either:
  5. one unicode.IsControl reports: C0, DEL and C1, so an ANSI escape, a newline or a tab;
  6. a bidi control (unicode.Bidi_Control: U+061C, U+200E and U+200F, U+202A to U+202E, U+2066 to U+2069), which reorders what a terminal shows. U+202E can make a line read backwards.
  7. Consistency. Members that contradict each other are ErrInconsistent, naming the pair: kind none with a non-zero exitCode or with signal; a class without a kind, or that doesn't belong to its kind; a kind other than none without a class; ended without kind or exitCode; signalled, or class signalled, without signal; lastPhase without lastBeatAt or the reverse, or either with a class other than hung.

The decoded document's times are in UTC. There is no JSON Schema file: the typed decoder is the schema.

Encode and WriteFile

appcause.Encode(d, redact) writes a document as the launcher does:

  1. every string member goes through redact first; a nil redact is ErrInvalid, so pass an identity function where nothing needs redacting;
  2. each control character in summary, node, an evidence line or a fault's gpu is written as a space, so stderr the launcher quotes never fails its write. Invalid UTF-8 is left for step 4 to refuse;
  3. summary is cut to 384 bytes and each evidence line to 256, at a rune boundary; the newest three evidence entries, the first two faults and the first eight Xids of each are kept;
  4. the result is checked as Decode checks it, so a control character in attempt or lastPhase is ErrMalformed;
  5. while the encoding exceeds 2048 bytes, the oldest evidence entry is dropped, then the second fault, then summary is halved. Without a control character no member escapes to more than twice its size, so what the fit keeps always fits and Encode does not return ErrTooLarge.

Decode(Encode(d)) returns d for a document whose times are in UTC and whose free text holds no control character.

appcause.WriteFile(path, b) writes in place: open with truncate, one write, fsync, close. Not by rename, because on Kubeflow the path is the container's termination-message file, a mount point a rename fails on.

The beat

{"schema":"launch.beat.v1","seq":41,"step":4180,"phase":"train","nodes":4,"staleAfter":120}
Member Bound
schema launch.beat.v1
seq ≥ 1, rising on every write
step ≥ 0
phase 1 to 64 bytes, no control characters
nodes ≥ 0
staleAfter whole seconds, 1 to 3600

appcause.DecodeBeat(b) takes the same steps as Decode, bounded by MaxBeatSize (512 bytes). appcause.ParseBeatLine(line) decodes a Kubeflow log line starting LAUNCH-BEAT (appcause.BeatLinePrefix) and returns false for any other line. appcause.EncodeBeat(b) refuses what DecodeBeat would.

Refine

appcause.Refine(sched, exec, doc, found) takes the scheduler's cause, the execution, the bytes the adapter read (up to 2049, so it can say a document is too large) and whether a document was found. It returns the cause to report, the decoded document, and whether the document was used. The cause keeps the scheduler's provenance, exit code and time, and its kind is always one this build defines.

The document is used when it decodes at ended, agrees with the scheduler, and its attempt is the execution's Token. In the table, D is the scheduler's own Detail, and <c>: <s> the document's class and summary (just <c> when it has no summary):

Scheduler cause Document Kind reported Detail Used
NonZeroExit a kind this build defines, not none the document's launch <c>: <s>; D yes
NonZeroExit hung, collective-failed, gpu-fault or gpu-out-of-memory where this build doesn't define it NonZeroExit launch <c>: <s>; D yes
NonZeroExit or OutOfMemory kind none unchanged D; launch document says none against a scheduler failure no
OutOfMemory any other kind OutOfMemory launch <c>: <s>; D yes
None not read: a success isn't refined None D no
any other (Preempted, NodeLost, TimeLimit, Cancelled, …) any unchanged D; launch <c>: <s>, with none for <c> under kind none yes
any none found unchanged D no
any refused unchanged D; launch document <reason> no
any used, with an empty Token as above as above, then ; launch attempt unchecked yes

The reasons a document is refused are over 2048 bytes, of schema "<name>" (or of no schema), does not decode: <error>, left at <phase>: the launcher did not finish, inconsistent: <pair>, and of another execution <attempt>. When D is empty its separator is dropped.

Progress

An adapter that reads the beat implements dispatch.ProgressReader:

type ProgressReader interface {
    Progress(ctx context.Context, ref ObjectRef) (Progress, error)
}

type Progress struct {
    Step   int       // the beat's step
    Phase  string    // the beat's phase
    Seen   time.Time // the adapter's clock: when it last saw seq change; zero with no beat
    Stale  bool      // the beat hasn't changed for its staleAfter while the object runs; only while Judged
    Judged bool      // the adapter has held a reading of the object for at least staleAfter
}

Staleness is judged on the adapter's own clock, never on a time written on a compute node. An adapter judges nothing until it has held a reading of the object's beat for the beat's staleAfter, so a restarted one, or a one-shot reader, answers Judged false at first. Nor does it judge while the scheduler has the object suspended. An object that isn't running answers its last beat, never stale.

Case Answer
an object the adapter can't find ErrNotFound
the object exists, no beat seen a zero Progress and no error: no evidence of anything
a beat that doesn't decode ErrInvalid, wrapping the appcause refusal; never Stale
the scheduler can't be reached ErrUnreachable, as for Inspect
a read-only Backend works

Progress is never recorded, is no Status field, and is no evidence for any state or cause. Read it through a cluster's Observer, as in read a running job's progress.