H5 (review r2, A-308, A-312): the shadow watches no indexer modules; it reads the entries its wants name and asks the verb module for a module a candidate adds

Builds: design 47 G §421, §628
This commit is contained in:
2026-11-12 22:28:15 +01:00
parent 1d409cd852
commit e558510a54
8 changed files with 226 additions and 31 deletions
+89 -10
View File
@@ -8,12 +8,14 @@ import (
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
nodeengine "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
"github.com/novox/mesh-host/internal/buckets"
"github.com/novox/mesh-host/internal/compose/frombus"
engcomp "github.com/novox/mesh-host/internal/compositions"
"github.com/novox/mesh-host/internal/judge"
"maps"
"sort"
"strings"
"sync"
@@ -61,6 +63,8 @@ type Shadow struct {
// after a bound (laterAgain), whether or not an input moves (issue 1126, 2026-10-28: ace kept "the vault's own: not
// yet ... no responders" in its answer to seed-7).
owed bool
// entryMoved wakes the run when an entry it asked of the catalog half is answered or found missing (§421).
entryMoved chan struct{}
// ready says this run read every input once: the verb compose-candidate composes only then (ComposeCandidate).
ready atomic.Bool
}
@@ -72,7 +76,7 @@ type answeredAt struct {
}
// inputWords name the shadow's inputs, in Run's order, as an answer says which of them woke it.
var inputWords = [...]string{"the candidate", "assignment", "records", "modules", "values", "haves"}
var inputWords = [...]string{"the candidate", "assignment", "records", "wants", "values", "haves"}
// wokenBy says what moved between the answer a proposal stands at (had, when done) and the one about to be composed (at):
// its first answer, a retry, its candidate's revisions, or the inputs that changed, by their words.
@@ -106,8 +110,28 @@ type candidateKey struct {
// NewShadow is the shadow composer of one node; answer writes the node's answers into its own have key.
func NewShadow(env Env, answer func(ctx context.Context, answers map[string]nodeengine.CandidateAnswer)) *Shadow {
return &Shadow{c: New(env), answer: answer, candidates: map[string]map[string]candidateKey{},
answers: map[string]nodeengine.CandidateAnswer{}, ran: map[string]string{}}
s := &Shadow{answer: answer, candidates: map[string]map[string]candidateKey{},
answers: map[string]nodeengine.CandidateAnswer{}, ran: map[string]string{}, entryMoved: make(chan struct{}, 1)}
s.c = s.composer(env)
return s
}
// composer is a composer for the shadow: it asks the catalog half's entry of each build the node's wants name, and wakes the
// run when one answers (design 47 G §421, A-308: the node-engine no longer watches the indexer's modules).
func (s *Shadow) composer(env Env) *Composer {
env.ComposedState = nil // the node's own composer keeps the composition state; the shadow writes nothing
c := New(env)
c.forCandidates = true
if c.entries != nil {
c.entries.Changed = func(row meshcatalogclient.EntryRow) {
c.entryChanged(row)
select {
case s.entryMoved <- struct{}{}:
default:
}
}
}
return c
}
// Keep runs the shadow until ctx ends, beginning again after backoff(try) whenever it stops: an input it cannot watch
@@ -153,7 +177,7 @@ func (s *Shadow) Run(ctx context.Context) error {
s.answered = map[string]answeredAt{}
s.moved = [len(inputWords)]uint64{}
s.retry = map[string]bool{}
s.c = New(s.c.env)
s.c = s.composer(s.c.env)
s.mu.Unlock()
s.ready.Store(false)
defer s.ready.Store(false)
@@ -164,7 +188,7 @@ func (s *Shadow) Run(ctx context.Context) error {
{buckets.ProposalCandidates, ">", nil, nil},
{buckets.Assignments, ">", (*Composer).takeAssignments, nil},
{buckets.Have, "*." + nodeengineclient.NodeWord, nil, nil},
{buckets.Modules, ">", (*Composer).takeModule, nil},
{buckets.Wants, "want." + node + ".>", (*Composer).takeWant, nil},
{ResolvedBucket, node + ".>", (*Composer).takeValue, nil},
// What this node runs moved: an apply ends in its module's have.
{buckets.Have, node + ".>", nil, nil},
@@ -209,6 +233,9 @@ func (s *Shadow) Run(ctx context.Context) error {
case <-again:
again = nil
dirty = true
case <-s.entryMoved:
s.moved[3]++
dirty = true
case <-waiting.C:
if !ready {
s.notReady(ctx, ins, caught)
@@ -245,10 +272,15 @@ func (s *Shadow) Run(ctx context.Context) error {
continue
}
}
if !ready && !all(caught) {
continue
}
// What the wants name is read from the catalog half's entries; an answer waits until each entry asked has come (§421).
if (dirty || !ready) && s.c.syncShadowEntries(ctx) {
continue
}
if !ready {
if ready = all(caught); !ready {
continue
}
ready = true
s.ready.Store(true)
dirty = true
}
@@ -386,6 +418,12 @@ func (s *Shadow) answerAll(ctx context.Context) {
proposals = append(proposals, l)
}
// A proposal whose keys' revisions and the node's inputs are those its answer stands at is not answered again.
if len(s.candidates) == 0 {
// No proposal is left that adds a module: the entries asked for those are no longer kept (A-312).
c.mu.Lock()
c.addedFps = nil
c.mu.Unlock()
}
for g := range s.answered {
if _, ok := s.candidates[g]; !ok {
delete(s.answered, g)
@@ -554,6 +592,46 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
inOwn := c.inOwnOf(*assignment)
c.mu.Unlock()
fps := shadowBuilds(running, *assignment, modules, inOwn)
// A module the candidate adds that no want here names: the trunk's build is asked of the catalog half's verb module, and its
// entry by the verb entry (design 47 G §421, A-312). One with no build to take is held, with the reason.
heldAdded := map[string]string{}
folded := map[string]bool{}
for _, m := range inOwn {
folded[m] = true
}
for _, pm := range assignment.Modules {
if _, has := fps[pm.Module]; has || folded[pm.Module] || pm.Module == "" {
continue
}
fp, entry, held, pending, why := c.addedModule(ctx, pm.Module)
if pending {
// Its answer wakes the shadow (entryMoved), which composes this proposal again: until then this is no answer to keep, as one
// that met a read the bus did not answer is none.
c.missed.Add(1)
return nodeengine.CandidateAnswer{Proposal: proposal, Revision: int64(rev), Verdict: nodeengine.CandidateAnswerVerdictRefused,
Refused: why + ", so this answer waits for it"}, true
}
if !held {
heldAdded[pm.Module] = why
continue
}
digest, raw, err := entryManifest(entry)
if err != nil {
heldAdded[pm.Module] = fmt.Sprintf("the entry of %s's build %s holds no manifest that can be read: %v", pm.Module, fp, err)
continue
}
m := meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: entry.Repository, Commit: entry.Commit, Path: entry.Path,
Needs: entry.Needs, Packages: entry.Packages, Verdict: entry.Verdict}
if entry.Inputs != nil {
m.Problems, m.Warnings, m.Unknown = entry.Inputs.Problems, entry.Inputs.Warnings, entry.Inputs.Unknown
}
c.mu.Lock()
c.modules[pm.Module] = m
c.manifests[digest] = raw
c.mu.Unlock()
modules[pm.Module] = m
fps[pm.Module] = fp
}
kept := map[string]string{}
for module, fp := range fps {
if mod, ok := modules[module]; ok && mod.Fp2 == fp {
@@ -571,7 +649,7 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
c.wants = held
c.mu.Unlock()
a := frombus.Answer(ctx, reader{c: c}, c.env.Mesh, frombus.Scope{Node: node, KeptAt: kept, Assignments: given, InOwn: inOwn,
SameValue: c.sameValue, HeldToday: s.heldToday()}, fps, running, proposal, rev)
SameValue: c.sameValue, HeldToday: s.heldToday(heldAdded)}, fps, running, proposal, rev)
s.mu.Lock()
ran := make(map[string]string, len(s.ran))
for m, d := range s.ran {
@@ -583,8 +661,9 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin
// heldToday is what the node holds today: each module whose have's phase is held, and what its own composer holds, the
// node's own composition ("node") among them when it composes none of its own.
func (s *Shadow) heldToday() map[string]string {
func (s *Shadow) heldToday(added map[string]string) map[string]string {
out := map[string]string{}
maps.Copy(out, added)
s.mu.Lock()
for m, how := range s.heldNow {
if how != "" {