H 4.11.  Nesting: parent and children

P A stage may run inside another stage of the same run: a step the
pipeline's code calls from within a step.  The receipt of such a step
MAY carry "parent", a string: the node id of the step that called it.
The caller's receipt MAY carry "children", an array of strings: the
node ids of the steps it called, in call order.  A node id is the
stage's "name", followed by "#" and the stage's instance where the
receipt's "stage" records one as "instance".  Both members are absent
at the top level and on a step that called nothing.

P Nesting records structure, not data.  A child's return that the
caller used in its own work is not recorded as one of the caller's
inputs.  Section 4.18 records the one thing a producer can observe at
the caller's end.

H 4.12.  The Close Receipt

P From minor 4, a producer ends every run with a close receipt, written
when the run closes, before its final manifest and before any
signature.  Its digest is the chain head, so a signature over the
chain head covers it.  It has:

B "stage.name" "onetrace.close", which the run declares as its last
stage, after its own stages;

B "instrument.id" "onetrace.close", "instrument.kind" "close", the
producer's own version, and "rederivable" "false";

B empty "inputs" and "outputs", and "outcome.class" "ok";

B in "assertions.constants", three members: "onetrace.closed", the
string "true"; "onetrace.steps", the number of receipts before it, as
a decimal string; and "onetrace.ended_by", exactly one of the five
forms below;

B no "effect_label" (Section 4.14), and, in a re-run, "rerun"
(Section 4.13), as every receipt of a re-run carries.

V      exit
V      unhandled exception: <class>
V      SIGTERM
V      re-run stopped before <node>: effect <value> (<basis>)
V      re-run stopped before <node>: effect not recorded

P "exit" says the producer's process exited normally, which a signal
handler of the pipeline's own can cause; it does not say that the
work ran to its end.  "SIGTERM" says the producer's own handler
received that signal.  The two "re-run stopped" forms are written by a
re-run stopped by the replay rule (Section 12.3), the second at a step
that has no effect label.  A run whose producer stops recording at a
bound of its own declares a boundary at the step that reached it
(Section 8) and closes with "exit": a bound is not a sixth form.

P The stage name "onetrace.close" and the instrument kind "close" are
reserved from minor 4: a producer refuses a stage of that name that it
did not write itself.  Constants whose names begin "onetrace." are
reserved for the producer's own: a producer refuses a stage's constant
of that form, and every comparison (Section 12.1) leaves them out of a
step's settings, so a run that closed one way reads the same as a run
of the same pipeline that closed another way.

P "onetrace.close" is declared, so no receipt before it can read
"complete": only the close receipt can, and only when every declared
stage emitted and no boundary stands.  A verifier reads completeness
off the last receipt, as before, and adds no rule for it.

P *The two-part rule.*  A receipt is a close receipt only when its own
"format" is "stage-receipt/0.4" or later and its instrument is
"onetrace.close" of kind "close".  Before minor 4 the name was not
reserved, so a record written under an earlier minor can hold an
ordinary stage named "onetrace.close", and such a receipt is read as
the step it is.  The same rule, with "onetrace.check" and "check",
identifies a check receipt (Section 4.20).  Every reader applies it:
verifiers and the operations of Section 12 alike.

P A run with no close receipt was stopped without closing, or was
written before minor 4.  Its chain verifies to its last receipt.  A
verifier MUST NOT fail a run for lacking a close receipt unless it is
asked to require one; it SHOULD report the absence as NOT RUN, naming
the last receipt the record holds.  The report cannot tell a stopped
run from an earlier one, and says only that the record holds no close.

P A verifier that implements minor 4 MUST fail a close receipt that is
not the last receipt of its chain, a second close receipt, an
"onetrace.steps" that is not the number of receipts before it, and an
"onetrace.ended_by" outside its five forms.

H 4.13.  The Re-run Mark: rerun

P A run that re-runs a recorded run carries the OPTIONAL object
"rerun" in every receipt, the producer's own receipts included, and a
copy in its manifest (Section 6).  Its members are strings, except
"substituted":

D kind: Exactly one of "twin" (a re-run under another run's recorded
configuration), "counterfactual" (a re-run with one step's output put
in place from another run), "reproduce" (a re-run of the run's own
steps), and "check" (the run a check produced, Section 4.20).

D of_run: The "run_id" of the run re-run.

D of_chain_head: That run's chain head.

D config_of_run, config_of_chain_head: The "run_id" and chain head of
the run whose configuration was used.  REQUIRED for "twin"; present
for "check" when the check ran under that run's configuration; absent
otherwise.

D substituted: REQUIRED for "counterfactual", absent otherwise.  An
object whose members are all strings: "step" (the node id
substituted), "from_run" and "from_chain_head" (the run its output
came from), "from_receipt" (the digest of that run's receipt at the
step), and "output" and "output_digest" (the name and digest of the
output put in place).

