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
This commit is contained in:
2026-11-21 22:32:36 +01:00
parent d0129d08ae
commit 3991d531bf
+24 -5
View File
@@ -237,7 +237,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
@@ -339,9 +352,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)
@@ -350,6 +363,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)
@@ -371,7 +385,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)
@@ -399,6 +413,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)
@@ -1432,6 +1447,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.)
{