diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside.go index 0b0dfe905..d215cb155 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside.go @@ -7,6 +7,7 @@ import ( "fmt" "io/fs" "os" + "slices" "strconv" "strings" "sync" @@ -287,8 +288,16 @@ func (p *passer) outsideReview(ctx context.Context, module, fp string, nodes []s override := map[string]string{} // A wait of another fingerprint of this module is replaced by the newer want. for key, raw := range kept { - if w, err := outside.Decode(raw); err == nil && w.Module == module && w.FP != fp { + w, err := outside.Decode(raw) + switch { + case err != nil || w.Module != module: + case w.Ending != "": + // an end written and not said stands until its say finishes it, whatever the want names now (§831) + case w.FP != fp: p.outsideEnd(ctx, key, w, outside.HowReplaced, now) + case w.Decided != "" && !slices.Contains(nodes, w.Node): + // a decided record of a module no longer placed on its machine goes, with no event (§830 2.) + p.outsideEnd(ctx, key, w, "", now) } } for _, node := range nodes { @@ -319,7 +328,11 @@ func (p *passer) outsideReview(ctx context.Context, module, fp string, nodes []s } due := prev != nil && (prev.Release != "" || (prev.Settling && !now.Before(prev.SettleEnds))) var d outside.Decision - if prev != nil && !(first || changed || dirty || due) { + if prev != nil && prev.Ending != "" { + // An end written and not said: it is said again under its id until the bus takes it, and that finishes the wait (§831). + d = outside.Judge(prev, node, module, fp, outside.Facts{}) + p.outsideEnd(ctx, key, *prev, prev.Ending, now) + } else if prev != nil && !(first || changed || dirty || due) { // nothing to judge by: the wait stands as kept; the bound's ask is made when it has run d = outside.Decision{Wait: prev, Waiting: prev.Standing() || prev.Settling, Own: prev.Decided == outside.HowFailed || prev.Decided == outside.HowOwnFailure, Counted: prev.Decided == outside.HowGoOn} @@ -396,11 +409,10 @@ func (p *passer) outsideAnswered(w *outside.Wait, node, module, fp string) bool func (p *passer) outsideApply(ctx context.Context, key, hex, node, module, fp string, prev *outside.Wait, d outside.Decision, now time.Time, running bool) { o := p.outside switch { + case prev != nil && prev.Ending != "": + return // its end is owed, and its say finishes it (outsideReview) case d.End != "": p.outsideEnd(ctx, key, *prev, d.End, now) - if d.Wait != nil { - p.keepWait(ctx, key, *d.Wait) - } return case d.Wait == nil: if prev != nil { @@ -471,14 +483,47 @@ func (p *passer) outsideBody(w outside.Wait) meshwants.Wait { Words: fmt.Sprintf("%s on %s waits on %s", w.Module, w.Node, w.On)} } -// outsideEnd ends a wait: its wait-ended with how (none for a settle, which was never said), its finding and ask taken away, and -// its record deleted unless the end decided it (the caller keeps that record). +// outsideEnd ends a wait (design 47 H2b §831): a standing wait's end, `how`, is written into its record (`ending`) before it is said, +// and said before anything of the wait goes; only once the bus has taken `wait-ended` are its ask and finding taken away and the +// record written decided or deleted (outside.EndedAs). While the say is owed the record, its ask and its finding stand. A wait that +// was never said (a settle, a decided one) and a `how` of "" end at once and delete the record. func (p *passer) outsideEnd(ctx context.Context, key string, w outside.Wait, how string, now time.Time) { - if w.Standing() && how != "" { - body := p.outsideBody(w) - body.How = how - p.wantsOwe(waitOrder(key, w.ClockFrom), meshwants.EventWaitEnded, body, waitEventID(w.Node, w.Module, key[strings.LastIndex(key, ".")+1:], "ended."+how, w.ClockFrom), nil) + if how == "" || !(w.Standing() || w.Ending != "") { + p.outsideEnded(ctx, key, w, nil) + return } + if w.Ending == "" { + w.Ending = how + if !p.written(ctx, buckets.Waits(), key, func() ([]byte, error) { return outside.Encode(w) }) { + p.logf("the end of %s on %s (%s) is not written, so it is not said", w.Module, w.Node, how) + return + } + } + body := p.outsideBody(w) + body.How = how + done := context.WithoutCancel(ctx) + hex := key[strings.LastIndex(key, ".")+1:] + p.wantsOwe(waitOrder(key, w.ClockFrom), meshwants.EventWaitEnded, body, waitEventID(w.Node, w.Module, hex, "ended."+how, w.ClockFrom), func() { + p.outsideEnded(done, key, w, outside.EndedAs(w, how)) + }) + if w.Ending != "" && p.waitEndingKept(key) { + p.logf("the end of %s on %s (%s) is not said yet: its ask, its finding and its record stand", w.Module, w.Node, how) + } +} + +// waitEndingKept says the record under key still holds an end not yet finished. +func (p *passer) waitEndingKept(key string) bool { + raw := p.w.value(buckets.Waits(), key) + if raw == nil { + return false + } + w, err := outside.Decode(raw) + return err == nil && w.Ending != "" +} + +// outsideEnded is what the bus taking a wait's end lets go: its finding, its ask and its timer, and the record, written decided or +// deleted. +func (p *passer) outsideEnded(ctx context.Context, key string, w outside.Wait, decided *outside.Wait) { p.outsideFinding(w, false) if ask, err := asks.OutsideAskKey(w.Node, w.Module, w.FP); err == nil { p.remove(ctx, buckets.Asks(), ask) @@ -489,6 +534,10 @@ func (p *passer) outsideEnd(ctx context.Context, key string, w outside.Wait, how p.outside.mu.Unlock() } p.wakeSet("wait."+key, time.Time{}) // a wait that ended arms nothing + if decided != nil { + p.keepWait(ctx, key, *decided) + return + } p.remove(ctx, buckets.Waits(), key) } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_test.go index c4714d943..a1a254ca3 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_test.go @@ -354,6 +354,71 @@ func TestTheWaitOnAnOutsideCause(t *testing.T) { } } }) + // Design 47 H2b §831 (1984/AC-831a to AC-831d): an end is written into the record before it is said, and nothing of the wait goes + // before the bus took it. + t.Run("an end is written before it is said: the record stays ending with its ask and finding while the say is owed, then is decided; a restart says it again, no wait-held (§831)", func(t *testing.T) { + askKey, _ := asks.OutsideAskKey("ace", "nats", fpTest) + waitKey := outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")) + ended := func(r *outsideRig) (n int) { + for _, e := range r.events { + if e == meshwants.EventWaitEnded { + n++ + } + } + return n + } + // asked at the bound, then the operator's Go on, the say of the end refused once + start := func() *outsideRig { + r := newOutsideRig(t) + r.notRunning = true + r.cond("machine.hub.silent", "ace") + r.review(false, nil) + r.now = r.now.Add(31 * time.Minute) + r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`)) + <-r.woke + r.review(false, nil) + _, ask, err := assign.DecodeAsk(askKey, r.p.w.value(buckets.Asks(), askKey)) + if err != nil { + t.Fatal(err) + } + v, _ := mdc.EncodeAnswer(mdc.Answer{Option: assign.OptionGoOn, Warrant: ask.ID + "@2026-11-11T10:32:00Z", Words: "the operator"}) + r.p.w.put(buckets.Answers, askKey, v) + r.refuse = 1 + r.review(false, nil) + return r + } + r := start() + if w := r.wait(); w.Ending != outside.HowGoOn || w.Decided != "" || outside.StateOf(w) != "ending:go-on" || r.p.w.value(buckets.Asks(), askKey) == nil || len(r.found) != 1 || ended(r) != 0 { + t.Fatalf("AC-831a: with the say refused the record is %+v (%s), ask %v findings %v, ended %d", w, outside.StateOf(r.wait()), r.p.w.value(buckets.Asks(), askKey) != nil, r.found, ended(r)) + } + r.now = r.p.owedNext() + r.p.sayOwed() + if w := r.wait(); w.Decided != outside.HowGoOn || w.Ending != "" || r.p.w.value(buckets.Asks(), askKey) != nil || len(r.found) != 0 || ended(r) != 1 { + t.Errorf("AC-831b: once said the record is %+v, ask %v, findings %v, ended %d", w, r.p.w.value(buckets.Asks(), askKey) != nil, r.found, ended(r)) + } + // AC-831c: a restart between the two (the owed events are lost with the process) says the end again under its id + r = start() + held := len(r.ids) + r.p.owed.list = nil + r.p.outside.started = false + r.now = r.now.Add(time.Minute) + r.review(false, nil) + if w := r.wait(); w.Decided != outside.HowGoOn || ended(r) != 1 || len(r.ids) != held+1 || !strings.Contains(r.ids[len(r.ids)-1], ".ended.go-on.") || r.events[len(r.events)-1] != meshwants.EventWaitEnded { + t.Errorf("AC-831c: after a restart the record is %+v, events %v", w, r.events) + } + // AC-831d: the bus took the end and the process went before the record's write: the end is said again, then the rest is done + w := r.wait() + w.Decided, w.Ending = "", outside.HowGoOn + raw, _ := outside.Encode(w) + r.p.w.put(buckets.Waits(), waitKey, raw) + r.p.w.put(buckets.Asks(), askKey, []byte(`{}`)) + r.p.outside.started = false + r.now = r.now.Add(time.Minute) + r.review(false, nil) + if w := r.wait(); w.Decided != outside.HowGoOn || w.Ending != "" || r.p.w.value(buckets.Asks(), askKey) != nil || ended(r) != 2 { + t.Errorf("AC-831d: after the restart the record is %+v, ask %v, ended %d", w, r.p.w.value(buckets.Asks(), askKey) != nil, ended(r)) + } + }) t.Run("a newer want ends the wait replaced, and a restart judges it again", func(t *testing.T) { r := newOutsideRig(t) r.cond("machine.hub.unreachable", "ace") @@ -498,4 +563,128 @@ func TestTheToolsReadAndReleaseAnOutsideWait(t *testing.T) { if r.bodies[len(r.bodies)-1].How != "go-on" || n.Haves["ace"]["nats"].Health != nodeengineclient.HealthOK { t.Errorf("last %+v health %s", r.bodies[len(r.bodies)-1], n.Haves["ace"]["nats"].Health) } + // Design 47 H2b §830 (1984/AC-830a to AC-830c): the state is derived from the record, a decided record lives until its fingerprint + // runs healthy or is replaced, and assigner_wait_drop drops it by hand. + t.Run("assigner_waits derives the states; a decided record goes when healthy or replaced, with no second end; assigner_wait_drop drops it (§830)", func(t *testing.T) { + stateOf := func(r *outsideRig) (states []string) { + s := newPutTools(memStore{waitsState: &memKV{values: map[string][]byte{}}}, func(string, any) (json.RawMessage, error) { return nil, nil }) + for k, v := range r.p.w.read(buckets.Waits()) { + s.st.put(waitsState, k, v) + } + got, err := s.doWaits(map[string]any{}) + if err != nil { + t.Fatal(err) + } + for _, w := range got.(map[string]any)["waits"].([]any) { + states = append(states, w.(waitSaid).State) + } + return states + } + askKey, _ := asks.OutsideAskKey("ace", "nats", fpTest) + heard := `{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}` + // a settle, then own-failure + r := newOutsideRig(t) + r.review(false, nil) + if got := stateOf(r); len(got) != 1 || got[0] != "settling" { + t.Fatalf("AC-830a: a settle is %v", got) + } + r.now = r.now.Add(2 * time.Minute) + r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-raised", []byte(heard)) + <-r.woke + r.review(false, nil) + if got := stateOf(r); len(got) != 1 || got[0] != "decided:own-failure" { + t.Errorf("AC-830a: a settle's end is %v", got) + } + // waiting, asked past the bound, decided go-on + r = newOutsideRig(t) + r.notRunning = true + r.cond("machine.hub.silent", "ace") + r.review(false, nil) + if got := stateOf(r); len(got) != 1 || got[0] != "waiting" { + t.Fatalf("AC-830a: a standing wait is %v", got) + } + r.now = r.now.Add(31 * time.Minute) + r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(heard)) + <-r.woke + r.review(false, nil) + if got := stateOf(r); len(got) != 1 || got[0] != "asked" { + t.Fatalf("AC-830a: a wait past its bound is %v", got) + } + _, ask, _ := assign.DecodeAsk(askKey, r.p.w.value(buckets.Asks(), askKey)) + v, _ := mdc.EncodeAnswer(mdc.Answer{Option: assign.OptionGoOn, Warrant: ask.ID + "@2026-11-11T10:32:00Z", Words: "the operator"}) + r.p.w.put(buckets.Answers, askKey, v) + r.review(false, nil) + if got := stateOf(r); len(got) != 1 || got[0] != "decided:go-on" || r.wait().On != "silent:hub" || r.wait().Since.IsZero() { + t.Fatalf("AC-830a: a Go on is %v, record %+v", got, r.wait()) + } + // AC-830b: a want naming another fingerprint deletes it, with no second end; a healthy module deletes it too + ended := func() (n int) { + for _, e := range r.events { + if e == meshwants.EventWaitEnded { + n++ + } + } + return n + } + before := ended() + n := assign.Nodes{Online: map[string]bool{"ace": true}, Haves: map[string]map[string]nodeengine.HaveByNodeModuleValue{}} + saved := r.p.w.value(buckets.Waits(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:"))) + r.p.outsideReview(context.Background(), "nats", "src2:"+strings.Repeat("c", 64), []string{"ace"}, n, false, func(string, string) bool { return false }) + if len(r.p.w.read(buckets.Waits())) != 0 || ended() != before { + t.Errorf("AC-830b: a decided record of another fingerprint stands (%v) or ends again (%d)", stateOf(r), ended()-before) + } + restore := func() { + _, _ = r.p.kvs[buckets.Waits()].Put(context.Background(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), saved) + r.p.w.put(buckets.Waits(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), saved) + } + restore() + r.notRunning, r.health = false, nodeengineclient.HealthOK + r.review(false, nil) + if len(r.p.w.read(buckets.Waits())) != 0 || ended() != before { + t.Errorf("AC-830b: a decided record of a module running healthy stands (%v) or ends again", stateOf(r)) + } + restore() + r.notRunning, r.health = true, nodeengineclient.HealthFailed + r.p.outsideReview(context.Background(), "nats", fpTest, nil, n, false, func(string, string) bool { return false }) + if len(r.p.w.read(buckets.Waits())) != 0 { + t.Errorf("AC-830b: a decided record of a module no longer placed on its machine stands (%v)", stateOf(r)) + } + // AC-830c: assigner_wait_drop drops a decided record, and the next failing check there is a new wait + key := outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")) + st := memStore{waitsState: &memKV{values: map[string][]byte{key: saved}}} + var acts []string + act := func(verb string, body any) (json.RawMessage, error) { + raw, _ := json.Marshal(body) + acts = append(acts, string(raw)) + return json.RawMessage(`{"ok":true,"log":"logged"}`), nil + } + if _, err := dropWait(st, act, key, "", "person.jochen"); err == nil { + t.Error("AC-830c: a drop with no why is taken") + } + if _, err := dropWait(st, act, key, "the hub is back", "person.jochen"); err != nil || len(st[waitsState].values) != 0 || len(acts) != 1 || !strings.Contains(acts[0], waitDropTool+" "+key) { + t.Fatalf("AC-830c: the drop answered %v, left %d, acts %v", err, len(st[waitsState].values), acts) + } + standing, _ := outside.Encode(outside.Wait{Node: "ace", Module: "nats", FP: fpTest, Since: r.now, ClockFrom: r.now}) + st[waitsState].values[key] = standing + if _, err := dropWait(st, act, key, "x", "person.jochen"); err == nil || len(st[waitsState].values) != 1 { + t.Error("AC-830c: a wait that stands is dropped") + } + // the record gone, the next failing check there is held as a new wait + held := 0 + for _, e := range r.events { + if e == meshwants.EventWaitHeld { + held++ + } + } + r.review(false, nil) + after := 0 + for _, e := range r.events { + if e == meshwants.EventWaitHeld { + after++ + } + } + if after != held+1 || r.wait().Decided != "" { + t.Errorf("AC-830c: after the drop the next failing check is not held as a new wait: held %d then %d, %+v", held, after, r.wait()) + } + }) } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_tools.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_tools.go index 2209af6cd..d78b23492 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_tools.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/outside_tools.go @@ -29,6 +29,8 @@ const waitsState = buckets.WaitsState type waitSaid struct { Key string `json:"key"` outside.Wait + // State is derived from the record at the read (design 47 H2b §830 1.): settling, waiting, asked, ending: or decided:. + State string `json:"state"` // Settling's end is in the record; Ends is when the bound runs from clock-from, empty for a settle. BoundEnds string `json:"bound-ends,omitempty"` } @@ -50,7 +52,7 @@ func (s *putTools) doWaits(args map[string]any) (any, error) { if err != nil || (arg(args, "node") != "" && w.Node != arg(args, "node")) || (arg(args, "module") != "" && w.Module != arg(args, "module")) { continue } - said := waitSaid{Key: key, Wait: w} + said := waitSaid{Key: key, Wait: w, State: outside.StateOf(w)} if w.Standing() { if d, err := time.ParseDuration(w.Bound); err == nil { said.BoundEnds = w.ClockFrom.Add(d).UTC().Format("2006-01-02T15:04:05Z") @@ -86,7 +88,7 @@ func (s *putTools) doReleaseWait(args map[string]any, by string) (any, error) { if err != nil || !found { continue } - if c, err := outside.Decode(raw); err == nil && c.Decided == "" { + if c, err := outside.Decode(raw); err == nil && c.Decided == "" && c.Ending == "" { key, w = k, c } } @@ -114,7 +116,9 @@ func (s *putTools) doReleaseWait(args map[string]any, by string) (any, error) { func (s *putTools) waitsTool() stdio.Tool { return stdio.Tool{Name: toolWaits, Description: "Every wait of the delivery and where it stands: a moved module's failing health check on a " + "machine whose open conditions name a cause outside the delivery (design 47 G §706), with its module, machine, fingerprint, the " + - "condition's key, what it stands `on`, its clock-from, bound, its ask and its state; a settle shows as settling with its end. Narrowed by " + + "condition's key, what it stands `on`, its clock-from, bound, its ask and its state, derived from the record: settling (with its end), " + + "waiting, asked, ending: (an end not said yet) or decided: (a decided record lives until its fingerprint runs healthy, " + + "a want names another one or the module is no longer placed there, and answers its last `on` and `since`). Narrowed by " + "machine or module. Read-only.", Input: schema(map[string]string{"node": "one machine", "module": "one module"}, nil), Run: s.doWaits} } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go index b0b18ff0a..b3fd26615 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go @@ -401,6 +401,7 @@ func serveTools() error { tools = append(tools, engineReadsTools(runtimeStore{})...) tools = append(tools, writtenTools(runtimeStore{})...) tools = append(tools, progressDropTools(runtimeStore{}, stdio.Ask)...) // a tier progress whose tier never runs (§824 7.) + tools = append(tools, waitDropTools(runtimeStore{}, stdio.Ask)...) // a decided wait record (§830 2.) tools = append(tools, whyTools(runtimeStore{})...) tools = append(tools, askAgainTools(runtimeStore{}, stdio.Ask, time.Now)...) tools = append(tools, wantDropTools(runtimeStore{}, stdio.Ask)...) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/waitdrop_tool.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/waitdrop_tool.go new file mode 100644 index 000000000..bb3749d0f --- /dev/null +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/waitdrop_tool.go @@ -0,0 +1,63 @@ +package main + +import ( + "encoding/json" + "errors" + "fmt" + + "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" + stdio "git.novox.be/novox/mesh-sdk/go" + + "mesh-delivery-assigner/internal/outside" +) + +// waitDropTool drops one decided wait record by hand (design 47 H2b §830 2.): a wait that ended `go-on`, `failed` or `own-failure` +// keeps its record in the state `waits` until its fingerprint runs healthy, so a check that goes on failing there is not held again; +// dropping it makes the next failing check there a new wait. The act is recorded in the hand-act log first; only a decided record is +// dropped (a wait that stands is released by assigner_release). +const waitDropTool = "assigner_wait_drop" + +// dropWait deletes the decided record under key, the act first recorded through the seat mesh-hand-acts. +func dropWait(st seatStore, ask func(string, any) (json.RawMessage, error), key, why, by string) (any, error) { + switch { + case key == "": + return nil, errors.New("name the wait's key, ..: assigner_waits lists them") + case why == "": + return nil, errors.New("a wait dropped by hand says why") + case by == "" || by == stdio.Unproven: + return nil, errors.New("a wait dropped by hand names who drops it, and the runtime proved no caller") + } + raw, _, found, err := st.get(waitsState, key) + if err != nil { + return nil, err + } + if !found { + return nil, fmt.Errorf("the assigner holds no wait under %s: assigner_waits lists them", key) + } + w, err := outside.Decode(raw) + if err != nil { + return nil, fmt.Errorf("%s holds no wait on an outside cause: %w", key, err) + } + if w.Decided == "" { + return nil, fmt.Errorf("the wait %s is %s, not decided: assigner_release takes a wait that stands, and an end not said is said by the assigner (assigner_owed)", key, outside.StateOf(w)) + } + taken, err := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: waitDropTool + " " + key, Why: why + " (" + by + ")", Cause: "outside-wait-drop"}) + if err != nil { + return nil, fmt.Errorf("the drop of %s is not recorded, so the wait stays: %w", key, err) + } + if err := st.del(waitsState, key); err != nil { + return nil, fmt.Errorf("the wait %s is not dropped: %w", key, err) + } + return map[string]any{"key": key, "dropped": json.RawMessage(raw), "by": by, "hand-act": taken.Log}, nil +} + +// waitDropTools is the tool over the runtime's states. +func waitDropTools(st seatStore, ask func(string, any) (json.RawMessage, error)) []stdio.Tool { + return []stdio.Tool{{Name: waitDropTool, Description: "Drop one decided wait record by hand (design 47 H2b §830 2.): the key .. of the state waits, " + + "of a wait that ended go-on, failed or own-failure, so the next failing check of that module there is held as a new wait. Recorded as a hand act first; " + + "refused for a wait that stands or whose end is not said (assigner_release takes the first).", + Input: schema(map[string]string{"key": "the wait's key as assigner_waits answers it", "why": "why the record is dropped"}, []string{"key", "why"}), + Run: func(a map[string]any) (any, error) { + return dropWait(st, ask, arg(a, "key"), arg(a, "why"), stdio.CallerOf(a)) + }}} +} diff --git a/modules/mesh-delivery-assigner/internal/outside/outside.go b/modules/mesh-delivery-assigner/internal/outside/outside.go index a9965cabd..a223d3041 100644 --- a/modules/mesh-delivery-assigner/internal/outside/outside.go +++ b/modules/mesh-delivery-assigner/internal/outside/outside.go @@ -105,9 +105,8 @@ type Wait struct { // Settling: no outside cause was open at the failing check; the judgement is held until SettleEnds. Settling bool `json:"settling,omitempty"` SettleEnds time.Time `json:"settle-ends,omitempty"` - // Ask is the id of the asking made at the bound, and State where the wait stands in words (settling, waiting, asked). - Ask string `json:"ask,omitempty"` - State string `json:"state,omitempty"` + // Ask is the id of the asking made at the bound. Where the wait stands in words is derived at the read, never kept (StateOf). + Ask string `json:"ask,omitempty"` // Release is a release by hand not taken up yet: go-on, failed or rejudge, by By and why Why. Release string `json:"release,omitempty"` By string `json:"by,omitempty"` @@ -115,7 +114,10 @@ type Wait struct { // HeldSaid counts the wait-held the wait was the record of, raised by one in the write that makes a new one, so an `on` back at // an earlier cause makes a new message id (design 47 H §832 3.). HeldSaid int `json:"held-said,omitempty"` - // Decided is `go-on` or `failed` once the wait ended so. + // Ending is the `how` of an end written and not yet said (design 47 H2b §831): the record stands with its ask and finding until the + // bus has taken `wait-ended`, and is judged no more. + Ending string `json:"ending,omitempty"` + // Decided is `go-on`, `failed` or `own-failure` once the wait ended so and its end was said. Decided string `json:"decided,omitempty"` } @@ -138,7 +140,43 @@ func Decode(raw []byte) (Wait, error) { } // Standing says a wait is said (`wait-held`) and not only settling, nor decided. -func (w Wait) Standing() bool { return !w.Settling && w.Decided == "" } +func (w Wait) Standing() bool { return !w.Settling && w.Decided == "" && w.Ending == "" } + +// The states of a wait as `assigner_waits` says them, derived from the record (design 47 H2b §830 1.). +const ( + StateSettling = "settling" + StateWaiting = "waiting" + StateAsked = "asked" + StateEnding = "ending:" + StateDecided = "decided:" +) + +// StateOf derives where a wait stands from its record: `settling`, `waiting` (standing, no ask), `asked` (standing, with its ask), +// `ending:` (an end not yet said) or `decided:`. +func StateOf(w Wait) string { + switch { + case w.Decided != "": + return StateDecided + w.Decided + case w.Ending != "": + return StateEnding + w.Ending + case w.Settling: + return StateSettling + case w.Ask != "": + return StateAsked + } + return StateWaiting +} + +// EndedAs is the record a wait's end leaves once `wait-ended` was said (design 47 H2b §831): the wait decided for `go-on`, `failed` and +// `own-failure`, nil (the record is deleted) for `healthy`, `cleared` and `replaced`. +func EndedAs(w Wait, how string) *Wait { + switch how { + case HowGoOn, HowFailed, HowOwnFailure: + w.Release, w.Ask, w.Ending, w.Settling, w.SettleEnds, w.Decided = "", "", "", false, time.Time{}, how + return &w + } + return nil +} // Facts are what a judging reads: the module's check on the node at the wait's fingerprint (Failing, Healthy), the keeper's // conditions as read now (Read false: the kept call is unanswered), whether the module holds the seat mesh-conditions itself, @@ -183,6 +221,10 @@ type Decision struct { // Judge is one judging of the check at the node (§706). prev is the kept wait of that module at that fingerprint, nil for none. func Judge(prev *Wait, node, module, fp string, f Facts) Decision { + if prev != nil && prev.Ending != "" { + // An end written and not yet said: the record is judged no more and makes no wait-held (§831); the end's say finishes it. + return Decision{Wait: prev, Own: prev.Ending == HowFailed || prev.Ending == HowOwnFailure, Counted: prev.Ending == HowGoOn} + } if prev != nil && prev.Decided != "" { // Decided by the operator: it holds for this fingerprint until the module runs healthy. if f.Healthy { @@ -244,14 +286,14 @@ func Judge(prev *Wait, node, module, fp string, f Facts) Decision { if prev != nil && prev.Settling { next = *prev } else { - next.Settling, next.SettleEnds, next.State = true, f.Now.Add(f.Settle), "settling" + next.Settling, next.SettleEnds = true, f.Now.Add(f.Settle) } if f.Now.Before(next.SettleEnds) { return Decision{Wait: &next, Waiting: true, Due: next.SettleEnds} } next.Settling, next.SettleEnds = false, time.Time{} } - next.On, next.Cause, next.Settling, next.State = OnUnread, "", false, "waiting" + next.On, next.Cause, next.Settling = OnUnread, "", false return stand(prev, next, f) } causes := Causes(f.Conds, node, f.Moved) @@ -264,7 +306,7 @@ func Judge(prev *Wait, node, module, fp string, f Facts) Decision { } } } - next.On, next.Cause, next.Settling, next.SettleEnds, next.State = c.On, c.Key, false, time.Time{}, "waiting" + next.On, next.Cause, next.Settling, next.SettleEnds = c.On, c.Key, false, time.Time{} return stand(prev, next, f) } if standing { @@ -282,7 +324,7 @@ func Judge(prev *Wait, node, module, fp string, f Facts) Decision { } return Decision{Wait: prev, Waiting: true, Due: prev.SettleEnds} } - next.Settling, next.SettleEnds, next.State, next.On, next.Cause = true, f.Now.Add(f.Settle), "settling", "", "" + next.Settling, next.SettleEnds, next.On, next.Cause = true, f.Now.Add(f.Settle), "", "" return Decision{Wait: &next, Waiting: true, Due: next.SettleEnds} } @@ -299,11 +341,10 @@ func stand(prev *Wait, next Wait, f Facts) Decision { case f.Running: // §827: a module that runs its wanted build is asked about nothing; an ask that stands is withdrawn, the wait stands. if prev != nil && prev.Standing() && prev.Ask != "" { - d.Withdraw, next.Ask, next.State = true, "", "waiting" + d.Withdraw, next.Ask = true, "" } case f.Bound > 0 && !f.Now.Before(next.ClockFrom.Add(f.Bound)): d.Ask = true - next.State = "asked" } d.Wait = &next return d diff --git a/modules/mesh-delivery-assigner/manifest_test.go b/modules/mesh-delivery-assigner/manifest_test.go index 5c697733e..727db8841 100644 --- a/modules/mesh-delivery-assigner/manifest_test.go +++ b/modules/mesh-delivery-assigner/manifest_test.go @@ -116,7 +116,7 @@ func TestManifest(t *testing.T) { // which lists and asks again what each node's engine reads. if !slices.Equal(m.Tools, []string{"assigner_put", "assigner_release", "assigner_puts", "assigner_waits", "assigner_inputs", "assigner_inputs_drop", "assigner_compositions", "assigner_compositions_drop", "assignments", "seat-holders", "wants", "asks", "assigner_read_assignments", "assigner_read_seat_holders", "assigner_read_wants", "assigner_read_findings", "assigner_read_differences", "assigner_read_copies", - "assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_progress_drop", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before", "assigner_validate"}) { + "assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_progress_drop", "assigner_wait_drop", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before", "assigner_validate"}) { t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5), assigner_why (design 47 G A-439) and assigner_assignment_drop after assigner_want_drop (design 47 H2 H-A-509)", m.Tools) } if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs { diff --git a/modules/mesh-delivery-assigner/module.json b/modules/mesh-delivery-assigner/module.json index b678478d4..4c1ece8ae 100644 --- a/modules/mesh-delivery-assigner/module.json +++ b/modules/mesh-delivery-assigner/module.json @@ -137,6 +137,7 @@ "assigner_ask_again", "assigner_written", "assigner_progress_drop", + "assigner_wait_drop", "assigner_why", "assigner_want_drop", "assigner_assignment_drop",