G1, D0: seat readers decode tolerantly and say their form

The seat generator gives every value, event and answer the wire field form
(left out while 1) and a tolerant decoder answering the form it read; each
contract carries its forms and a digest of its fields, and the compare fails
a definition whose fields changed while its form did not. Every delivery seat
is regenerated, and the readers take the form.

Builds: design 47 H2 §780; H-A-352
This commit is contained in:
2026-11-21 23:11:10 +01:00
parent 2df32b7892
commit ff7db33720
56 changed files with 3659 additions and 946 deletions
@@ -4,9 +4,7 @@
package nodebuildnode
import (
"bytes"
"encoding/json"
"errors"
"strings"
"time"
)
@@ -14,6 +12,20 @@ import (
// Seat is the seat's name.
const Seat = "node-build-node"
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
// a reader of a value of another form says "form N, this reader knows M".
const Form = 1
// FormBuildStep is the form of what the part build-step adds.
const FormBuildStep = 1
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
// whose fields changed while its forms did not (design 47 H2 §780).
const (
generatedForms = "1 build-step:1"
generatedFieldsDigest = "3c8081a3209e1638ad3cd1a0a3abe1ae979347bb22e7f0c35a2cc132df7e21b4"
)
const (
VerbCurrent = "current"
VerbPause = "pause"
@@ -140,18 +152,13 @@ func ParseStepsByAskerNodeIDKey(key string) (string, string, string, bool) {
return v0, v2, v4, true
}
// DecodeStepsByAskerNodeIDValue reads one value of the state steps under the form "<asker>.<node>.<id>", refusing a field StepsByAskerNodeIDValue does not know and any text after the value.
func DecodeStepsByAskerNodeIDValue(raw []byte) (StepsByAskerNodeIDValue, error) {
// DecodeStepsByAskerNodeIDValue reads one value of the state steps under the form "<asker>.<node>.<id>" as another part wrote it: a field StepsByAskerNodeIDValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeStepsByAskerNodeIDValue(raw []byte) (StepsByAskerNodeIDValue, int, error) {
var v StepsByAskerNodeIDValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
return v, formRead(raw), nil
}
// StepsByNodeIDKey is the key of one value of the state steps under the form "<node>.<id>".
@@ -176,18 +183,13 @@ func ParseStepsByNodeIDKey(key string) (string, string, bool) {
return v0, v2, true
}
// DecodeStepsByNodeIDValue reads one value of the state steps under the form "<node>.<id>", refusing a field StepsByNodeIDValue does not know and any text after the value.
func DecodeStepsByNodeIDValue(raw []byte) (StepsByNodeIDValue, error) {
// DecodeStepsByNodeIDValue reads one value of the state steps under the form "<node>.<id>" as another part wrote it: a field StepsByNodeIDValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeStepsByNodeIDValue(raw []byte) (StepsByNodeIDValue, int, error) {
var v StepsByNodeIDValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
return v, formRead(raw), nil
}
// PausesByPausedNodeKey is the key of one value of the state pauses under the form "paused.<node>".
@@ -211,18 +213,13 @@ func ParsePausesByPausedNodeKey(key string) (string, bool) {
return v1, true
}
// DecodePausesByPausedNodeValue reads one value of the state pauses under the form "paused.<node>", refusing a field PausesByPausedNodeValue does not know and any text after the value.
func DecodePausesByPausedNodeValue(raw []byte) (PausesByPausedNodeValue, error) {
// DecodePausesByPausedNodeValue reads one value of the state pauses under the form "paused.<node>" as another part wrote it: a field PausesByPausedNodeValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodePausesByPausedNodeValue(raw []byte) (PausesByPausedNodeValue, int, error) {
var v PausesByPausedNodeValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
return v, formRead(raw), nil
}
// PausesByDroppedIDKey is the key of one value of the state pauses under the form "dropped.<id>".
@@ -246,18 +243,13 @@ func ParsePausesByDroppedIDKey(key string) (string, bool) {
return v1, true
}
// DecodePausesByDroppedIDValue reads one value of the state pauses under the form "dropped.<id>", refusing a field PausesByDroppedIDValue does not know and any text after the value.
func DecodePausesByDroppedIDValue(raw []byte) (PausesByDroppedIDValue, error) {
// DecodePausesByDroppedIDValue reads one value of the state pauses under the form "dropped.<id>" as another part wrote it: a field PausesByDroppedIDValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodePausesByDroppedIDValue(raw []byte) (PausesByDroppedIDValue, int, error) {
var v PausesByDroppedIDValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
return v, formRead(raw), nil
}
// PausesByCapacityNodeKey is the key of one value of the state pauses under the form "capacity.<node>".
@@ -281,18 +273,13 @@ func ParsePausesByCapacityNodeKey(key string) (string, bool) {
return v1, true
}
// DecodePausesByCapacityNodeValue reads one value of the state pauses under the form "capacity.<node>", refusing a field PausesByCapacityNodeValue does not know and any text after the value.
func DecodePausesByCapacityNodeValue(raw []byte) (PausesByCapacityNodeValue, error) {
// DecodePausesByCapacityNodeValue reads one value of the state pauses under the form "capacity.<node>" as another part wrote it: a field PausesByCapacityNodeValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodePausesByCapacityNodeValue(raw []byte) (PausesByCapacityNodeValue, int, error) {
var v PausesByCapacityNodeValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
return v, formRead(raw), nil
}
// ToolchainsByNodeLanguageKey is the key of one value of the state toolchains under the form "<node>.<language>".
@@ -317,18 +304,13 @@ func ParseToolchainsByNodeLanguageKey(key string) (string, string, bool) {
return v0, v2, true
}
// DecodeToolchainsByNodeLanguageValue reads one value of the state toolchains under the form "<node>.<language>", refusing a field ToolchainsByNodeLanguageValue does not know and any text after the value.
func DecodeToolchainsByNodeLanguageValue(raw []byte) (ToolchainsByNodeLanguageValue, error) {
// DecodeToolchainsByNodeLanguageValue reads one value of the state toolchains under the form "<node>.<language>" as another part wrote it: a field ToolchainsByNodeLanguageValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeToolchainsByNodeLanguageValue(raw []byte) (ToolchainsByNodeLanguageValue, int, error) {
var v ToolchainsByNodeLanguageValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
return v, formRead(raw), nil
}
// DetectedStepsByModuleArtifactKey is the key of one value of the state detected-steps under the form "<module>.<artifact>".
@@ -353,18 +335,13 @@ func ParseDetectedStepsByModuleArtifactKey(key string) (string, string, bool) {
return v0, v2, true
}
// DecodeDetectedStepsByModuleArtifactValue reads one value of the state detected-steps under the form "<module>.<artifact>", refusing a field DetectedStepsByModuleArtifactValue does not know and any text after the value.
func DecodeDetectedStepsByModuleArtifactValue(raw []byte) (DetectedStepsByModuleArtifactValue, error) {
// DecodeDetectedStepsByModuleArtifactValue reads one value of the state detected-steps under the form "<module>.<artifact>" as another part wrote it: a field DetectedStepsByModuleArtifactValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeDetectedStepsByModuleArtifactValue(raw []byte) (DetectedStepsByModuleArtifactValue, int, error) {
var v DetectedStepsByModuleArtifactValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
return v, formRead(raw), nil
}
// AskArtifact is one artifact of a build ask: built from the fetched tree, or copied from an upstream pin.
@@ -381,6 +358,8 @@ type AskTaken struct {
Ask string `json:"ask"`
Asker string `json:"asker"`
At time.Time `json:"at"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
// the node that took it, as in the subject
Node string `json:"node"`
}
@@ -423,10 +402,12 @@ type Capacity struct {
ConfiguredFrom string `json:"configured-from,omitempty"`
CoresPerStep float64 `json:"cores-per-step,omitempty"`
Effective int64 `json:"effective"`
Ineligible string `json:"ineligible,omitempty"`
OutsideHours bool `json:"outside-hours,omitempty"`
QuotaCores float64 `json:"quota-cores,omitempty"`
QuotaFrom string `json:"quota-from,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
Ineligible string `json:"ineligible,omitempty"`
OutsideHours bool `json:"outside-hours,omitempty"`
QuotaCores float64 `json:"quota-cores,omitempty"`
QuotaFrom string `json:"quota-from,omitempty"`
// the layout version
V int64 `json:"v,omitempty"`
Why string `json:"why"`
@@ -462,10 +443,12 @@ const (
// DetectedSteps is the steps detected for one artifact at its newest build-input fingerprint, replaced when a newer fingerprint is detected and by steps with again (design 47 G section 326).
type DetectedSteps struct {
At *time.Time `json:"at,omitempty"`
Fingerprint string `json:"fingerprint"`
Steps []DetectedStep `json:"steps"`
V int64 `json:"v"`
At *time.Time `json:"at,omitempty"`
Fingerprint string `json:"fingerprint"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
Steps []DetectedStep `json:"steps"`
V int64 `json:"v"`
}
// Drop is an ask a caller no longer waits for.
@@ -473,6 +456,8 @@ type Drop struct {
// when (RFC 3339 time)
At *time.Time `json:"at,omitempty"`
By string `json:"by,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
// the layout version
V int64 `json:"v,omitempty"`
Why string `json:"why"`
@@ -624,9 +609,11 @@ type ModuleTree struct {
// Pause is whether the node takes no new ask.
type Pause struct {
// when (RFC 3339 time)
At *time.Time `json:"at,omitempty"`
By string `json:"by,omitempty"`
Paused bool `json:"paused"`
At *time.Time `json:"at,omitempty"`
By string `json:"by,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
Paused bool `json:"paused"`
// the layout version
V int64 `json:"v,omitempty"`
}
@@ -697,8 +684,10 @@ type Step struct {
AgainAt *time.Time `json:"again-at,omitempty"`
// when (RFC 3339 time)
Ended *time.Time `json:"ended,omitempty"`
ID string `json:"id"`
Node string `json:"node"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
ID string `json:"id"`
Node string `json:"node"`
// the name of the object in the build module's outputs store that holds the step's answer when the step's value would be over what the steps state holds (design 47 G A-290): a check's whole answer, its result then empty; a run's output, its result the run's answer without it. Read through the verb output
OutputObject string `json:"output-object,omitempty"`
Owner string `json:"owner,omitempty"`
@@ -799,6 +788,8 @@ type StepEnded struct {
Commit string `json:"commit,omitempty"`
Ended *time.Time `json:"ended,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
// the ask's id
ID string `json:"id"`
// the packages that passed at their digest, for the runner to keep
@@ -843,7 +834,9 @@ type StepProgress struct {
Ask string `json:"ask"`
Asker string `json:"asker"`
At time.Time `json:"at"`
Phase string `json:"phase"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
Phase string `json:"phase"`
}
// The values of StepProgress's phase.
@@ -942,6 +935,8 @@ type Toolchain struct {
At *time.Time `json:"at,omitempty"`
// the sha256: digest of the language's toolchain program as the build module runs it: the program of the module that provides that language's toolchain, never the build module's own (design 47 G section 472)
Digest string `json:"digest,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
// go or typescript
Language string `json:"language"`
Recipe string `json:"recipe"`
@@ -953,7 +948,9 @@ type Toolchain struct {
// ToolchainReported is a node's toolchain of a language, said at the build module's start and each time its toolchains key of the language changes (design 47 G section 492).
type ToolchainReported struct {
// the digest of the program of the provision the build module requires for that language's toolchain, never the build module's own
Digest string `json:"digest"`
Digest string `json:"digest"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
Language string `json:"language"`
Node string `json:"node"`
Recipe string `json:"recipe"`
@@ -1019,6 +1016,8 @@ type KeptArtifactAnswer struct {
Digest string `json:"digest,omitempty"`
// why it could not answer
Error string `json:"error,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
// the fingerprint asked
Fp string `json:"fp"`
// the module asked
@@ -1065,6 +1064,8 @@ type StepsAnswer struct {
// why a drop deleted nothing, naming the hand-act log when it refused
Error string `json:"error,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
// answered from the kept answer
Kept bool `json:"kept,omitempty"`
Steps []DetectedStep `json:"steps,omitempty"`
@@ -1084,6 +1085,8 @@ type OutputAnswer struct {
Ask string `json:"ask"`
// how many chunks are sent; 0 when this node keeps no answer of that ask
Chunks int64 `json:"chunks"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
}
// DeliveryAccept is the body of delivery.
@@ -1133,3 +1136,113 @@ type ToolchainsByNodeLanguageValue = Toolchain
// DetectedStepsByModuleArtifactValue is one value of the state detected-steps under the key <module>.<artifact>.
type DetectedStepsByModuleArtifactValue = DetectedSteps
// DecodeCurrentAnswer reads a CurrentAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeCurrentAnswer(raw []byte) (CurrentAnswer, int, error) {
var v CurrentAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodePauseAnswer reads a PauseAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodePauseAnswer(raw []byte) (PauseAnswer, int, error) {
var v PauseAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeResumeAnswer reads a ResumeAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeResumeAnswer(raw []byte) (ResumeAnswer, int, error) {
var v ResumeAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeDropAnswer reads a DropAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeDropAnswer(raw []byte) (DropAnswer, int, error) {
var v DropAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeKeptArtifactAnswer reads a KeptArtifactAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeKeptArtifactAnswer(raw []byte) (KeptArtifactAnswer, int, error) {
var v KeptArtifactAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeStepsAnswer reads a StepsAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeStepsAnswer(raw []byte) (StepsAnswer, int, error) {
var v StepsAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeOutputAnswer reads a OutputAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeOutputAnswer(raw []byte) (OutputAnswer, int, error) {
var v OutputAnswer
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeStepEndedEvent reads a StepEndedEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeStepEndedEvent(raw []byte) (StepEndedEvent, int, error) {
var v StepEndedEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeToolchainReportedEvent reads a ToolchainReportedEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeToolchainReportedEvent(raw []byte) (ToolchainReportedEvent, int, error) {
var v ToolchainReportedEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeStepProgressEvent reads a StepProgressEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeStepProgressEvent(raw []byte) (StepProgressEvent, int, error) {
var v StepProgressEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeAskTakenEvent reads a AskTakenEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeAskTakenEvent(raw []byte) (AskTakenEvent, int, error) {
var v AskTakenEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// formRead is the form a value says on the wire: 1 when it says none, or is no object.
func formRead(raw []byte) int {
var f struct {
Form int `json:"form"`
}
if json.Unmarshal(raw, &f) != nil || f.Form < 1 {
return 1
}
return f.Form
}