Endings

Ending describes every ending; ExitCase describes what a frame can observe. A panic runs no release, so the latter is not an Ending projection. Lifetime and failure are independent obligations. A loose worker’s ending is its own, not an implicit failure of the run or session that started it.

The type and its projections

Ending<V, F, S> = Ok(V) | Err(F) | Exited(u8) | Stopped(S) | Panic(String)
End              = Ending<Value, Error, Stop>
Done             = Ending<(), ErrorRecord, CancelCause>
protocol::Ending = Ending<FOValue, ErrorFact, CancelCause>
ExitCase<F>      = Ok | Err(F) | Exited(u8) | Stopped(CancelCause)

guard’s release reads ExitCase<ErrorRecord>: no success value, no panic. It shares Ending’s tag table and four payload types; a unit test pins its closed type to Done::ty() without panic. The machine constructs it once from the borrowed body outcome and saves the outcome to restore after release. Observation cannot consume that outcome (a-guard-acquires).

  • Stop { cause, owner: Option<ScopeId>, at: Option<Prov> } retains the scope that may consume a stop and the location it unwound through. Errors and stops stay distinct because observers consume them differently.
  • Settled<T> = Result<T, Break> remains the machine’s currency in flight, not another ending. End::into_settled returns or raises; a panic resumes its unwind. Ending::outcome separates the ok/err half from the halts, typed Ending<Infallible, Infallible, S>; widen embeds them back.
  • One tag table names ok, err, exited, stopped, panic for data and checker labels; serde gives the corresponding kebab-case variant names.
  • A caught run panic is Ran { ending: Panic(text), … }, status 101 (PANIC_CODE), with the checkpoint restored and capture and trail discarded. Report::Faulted means only that the report was lost: what ran is unknown.
  • The wire error is the ErrorFact ({frame, reason, site}, a total site), serialized through its first-order encoding with the typed reason. Done carries its projection, the ErrorRecord a program reads: [frame, message, status, site], with message and status derived from the reason. A non-data result (handle, block or function) becomes Err, code 1, completed from the run’s retained base and rendered with its reason-derived advice. Exarch’s exit tip reads the wire fact’s reason().
  • Report::Ran(Ran { ending, rendered, single_command, captured, trail }) holds rendering and run context outside the cases; hosts pass the Ran whole. Ok has no redundant status; command-exit wording is derived.

Who consumes what

Observerokerrexitedstoppedpanic
Run top (End)valueerrorbyteStoptext
Wire endingFOValue or boundary errrecordbytecausetext
poll’s ready.outcomedatarecord, including a converted own stopre-raiseforeign: re-raiseresume unwind
audit Bdatarecordpass, drop trailpass, drop trailunwind
guard release (ExitCase)Unitrecordbytecauseno release
await, race winner, brood joinreturnraiseraiseraiseresume unwind
first-settled, is-donedo not inspect endingsamesamesamesame
Worker done, workers row (Done)Unitrecordbytecausetext
Batch --auditvaluerecordbytecausetext
Batch resultsilent, 0rendered, failure codesilent, chosen coderendered, cause coderendered, 101
Batch loose-worker donesilentsilentsilentsilentsilent
Last returning run’s loose-worker joindropdropdropdropdrop
REPL lineprint valuerenderedend sessionrenderedrendered
REPL loose-worker donenext-prompt claim gate, Done::saidsamesamesamesame
Bootsettled settings or capabilities-refused diagnostic (host exit 2)rc failure: rendered, derived codecoderendered, coderendered, 101
Exarch tool resultVALUE, 0rendered; exit tip iff reason is a process Exitedchosen coderendered; timeout tip iff TimedOutrendered + panic tip
Exarch loose-worker doneadmission claim gate: card and wake togethersamesamesamesame
Synod Display::Doneunnarratedsamesamesamesame
Pipeline collectorlast valueranked verdicttear siblings down, rankforgive by stage name; foreign: tear down, ranktear down, resume at fold