D writes_allowed: For "reproduce" only: "true" when the re-run was
asked to execute steps recorded as writing (Section 12.3), "false"
otherwise.

D from_stage: REQUIRED for "check", absent for every other kind: the
node id the check started from.

P The mark is in every receipt, under the chain, so a receipt read
alone shows it and a run cannot lose it without its chain being
re-linked.  The manifest's copy is read only where every receipt
carries the same "rerun": no digest covers the manifest's other
members, so the copy alone marks nothing.  A run whose receipts carry
no "rerun" is an original run as far as its record says.  A re-run is
never made a reference and is not counted as an original run.

P A verifier that implements minor 4 MUST fail a run whose receipts
disagree on "rerun", whose manifest copy disagrees with its receipts,
whose "kind" is outside the four, or that lacks a member its kind
requires, and a counterfactual whose substituted step's outputs do not
hold "substituted.output_digest".

H 4.14.  The Effect Label: effect_label

P "effect_label" is an OPTIONAL object on a step's receipt that says
whether running the step again would act on the world.  Its members
are "value", exactly one of "read", "write" or "unknown", and "basis",
what the label rests on, exactly one of "declared on the stage",
"model call", "model call stored by the provider", "http method",
"not classified", or "substituted, not executed".  A step whose output
a re-run put in place without executing it (Section 12.3) carries
"read" with the basis "substituted, not executed".

P An absent label and the value "unknown" are different states
(Section 11.3.3).  Absent says no label was recorded, as on every step
written before minor 4; "unknown" says the producer could not classify
the call.  A reader's words for an absent label are "effect not
recorded".  The receipts a producer writes for itself, such as the
close receipt, carry no label: they are never executed as steps.

P A label is a claim about the kind of call, not about the external
system's behaviour.  A replay reads "unknown" as "write", and reads a
receipt whose "effects" (Section 4.10) holds any entry as "write",
whatever its label.

P A verifier that implements minor 4 MUST fail an "effect_label.value"
outside its three values, and a receipt labelled "read" whose
"effects" holds an entry.

H 4.15.  Expectations

P "expectations" is an OPTIONAL array on a step's receipt, one entry
for each expectation the stage declared about its own output.  Each
entry is an object with the members "name" (unique in the step),
"kind" (exactly one of "range", "unit", "relation", or "member"),
"target" (the output's name and a JSON Pointer [RFC6901] into it, as
"return.json#/value"), "declaration" (the kind's own members, every one
a string, such as "lo", "hi", "unit", "of", "op" and "within"),
"declaration_digest" (the digest of "declaration" in canonical form),
and "declared" ("with the run").  Every bound is a decimal string and
is compared as a decimal.

P An expectation written after the run is never added to its
receipts.  It lives in a file of its own, outside this document, with
the same members and "declared" set to "after the run", and a report
names every row read from such a file as declared after the run.

P A verifier that implements minor 4 reports one row for each entry:
PASS, FAIL naming the value and the rule, or NOT RUN where the output
was not kept, the target names no value, or the value is not a
decimal.  It MUST fail an entry whose "declaration_digest" does not
recompute.

H 4.16.  Kept Configuration: config_kept

P "config_kept" is an OPTIONAL object on a step's receipt naming the
instrument's configuration, kept as the file
"config/<receipt stem>/config.json", beside the run's "artifacts/" and
never among its outputs: "name" ("config.json"), "digest" and "bytes".  The receipt stem is the receipt file's name without its ".json", for example "03-answer".  The kept file is the step's whole configuration in canonical
form, so its digest equals "instrument.config_digest".  A producer that
leaves keys out of the kept file adds "partial", the string "true", and
"digest" is then the digest of the bytes kept.

P A verifier that implements minor 4 checks the kept file's bytes
against "config_kept.digest" where the file is present.  It MUST fail a
receipt whose "config_kept.digest" is not equal to its
"instrument.config_digest" and that carries no "partial"; where
"partial" is "true", it reports that comparison as NOT RUN, with the
reason "configuration kept in part", and never fails it.  It MUST fail
a "partial" other than "true".

H 4.17.  Empty Outputs

P An artifact reference in "outputs" MAY carry "empty": "true" when the
producer wrote zero bytes or encoded no value (a null, an empty
string, an empty array or an empty object), "false" otherwise.  Absent
is not "false": it says the producer did not say.  A verifier that
implements minor 4 MUST fail any other value.

H 4.18.  Return Holds

