From b113e57c6cce442d559081c2f3d7b6eed1a7dd86 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 22:25:33 +0100 Subject: [PATCH 1/3] Order the ghost's entry case and end the first shadow before its setting changes Review round 2 (2), fix-a-bug-met-twice: the ghost's entry was answered at once, so a pass could read it entry-missing before the assertion read entry-asked; its answer now waits until the assertion has read. The 250 ms real sleep before compose now is gone: askedWithin is set to none, then to an hour for the ask made again at once. The first shadow ran on while notReadyAfter was set for the next step, a data race; it is ended first. Builds: design 47 H H-A-312 --- internal/selfcompose/selfcompose_test.go | 29 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/internal/selfcompose/selfcompose_test.go b/internal/selfcompose/selfcompose_test.go index 32736a8f..6c7892e4 100644 --- a/internal/selfcompose/selfcompose_test.go +++ b/internal/selfcompose/selfcompose_test.go @@ -236,7 +236,20 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := b.env() - env.Entry = half.call() + // The ghost's entry (issue 1966's step below) is answered only once that step has read it as asked: answered at once, + // a pass could read it as entry-missing before the assertion (review round 2; the race H-A-303's review saw too). + ghostFp := meshcatalogclient.SourcePrefix2 + strings.Repeat("8", 64) + ghostRead := make(chan struct{}) + var ghostOnce sync.Once + readGhost := func() { ghostOnce.Do(func() { close(ghostRead) }) } + defer readGhost() + entry := half.call() + env.Entry = func(key string, body any) (json.RawMessage, error) { + if in, ok := body.(meshcatalog.EntryInput); ok && in.Fingerprint == ghostFp { + <-ghostRead + } + return entry(key, body) + } // The vault's own: keeper's password sealed to n1's key, sealed again (other bytes) at every ask. var asks, generation int sealedAt := map[string]int{} // each box handed, by the generation it opens to @@ -338,9 +351,9 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { b.mu.Unlock() // Issue 774, 2026-10-31: the verb compose makes a pass now and says how it went; a composer that runs no watch // makes none, and says so rather than waiting. - // The pass made at the start is less than askedWithin old for a moment: the ask waits that out first. - setFor(t, &askedWithin, 200*time.Millisecond) - time.Sleep(250 * time.Millisecond) + // The pass made at the start is the answer while it is less than askedWithin old: with none counted recent, the ask + // makes a pass (no real wait for the start's pass to age, review round 2). + setFor(t, &askedWithin, 0) madeBefore := composed.Load() cctx, ccancel := context.WithTimeout(ctx, 5*time.Second) nowPass, err := c.ComposeNow(cctx) @@ -349,6 +362,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { t.Errorf("compose now: %+v (%v), %d pass(es) made; want one pass, composed", nowPass, err, composed.Load()-madeBefore) } // Asked again at once, the last pass is the answer: a caller in a loop drives no passes back to back (review round 1). + setFor(t, &askedWithin, time.Hour) madeBefore = composed.Load() if again, err := c.ComposeNow(ctx); err != nil || !again.Earlier || !again.At.Equal(nowPass.At) || composed.Load() != madeBefore { t.Errorf("compose now asked again at once: %+v (%v), %d pass(es) made; want the last pass, none made", again, err, composed.Load()-madeBefore) @@ -370,7 +384,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { // Issue 1966 (novox, 2026-11-09): every pass names each wanted module it composed nothing of, or composed from the indexer's // manifest for want of a done build, with why, and a want it did not take; said once; the agent's word that it waits // hands a composition the node believes handed again. - tfp, ghostFp := toolFp, meshcatalogclient.SourcePrefix2+strings.Repeat("8", 64) + tfp := toolFp c.holdEntry(t, "tool", tfp, toolBody) for module, w := range map[string]meshwants.WantsByWantNodeModuleValue{"tool": {Fp: tfp, Self: true}, "ghost": {Fp: ghostFp, Self: true}, "nofp": {Self: true}} { raw, _ := bucketstest.Want(w) @@ -398,6 +412,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { !strings.Contains(why["nofp"], "want not taken: its want names no fingerprint") || why["lemurs"] != "" { t.Errorf("the pass says it composed nothing of %q", why) } + readGhost() c.compose(ctx) if n := said("the node composes nothing of nofp"); n != saidOfNofp || n == 0 { t.Errorf("the journal says why nofp is not composed %d times after the second pass, %d after the first: want the same, not none", n, saidOfNofp) @@ -1431,6 +1446,10 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { return !ok && len(a) == 7 }) + // The shadow ends here: its tries read notReadyAfter, which the step below sets (review round 2, the race detector). + scancel() + <-kept + // Issue 1126, A7 AC1: a assignment that cannot be read composes nothing and says why; the node never applies a // composition made elsewhere instead. (A assignment read without the node's key composes nothing either: above.) { -- 2.54.0 From 65944090847409c474cee0dd6f1fba33b127b6b8 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 22:43:14 +0100 Subject: [PATCH 2/3] Wait for the shadow's settled answer and end the second shadow before its setting is restored fix-a-bug-met-twice, the kind: TestTheNodeComposesItsWantsFromTheBus asserted on output its composer and shadows still produced, or let their goroutines outlive a setting they read. The groups' answers are now waited for until every group is answered as it should be, not read from whichever answer came first (which flaked, and the settled one then read as handed again for nothing changed); the second shadow is ended before the test's cleanup restores notReadyAfter. Carries the ghost-entry order and the first shadow's end from the packet filter branch. Builds: design 47 H H-A-312 --- internal/selfcompose/selfcompose_test.go | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/selfcompose/selfcompose_test.go b/internal/selfcompose/selfcompose_test.go index 6c7892e4..8fc5ddeb 100644 --- a/internal/selfcompose/selfcompose_test.go +++ b/internal/selfcompose/selfcompose_test.go @@ -1292,7 +1292,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { } } readOnly.mu.Unlock() - for group, want := range map[string]func(nodeengine.CandidateAnswer) bool{ + groups := map[string]func(nodeengine.CandidateAnswer) bool{ "same": func(a nodeengine.CandidateAnswer) bool { return a.Verdict == nodeengine.CandidateAnswerVerdictSame && a.Proposal == "same" && a.Revision == 3 && len(a.Same) == 2 }, @@ -1327,11 +1327,19 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { return a.Verdict == nodeengine.CandidateAnswerVerdictRefused && a.Returns == "" && a.Revision == 7 && strings.Contains(a.Refused, "composes nothing") }, - } { - if !want(answers[group]) { - t.Errorf("%s: %+v", group, answers[group]) - } } + // Answered as each group should be: the shadow answers again while what it reads comes in (what runs, an entry), so an + // answer before the last may still hold lemurs as it runs; the test waits for the answer that settles every group + // (fix-a-bug-met-twice: asserting on whichever answer came first flaked, and the settled one then read as "handed + // again for nothing changed"). + waitFor("every group answered as it should be", func(a map[string]nodeengine.CandidateAnswer) bool { + for group, want := range groups { + if !want(a[group]) { + return false + } + } + return true + }) // The node's own key changing (its answers written) composes nothing again; a group's key deleted drops its answer. sb.put(buckets.Have, "n1.node", rec, 2) select { @@ -1482,8 +1490,11 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { nanswered := make(chan map[string]nodeengine.CandidateAnswer, 8) nsh := NewShadow(nenv, func(_ context.Context, a map[string]nodeengine.CandidateAnswer) { nanswered <- a }) nctx, ncancel := context.WithCancel(ctx) - defer ncancel() - go func() { _ = nsh.Run(nctx) }() + // The shadow has ended before the test's cleanup restores notReadyAfter, which its run reads (fix-a-bug-met-twice: + // a goroutine outliving the setting it reads, the race of the first shadow above too). + nDone := make(chan struct{}) + defer func() { ncancel(); <-nDone }() + go func() { _ = nsh.Run(nctx); close(nDone) }() nb.made(6) nb.putAssigned(tp, 1) nb.put(buckets.Have, "n1.node", rec, 1) -- 2.54.0 From ed8aa8347556f7eb2d05dc2a8d13dda243b440c5 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 22:46:55 +0100 Subject: [PATCH 3/3] End the composer's loop before its settings are restored fix-a-bug-met-twice, the same kind as the shadows: the composer's loop of TestTheNodeComposesItsWantsFromTheBus ran on, until the deferred cancel, past the cleanup that restores composeAgain, laterAgain, passSaysEvery and slowAfter, which its passes read. The test now cancels it and waits for its out to close first. -race -count=50: 50 of 50, no race. Suspected, not fixed: the flake "the composer handed n1.tool.7777..., and nothing changed" (trunk line 691, 1 of 60 at review, 0 of 200 here), I think a compose-again pass handing a composition late after the issue 1966 step. Builds: design 47 H H-A-312 --- internal/selfcompose/selfcompose_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/selfcompose/selfcompose_test.go b/internal/selfcompose/selfcompose_test.go index 8fc5ddeb..c2632498 100644 --- a/internal/selfcompose/selfcompose_test.go +++ b/internal/selfcompose/selfcompose_test.go @@ -280,6 +280,14 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { if err != nil { t.Fatal(err) } + // The composer's loop has ended (its out closed) before the test's cleanup restores composeAgain, laterAgain, + // passSaysEvery and slowAfter, which its passes read (fix-a-bug-met-twice: a goroutine outliving the setting it reads, + // as the shadows below). + defer func() { + cancel() + for range out { + } + }() // oldie is placed and no want names it (a module at a build of the old form, nats on novox): the node runs it inside // its own composition, and composes it there again, even before the agent has applied anything (Running empty). oldie := `{"module":"oldie","version":"1","capabilities":["systemd"],"resources":[{"id":"service","type":"service","unit":"oldie.service","state":"running","boot":"enabled"}]}` -- 2.54.0