A worker base converts an in-session Cancelled/TimedOut stop to its own error before these observations; foreign stops remain escapes (delimiters-are-handlers-for-poll). The REPL hook Outcome remains a host coarsening of reports and transport loss, not a parallel ending: it folds errors, panics and lost reports into its hook-fault policy.

One rendering, one status

End::render supplies the diagnostic; hosts print it verbatim. One private Diagnosis feeds one renderer, borrowing the session’s ExitHints, with error and stop constructors supplying fields rather than constructing an error just to draw a stop. Ok, Exited and reader-gone stops draw nothing; Err and other stops draw carets or compact reports; Panic draws spanless run panicked: ….

A failure that reports success is unrepresentable. Two traits split the family by whether success is in range. FailureCode::failure_code(&self) -> NonZeroU8 belongs to what can only fail: CancelCause, Stop, Failure, Reason, Error, ErrorFact, ErrorRecord. ExitCode::code(&self) -> u8 belongs to what may succeed: an Ending (0, the failure’s code, the chosen exit byte, the cause’s code, or 101) and a Break. Report::code delegates for Ran and reads the nonzero status of Static/Faulted. The process edge is std::process::ExitCode::from(u8).

Integer doorRule
External failureretain raw i32 in Failure::Exited; failure_byte clamps into 1..=255 when deriving the failure code
exit nrefuse outside 0..=255
fail mString, reason Raised(Claim { m, 1 }), code 1
raise eany record is a Claim with its own frame, message, status and site, refused at status 0 and above 255
  • The clamp’s floor is 1, not 0: Windows NTSTATUS read as i32 may be negative, and a failed command must not become success. Failure::Exited keeps its raw i32 for the message and the denial/limit hints; those hints read the raw reason, never code.
  • One failure-code table lives on Reason. Error, ErrorFact and process failures delegate to it (ErrorRecord stores its status), process through Failure: exited clamps, signaled gives 128+s, not-found 127, not-runnable 126, timed-out 124, cancelled 143, raised its claim’s status (1 for fail). Typed operational families (denied, io, invalid, evaluation, state, compile, launch, protocol, host) and invariant also give 1. Reason::stopped maps the two causes a worker converts, Cancelled and TimedOut, onto their reasons, so a converted stop takes its code and words from the table. A panic belongs to the ending, code 101.
  • Stored host rejection statuses (Rejection.status, Report::Static and Faulted) remain NonZeroU8. A desk refusal retains its typed Reason, with no status field; WireError carries it separately from report context and ordered stored hints. Serde and data’s NonZeroU8 decoder refuse 0; data’s u8 decoder refuses integers outside 0..=255. Neither is another clamp.
  • exited n is an ending (the computation ran exit n) and, separately, a Failure of a process (process [.., failure: exited n]); it is not itself a Reason. See the error record.
  • Command-audit fact::Command.status is u8, since a command can succeed; the two command-audit observers read Break’s code.
  • Signal handlers call failure_code without allocation or locking, widening only at _exit/ExitProcess. Failure::Signaled projects 128 + n through failure_byte; Signal::of_status decodes a status to a signal only where a supervisor left no word (the-ending-is-amended-where-it-is-reaped). The utility subprocess’s own i32 clamp in core/src/uutils.rs is outside the shell ending family and is unchanged.

Unit and the two encodings

