MH-0: an entry whose ask failed is asked again, at most entry-asks times, then unanswered

The node-engine consumes the entries client's asking again (H-A-60, H-A-110): the setting entry-asks (default 5; module.json
config and file resource, read at the engine's start) goes to Entries.Asks; Entries.AskAgain is called at each link's start and
on each catalog-revision the composer hears (the shadow's cache too); the finding entry-unanswered joins the engine's finding
kinds, written with a journal line when an entry ends unanswered and cleared when it is answered or no longer wanted; the
shadow's wait and the have's hold end on it instead of waiting without bound.

Builds: design 47 H, H-A-60, H-A-110

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-20 04:25:00 +01:00
parent e4d098c4b9
commit 39e16689fa
12 changed files with 286 additions and 5 deletions
+79
View File
@@ -635,6 +635,7 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
// it is bound to), never of every module placed there, and beside the pass.
func TestOnlyWhatTheNodeNeedsOfAnotherNodesPlacementIsAsked(t *testing.T) {
t.Run("a trunk build the catalog gave none of waits its backoff or a catalog-revision (A-487a)", trunkAskBackoffAndCatalogRevision)
t.Run("an entry whose ask failed is asked again on each catalog-revision, at most entry-asks times, then unanswered (H-A-60, H-A-110)", entryAskedAgainThenUnanswered)
env := newFakeBus().env()
env.Node = "n1"
var mu sync.Mutex
@@ -770,3 +771,81 @@ func trunkAskBackoffAndCatalogRevision(t *testing.T) {
t.Error("catalog-revision was heard and the wait of the module stands")
}
}
// Design 47 H, H-A-60 and H-A-110: an entry whose ask failed in transport is asked again on each catalog-revision the composer hears
// (never on a timer), at most the setting entry-asks times; one more failure and it is unanswered, said in the journal and as the
// finding entry-unanswered, which the shadow does not wait on; asked again by hand and answered, the finding is cleared.
func entryAskedAgainThenUnanswered(t *testing.T) {
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("c", 64)
var calls atomic.Int32
var answers atomic.Bool
env := newFakeBus().env()
env.EntryAsks = 2
env.Entry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) {
calls.Add(1)
if answers.Load() {
return json.Marshal(meshcatalog.EntryAnswer{Entry: meshcatalog.CatalogEntry{Module: "web", Fp: fp}})
}
return nil, errors.New("the bus did not answer")
})
var mu sync.Mutex
var said []string
told := []string{}
env.Say = func(line string) { mu.Lock(); said = append(said, line); mu.Unlock() }
env.EntryUnanswered = func(got string, asks int, unanswered bool) {
mu.Lock()
told = append(told, fmt.Sprintf("%s %d %v", got, asks, unanswered))
mu.Unlock()
}
heard := make(chan []byte)
env.Hear = func(string) (<-chan []byte, func(), error) { return heard, func() {}, nil }
c := New(env)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go c.hearCatalogRevisions(ctx, func() {})
state := func() meshcatalogclient.EntryState { _, st := c.entries.Need(ctx, fp); return st }
c.entries.Need(ctx, fp)
// Each catalog-revision asks the failed entry again once: three asks in all, the third being the one past the bound of two.
for deadline := time.Now().Add(10 * time.Second); state() != meshcatalogclient.EntryUnanswered; {
if time.Now().After(deadline) {
t.Fatalf("the entry is %s after %d asks, want unanswered", state(), calls.Load())
}
select {
case heard <- nil:
case <-time.After(time.Millisecond):
}
}
for i := 0; i < 3; i++ {
heard <- nil // an unanswered entry is not asked again by an event
}
var gotTold, gotSaid string
for deadline := time.Now().Add(10 * time.Second); gotTold == "[]" || gotTold == ""; runtime.Gosched() {
mu.Lock()
gotTold, gotSaid = fmt.Sprint(told), strings.Join(said, "\n")
mu.Unlock()
if time.Now().After(deadline) {
break
}
}
if calls.Load() != 3 || gotTold != "["+fp+" 2 true]" || !strings.Contains(gotSaid, "is unanswered") || !strings.Contains(gotSaid, fp) {
t.Errorf("asked %d times, told %s, said %q; want 3 asks, the finding told once with 2 asks and the journal line", calls.Load(), gotTold, gotSaid)
}
// The shadow's wait on the entry ends: it is no longer pending.
c.mu.Lock()
c.wants = map[string]meshwants.WantsByWantNodeModuleValue{"web": {Fp: fp}}
c.mu.Unlock()
if c.syncShadowEntries(ctx) {
t.Error("the shadow still waits on an unanswered entry")
}
// Asked again by hand and answered, the finding is cleared.
answers.Store(true)
if err := c.entries.Again(ctx, fp); err != nil {
t.Fatal(err)
}
mu.Lock()
gotTold = fmt.Sprint(told)
mu.Unlock()
if gotTold != "["+fp+" 2 true "+fp+" 0 false]" {
t.Errorf("told %s after the answer, want the finding cleared", gotTold)
}
}