From 76b2e8dc7d566482175d8e12693cecce4f7cc1fa Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 05:10:24 +0100 Subject: [PATCH] A-60: the assigner asks an unreached entry again to entry-asks, then writes entry-unanswered The passer's catalog entries are the followed branches' own, so each catalog-revision asks again an entry whose ask failed to reach the holder, and so does each reopening of the assigner's link to the bus; the manifest's setting entry-asks (default 5) bounds it, and past it the assigner's finding writer writes entry-unanswered (and entry-not-found) through the entries client. Builds: design 47 H H-A-60 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- .../cmd/mesh-delivery-assigner/main.go | 40 +++++++++++++++++- .../cmd/mesh-delivery-assigner/main_test.go | 42 +++++++++++++++++++ .../mesh-delivery-assigner/manifest_test.go | 3 +- modules/mesh-delivery-assigner/module.json | 17 ++++++++ 4 files changed, 99 insertions(+), 3 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go index 13e52448..745d4e0a 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -619,8 +619,12 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, } iv.candidates.Store(&keep) // A held revert's running entry and its want's, asked of the seat mesh-catalog's verb entry (design 47 G §710, A-217). - p.entries = meshcatalogclient.NewEntries(iv.h.call) - p.entries.Changed = func(meshcatalogclient.EntryRow) { wake() } + entryAsks, err := settingFile(getenv("MESH_ASSIGNER_ENTRY_ASKS_FILE")) + if err != nil { + return err + } + p.entries = entriesOf(iv.h.branches, iv.h.call, entryAsks, iv.writer, wake) + askAgainOnReconnect(ctx, nc, p.entries) // The revisions that are not current are removed when one ceases to be current and once now (revisions.go, // design 47 H §764, H-A-86). p.graph.revisions = &revisionRemover{ctx: ctx, objects: objects, inUse: inUseOf(w), logf: logger.Printf} @@ -814,3 +818,35 @@ func hearReadsChanged(ctx context.Context, js jetstream.JetStream, hub *process. hub.Stop() }() } + +// entriesOf are the catalog entries the passer asks by fingerprint: the followed branches' own, so each catalog-revision asks +// again an entry whose ask failed to reach the holder, at most asks times (the setting entry-asks, 0 its default), and the +// assigner's finding writer writes entry-not-found and entry-unanswered of them (design 47 H, H-A-60). Each change wakes a pass. +func entriesOf(b *meshcatalogclient.Branches, call meshcatalogclient.Call, asks int, w views.WireWriter, wake func()) *meshcatalogclient.Entries { + if b == nil || b.Entries == nil { + b = &meshcatalogclient.Branches{Entries: meshcatalogclient.NewEntries(call)} + } + b.Entries.Asks = asks + if w == nil { + b.Entries.Changed = func(meshcatalogclient.EntryRow) { wake() } + return b.Entries + } + b.WriteEntryFindings(w, func(meshcatalogclient.EntryRow) { wake() }) + return b.Entries +} + +// askAgainOnReconnect asks the entries again whose ask failed each time the assigner's link to the bus opens again (design 47 +// H, H-A-60), after whatever the connection already does then. +func askAgainOnReconnect(ctx context.Context, nc process.Subscriber, e *meshcatalogclient.Entries) { + conn, ok := nc.(*nats.Conn) + if !ok || conn == nil { + return + } + before := conn.Opts.ReconnectedCB + conn.SetReconnectHandler(func(c *nats.Conn) { + if before != nil { + before(c) + } + e.AskAgain(ctx) + }) +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main_test.go index 0338bcbf..cd1af9b7 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main_test.go @@ -16,6 +16,7 @@ import ( "os" "path/filepath" "reflect" + "runtime" "slices" "strings" "testing" @@ -26,6 +27,7 @@ import ( mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-sdk/go/catalogue" "git.novox.be/novox/mesh-sdk/go/process" "git.novox.be/novox/mesh-sdk/go/seatlist" @@ -209,3 +211,43 @@ func putInto(into map[string][]byte) func(mcseat.Finding) error { return err } } + +// fakeWire is a views part's finding writer that hands each written finding's kind on. +type fakeWire struct{ written chan string } + +func (f fakeWire) WriteWire(_ context.Context, finding map[string]any) error { + k, _ := finding["kind"].(string) + f.written <- k + return nil +} +func (fakeWire) Clear(context.Context, string, string, string, string) error { return nil } +func (fakeWire) ModuleNode() (string, string) { return "mesh-delivery-assigner", "n1" } + +// H-A-60: the assigner's entries are asked again to the setting entry-asks, then written through its finding writer as the +// finding entry-unanswered. +func TestAnUnreachedEntryEndsInTheAssignersFindingEntryUnanswered(t *testing.T) { + ctx := context.Background() + unreached := func(string, any) (json.RawMessage, error) { return nil, errors.New("no responders") } + w := fakeWire{written: make(chan string, 4)} + e := entriesOf(nil, unreached, 1, w, func() {}) + if e.Asks != 1 { + t.Fatalf("entry-asks %d, want 1 from the setting", e.Asks) + } + e.Need(ctx, "src2:u") + deadline := time.Now().Add(5 * time.Second) + for { + select { + case kind := <-w.written: + if kind != meshcatalogclient.EntryUnansweredKind { + t.Fatalf("the finding written is %q, want %s", kind, meshcatalogclient.EntryUnansweredKind) + } + return + default: + } + if time.Now().After(deadline) { + t.Fatal("no finding entry-unanswered is written past the bound") + } + e.AskAgain(ctx) + runtime.Gosched() + } +} diff --git a/modules/mesh-delivery-assigner/manifest_test.go b/modules/mesh-delivery-assigner/manifest_test.go index 9989b6ae..16bf094b 100644 --- a/modules/mesh-delivery-assigner/manifest_test.go +++ b/modules/mesh-delivery-assigner/manifest_test.go @@ -165,7 +165,7 @@ func TestManifest(t *testing.T) { } file, _ := os.ReadFile("module.json") if err := json.Unmarshal(file, &raw); err != nil || raw.Config["outside-wait-minutes"].Default != float64(30) || raw.Config["outside-settle-seconds"].Default != float64(90) || - raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 9 || raw.Config["tier-bound"].Default != float64(30) || + raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 10 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || raw.Config["composition-runs-cap-mib"].Default != float64(16) || raw.Config["composition-runs-kept"].Default != "24h" || raw.Config["composition-step-bound"].Default != "30m" || raw.Config["run-untaken-bound"].Default != "24h" || raw.Config["blame-tries"].Default != float64(20) { t.Errorf("config = %+v (%v), want outside-wait-minutes of 30, outside-settle-seconds of 90 and ask-operator-for of take-off,remove-node,stops (A-425a)", raw.Config, err) @@ -181,6 +181,7 @@ func TestManifest(t *testing.T) { {"MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE", "${dir:state}/run-untaken-bound", "run-untaken-bound"}, {"MESH_ASSIGNER_BLAME_TRIES_FILE", "${dir:state}/blame-tries", "blame-tries"}, {"MESH_ASSIGNER_TIER_BOUND_FILE", "${dir:state}/tier-bound", "tier-bound"}, // design 47 H §751 + {"MESH_ASSIGNER_ENTRY_ASKS_FILE", "${dir:state}/entry-asks", "entry-asks"}, // design 47 H H-A-60 } { if !strings.Contains(string(file), `"`+f.env+`": "`+f.path+`"`) || !strings.Contains(string(file), `"path": "`+f.path+`"`) || !strings.Contains(string(file), `"content": "${config:`+f.key+`}"`) { diff --git a/modules/mesh-delivery-assigner/module.json b/modules/mesh-delivery-assigner/module.json index d3032c70..5dfdd07d 100644 --- a/modules/mesh-delivery-assigner/module.json +++ b/modules/mesh-delivery-assigner/module.json @@ -185,6 +185,14 @@ "trusted": false, "default": 30 }, + "entry-asks": { + "type": "number", + "description": "how often the assigner asks a catalog entry again, on each catalog-revision and when its link to the bus opens again, after its ask failed to reach the holder of the seat mesh-catalog; one more failure leaves it unanswered, with the finding entry-unanswered (design 47 H, H-A-60).", + "minimum": 1, + "maximum": 100, + "trusted": false, + "default": 5 + }, "composition-runs-cap-mib": { "type": "number", "description": "the cap of the state composition-runs in MiB, the process refusing a new composition run at it with its steps ending could not run naming the fill (design 47 G section 719, A-469d); its maximum is the manifest's max-mib.", @@ -275,6 +283,14 @@ "mode": "0600", "content": "${config:tier-bound}" }, + { + "id": "entry-asks", + "type": "file", + "path": "${dir:state}/entry-asks", + "owner": "mesh-delivery-assigner", + "mode": "0600", + "content": "${config:entry-asks}" + }, { "id": "composition-runs-cap-mib", "type": "file", @@ -329,6 +345,7 @@ "MESH_ASSIGNER_OUTSIDE_SETTLE_FILE": "${dir:state}/outside-settle-seconds", "MESH_ASSIGNER_ASK_OPERATOR_FOR_FILE": "${dir:state}/ask-operator-for", "MESH_ASSIGNER_TIER_BOUND_FILE": "${dir:state}/tier-bound", + "MESH_ASSIGNER_ENTRY_ASKS_FILE": "${dir:state}/entry-asks", "MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE": "${dir:state}/composition-runs-cap-mib", "MESH_ASSIGNER_COMPOSITION_RUNS_KEPT_FILE": "${dir:state}/composition-runs-kept", "MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "${dir:state}/composition-step-bound",