A Unit variant payload is absent. It is enforced at the two doors: datum::tag (and Value::variant) writes it absent, and datum::untag, the one read door, reads an explicit Unit as absent. Nullary decoders therefore match absence alone; payload decoders read absence as Unit. Other payloads still must match their type. No decoder, Ending’s included, needs a Unit special case.

  • Wire: generic serde is externally tagged in kebab-case: {"exited":3}, {"stopped":"timed-out"}. Ending<(), …>::Ok(()) serializes as {"ok":null}; the actual protocol alias carries FOValue, so its Unit result is {"ok":"unit"}. An error carries the record.
  • Data: Datum gives payload-less `ok, `err record, `exited 3, `stopped cause and `panic text. Display::Done stores core Done through data::datum::as_datum: serialize the encoded FOValue, deserialize then Done::decode. For example its Unit outcome is {"variant":{"label":"ok","payload":null}}, not serde’s {"ok":null}.
  • Batch --audit projects the whole wire ending with map and Datum, without re-decoding a record or inventing a fallback. Its legible JSON is a separate presentation: {"tag":"exited","payload":3} and {"tag":"ok"} for Unit. audit B still hands over only ok/err.

No reader decodes one ending encoding as the other. Old wire and session-record shapes need not decode; no compatibility is owed.

Three lifetimes

WorkDoes its failure count?When it stops
Brood: a gather or worker body’s childrenyes (I4)owner joins on return, cancels and drains on halt
Loose session spawn/watchonly explicit await, race or poll observes itreturning batch waits; halting session takes it down
External detachnooutlives the session

Lifetime ⟂ failure. Run.last puts the session’s wait inside the run’s frame, before its closing poll. Only a returning body enters it. outlive uses claim_first and replay, not a second wait loop: claim still-unclaimed session workers in birth order, write stdout then stderr, drop all five endings. The script retains its own value and status. Cancellation during the wait or a replay failure can still halt the run.

Taking workers down on return makes spawn { write-report }; echo done a timing race with silent data loss. Waiting gives the written program a stable lifetime without making its independent workers an implicit success condition. A batch worker failure emits no failure notice or diagnostic and never changes the run’s status; its written bytes are replayed. Halts (exit, uncaught failure, stop, panic) skip the wait; session teardown takes workers down silently in batch. REPL quit keeps its existing taking-down line. Exarch session end is also a halt.

The cost is explicit: a forgotten spawn { serve } holds a returning script open. Cancel work no longer needed, use exit or Ctrl-C to halt, or use Unix detach for an external meant to outlive the session. A ral block has no outlive form.

A notice observes claim state, not future intent

WorkerState::unclaimed is Running | Ready(_). Stopping is claimed; a consumed worker has no row, so absence also means claimed. An announcing host requires a present unclaimed row when it observes the notice; the one gate is DoneEvent::unclaimed_in(&rows):

  • REPL holds DoneEvents until Session::iterate reaches the next prompt (not inside prompt rendering), probes once, then prints one faint note: worker #id (title) … per still-unclaimed result. A failed probe announces nothing.
  • Exarch gates at batch admission: only an unclaimed result gets both the Display::Done card and the model wake. A failed probe announces nothing. Other surfaced values replay even when the done is suppressed.
  • Batch, -c and stdin scripts silently consume done; they announce none.

A claim before that check suppresses the announcement. A later await cannot retract an announcement already made at an earlier prompt or admission. Done::parts/said supplies every host’s words: returned, failed: … (the record’s message), ran `exit 3` , the cause’s message, or panicked: …. A worker is not a process; its failure is not worded exit N.

Shapes not taken

  • A concrete engine enum plus host enums, or Settled plus panic everywhere: parallel copies survive; three payload parameters are sufficient.
  • Convert every stop to an error record: foreign stops would become data to try or poll, erasing the consumption boundary.
  • A sixth wire-only non-data case: failure at the boundary is err.
  • Rendering inside each case, duplicate command-exit flags or an always-zero success status: these are run context or derivable facts.
  • Batch exit ↦ ok (), or treating panic as no ending: the report lies.
  • Replay every completion card but gate only the wake: a claimed result is still spuriously announced.
  • A second dispatch for work that outlives its run: its report would need merging; the wait and its bytes, cancellation and trail belong inside the last run.
  • A status newtype for the entire family: success is in range for an ending and out of range for a failure, so u8 and NonZeroU8 behind two traits, not one type. Keep no inherent or const code; enum matching is signal-safe without it.
  • A separate wire Failure { record, status }: it stores the status twice and re-decodes the record to read its reason.
  • Accept an explicit Unit payload in each nullary decoder: thirty copies of one rule; untag is the door.
  • Clamp exit: silently changes a chosen number. Its door refuses. fail takes text, not a number; raise reports the record’s claim.

Where

The code is mapped in engine-protocol, a run, end to end, a-worker-ends-with-its-children, cards and docs/SPEC.md §8, §11, §13.4, §16.3.