BM4b (sdk): an end over the steps state's value is read through the verb answer

A step's end is an event, not a verb's answer, so an end over what the steps
state's value or step-ended carries has a reader of its own: keepOver keeps it
in the steps objects as answer.<ask>, the step key and step-ended carry
answer-object in place of output-object, and the build seats gain the read
verb answer (ask and call, marked chunks); output stays the run text's reader.
Step.Whole and StepEnded.ReadOutput read through answer.

Builds: design 47 H2 §791; H-A-412 (2) and its addendum
This commit is contained in:
2026-11-22 01:08:58 +01:00
parent 8617b521a6
commit fad9f059ee
40 changed files with 442 additions and 171 deletions
+15 -9
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"git.novox.be/novox/mesh-sdk/go/buscalls"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// OutputsStore is the local name of the object store a build seat's holder keeps a run's output in (design 47 H2 §791,
@@ -11,32 +12,37 @@ import (
// output reads (H-A-399 (1)).
const OutputsStore = "outputs"
// OutputObjects is the object store of OutputsStore as a holder uses it (mesh-sdk busstate.ObjectsOf(OutputsStore)).
// AnswersStore is the local name of the object store a build seat's holder keeps a step's end in when it is over what the
// steps state's value or step-ended carries (design 47 H2 H-A-412 addendum): the steps state's own objects store,
// `steps-objects`, which the holder's manifest `requires` with its steps state, and which the seat's verb answer reads.
var AnswersStore = catalogue.StateObjectsName("steps")
// OutputObjects is an object store as a holder uses it (mesh-sdk busstate.ObjectsOf(OutputsStore), or of AnswersStore).
type OutputObjects interface {
Put(name string, data []byte, description string) (buscalls.ObjectInfo, error)
Get(name string) (buscalls.ObjectData, error)
}
// KeepOutputIn is a holder's Puller.KeepOutput over its store of outputs.
func KeepOutputIn(o OutputObjects) func(object string, body []byte) error {
// KeepAnswerIn is a holder's Puller.KeepAnswer over its store of answers (AnswersStore).
func KeepAnswerIn(o OutputObjects) func(object string, body []byte) error {
return func(object string, body []byte) error {
if o == nil {
return fmt.Errorf("this module keeps no %s store", OutputsStore)
return fmt.Errorf("this module keeps no %s store", AnswersStore)
}
_, err := o.Put(object, body, "a run's answer, named by its step-ended")
_, err := o.Put(object, body, "a step's end over what its key or step-ended carries, named by it")
return err
}
}
// ReadOutputFrom is a holder's read of a kept answer for OutputTool over its store of outputs.
func ReadOutputFrom(o OutputObjects) func(object string) ([]byte, error) {
// ReadAnswerFrom is a holder's read of a kept end for AnswerTool over its store of answers (AnswersStore).
func ReadAnswerFrom(o OutputObjects) func(object string) ([]byte, error) {
return func(object string) ([]byte, error) {
if o == nil {
return nil, fmt.Errorf("this module keeps no %s store", OutputsStore)
return nil, fmt.Errorf("this module keeps no %s store", AnswersStore)
}
got, err := o.Get(object)
if err != nil {
return nil, fmt.Errorf("the answer %s in the %s store: %w", object, OutputsStore, err)
return nil, fmt.Errorf("the answer %s in the %s store: %w", object, AnswersStore, err)
}
return got.Data, nil
}
@@ -22,23 +22,23 @@ func (f fakeOutputs) Get(name string) (buscalls.ObjectData, error) {
return buscalls.ObjectData{Data: d}, nil
}
// Design 47 G A-254: what a holder keeps through KeepOutputIn it reads again through ReadOutputFrom; with no store both refuse by name.
// Design 47 G A-254: what a holder keeps through KeepAnswerIn it reads again through ReadAnswerFrom; with no store both refuse by name.
func TestOutputsKeptAreRead(t *testing.T) {
st := fakeOutputs{m: map[string][]byte{}}
if err := KeepOutputIn(st)("output.a1", []byte("x")); err != nil {
if err := KeepAnswerIn(st)("answer.a1", []byte("x")); err != nil {
t.Fatal(err)
}
if got, err := ReadOutputFrom(st)("output.a1"); err != nil || string(got) != "x" {
if got, err := ReadAnswerFrom(st)("answer.a1"); err != nil || string(got) != "x" {
t.Fatalf("read %q, %v", got, err)
}
if _, err := ReadOutputFrom(st)("output.none"); err == nil {
if _, err := ReadAnswerFrom(st)("answer.none"); err == nil {
t.Fatal("an absent answer was read")
}
// Design 47 H2 §791: the store is the holder's `outputs` objects.
if err := KeepOutputIn(nil)("o", nil); err == nil || !strings.Contains(err.Error(), "no outputs store") {
t.Fatalf("no store kept an answer, or did not name the outputs store: %v", err)
// Design 47 H2 H-A-412 addendum: a kept end is in the steps state's own objects, not in the `outputs` objects.
if err := KeepAnswerIn(nil)("o", nil); err == nil || !strings.Contains(err.Error(), "no steps-objects store") {
t.Fatalf("no store kept an answer, or did not name the steps objects: %v", err)
}
if _, err := ReadOutputFrom(nil)("o"); err == nil {
if _, err := ReadAnswerFrom(nil)("o"); err == nil {
t.Fatal("no store read an answer")
}
}
+12 -12
View File
@@ -83,10 +83,10 @@ type Puller struct {
// every ProgressEvery while it runs, step-ended when an ask outside a pipeline ends (design 47 G §496, §602). Nil says
// none, a test's. ProgressEvery defaults to DefaultProgressEvery.
Say func(event string, body any, id string) error
// KeepOutput keeps a step's answer over what its key holds in the steps state (a check's or a run's, design 47 G A-290)
// as the object named object, which the key and a run's step-ended name and the seat's verb `output` answers (A-254); a
// holder keeps it in the object store its manifest requires. Nil keeps none: such an answer ends the ask failed, saying so.
KeepOutput func(object string, body []byte) error
// KeepAnswer keeps a step's answer over what its key holds in the steps state (a check's or a run's, design 47 G A-290)
// as the object named object, which the key and a run's step-ended name and the seat's verb `answer` answers (A-254); a
// holder keeps it in its steps objects (AnswersStore, H-A-412). Nil keeps none: such an answer ends the ask failed, saying so.
KeepAnswer func(object string, body []byte) error
// Prior says how many runs of the ask under a step key started before (the Run of the step the key holds, PriorRuns; 0 for
// none), so the poison rule and the transport fault's run count only runs that started, never an ask given back before it
// ran. Nil counts the bus's deliveries (a test's).
@@ -713,7 +713,7 @@ func (p *Puller) endUnrun(msg *Pulled, ask sdkstep.StepAsk, key string, step sdk
why = fmt.Errorf("the ask is on its last delivery (%d) and no run of it started: it is out of its deliveries and run no more", msg.Delivered)
}
p.logf("the ask %s is ended on %s: %v", ask.ID, p.Node, why)
if _, ferr := finish(p.Put, p.KeepOutput, key, step, nil, why, p.Logf); ferr != nil {
if _, ferr := finish(p.Put, p.KeepAnswer, key, step, nil, why, p.Logf); ferr != nil {
p.logf("the end of the ask %s could not be written on %s, so it is given back: %v", ask.ID, p.Node, ferr)
_ = msg.Nak()
return
@@ -879,7 +879,7 @@ func (p *Puller) run(ctx context.Context, msg *Pulled, ask sdkstep.StepAsk, key
p.logf("the ask %s ended on a transport fault and its step could not be written again (%v): it ends failed", ask.ID, aerr)
}
}
written, ferr := finish(p.Put, p.KeepOutput, key, step, result, err, p.Logf)
written, ferr := finish(p.Put, p.KeepAnswer, key, step, result, err, p.Logf)
if ferr != nil {
// No end was written: the ask is not acknowledged as done, so the stream gives it again and a run that can
// write its end (or the poison rule, issue 1907) ends it where its asker sees it (issue 1930).
@@ -889,7 +889,7 @@ func (p *Puller) run(ctx context.Context, msg *Pulled, ask sdkstep.StepAsk, key
}
// step-ended says the end the key holds (design 47 G A-290): its outcome, and the answer only when the key kept it, so no
// step reads passed in one place and failed in another.
if len(written.Result) == 0 && written.OutputObject == "" {
if len(written.Result) == 0 && written.AnswerObject == "" {
result = nil
}
outcome := "passed"
@@ -898,9 +898,9 @@ func (p *Puller) run(ctx context.Context, msg *Pulled, ask sdkstep.StepAsk, key
if len(outcome) > 300 {
outcome = outcome[:300] + "..."
}
p.sayEnded(msg, ask, sdkstep.OutcomeFailed, written.Reason, result, written.OutputObject)
p.sayEnded(msg, ask, sdkstep.OutcomeFailed, written.Reason, result, written.AnswerObject)
} else {
p.sayEnded(msg, ask, sdkstep.OutcomePassed, "", result, written.OutputObject)
p.sayEnded(msg, ask, sdkstep.OutcomePassed, "", result, written.AnswerObject)
}
p.logf("the %s ask %s ended on %s after %s, in its phase %q; %s%s", ask.Kind, ask.ID, p.Node,
now().Sub(step.Started).Round(time.Second), step.Phase, outcome, stepOutcomeWords(result))
@@ -1099,8 +1099,8 @@ func (p *Puller) say(event string, body any, id string) {
// sayEnded says step-ended for an ask outside a pipeline, whatever its asker (design 47 G §602): a pipeline step's end is
// its run's own (AskSteps.SayStep). The end of a run carries the run's answer (A-254): the last line of its program's
// standard output, inline as `output` up to sdkstep.StepEndedInlineMost, else as `output-object`, the object kept, the step's
// key naming it (design 47 G A-290: finish kept it with KeepOutput, so it is not put twice); a program that exits other than 0
// standard output, inline as `output` up to sdkstep.StepEndedInlineMost, else as `answer-object`, the object kept, the step's
// key naming it (design 47 G A-290: finish kept it with KeepAnswer, so it is not put twice); a program that exits other than 0
// ends failed with its answer carried.
func (p *Puller) sayEnded(msg *Pulled, ask sdkstep.StepAsk, outcome, said string, result any, kept string) {
if p.Say == nil || ask.Step != nil || ask.Install != nil {
@@ -1114,7 +1114,7 @@ func (p *Puller) sayEnded(msg *Pulled, ask sdkstep.StepAsk, outcome, said string
if len(ans.Output) <= sdkstep.StepEndedInlineMost {
end.Output = string(ans.Output)
} else if kept != "" {
end.OutputObject = kept
end.AnswerObject = kept
} else {
outcome, said = sdkstep.OutcomeFailed, fmt.Sprintf("the run's answer is %d bytes, over what the end carries, and no object of it was kept", len(ans.Output))
}
@@ -279,7 +279,7 @@ func TestACheckAnswerOverTheStepsStateIsKeptAndReadBackWhole(t *testing.T) {
publishAsk(t, js, a)
p := &Puller{Source: &JetStreamAsks{JS: js, Language: sdkstep.AskGo}, Language: sdkstep.AskGo, Node: "ace", Put: put,
Capacity: func() int { return 1 }, PullWait: 100 * time.Millisecond,
KeepOutput: func(object string, body []byte) error { _, err := objects.PutBytes(ctx, object, body); return err },
KeepAnswer: func(object string, body []byte) error { _, err := objects.PutBytes(ctx, object, body); return err },
Run: func(context.Context, sdkstep.StepAsk) (any, error) { return answer, nil }}
go p.Pull(ctx)
key, _ := askKey(a, "ace")
@@ -292,14 +292,14 @@ func TestACheckAnswerOverTheStepsStateIsKeptAndReadBackWhole(t *testing.T) {
step, err = sdkstep.DecodeStep(e.Value())
return err == nil && sdkstep.Ended(step)
})
if step.State != sdkstep.StepPassed || step.OutputObject != sdkstep.OutputObjectName(a.ID) || len(step.Result) != 0 {
t.Fatalf("the key ended %s (%s) naming %q with %d bytes of result, want passed, naming the object and no result", step.State, step.Reason, step.OutputObject, len(step.Result))
if step.State != sdkstep.StepPassed || step.AnswerObject != sdkstep.AnswerObjectName(a.ID) || len(step.Result) != 0 {
t.Fatalf("the key ended %s (%s) naming %q with %d bytes of result, want passed, naming the object and no result", step.State, step.Reason, step.AnswerObject, len(step.Result))
}
verb := func(k string, body any) (json.RawMessage, error) {
if k != "seat:node-build-go.output@ace" {
if k != "seat:node-build-go.answer@ace" {
return nil, fmt.Errorf("asked %s", k)
}
data, err := objects.GetBytes(ctx, sdkstep.OutputObjectName(body.(map[string]any)["ask"].(string)))
data, err := objects.GetBytes(ctx, sdkstep.AnswerObjectName(body.(map[string]any)["ask"].(string)))
if err != nil {
return nil, err
}
@@ -14,7 +14,7 @@ import (
)
// Design 47 G A-254, A-290: a build seat's step-ended of a run carries the run's answer, the last line of its program's standard
// output: inline as `output` up to the event bound, else as `output-object`, the object the holder keeps, which the verb `output`
// output: inline as `output` up to the event bound, else as `answer-object`, the object the holder keeps, which the verb `output`
// answers. The step's key holds the answer only within what the steps state holds per value: over it, a check's whole answer or a
// run's output is the object output.<ask> the key names, kept once; the key and step-ended always say the same outcome, a run
// whose program exited other than 0 failed in both, its answer kept (A-290).
@@ -62,7 +62,7 @@ func TestStepEndedOfARunCarriesItsAnswer(t *testing.T) {
kept, keeps := map[string][]byte{}, 0
p := &Puller{Source: src, Language: sdkstep.AskGo, Node: "shanks", Put: st.put, Capacity: func() int { return 1 },
PullWait: 10 * time.Millisecond, Heartbeat: time.Hour, Say: sy.say,
KeepOutput: func(object string, body []byte) error {
KeepAnswer: func(object string, body []byte) error {
mu.Lock()
defer mu.Unlock()
keeps++
@@ -100,28 +100,28 @@ func TestStepEndedOfARunCarriesItsAnswer(t *testing.T) {
}
mu.Lock()
defer mu.Unlock()
name := sdkstep.OutputObjectName(a.ID)
name := sdkstep.AnswerObjectName(a.ID)
if c.objectKept {
if end["output-object"] != name || end["output"] != nil || string(kept[name]) != big {
t.Fatalf("end %v and kept %d bytes, want the object %s holding the whole answer and no inline output", end["output-object"], len(kept[name]), name)
if end["answer-object"] != name || end["output"] != nil || string(kept[name]) != big {
t.Fatalf("end %v and kept %d bytes, want the object %s holding the whole answer and no inline output", end["answer-object"], len(kept[name]), name)
}
} else if end["output-object"] != nil {
t.Fatalf("an object %v was named, want none", end["output-object"])
} else if end["answer-object"] != nil {
t.Fatalf("an object %v was named, want none", end["answer-object"])
}
switch {
case c.keyObject == "":
if step.OutputObject != "" || (c.keepErr == nil && keeps != 0) {
t.Fatalf("the key names %q and %d objects were kept, want none", step.OutputObject, keeps)
if step.AnswerObject != "" || (c.keepErr == nil && keeps != 0) {
t.Fatalf("the key names %q and %d objects were kept, want none", step.AnswerObject, keeps)
}
case c.check:
var whole map[string]any
if step.OutputObject != name || len(step.Result) != 0 || keeps != 1 || json.Unmarshal(kept[name], &whole) != nil || whole["fetch"] == nil {
t.Fatalf("the key names %q with result %.80s, %d keeps; want the object %s holding the whole check answer, kept once", step.OutputObject, step.Result, keeps, name)
if step.AnswerObject != name || len(step.Result) != 0 || keeps != 1 || json.Unmarshal(kept[name], &whole) != nil || whole["fetch"] == nil {
t.Fatalf("the key names %q with result %.80s, %d keeps; want the object %s holding the whole check answer, kept once", step.AnswerObject, step.Result, keeps, name)
}
default:
var rest sdkstep.RunAnswer
if step.OutputObject != name || keeps != 1 || string(kept[name]) != c.keyObject || json.Unmarshal(step.Result, &rest) != nil || rest.Output != nil || rest.Key != c.answer.Key {
t.Fatalf("the key names %q with result %.80s, %d keeps; want the object %s holding the output, kept once, and the run answer without it", step.OutputObject, step.Result, keeps, name)
if step.AnswerObject != name || keeps != 1 || string(kept[name]) != c.keyObject || json.Unmarshal(step.Result, &rest) != nil || rest.Output != nil || rest.Key != c.answer.Key {
t.Fatalf("the key names %q with result %.80s, %d keeps; want the object %s holding the output, kept once, and the run answer without it", step.AnswerObject, step.Result, keeps, name)
}
}
})
@@ -60,22 +60,22 @@ func SeatTools(seat, what string, p *Puller) []stdio.Tool {
}
}
// OutputTool serves `<seat>.output` (design 47 G A-254, A-257): a run's answer by its ask, as the object the holder keeps it in
// (sdkstep.OutputObjectName), read with read, which answers nil for none. The verb's answer is marked chunks: the bundle answers
// the whole answer as the member `file` (base64) and the tool runner sends it in chunks and answers their count; an ask
// whose answer this node does not keep answers no chunks.
func OutputTool(seat string, read func(object string) ([]byte, error)) stdio.Tool {
return stdio.Tool{Name: seat + ".output",
Description: "A run's answer by its ask, when its step-ended named it as an output-object: the answer's bytes in chunks, of any size.",
// AnswerTool serves `<seat>.answer` (design 47 G A-254, A-257; H2 H-A-412 addendum): a step's end over what its key or
// step-ended carries, by its ask, as the object the holder keeps it in (sdkstep.AnswerObjectName), read with read, which
// answers nil for none. The verb's answer is marked chunks: the bundle answers the whole end as the member `file` (base64)
// and the tool runner sends it in chunks and answers their count; an ask whose end this node does not keep answers no chunks.
func AnswerTool(seat string, read func(object string) ([]byte, error)) stdio.Tool {
return stdio.Tool{Name: seat + "." + sdkstep.AnswerVerb,
Description: "A step's answer by its ask, when its step key or step-ended named it as an answer-object: the kept end's bytes in chunks, of any size.",
Input: map[string]any{"type": "object", "required": []string{"ask", "call"}, "properties": map[string]any{
"ask": map[string]any{"type": "string", "description": "the ask's id"},
"call": map[string]any{"type": "string", "description": "the subject token of this send's chunks"}}},
Run: func(args map[string]any) (any, error) {
ask, _ := args["ask"].(string)
if ask == "" {
return nil, errors.New("the verb output is asked for no ask")
return nil, errors.New("the verb answer is asked for no ask")
}
body, err := read(sdkstep.OutputObjectName(ask))
body, err := read(sdkstep.AnswerObjectName(ask))
if err != nil {
return nil, err
}
@@ -72,12 +72,12 @@ func TestSeatToolsCurrentPauseResume(t *testing.T) {
}
}
// Design 47 G A-254: `<seat>.output` answers a run's answer by its ask as the whole file (base64), which the tool runner sends in
// Design 47 G A-254, H2 H-A-412 addendum: `<seat>.answer` answers a step's kept end by its ask as the whole file (base64), which the tool runner sends in
// chunks (A-257); an ask this node keeps no answer of answers no chunks.
func TestOutputToolAnswersTheKeptAnswer(t *testing.T) {
kept := map[string][]byte{sdkstep.OutputObjectName("a1"): []byte(`{"verdict":"x"}`)}
tool := OutputTool("node-build-go", func(object string) ([]byte, error) { return kept[object], nil })
if tool.Name != "node-build-go.output" {
func TestAnswerToolAnswersTheKeptAnswer(t *testing.T) {
kept := map[string][]byte{sdkstep.AnswerObjectName("a1"): []byte(`{"verdict":"x"}`)}
tool := AnswerTool("node-build-go", func(object string) ([]byte, error) { return kept[object], nil })
if tool.Name != "node-build-go.answer" {
t.Fatalf("name %q", tool.Name)
}
got, err := tool.Run(map[string]any{"ask": "a1", "call": "c"})
+6 -6
View File
@@ -21,7 +21,7 @@ import (
type Put func(key string, value any) (uint64, error)
// Keep keeps a step's answer that is over what the steps state holds per value as the object named object in the build
// module's outputs store (design 47 G A-290), the object the seat's verb output answers: Puller.KeepOutput, KeepOutputIn.
// module's steps objects (design 47 G A-290, H2 H-A-412), the object the seat's verb answer answers: Puller.KeepAnswer, KeepAnswerIn.
type Keep func(object string, body []byte) error
// EndAttempts and EndRetry bound how a step's end is written: a write that fails is tried again, since the end
@@ -122,7 +122,7 @@ func finish(put Put, keep Keep, key string, step sdkstep.Step, result any, err e
if step.Reason != "" {
why = fmt.Sprintf("the step ended %s (%s), and its end could not be written: %v", ended, step.Reason, werr)
}
step.State, step.Reason, step.Result, step.OutputObject = sdkstep.StepFailed, why, nil, ""
step.State, step.Reason, step.Result, step.AnswerObject = sdkstep.StepFailed, why, nil, ""
if ferr := writeEnd(put, key, step); ferr != nil {
if logf != nil {
logf("the failed end of the step %s could not be written either: %v", key, ferr)
@@ -134,7 +134,7 @@ func finish(put Put, keep Keep, key string, step sdkstep.Step, result any, err e
// keepOver is step as its key keeps it (design 47 G A-290): a value within what the steps state holds per value
// (kvlimit.ModuleStateValueBytes less the headers' room) keeps its answer itself; over it, the answer is kept with keep as the
// object sdkstep.OutputObjectName(step.ID), which the key names as its output-object: a run's output, the key keeping the
// object sdkstep.AnswerObjectName(step.ID), which the key names as its answer-object: a run's output, the key keeping the
// run answer without it, else the whole answer, the key's result then empty. A step whose answer cannot be kept ends failed,
// saying why, with no answer, so it never reads passed where its answer is lost.
func keepOver(keep Keep, step sdkstep.Step, result any) sdkstep.Step {
@@ -142,7 +142,7 @@ func keepOver(keep Keep, step sdkstep.Step, result any) sdkstep.Step {
if err != nil || len(step.Result) == 0 || kvlimit.Check("steps", "", len(raw), kvlimit.ModuleStateValueBytes) == nil {
return step
}
object, body, rest := sdkstep.OutputObjectName(step.ID), []byte(step.Result), json.RawMessage(nil)
object, body, rest := sdkstep.AnswerObjectName(step.ID), []byte(step.Result), json.RawMessage(nil)
if ans, ok := runAnswerIn(result); ok {
body, ans.Output = ans.Output, nil
if rest, err = json.Marshal(ans); err != nil {
@@ -162,7 +162,7 @@ func keepOver(keep Keep, step sdkstep.Step, result any) sdkstep.Step {
if err := keep(object, body); err != nil {
return lost(fmt.Sprintf("the step's answer makes its value %d bytes, over what the steps state holds, and could not be kept as the object %s: %v", len(raw), object, err))
}
step.Result, step.OutputObject = rest, object
step.Result, step.AnswerObject = rest, object
return step
}
@@ -187,7 +187,7 @@ func runAnswerIn(result any) (sdkstep.RunAnswer, bool) {
// again writes the step as given again after a transport fault: the state again with the run's cause, and when the bus gives
// the ask again (ADR 0664 §1). The key is not ended: its asker keeps waiting on it.
func again(put Put, key string, step sdkstep.Step, err error, delay time.Duration) error {
step.State, step.Reason, step.Passing, step.Result, step.OutputObject = sdkstep.StepAgain, err.Error(), true, nil, ""
step.State, step.Reason, step.Passing, step.Result, step.AnswerObject = sdkstep.StepAgain, err.Error(), true, nil, ""
step.Ended, step.AgainAt = time.Time{}, now().UTC().Add(delay)
return writeEnd(put, key, step)
}