P "return_holds" is an OPTIONAL array on the receipt of a step that
called other steps (Section 4.11).  Each entry is an object with "at"
(a JSON Pointer into the caller's return), "child" (the node id of a
step it called), "child_at" (a pointer into that child's return) and
"digest" (the digest of the held part in canonical form): the caller's
return holds, as the same object, that part of the child's return.
"[]" says the producer checked and found nothing held; absent says it
did not check.  A producer that writes the member writes it, "[]"
included, on every receipt whose step has children.  It records what
the producer observed, not that the caller used the value.

H 4.19.  Auto-Recorded Steps

P A producer MAY record steps it observed through a library's calls,
in place of steps the pipeline declared in its code.  Such a step's
receipt carries the OPTIONAL object "auto", whose members are
"declared", always "false"; "call", the library's public method name;
"library", the distribution's name; and, for an HTTP call, "target",
an object with "host", "method", "query_names" and exactly one of
"path_digest" (the digest of the request path, the default) or "path";
for a model call, "target", an object with "host" alone, the host the
model client's request went to; and, on a step recorded from a thread that did not carry the run's
context, "context", the string "thread without the run's context".  A
receipt without "auto" is a declared step, as every receipt written
before minor 4 is.

P A run the producer opens itself to hold such steps is an
auto-recorded run.  Its manifest carries the OPTIONAL object "auto":
"boundary" ("process" or "request"), "key" (what keyed a run per
request), and "hooks", an array of objects with "library", "status" and
"version", where "version" is present only when the entry's "status" is
"hooked".  Every auto-recorded run declares a boundary when it opens,
over the steps outside the libraries observed, of "kind" "not
observed", its "note" naming those steps, so its coverage never reads
"complete" (Section 8).

P A run the pipeline declared in its code MAY also hold such steps, at
its top level or as children of its own steps.  It is not an
auto-recorded run: its manifest carries no "auto", it declares no
boundary for them, and it keeps its own declared coverage, so its close
receipt can read "complete".  It gains each such step's stage name in
"declared_stages" (Section 8) the first time a step of that stage is
recorded, before its last declared stage; no name is removed or
reordered.  Each receipt's "declared_stages" is the list as known when
the receipt was written, so an earlier receipt may list fewer names
than a later one, and the close receipt's list is the run's whole list.

P A step recorded from an HTTP call has two outputs: "status", the
canonical JSON object {"status": "<code>"}, and "response", the
response body's bytes.  A call that followed redirects is one step,
whose "status" is the final response's and whose "response" is the
final body; a producer MAY add the number of hops to "status", as
{"redirects": "<n>", "status": "<code>"}.  A streamed response has
"status" alone.  A status that
differs is thus an output that differs, whatever the body.

P What an auto-recorded step did not observe or did not write is said
in constants of the producer's own (Section 4.12), which every
comparison leaves out of a step's settings: "onetrace.http.body",
"not observed: streamed", where the response was streamed and there is
no "response" output; "onetrace.http.request", "not observed:
streamed", where the request body was streamed and there is no
"request" input, or "not observed: the text cannot be encoded as it
will be sent", where the body's text cannot be encoded as the library
will send it; and "onetrace.model_call", "not written: the hook did
not see the client's request" or "not written: embeddings have no
record format in this release", where a model step wrote no model-call
record.

P An auto-recorded step always carries "effect_label" (Section 4.14).
A verifier that implements minor 4 MUST fail an "auto.declared" other
than "false", an "auto.context" other than "thread without the run's
context", and a receipt with "auto" and no "effect_label"; it checks
that the label's basis is one the producer documents for that library.
It checks that an auto-recorded run holding a receipt with "auto" has
the manifest's "auto" and the boundary, and it knows an auto-recorded
run by either: the manifest's "auto", or that boundary in the manifest
or in any receipt's coverage.  It makes no claim about an auto-recorded
run rewritten without both and re-linked, which reads as a run declared
in code, nor about a run declared in code that declares that boundary
itself, which reads as an auto-recorded run.  Within one chain, a later
receipt's "declared_stages" MAY hold more names than an earlier
receipt's only where each added name is the stage of a receipt with
"auto" in the chain, and every earlier name keeps its place; a verifier
MUST fail a removal, a reorder, or any other added name.

H 4.20.  Check Runs

P A check run records one check a tool ran against two recorded runs.
It has one declared stage, "onetrace.check", whose instrument is
"onetrace.check" of kind "check", and the close receipt.  What the
check ran and what came back are ordinary constants and assertions of
that receipt: the constants "verb", "argv", "runner_digest",
"rerun_plan" (for "reproduce" only), "timeout_seconds", "baseline",
"candidate", "stage", "claim" and "predicted", and the assertions
"exit", "result" and "came_back", which reads "as predicted",
"otherwise", or "did not run: " followed by the reason.  The stage name and the instrument kind are reserved
from minor 4, and a check receipt is identified by the two-part rule of
Section 4.12.  The run a check produced by re-running a stage carries
"rerun" of kind "check" (Section 4.13).

P A check run's constants can hold local paths, and its outputs a
command's output.  The rule of Section 7 on secrets covers them as it
covers any record.
