diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks.go index 93f8dc4c1..e97463615 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks.go @@ -17,7 +17,7 @@ import ( // teller only filled them from an answer given in the view, so an ask nobody opened the view for reached nobody: on // 2026-10-25 seven modules stayed held on every machine and the operator was never asked. Now the teller raises each on the // operator channel as it raises the gate's merge asks: as the asker mesh-delivery-teller, once per router id, through the same -// records, the same wait for room and the same warrants. The operator's answer, from the phone or from the view, is written +// records, the same wait and the same warrants. The operator's answer, from the phone or from the view, is written // under the ask's own key in the bucket answers, which the assigner reads (mesh-delivery-assigner pass.go answeredWith); none // of these asks needs proof of who answered (mesh-sdk go/delivery AskNeedsProof). diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks_test.go index 86022dfc7..0b3680d7c 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks_test.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks_test.go @@ -154,27 +154,14 @@ func TestAnAssignerAskAnsweredInTheViewOrTakenAwayIsTakenBack(t *testing.T) { } } -// 1906/H1: an assigner ask refused for want of room waits and is asked again when another of the teller's asks ends; a refusal for -// its words is said as a condition about a delivery ask. -func TestAnAssignerAskWaitsForRoomAndARefusalIsSaidAsADeliveryAsk(t *testing.T) { +// 1906/H1: an assigner ask refused for its words is said as a condition about a delivery ask. +func TestAnAssignerAskRefusedIsSaidAsADeliveryAsk(t *testing.T) { anAssignerAskWrittenAgainAfterBeingTakenAwayIsAskedAgainUnderANewAsking(t) b := newBed(t) assigner, _ := withView(b) - _, first := b.holdOf(t, 1, 1) key, value, ask := holdAsk(t) assigner[key] = value b.t.OnAssignerAsk(key) - b.refuse(t, ask.ID, roomRefusal) - b.deliver(t, warrantFor(first, "keep")) - got := b.askedIDs() - if len(got) != 3 || got[2] != ask.ID { - t.Fatalf("asks = %v, want the assigner's %s asked again", got, ask.ID) - } - - b = newBed(t) - assigner, _ = withView(b) - assigner[key] = value - b.t.OnAssignerAsk(key) b.refuse(t, ask.ID, "the ask has no headline") if len(b.conds) != 1 || b.conds[0].Subject.Scope != "delivery" || strings.Contains(b.conds[0].Explanation, "merge") { t.Errorf("conditions = %+v", b.conds) diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/ends.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/ends.go index 65273455c..353efcba0 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/ends.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/ends.go @@ -13,7 +13,7 @@ import ( ) // EndAsk ends one ask of the teller's by hand (the tool teller_end_ask, issue 774): an ask open at the router is cancelled -// there and marked ended here, and one waiting for room is dropped from the wait, so it is asked no more under that router +// there and marked ended here, and one waiting to be asked again is dropped from the wait, so it is asked no more under that router // id. The ask is named by its router id or by the key of the gate's or the assigner's asks it was asked for (then its latest // asking). An ask that is neither open nor waiting is said so and left: it holds no place at the router. The gate's or the // assigner's key is not the teller's to take away: a later asking of it, under a new router id, is asked as any. @@ -37,7 +37,7 @@ func (t *Teller) EndAsk(ask, why, by string) ends.Result { if ws, rec, err := t.waiting(); err == nil && rec != nil { if i := slices.IndexFunc(ws, func(x waitingAsk) bool { return x.ID == id }); i >= 0 { if t.keepWaiting(slices.Delete(ws, i, i+1), rec) != nil { - r.Says = "the ask " + id + " waits for room, and the wait could not be written: it is not ended" + r.Says = "the ask " + id + " waits to be asked again, and the wait could not be written: it is not ended" return r } waited = true @@ -51,7 +51,7 @@ func (t *Teller) EndAsk(ask, why, by string) ends.Result { if !open(k) { r.Ended = waited if waited { - r.Says = "the ask " + id + " waited for room at the router: it is dropped from the wait and asked no more" + r.Says = "the ask " + id + " waited to be asked again: it is dropped from the wait and asked no more" } else { r.Says = "the ask " + id + " is not open (answered, lapsed or ended already): it holds no place at the router, and nothing is done" } @@ -65,7 +65,7 @@ func (t *Teller) EndAsk(ask, why, by string) ends.Result { } t.markHand(key, id) r.Ended = true - r.Says = "the ask " + id + " is cancelled at the router, which frees its place; the next ask waiting for room is asked when the router says it ended" + r.Says = "the ask " + id + " is cancelled at the router, which frees its place" t.logf("%s: the ask %s is ended by hand, by %s: %s", key, id, by, why) return r } diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go index 304549ddb..d8d2289d2 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go @@ -489,78 +489,6 @@ func TestTellerCarriesAnAskAndWritesTheAnswer(t *testing.T) { // 1343/AC1, AC2 } } -// TestTellerAsksAgainAnAskRefusedForWantOfRoom starts the program against the bus: the router (the test) refuses the assigner's -// ask for want of room, as the live router did on 2026-10-21 (issue 1610), and then says another of the teller's asks -// lapsed; the refused ask is on the seat's work queue again, which the bus's duplicate window would have dropped under its -// first message id (1610/AC1 on the real bus). -func TestTellerAsksAgainAnAskRefusedForWantOfRoom(t *testing.T) { // 1610/AC1 - t.Cleanup(nowIs(time.Now().UTC())) - b := startFull(t) - b.place(t) - assigner := b.as(t, "n1.mesh-delivery-assigner") - broker := filepath.Join(t.TempDir(), "broker") - cred, _ := json.Marshal(process.Account{URL: b.srv.ClientURL(), Node: "n1", Module: "mesh-delivery-teller", User: "n1.mesh-delivery-teller", Password: "pw"}) - if err := os.WriteFile(broker, cred, 0o600); err != nil { - t.Fatal(err) - } - env := map[string]string{"MESH_BROKER_FILE": broker} - logs := &syncBuffer{} - rn := startRunner(b.ctx, func(c context.Context) error { return run(c, func(k string) string { return env[k] }, logs) }) - t.Cleanup(func() { rn.finish(t, 10*time.Second) }) - kv, err := assigner.KeyValue(b.ctx, assignerAsks) - if err != nil { - t.Fatal(err) - } - seat, err := b.js.Stream(b.ctx, "SEAT_OPERATOR_CHANNEL") - if err != nil { - t.Fatal(err) - } - b.listening(t) - // lastAsk waits for the seat's queue to hold an ask newer than seq under id, and gives its sequence. - lastAsk := func(id string, after uint64) uint64 { - t.Helper() - for deadline := time.Now().Add(10 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { - raw, err := seat.GetLastMsgForSubject(b.ctx, seatAsk) - if err != nil || raw.Sequence <= after { - continue - } - var a oc.Ask - if json.Unmarshal(raw.Data, &a) == nil && a.ID == id { - return raw.Sequence - } - } - t.Fatalf("the ask %s is not on the seat's queue after sequence %d\n%s", id, after, logs.String()) - return 0 - } - say := func(w oc.Warrant) { - t.Helper() - raw, _ := json.Marshal(w) - if err := b.ctl.Publish(seatDecided, raw); err != nil { - t.Fatal(err) - } - } - - key, value, held := holdAskAt(t, 1, 1) - if _, err := kv.Put(b.ctx, key, value); err != nil { - t.Fatal(err) - } - first := lastAsk(held.ID, 0) - say(oc.Warrant{Ask: held.ID, Asker: tellerModule, Outcome: occ.OutcomeRefused, Words: roomRefusal, At: occ.FormatTime(now)}) - for deadline := time.Now().Add(10 * time.Second); !strings.Contains(logs.String(), "for want of room"); time.Sleep(50 * time.Millisecond) { - if time.Now().After(deadline) { - t.Fatalf("the refusal was not heard\n%s", logs.String()) - } - } - key2, value2, ga2 := holdAskAt(t, 2, 1) - if _, err := kv.Put(b.ctx, key2, value2); err != nil { - t.Fatal(err) - } - second := lastAsk(ga2.ID, first) - // The other ask lapses at the router: there is room, and the refused ask is asked again. - say(oc.Warrant{Ask: ga2.ID, Asker: tellerModule, Outcome: occ.OutcomeExpired, At: occ.FormatTime(now), AskDigest: occ.Digest(ga2)}) - lastAsk(held.ID, second) -} - // TestTellerFillsAnAskFromTheViewsAnswerOnce starts the program against the bus with the permissions above: the assigner's // fixture hold ask is written, then the view's answer under `.view`; the answer is under the ask's own key, once // (rewriting the view's answer does not write a second), and a view answer under a key that is no assigner's (a merge's) fills nothing diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/room_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/room_test.go deleted file mode 100644 index 4747126b1..000000000 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/room_test.go +++ /dev/null @@ -1,233 +0,0 @@ -package main - -import ( - "encoding/json" - occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient" - oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel" - "strings" - "testing" -) - -// roomRefusal is the router's words when an asker already holds occ.MostOpen open asks, as the live router said them to -// the teller on 2026-10-21 at 11:21:08 local (novox journal of mesh-delivery-teller.service: "the router refused the ask -// merge-design_61_print_and_scan-8cc11c5b8c32-d916c290f50f: its asker already has 3 open asks"; mesh-catalog -// modules/messenger cmd/messenger/asks.go:529-531). -const roomRefusal = "its asker already has 3 open asks" - -// refuse is the router's refusal of an ask: it keeps no record of a refused ask (asks.go refuseAsk only tells its asker), -// so the id may be asked again. -func (b *bed) refuse(t *testing.T, id, words string) { - t.Helper() - delete(b.seenIDs, id) - delete(b.records, id) - b.deliver(t, oc.Warrant{Ask: id, Asker: tellerModule, Outcome: occ.OutcomeRefused, Words: words, At: occ.FormatTime(now)}) -} - -// expire is the router's word that an ask of the teller's lapsed with nobody's answer: one of its asks ended. -func (b *bed) expire(t *testing.T, ask oc.Ask) { - t.Helper() - b.deliver(t, oc.Warrant{Ask: ask.ID, Asker: tellerModule, Outcome: occ.OutcomeExpired, At: occ.FormatTime(now), AskDigest: occ.Digest(ask)}) -} - -// askedIDs is the router ids of every ask the bus carried, in order. -func (b *bed) askedIDs() []string { - var out []string - for _, p := range b.askedOf(oc.AcceptSubjectAsk(tellerModule)) { - var a struct { - ID string `json:"id"` - } - _ = json.Unmarshal(p.body, &a) - out = append(out, a.ID) - } - return out -} - -// The live fault of issue 1610: asks open, one refused by the router for want of room, and the operator then answers one of the -// open. The refused is asked again, under its own router id and a new bus message id, and nothing is said as a fault. -func TestAnAskRefusedForWantOfRoomIsAskedAgainWhenAnotherEnds(t *testing.T) { // 1610/AC1 - b := newBed(t) - _, first := b.holdOf(t, 1, 1) - key2, second := b.holdOf(t, 2, 1) - b.refuse(t, second.ID, roomRefusal) - if len(b.conds) != 0 { - t.Errorf("a refusal for want of room is said as a fault before it was asked again: %+v", b.conds) - } - if got := b.askedIDs(); len(got) != 2 { - t.Fatalf("asked %v before room came", got) - } - b.deliver(t, warrantFor(first, "keep")) - got := b.askedIDs() - if len(got) != 3 || got[2] != second.ID { - t.Fatalf("asks = %v, want the refused %s asked again once the first was answered", got, second.ID) - } - pubs := b.askedOf(oc.AcceptSubjectAsk(tellerModule)) - if pubs[2].id == pubs[1].id { - t.Errorf("asked again under the bus message id %s of its first asking: the bus drops it as a duplicate", pubs[2].id) - } - if len(b.busDropped) != 0 || len(b.dropped) != 0 || len(b.conds) != 0 { - t.Errorf("bus dropped %v, router dropped %v, conditions %+v", b.busDropped, b.dropped, b.conds) - } - // Taken this time: an answer to it writes the answer as for any ask. - b.deliver(t, warrantFor(second, "keep")) - if _, ok := b.answers.written[answerKey(key2)]; !ok { - t.Errorf("the answer to the ask asked again was not written; logs:\n%s", b.logs.String()) - } - // And it is asked no more: its answer ends its wait. - _, third := b.holdOf(t, 3, 1) - b.expire(t, third) - if got := b.askedIDs(); len(got) != 4 || got[3] == second.ID { - t.Errorf("asks after the answer = %v, want only the third asked", got) - } -} - -func TestAnAskRefusedForWantOfRoomIsNotAskedAgainOnceTheAssignerMovedOn(t *testing.T) { // 1610/AC2 - b := newBed(t) - _, first := b.holdOf(t, 1, 1) - key, gone := b.holdOf(t, 2, 1) - b.refuse(t, gone.ID, roomRefusal) - // Taken away by the assigner (the hold lifted) before room came. - delete(b.assigner, key) - b.t.OnAssignerAskGone(key) - key3, g3 := b.holdOf(t, 3, 1) - b.refuse(t, g3.ID, roomRefusal) - // Rewritten by the assigner under its next asking before room came: the later asking is asked under its own id, and the - // refused earlier asking is not asked again. - _, v3b, g3b := holdAskAt(t, 3, 2) - b.assigner[key3] = v3b - b.t.OnAssignerAsk(key3) - before := len(b.askedIDs()) - if ids := b.askedIDs(); ids[before-1] != g3b.ID { - t.Fatalf("asks = %v, want the next asking %s asked", ids, g3b.ID) - } - b.deliver(t, warrantFor(first, "keep")) - b.expire(t, g3b) - if after := b.askedIDs()[before:]; len(after) != 0 { - t.Errorf("asked again %v, which the assigner no longer asks", after) - } -} - -func TestAnAskRefusedForWantOfRoomTooOftenIsSaidAsACondition(t *testing.T) { // 1610/AC3 - b := newBed(t) - _, held := b.holdOf(t, 1, 1) - for i := 0; i < mostRoomRefusals; i++ { - if len(b.conds) != 0 { - t.Fatalf("a condition after %d refusals: %+v", i, b.conds) - } - b.refuse(t, held.ID, roomRefusal) - _, other := b.holdOf(t, 2+i, 1) - b.expire(t, other) - } - var again int - for _, id := range b.askedIDs() { - if id == held.ID { - again++ - } - } - if again != mostRoomRefusals { - t.Errorf("asked %d times, want %d (once, and again after each refusal but the last)", again, mostRoomRefusals) - } - asked := len(b.askedIDs()) - if len(b.conds) != 1 || b.conds[0].State != occ.StateRaised || !strings.Contains(b.conds[0].Summary, "open asks") { - t.Fatalf("conditions = %+v", b.conds) - } - _, last := b.holdOf(t, 8, 1) - b.expire(t, last) - if len(b.askedIDs()) != asked+1 { - t.Errorf("asked again after the bound: %v", b.askedIDs()) - } -} - -func TestAnAskWaitingForRoomIsAskedAgainAtStart(t *testing.T) { // 1610/AC4 - b := newBed(t) - key, held := b.holdOf(t, 1, 1) - b.refuse(t, held.ID, roomRefusal) - // The teller starts again: a new teller on the same buckets, and the watch hands over the key it holds. - b2 := newBed(t) - b2.store, b2.answers, b2.assigner = b.store, b.answers, b.assigner - b2.client.State = b.store - b2.t.Store, b2.t.Answers, b2.t.Assigner = b.store, b.answers, b.assigner - b2.t.OnAssignerAsk(key) - if len(b2.askedIDs()) != 0 { - t.Fatalf("asked before the watch handed over its keys: %v", b2.askedIDs()) - } - b2.t.OnCurrent() - if got := b2.askedIDs(); len(got) != 1 || got[0] != held.ID { - t.Errorf("asks at start = %v, want %s asked again", got, held.ID) - } -} - -func TestAnAskRefusedForItsWordsIsSaidAtOnceAndNotAskedAgain(t *testing.T) { // 1610/AC5 - b := newBed(t) - _, first := b.holdOf(t, 1, 1) - _, bad := b.holdOf(t, 2, 1) - b.refuse(t, bad.ID, "its words carry an address, which may not leave the mesh") - if len(b.conds) != 1 { - t.Fatalf("conditions = %+v", b.conds) - } - b.deliver(t, warrantFor(first, "keep")) - if got := b.askedIDs(); len(got) != 2 { - t.Errorf("asks = %v: an ask refused for its words was asked again", got) - } -} - -// restart is a new teller on the same buckets and the same bus (its message ids still in the bus's duplicate window), and -// the router's records as they stand; the watch hands over the assigner's keys, then says it has handed over all. -func (b *bed) restart(t *testing.T) *bed { - t.Helper() - n := newBed(t) - n.store, n.answers, n.assigner, n.records, n.msgIDs, n.seenIDs = b.store, b.answers, b.assigner, b.records, b.msgIDs, b.seenIDs - n.client.State = b.store - n.t.Store, n.t.Answers, n.t.Assigner = b.store, b.answers, b.assigner - for key := range b.assigner { - n.t.OnAssignerAsk(key) - } - n.t.OnCurrent() - return n -} - -// Review of 38116fe0 (reviewer-1610): an ask asked again whose refusal the teller never heard (it was away; the router's -// warrants come on a plain subscription) is asked again at the next start: the router keeps no record of a refused ask, -// so no record there means it was not taken. -func TestAnAskAskedAgainWhoseRefusalWasMissedIsAskedAgainAtStart(t *testing.T) { // 1610/AC4 - b := newBed(t) - _, held := b.holdOf(t, 2, 1) - b.refuse(t, held.ID, roomRefusal) - _, other := b.holdOf(t, 3, 1) - b.deliver(t, warrantFor(other, "keep")) - b.records[other.ID] = `{"state":"chosen"}` - if got := b.askedIDs(); got[len(got)-1] != held.ID { - t.Fatalf("asks = %v, want %s asked again", got, held.ID) - } - // Refused again, and the teller does not hear it: the router forgets it. - delete(b.seenIDs, held.ID) - delete(b.records, held.ID) - n := b.restart(t) - got := n.askedIDs() - if len(got) != 1 || got[0] != held.ID { - t.Fatalf("asks after the start = %v, want %s asked again; logs:\n%s", got, held.ID, n.logs.String()) - } - if len(n.busDropped) != 0 { - t.Errorf("the bus dropped %v as a duplicate", n.busDropped) - } -} - -// The same for a first asking: kept open by the teller, its refusal never heard, and no record at the router. -func TestAFirstAskingWhoseRefusalWasMissedIsAskedAgainAtStart(t *testing.T) { // 1610/AC4 - b := newBed(t) - _, held := b.holdOf(t, 1, 1) - delete(b.seenIDs, held.ID) // refused for room, unheard: the router keeps no record of it - delete(b.records, held.ID) - n := b.restart(t) - got := n.askedIDs() - if len(got) != 1 || got[0] != held.ID { - t.Fatalf("asks after the start = %v, want %s asked again; logs:\n%s", got, held.ID, n.logs.String()) - } - if len(n.busDropped) != 0 { - t.Errorf("the bus dropped %v as a duplicate", n.busDropped) - } - // An ask the router holds (it took the one asked again) is not asked again. - m := n.restart(t) - if got := m.askedIDs(); len(got) != 0 { - t.Errorf("an ask the router holds was asked again: %v", got) - } -} diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go index b990a67ea..70fe114d7 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go @@ -67,8 +67,8 @@ type Teller struct { // Say publishes a condition to the operator (mesh.seat.operator-channel.accept.condition.). Say func(c oc.Condition) error Logf func(format string, args ...any) - // Publish is the bus the asker publishes on, used to ask again an ask the router refused for want of room under a bus - // message id of its own (the bus drops a second message under an id it holds). + // Publish is the bus the asker publishes on, used to ask again an ask the router did not take under a bus message id + // of its own (the bus drops a second message under an id it holds). Publish func(subject string, body any, id string) error // Answered says an answer written under an ask's key as the event answered (ADR 0596 §2: the owner says what it // wrote; a reader hears it and asks the tool teller_answers, never the bucket). Nil says nothing. @@ -198,8 +198,8 @@ func (t *Teller) catchUp(id string) { if w == nil { if state == "" { // The router holds no record of an ask the teller holds open: it refused it (a refused ask is not kept) while - // the teller was away and did not hear it, or has not read it yet. It waits for room, and is asked again at the - // start or at the next end; the router drops a second ask under an id it holds (review of 38116fe0). + // the teller was away and did not hear it, or has not read it yet. It waits, and is asked again at the start or + // at the next end; the router drops a second ask under an id it holds (review of 38116fe0). t.unheard(id) } return @@ -286,8 +286,8 @@ func (t *Teller) sayAnswered(key, askID string, answer []byte) error { // Said is what the teller does with what became of a warrant: a good answer clears the condition of its ask; a warrant // that does not hold, or that the router refused, is said as a condition (ADR 0437 §9). Nothing is written for either. -// An ask the router refused for want of room is not said: it waits, and is asked again when one of the teller's asks -// ends (issue 1610). +// The channel holds no room to wait for (design 47 G A-424), so a refusal for want of room is said as any refusal is +// (design 47 H2 §813 (10)). func (t *Teller) Said(h occ.Handled, w oc.Warrant, err error) { t.mu.Lock() defer t.mu.Unlock() @@ -301,12 +301,6 @@ func (t *Teller) said(h occ.Handled, w oc.Warrant, err error) { // §638): the ask is closed as any ended ask is, so the teller treats it as the ended ask it was (as before §638). h = occ.Recorded } - if w.Outcome == occ.OutcomeRefused && forWantOfRoom(w.Words) { - if h == occ.Recorded { - t.roomRefused(w) - } - return // a second word of the same refusal is no end of an ask - } t.saidOnce(h, w, err) if h == occ.Recorded { if s, rec, _ := t.seenOf(w.Ask); rec != nil && isAssignerKey(s.Key) { @@ -404,41 +398,27 @@ func (t *Teller) clear(askID string) { _ = t.Store.Delete(condKey(id)) } -// Room at the router (issue 1610; design 47 G A-424 took the limit away). The router held at most three open asks of one asker and refused another at once -// in words, keeping no record of it (mesh-catalog modules/messenger cmd/messenger/asks.go:524-531, refuseAsk), so the -// same router id may be asked again. Merges come in bursts: on 2026-10-21 at 11:21 a fourth merge ask was refused so, and -// nothing asked it again, so the operator was never asked. Now an ask refused for want of room waits in the record -// `room`, and each time one of the teller's asks ends at the router (a warrant of any outcome: the room it held is free) -// the first that waits is asked again, under its own router id and a bus message id of its own (the bus drops a second -// message under an id it holds). It is asked again at most mostRoomRefusals times; refused that often it is said as a -// condition, as any refusal is. An ask the assigner took away or asked again under a newer asking meanwhile, or one already -// answered, is the assigner's no more, and is dropped from the wait. The teller holds no timer: an end, and its start, are the -// events that ask again. +// The asks the router did not take (issue 1610; design 47 G A-424 took the router's limit of open asks away, and design 47 +// H2 §813 (10) the teller's asking again for want of room). An ask the teller holds open and the router holds no record of +// (it was not taken, or its refusal was not heard) waits in the record `room`, and is asked again at the next end of one of +// the teller's asks and at the start, under its own router id and a bus message id of its own (the bus drops a second +// message under an id it holds). An ask the assigner took away or asked again under a newer asking meanwhile, or one +// already answered, is the assigner's no more, and is dropped from the wait. The teller holds no timer: an end, and its +// start, are the events that ask again. -// mostRoomRefusals is how many times an ask is refused for want of room before it is said as a condition and asked no -// more: each refusal follows an end of another ask, so it is that many asks answered while this one could not be asked. -const mostRoomRefusals = 6 - -// roomRecord is the key of the asks that wait for room, in the order they were refused. +// roomRecord is the key of the asks that wait to be asked again, in the order they were met. const roomRecord = "room" -// waitingAsk is one ask that waits for room: the ask key it was asked for, its router id, how often the router refused -// it for want of room, and whether it is asked again and its word not yet heard. +// waitingAsk is one ask that waits to be asked again: the ask key it was asked for, its router id, and whether it is asked +// again and its word not yet heard. type waitingAsk struct { - Key string `json:"key"` - ID string `json:"id"` - Refusals int `json:"refusals"` - Asked bool `json:"asked,omitempty"` + Key string `json:"key"` + ID string `json:"id"` + Asked bool `json:"asked,omitempty"` // Tries is how many times it was asked again: each time under a bus message id of its own, also across a start. Tries int `json:"tries,omitempty"` } -// forWantOfRoom says whether a refusal's words are the router's for an asker that already holds its most open asks -// ("its asker already has 3 open asks", asks.go:530). -func forWantOfRoom(words string) bool { - return strings.Contains(words, "already has") && strings.Contains(words, "open asks") -} - func (t *Teller) now() time.Time { if t.Now != nil { return t.Now() @@ -469,45 +449,12 @@ func (t *Teller) keepWaiting(ws []waitingAsk, prior *stdio.StateEntry) error { _, err = t.Store.Update(roomRecord, ws, prior.Revision) } if err != nil { - t.logf("the record of the asks waiting for room could not be kept: %v", err) + t.logf("the record of the asks waiting to be asked again could not be kept: %v", err) } return err } -// roomRefused keeps an ask the router refused for want of room waiting, or, refused that way mostRoomRefusals times, -// says it as a condition and drops it. -func (t *Teller) roomRefused(w oc.Warrant) { - ws, rec, err := t.waiting() - if err != nil { - t.logf("%v", err) - return - } - i := slices.IndexFunc(ws, func(x waitingAsk) bool { return x.ID == w.Ask }) - if i < 0 { - s, _, _ := t.seenOf(w.Ask) - ws = append(ws, waitingAsk{Key: s.Key, ID: w.Ask}) - i = len(ws) - 1 - } - ws[i].Refusals++ - ws[i].Asked = false - n := ws[i].Refusals - if n >= mostRoomRefusals { - ws = slices.Delete(ws, i, i+1) - if t.keepWaiting(ws, rec) != nil { - return - } - t.logf("the router refused the ask %s for want of room %d times (%s): it is asked no more, and said", w.Ask, n, w.Words) - t.raise(w.Ask, assignerWords.unaskedHeadline, fmt.Sprintf("the router refused it %d times for want of room: %s", n, w.Words)) - return - } - if t.keepWaiting(ws, rec) != nil { - return - } - t.logf("the router refused the ask %s for want of room (%s): it waits, and is asked again when one of the teller's asks ends (refused %d of at most %d times)", - w.Ask, w.Words, n, mostRoomRefusals) -} - -// endWait drops an ask from the wait once the router said it ended otherwise than for want of room. +// endWait drops an ask from the wait once the router said it ended. func (t *Teller) endWait(id string) { ws, rec, err := t.waiting() if err != nil || rec == nil { @@ -521,7 +468,7 @@ func (t *Teller) endWait(id string) { } // OnCurrent is the watch of the assigner's asks having handed over every key it holds now, at the teller's start: an ask that -// waited for room while the teller was away is asked again (the asks that held the room may have ended meanwhile). +// waited while the teller was away is asked again. // // An ask asked again whose word the teller did not hear (the router's warrants come on a plain subscription) waits once // more when the router holds no record of it: the router keeps none of a refused ask (review of 38116fe0). Up to @@ -569,7 +516,7 @@ func (t *Teller) OnCurrent() { t.askWaiting() } -// unheard puts an ask the teller holds open and the router holds no record of in the wait for room, once. +// unheard puts an ask the teller holds open and the router holds no record of in the wait, once. func (t *Teller) unheard(id string) { ws, rec, err := t.waiting() if err != nil { @@ -611,17 +558,17 @@ func (t *Teller) askWaiting() { } a, why := t.stillAsked(x) if why != "" { - t.logf("%s: the ask %s, waiting for room, is not asked again: %s", x.Key, x.ID, why) + t.logf("%s: the ask %s, waiting, is not asked again: %s", x.Key, x.ID, why) ws, changed = slices.Delete(ws, i, i+1), true continue } ws[i].Tries, changed = x.Tries+1, true if err := t.askAgain(a, fmt.Sprintf("%s.again-%d", a.ID, ws[i].Tries)); err != nil { - t.logf("%s: the ask %s, waiting for room, could not be asked again, and waits for the next end: %v", x.Key, x.ID, err) + t.logf("%s: the ask %s, waiting, could not be asked again, and waits for the next end: %v", x.Key, x.ID, err) return } ws[i].Asked = true - t.logf("%s: the ask %s is asked of the operator again (refused %d times for want of room)", x.Key, x.ID, x.Refusals) + t.logf("%s: the ask %s is asked of the operator again (try %d)", x.Key, x.ID, ws[i].Tries) i++ } } diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller_test.go index f64c4a384..b968f229c 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller_test.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller_test.go @@ -381,7 +381,7 @@ func TestAWarrantThatDoesNotHoldWritesNoAnswerAndRaisesTheCondition(t *testing.T } // design 47 G §653, A-172: the teller carries no merge ask. A router ask it holds under a key that is no assigner key (a merge -// ask kept before the Approve per merge went) answers nothing, and a merge ask waiting for room is dropped from the wait. +// ask kept before the Approve per merge went) answers nothing, and a merge ask waiting to be asked again is dropped from the wait. func TestAMergeAskOfBeforeTheApprovePerMergeWentAnswersNothingAndWaitsNoMore(t *testing.T) { b := newBed(t) _, _, ask := holdAskAt(t, 1, 1) @@ -396,7 +396,9 @@ func TestAMergeAskOfBeforeTheApprovePerMergeWentAnswersNothingAndWaitsNoMore(t * if ws, rec, _ := b.t.waiting(); rec != nil || len(ws) != 0 { t.Fatalf("the wait holds %v", ws) } - b.refuse(t, ask.ID, roomRefusal) // it waits for room, as a merge ask did + if err := b.t.keepWaiting([]waitingAsk{{Key: mergeKey, ID: ask.ID}}, nil); err != nil { // it waits, as a merge ask did + t.Fatal(err) + } b.deliver(t, warrantFor(ask, "keep")) if len(b.answers.written) != 0 { t.Errorf("a merge ask was answered: %v", b.answers.written) diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/unheard_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/unheard_test.go new file mode 100644 index 000000000..f74399178 --- /dev/null +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/unheard_test.go @@ -0,0 +1,99 @@ +package main + +import ( + "encoding/json" + occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient" + oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel" + "testing" +) + +// roomRefusal is the router's words when an asker already holds occ.MostOpen open asks, as the live router said them to +// the teller on 2026-10-21 at 11:21:08 local (novox journal of mesh-delivery-teller.service: "the router refused the ask +// merge-design_61_print_and_scan-8cc11c5b8c32-d916c290f50f: its asker already has 3 open asks"; mesh-catalog +// modules/messenger cmd/messenger/asks.go:529-531). +const roomRefusal = "its asker already has 3 open asks" + +// refuse is the router's refusal of an ask: it keeps no record of a refused ask (asks.go refuseAsk only tells its asker), +// so the id may be asked again. +func (b *bed) refuse(t *testing.T, id, words string) { + t.Helper() + delete(b.seenIDs, id) + delete(b.records, id) + b.deliver(t, oc.Warrant{Ask: id, Asker: tellerModule, Outcome: occ.OutcomeRefused, Words: words, At: occ.FormatTime(now)}) +} + +// askedIDs is the router ids of every ask the bus carried, in order. +func (b *bed) askedIDs() []string { + var out []string + for _, p := range b.askedOf(oc.AcceptSubjectAsk(tellerModule)) { + var a struct { + ID string `json:"id"` + } + _ = json.Unmarshal(p.body, &a) + out = append(out, a.ID) + } + return out +} + +// A refusal is said at once and the ask is not asked again, also one for want of room: the channel holds no room to wait +// for (design 47 G A-424), and the teller's asking again for it went (design 47 H2 §813 (10)). +func TestAnAskRefusedIsSaidAtOnceAndNotAskedAgain(t *testing.T) { // 1610/AC5, H2 §813 (10) + for _, words := range []string{"its words carry an address, which may not leave the mesh", roomRefusal} { + b := newBed(t) + _, first := b.holdOf(t, 1, 1) + _, bad := b.holdOf(t, 2, 1) + b.refuse(t, bad.ID, words) + if len(b.conds) != 1 { + t.Fatalf("%s: conditions = %+v", words, b.conds) + } + b.deliver(t, warrantFor(first, "keep")) + if got := b.askedIDs(); len(got) != 2 { + t.Errorf("%s: asks = %v: a refused ask was asked again", words, got) + } + } +} + +// restart is a new teller on the same buckets and the same bus (its message ids still in the bus's duplicate window), and +// the router's records as they stand; the watch hands over the assigner's keys, then says it has handed over all. +func (b *bed) restart(t *testing.T) *bed { + t.Helper() + n := newBed(t) + n.store, n.answers, n.assigner, n.records, n.msgIDs, n.seenIDs = b.store, b.answers, b.assigner, b.records, b.msgIDs, b.seenIDs + n.client.State = b.store + n.t.Store, n.t.Answers, n.t.Assigner = b.store, b.answers, b.assigner + for key := range b.assigner { + n.t.OnAssignerAsk(key) + } + n.t.OnCurrent() + return n +} + +// An ask kept open by the teller whose refusal it never heard (it was away; the router's warrants come on a plain +// subscription) is asked again at the next start: the router keeps no record of a refused ask, so no record there means it +// was not taken (review of 38116fe0); asked again and missed again, it is asked again at the start after. +func TestAnAskingWhoseRefusalWasMissedIsAskedAgainAtStart(t *testing.T) { // 1610/AC4 + b := newBed(t) + _, held := b.holdOf(t, 1, 1) + delete(b.seenIDs, held.ID) // refused for room, unheard: the router keeps no record of it + delete(b.records, held.ID) + n := b.restart(t) + got := n.askedIDs() + if len(got) != 1 || got[0] != held.ID { + t.Fatalf("asks after the start = %v, want %s asked again; logs:\n%s", got, held.ID, n.logs.String()) + } + if len(n.busDropped) != 0 { + t.Errorf("the bus dropped %v as a duplicate", n.busDropped) + } + // Asked again, and its refusal missed once more: the router forgets it, and the next start asks it again. + delete(n.seenIDs, held.ID) + delete(n.records, held.ID) + m := n.restart(t) + if got := m.askedIDs(); len(got) != 1 || got[0] != held.ID { + t.Fatalf("asks after the second start = %v, want %s asked again; logs:\n%s", got, held.ID, m.logs.String()) + } + // An ask the router holds (it took the one asked again) is not asked again. + o := m.restart(t) + if got := o.askedIDs(); len(got) != 0 { + t.Errorf("an ask the router holds was asked again: %v", got) + } +}