From 9be15fe3934945c6f49c55e967d1e7b709d4de6a Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 15 Nov 2026 15:54:32 +0100 Subject: [PATCH] teller: ask every assigner ask at once; drop a lapsed or unknown key; the view never holds a raise back The operator channel keeps no count of an asker's open asks (A-424), so the teller waits for no room: each of the assigner's asks is asked when it is written, and the asks it could not hand the router are asked again at each end and at its start. A key whose ask lapsed (its proposal ended) or that is of no kind the teller knows is dropped with a line, never asked. The view's answer only fills an answer given there; one it cannot read is said and the ask is raised all the same (it never held the raise back; its line said so wrongly). Builds: design 47 G A-424 --- .../cmd/mesh-delivery-teller-tools/main.go | 7 +- .../cmd/mesh-delivery-teller/assignerasks.go | 81 +++---------------- .../mesh-delivery-teller/assignerasks_test.go | 39 ++++++--- .../cmd/mesh-delivery-teller/teller.go | 26 +++--- .../cmd/mesh-delivery-teller/teller_test.go | 17 ++-- .../cmd/mesh-delivery-teller/viewanswers.go | 17 +++- .../internal/ends/ends.go | 7 +- 7 files changed, 75 insertions(+), 119 deletions(-) diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main.go index 27a6035a..fb0f0a76 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main.go @@ -32,10 +32,9 @@ func Tools(ask asker, now func() time.Time) []stdio.Tool { return []stdio.Tool{ {Name: ends.Tool, Description: "End one open ask the delivery teller holds at the operator channel, by hand, saying why: the teller " + - "cancels it at the router, which frees one of the three places the router gives the teller, or drops it from the " + - "teller's wait for room. For an ask whose question is gone but whose key was never taken away (a merge ask of a pull " + - "request merged by another path, a backup ask about a backup no longer failing), which otherwise holds its place " + - "until it lapses, so a newer ask is refused for want of room. Name the ask by its router id (as " + + "cancels it at the router, or drops it from the asks it could not hand the router. For an ask whose question is gone " + + "but whose key was never taken away (a backup ask about a backup no longer failing), which otherwise stays offered " + + "until it lapses. Name the ask by its router id (as " + "operator-channel's asks show it) or by the key of the gate's or the assigner's asks. Answers which ask it found, " + "whether it ended it, and what it did; an ask answered, lapsed or ended already is left and said so.", Input: map[string]any{"type": "object", "required": []string{"ask", "why"}, "properties": map[string]any{ 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 f9564d98..63b5b9ac 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/assignerasks.go @@ -1,15 +1,12 @@ package main import ( - "encoding/json" "fmt" - "slices" + "time" 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" - stdio "git.novox.be/novox/mesh-sdk/go" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents" @@ -24,69 +21,18 @@ import ( // 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). -// mostAssignerOpen is how many of the assigner's asks the teller keeps open at the router at once: every place the router gives -// one asker (occ.MostOpen). The assigner's are the only asks the teller makes there since the Approve per merge went (design 47 -// G §653), so no place is kept free for a merge ask any more: two old asks no longer leave a third, a proposal's, waiting with -// none open beside them. An assigner ask beyond these waits in the wait for room and is asked when one of them ends. -const mostAssignerOpen = occ.MostOpen +// The operator channel keeps no count of an asker's open asks and holds none back for room (design 47 G A-424): the teller asks +// each of the assigner's asks when the assigner writes it, as many as there are. The record `room` keeps only the asks the +// teller could not hand the router (a transport fault, a word not heard), asked again at the next end and at the start. -// assignerOpenRecord is the key of the router ids of the assigner's asks the teller asked. -const assignerOpenRecord = "assigner.open" - -// assignerOpen is the router ids of the assigner's asks open now: those asked whose ask is neither answered nor ended. An id -// that ended is dropped from the record as it is read. -func (t *Teller) assignerOpen() ([]string, *stdio.StateEntry) { - e, err := t.Store.Get(assignerOpenRecord) - if err != nil || e == nil { - return nil, e - } - var ids []string - if err := json.Unmarshal(e.Value, &ids); err != nil { - t.logf("the record %s cannot be read: %v", assignerOpenRecord, err) - return nil, e - } - return slices.DeleteFunc(ids, func(id string) bool { - k, _, err := t.keptOf(id) - return err == nil && !open(k) - }), e -} - -// assignerRoom says whether another of the assigner's asks may be asked now. -func (t *Teller) assignerRoom() bool { - ids, _ := t.assignerOpen() - return len(ids) < mostAssignerOpen -} - -// assignerAsked keeps that the assigner's ask with this router id is asked. -func (t *Teller) assignerAsked(id string) { - ids, e := t.assignerOpen() - if !slices.Contains(ids, id) { - ids = append(ids, id) - } - var err error - if e == nil { - _, err = t.Store.Create(assignerOpenRecord, ids) - } else { - _, err = t.Store.Update(assignerOpenRecord, ids, e.Revision) - } - if err != nil { - t.logf("the record %s could not be kept: %v", assignerOpenRecord, err) - } -} - -// waitForAssignerRoom puts an assigner ask in the wait for room, once. -func (t *Teller) waitForAssignerRoom(key, id string) { - ws, rec, err := t.waiting() - if err != nil { - t.logf("%v", err) - return - } - if slices.ContainsFunc(ws, func(x waitingAsk) bool { return x.ID == id }) { - return - } - if t.keepWaiting(append(ws, waitingAsk{Key: key, ID: id}), rec) == nil { - t.logf("%s: the assigner's ask %s waits: %d of the assigner's asks are open, every place the router gives the teller", key, id, mostAssignerOpen) +// lapsed says whether the assigner's ask lapsed: past the expiry its words name. A lapsed ask is asked of nobody: its proposal or +// question has ended, and the router would let it lapse at once (A-424: an ask lapses at its expiry). +func lapsed(a oc.Ask, now time.Time) (time.Time, bool) { + at, err := time.Parse(time.RFC3339, a.Expires) + if err != nil || at.IsZero() { + return time.Time{}, false } + return at, !now.Before(at) } // isAssignerKey says whether an ask key is one of the assigner's, not the merge ask's key of before the Approve per merge went. @@ -187,10 +133,6 @@ func (t *Teller) raiseAssignerAsk(key string) (catchUp string) { t.logf("%s: the record of the ask %s could not be kept, so it is not raised: %v", key, id, err) return } - if !t.assignerRoom() { - t.waitForAssignerRoom(key, id) - return - } if err := t.Asker.Ask(a.Ask); err != nil { // Kept but not published (a transport fault, the router restarting): nothing writes the key again, so the ask is not // forgotten but waits, kept on the bus, to be asked again at the next end and at the teller's start (issue 1966, @@ -199,7 +141,6 @@ func (t *Teller) raiseAssignerAsk(key string) (catchUp string) { t.unheard(id) return } - t.assignerAsked(id) t.logf("%s: the assigner's ask %s is asked of the operator (%s)", key, id, a.Ask.Headline) return } 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 91d2269d..d82198e2 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 @@ -184,25 +184,40 @@ func TestAnAssignerAskWaitsForRoomAndARefusalIsSaidAsADeliveryAsk(t *testing.T) // ackFor is the router's warrant for an option of level acknowledge, as the assigner's asks offer. func ackFor(a oc.Ask, option string) oc.Warrant { return warrantFor(a, option) } -// 1906/H5: given seven holds at once (as on 2026-10-25), when they are raised, then at most mostAssignerOpen are open at the -// router, and each hold answered lets the next waiting one be asked. -func TestABurstOfHoldsAsksNoMoreThanTheMostOpenAndTheNextWhenOneEnds(t *testing.T) { +// Design 47 G A-424 (was 1906/H5): given seven holds at once (as on 2026-10-25), when they are raised, then every one is asked of +// the operator at once: the channel keeps no count of open asks and the teller waits for no room. +func TestABurstOfHoldsIsAskedAtOnce(t *testing.T) { b := newBed(t) var held []oc.Ask for n := 0; n < 7; n++ { _, ask := b.holdOf(t, n, 1) held = append(held, ask) } - if got := b.askedIDs(); len(got) != mostAssignerOpen || got[0] != held[0].ID || got[1] != held[1].ID { - t.Fatalf("asked %v, want the first %d holds only; log:\n%s", got, mostAssignerOpen, b.logs.String()) - } - if len(b.dropped) != 0 || len(b.conds) != 0 { - t.Errorf("router dropped %v, conditions %+v", b.dropped, b.conds) - } - b.deliver(t, ackFor(held[0], "release")) got := b.askedIDs() - if len(got) != mostAssignerOpen+1 || got[len(got)-1] != held[mostAssignerOpen].ID { - t.Fatalf("asked %v after a hold was answered, want the next waiting hold asked next; log:\n%s", got, b.logs.String()) + if len(got) != len(held) { + t.Fatalf("asked %v, want all %d holds; log:\n%s", got, len(held), b.logs.String()) + } + for i, a := range held { + if got[i] != a.ID { + t.Errorf("asked %v, want %s in the order raised", got, a.ID) + } + } + if len(b.dropped) != 0 || len(b.conds) != 0 || strings.Contains(b.logs.String(), "waits") { + t.Errorf("router dropped %v, conditions %+v, log:\n%s", b.dropped, b.conds, b.logs.String()) + } + // A-424: a key whose ask lapsed (its proposal ended) and a key of no kind the teller knows are dropped with a line, never asked. + key, _, ask := holdAskAt(t, 8, 1) + ask.Expires = "2000-01-01T00:00:00Z" + value, err := asks.EncodeAsk(key, asks.Ask{Ask: rawAsk(t, ask), Asking: 1}) + if err != nil { + t.Fatal(err) + } + b.assigner[key] = value + b.t.OnAssignerAsk(key) + b.t.OnAssignerAsk("placement.p-1") + if got := b.askedIDs(); len(got) != len(held) || !strings.Contains(b.logs.String(), key+" is dropped: its ask "+ask.ID+" lapsed at 2000-01-01T00:00:00Z") || + !strings.Contains(b.logs.String(), "placement.p-1 is dropped: it is no ask key of a kind the teller knows") { + t.Errorf("asked %v; log:\n%s", got, b.logs.String()) } } 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 561444db..b990a67e 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go @@ -314,9 +314,10 @@ func (t *Teller) said(h occ.Handled, w oc.Warrant, err error) { } } if h == occ.Acted || h == occ.Recorded || h == occ.Done { - // One of the teller's asks ended at the router, so it has room for one more: the first ask waiting is asked again. + // One of the teller's asks ended at the router: the asks it could not hand the router are asked again (A-424: no room + // is waited for). t.endWait(w.Ask) - t.askWaiting(1) + t.askWaiting() } } @@ -403,7 +404,7 @@ func (t *Teller) clear(askID string) { _ = t.Store.Delete(condKey(id)) } -// Room at the router (issue 1610). The router holds at most occ.MostOpen open asks of one asker and refuses another at once +// 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 @@ -524,7 +525,7 @@ func (t *Teller) endWait(id string) { // // 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 -// occ.MostOpen are asked, the most the router can have room for. +// Every one waiting is asked: the channel holds no room to wait for (A-424). func (t *Teller) OnCurrent() { // The router's records are read outside the teller's lock (as catchUp's): a read that waits on the bus holds no warrant. t.mu.Lock() @@ -565,7 +566,7 @@ func (t *Teller) OnCurrent() { if changed && t.keepWaiting(ws, rec) != nil { return } - t.askWaiting(occ.MostOpen) + t.askWaiting() } // unheard puts an ask the teller holds open and the router holds no record of in the wait for room, once. @@ -584,9 +585,10 @@ func (t *Teller) unheard(id string) { } } -// askWaiting asks again the first n asks that wait for room and are not asked yet, dropping on the way every one the assigner -// no longer asks. One at an end: one ask ended, so there is room for one. -func (t *Teller) askWaiting(n int) { +// askWaiting asks again every ask that waits and is not asked yet, dropping on the way every one the assigner no longer asks: the +// channel holds no room to wait for (design 47 G A-424), so a wait is only an ask the router did not take or whose word was not +// heard, and one kept waiting before the change is asked at the next end or start. +func (t *Teller) askWaiting() { ws, rec, err := t.waiting() if err != nil { t.logf("%v", err) @@ -607,10 +609,6 @@ func (t *Teller) askWaiting(n int) { i++ continue } - if isAssignerKey(x.Key) && !t.assignerRoom() { - i++ // the assigner's asks hold their most open: it waits - continue - } 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) @@ -623,11 +621,7 @@ func (t *Teller) askWaiting(n int) { return } ws[i].Asked = true - t.assignerAsked(x.ID) 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) - if n--; n <= 0 { - return - } 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 5c0f826c..f64c4a38 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 @@ -277,9 +277,8 @@ func TestAnAssignersKeyBecomesOneRouterAskAndDeletingItCancelsIt(t *testing.T) { if n := len(b.askedOf(oc.AcceptSubjectCancel(tellerModule))); n != 1 { t.Errorf("the ask was cancelled %d times", n) } - // Issue 774: teller_end_ask ends one by hand, named by its key or its router id; the router's word that it ended asks the - // one waiting for room again (the assigner's asks hold at most mostAssignerOpen places, every one the router gives, design 47 - // G §653: the fourth waits). + // Issue 774: teller_end_ask ends one by hand, named by its key or its router id; nothing waits for room behind it (design 47 + // G A-424: every ask is asked at once). for _, c := range []struct { name string by func(key string, ask oc.Ask) string @@ -300,25 +299,25 @@ func TestAnAssignersKeyBecomesOneRouterAskAndDeletingItCancelsIt(t *testing.T) { } b.deliver(t, oc.Warrant{Ask: first.ID, Asker: tellerModule, Outcome: occ.OutcomeCancelled, At: occ.FormatTime(now), AskDigest: occ.Digest(first)}) if got := b.askedIDs(); len(got) != 4 || got[3] != third.ID { - t.Errorf("asks = %v, want the waiting %s asked once the ask ended by hand left", got, third.ID) + t.Errorf("asks = %v, want all four asked at once, %s the last, and none asked again", got, third.ID) } if again := b.t.EndAsk(k1, "again", "lead@shanks"); again.Ended || len(b.askedOf(oc.AcceptSubjectCancel(tellerModule))) != 1 { t.Errorf("a second end = %+v: an ended ask is left", again) } }) } - t.Run("774: an ask waiting for room is dropped from the wait; a name the teller holds no ask under is said", func(t *testing.T) { + t.Run("774: the fourth ask of one asker is open and ended by hand at the router; a name the teller holds no ask under is said", func(t *testing.T) { b := newBed(t) _, first := b.holdOf(t, 1, 1) b.holdOf(t, 2, 1) b.holdOf(t, 3, 1) _, third := b.holdOf(t, 4, 1) - if r := b.t.EndAsk(third.ID, "asked about what no longer holds", "lead@shanks"); !r.Ended || len(b.askedOf(oc.AcceptSubjectCancel(tellerModule))) != 0 { - t.Fatalf("end of a waiting ask = %+v", r) + if r := b.t.EndAsk(third.ID, "asked about what no longer holds", "lead@shanks"); !r.Ended || len(b.askedOf(oc.AcceptSubjectCancel(tellerModule))) != 1 { + t.Fatalf("end of the fourth ask = %+v", r) } b.deliver(t, warrantFor(first, "keep")) - if got := b.askedIDs(); len(got) != 3 { - t.Errorf("asks = %v: the ask ended while it waited was asked again", got) + if got := b.askedIDs(); len(got) != 4 { + t.Errorf("asks = %v: an ask was asked again after an end", got) } if r := b.t.EndAsk("hold.nothing.here", "a typo", "lead@shanks"); r.Ended || !strings.Contains(r.Says, "holds no ask") { t.Errorf("end of an unknown ask = %+v", r) diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/viewanswers.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/viewanswers.go index 5673e82e..81b026c1 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/viewanswers.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/viewanswers.go @@ -42,11 +42,20 @@ func (t *Teller) OnAssignerAsk(key string) { func (t *Teller) onAssignerAsk(key string) string { t.mu.Lock() defer t.mu.Unlock() - if _, err := viewstate.ViewAnswerKey(key); err != nil { - t.logf("the assigner's key %s is left and never answered from the view: %v", key, err) + if !isAssignerKey(key) { + t.logf("the assigner's key %s is dropped: it is no ask key of a kind the teller knows, so it is asked of nobody", key) return "" } - t.fillFromView(key) + if a, found, err := t.assignerAsk(key); err == nil && found { + if at, gone := lapsed(a.Ask, t.now()); gone { + t.logf("the assigner's key %s is dropped: its ask %s lapsed at %s (what it asked about has ended), so it is asked of nobody", key, a.Ask.ID, at.UTC().Format(time.RFC3339)) + return "" + } + } + // The view only fills an answer already given there; one it cannot read never holds the raise back (design 47 G A-424). + if _, err := viewstate.ViewAnswerKey(key); err == nil { + t.fillFromView(key) + } return t.raiseAssignerAsk(key) } @@ -66,7 +75,7 @@ func (t *Teller) fillFromView(askKey string) { } rawAnswer, at, found, err := t.viewAnswer(viewKey) if err != nil { - t.logf("%s: the view's answer could not be read, so the ask is left: %v", askKey, err) + t.logf("%s: the view's answer could not be read, so none is filled from it; the ask is raised all the same: %v", askKey, err) return } if !found { diff --git a/modules/mesh-delivery-teller/internal/ends/ends.go b/modules/mesh-delivery-teller/internal/ends/ends.go index a6f56eb3..718238e8 100644 --- a/modules/mesh-delivery-teller/internal/ends/ends.go +++ b/modules/mesh-delivery-teller/internal/ends/ends.go @@ -1,8 +1,7 @@ // Package ends is the teller's recovery tool teller_end_ask and the value it writes (issue 774; the instruction "tools are -// how a module is spoken to"). An ask the teller holds open at the router keeps one of the three places the router gives -// its asker (asks.MostOpen) until it is answered, it lapses, or the gate or the assigner takes its key away. When that last -// never comes (on 2026-10-31 two merge asks of pull requests merged by another path held two places for a day, and a -// assignments ask was refused for want of room), a person ends the ask by hand. The teller's process serves no request +// how a module is spoken to"). An ask the teller holds open at the router stays offered until it is answered, it lapses, or the +// assigner takes its key away; the channel holds no places to keep (design 47 G A-424). When the question it asks is gone and its +// key never goes, a person ends the ask by hand. The teller's process serves no request // subject (ADR 0437 §4), so the tool writes an end into the teller's state ends, which the teller watches, carries out // and answers there, as the indexer answers indexer_take_in. package ends