From 546e535375255c7991571e088418dd8ede9698df Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 21:06:29 +0100 Subject: [PATCH] Serve the node-engine seat's converged, and name a part a compose kept MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The holder of node-packet-filter asks the node's convergence state before it allows a port, and never assumes converged: the engine answers it from its record, adopted or converged, since the mode last changed (now recorded with its time), and the found firewall's kind when adopted; a record with no mode is refused. The composition read of the filter's holder names, under withheld-parts, the part node-packet-filter.allowed with why when the last compose kept the filter file because allowed did not answer. Builds: design 33 control-verbs §10, §14; design 08 control-verbs §4, §8; ADR 0683, ADR 0168; H-A-316, H-A-321 --- cmd/mesh-host/engineseat.go | 22 +++++++++++++++++- cmd/mesh-host/main.go | 9 ++++---- cmd/mesh-host/ownname_test.go | 33 +++++++++++++++++++++++++++ cmd/mesh-host/seatlist.go | 23 +++++++++++++++++++ internal/agent/composition.go | 9 ++++++++ internal/bootstrap/apply.go | 5 ++-- internal/link/handacts.go | 10 ++++++++ internal/selfcompose/filter.go | 11 +++++---- internal/selfcompose/selfcompose.go | 5 ++-- internal/selfcompose/versions_test.go | 10 ++++++++ internal/store/store.go | 14 ++++++++++++ module.json | 3 ++- 12 files changed, 140 insertions(+), 14 deletions(-) diff --git a/cmd/mesh-host/engineseat.go b/cmd/mesh-host/engineseat.go index e0decefb..81914329 100644 --- a/cmd/mesh-host/engineseat.go +++ b/cmd/mesh-host/engineseat.go @@ -7,8 +7,10 @@ import ( "errors" "fmt" "log" + "maps" "os" "path/filepath" + "slices" "strings" "sync/atomic" "syscall" @@ -287,7 +289,8 @@ const compositionReadFor = 20 * time.Second // compositionFrom answers the verb composition from the node agent that runs now (issue 774); refused in words while // none does. -func compositionFrom(current *agentNow, withheld func(ctx context.Context, module string) ([]link.WithheldSubject, string)) func(module, digest string, diff bool) (any, error) { +func compositionFrom(current *agentNow, withheld func(ctx context.Context, module string) ([]link.WithheldSubject, string), + parts func(module string) map[string]string) func(module, digest string, diff bool) (any, error) { return func(module, digest string, diff bool) (any, error) { ag := current.get() if ag == nil { @@ -305,10 +308,27 @@ func compositionFrom(current *agentNow, withheld func(ctx context.Context, modul view.Withheld = append(view.Withheld, agent.WithheldView{Subject: s.Subject, Why: s.Why}) } view.WithheldUnknown = unknown + // And each part the last compose kept because its read did not answer (design 08 control-verbs §4, H-A-321). + if parts != nil { + kept := parts(module) + for _, part := range slices.Sorted(maps.Keys(kept)) { + view.WithheldParts = append(view.WithheldParts, agent.WithheldPartView{Part: part, Why: kept[part]}) + } + } return view, nil } } +// withheldPartsOf is, of the composer that runs now, each part its last pass kept for module because its read did not answer. +func withheldPartsOf(composer *atomic.Pointer[selfcompose.Composer]) func(module string) map[string]string { + return func(module string) map[string]string { + if c := composer.Load(); c != nil { + return c.LastWithheldParts(module) + } + return nil + } +} + // applyOrderFrom answers the verb apply-order from the node agent that runs now (design 47 H §771): the order it applies its changed // wants in, with why; refused in words while none does. func applyOrderFrom(current *agentNow) func() (any, error) { diff --git a/cmd/mesh-host/main.go b/cmd/mesh-host/main.go index fb0749f4..b04587d4 100644 --- a/cmd/mesh-host/main.go +++ b/cmd/mesh-host/main.go @@ -593,7 +593,7 @@ func runApply(ctx context.Context, opts options, d *declaration.Declaration, raw // What this apply settles about the node, whichever way it went. The mode is what the // declaration said and the check above agreed with; the bundle, once applied, is consumed. - updated.Mode = apply.ModeOf(d) + updated.SetMode(apply.ModeOf(d), time.Now()) if from == fromBundle { updated.Genesis = &store.Genesis{Digest: digest, At: time.Now().UTC()} } @@ -1027,7 +1027,7 @@ func runLink(ctx context.Context, opts options) error { queue.Acts = engineActs(opts, mine.Node, queue, setuidSearch) go reconcileActs(ctx, queue.Acts) current := &agentNow{} - queue.Acts.Composition = compositionFrom(current, queue.WithheldOf) + queue.Acts.Composition = compositionFrom(current, queue.WithheldOf, withheldPartsOf(&composerNow)) queue.Acts.Compose = composeFrom(current, &composerNow) queue.Acts.ApplyOrder = applyOrderFrom(current) queue.Acts.Packages = packagesFrom(mine.Node, queue, &composerNow) @@ -1045,6 +1045,7 @@ func runLink(ctx context.Context, opts options) error { defer cancel() return processbuilds.Reader{Node: mine.Node, Run: processbuilds.Runner(opts.run())}.Read(ctx, d, module), nil } + queue.Acts.Converged = func() (any, error) { return convergedOf(opts.state) } queue.Acts.ComposeCandidate = composeCandidateFrom(mine.Node, &shadowNow) setRunsHere(runsFromAgent(current)) factsOfNow := func(ctx context.Context, ag *agent.Agent) { @@ -1680,7 +1681,7 @@ func applyModuleHeld(ctx context.Context, opts options, declared *declaration.De if node && known.Mode != "" && known.Mode != apply.ModeOf(declared) { announceOr(say)(fmt.Sprintf("this node's record said %s; what the mesh last said, signed, says %s — the record is repaired", known.Mode, apply.ModeOf(declared))) - known.Mode = apply.ModeOf(declared) + known.SetMode(apply.ModeOf(declared), time.Now()) } // **A file given by digest is fetched and verified before anything of the composition is applied** (novox/hq ADR @@ -1721,7 +1722,7 @@ func applyModuleHeld(ctx context.Context, opts options, declared *declaration.De }, announceOr(say)) if node { - updated.Mode = apply.ModeOf(declared) + updated.SetMode(apply.ModeOf(declared), time.Now()) } // Root acted on what an agent account's judgement reads — an account, a package, an action, sudo's rules: the search diff --git a/cmd/mesh-host/ownname_test.go b/cmd/mesh-host/ownname_test.go index 4f23a005..bbbfd5a0 100644 --- a/cmd/mesh-host/ownname_test.go +++ b/cmd/mesh-host/ownname_test.go @@ -8,8 +8,10 @@ import ( "testing" "time" + "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" "github.com/novox/mesh-host/internal/link" + "github.com/novox/mesh-host/internal/store" ) // Design 47 G §527, §634, A-149: the node-engine's own module is the module of its applied record at its own fingerprint, @@ -54,6 +56,37 @@ func TestTheEnginesOwnNameIsReadFromItsAppliedRecordOrItsFirstComposing(t *testi case <-time.After(5 * time.Second): t.Fatal("the writer was never made after the name was known") } + + // Design 33 control-verbs §10, §14: the seat's verb converged answers the node's convergence state as the record keeps + // it, adopted with its found firewall's kind or converged, since its mode last changed; a record with no mode is refused. + t.Run("converged answers the record's convergence state", func(t *testing.T) { + path := filepath.Join(t.TempDir(), "state.json") + found := time.Date(2026, 10, 2, 9, 0, 0, 0, time.UTC) + st := store.State{Firewall: &store.FoundFirewall{Kind: "ufw", FoundAt: found}} + if err := store.Save(path, st); err != nil { + t.Fatal(err) + } + if got, err := convergedOf(path); err == nil { + t.Errorf("a record with no mode answers %+v, want refused", got) + } + st.SetMode(store.ModeAdopted, found) + st.SetMode(store.ModeAdopted, found.Add(time.Hour)) // said again: its time is kept + if err := store.Save(path, st); err != nil { + t.Fatal(err) + } + acts := &link.HandActs{Converged: func() (any, error) { return convergedOf(path) }} + if got, err := acts.Call(link.EngineCall{Verb: link.ActConverged}); err != nil || + got != (nodeengine.ConvergedAnswer{State: "adopted", Since: "2026-10-02T09:00:00Z", Found: "ufw"}) { + t.Errorf("an adopted node answers %+v, %v; want adopted since its adoption, found ufw", got, err) + } + st.SetMode(store.ModeConverged, found.Add(48*time.Hour)) + if err := store.Save(path, st); err != nil { + t.Fatal(err) + } + if got, err := convergedOf(path); err != nil || got != (nodeengine.ConvergedAnswer{State: "converged", Since: "2026-10-04T09:00:00Z"}) { + t.Errorf("a converged node answers %+v, %v; want converged since it converged, no found firewall", got, err) + } + }) } // Design 47 H, H-A-60: how often an entry whose ask failed is asked again is the file the manifest's `entry-asks` feeds, five when it diff --git a/cmd/mesh-host/seatlist.go b/cmd/mesh-host/seatlist.go index f5bae1eb..136aa5c6 100644 --- a/cmd/mesh-host/seatlist.go +++ b/cmd/mesh-host/seatlist.go @@ -13,6 +13,7 @@ import ( "sync/atomic" "time" + "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" "git.novox.be/novox/mesh-sdk/go/catalogue" "git.novox.be/novox/mesh-sdk/go/seatdef" @@ -21,6 +22,7 @@ import ( "github.com/novox/mesh-host/internal/link" "github.com/novox/mesh-host/internal/seatwait" "github.com/novox/mesh-host/internal/selfcompose" + "github.com/novox/mesh-host/internal/store" ) // The node-engine reads the seat list as every part does (novox/hq ADR 0635 §1, ADR 0636): through the seat mesh-catalog, @@ -335,3 +337,24 @@ func entryAsks() int { } return n } + +// convergedOf is the node's convergence state as this engine keeps it in its record at path (ADR 0168): the answer of the +// seat node-engine's verb converged (design 33 control-verbs §10). A record that says no mode yet is refused, so its asker +// never takes it for converged. +func convergedOf(path string) (nodeengine.ConvergedAnswer, error) { + st, err := store.Load(path) + if err != nil { + return nodeengine.ConvergedAnswer{}, err + } + if st.Mode != store.ModeAdopted && st.Mode != store.ModeConverged { + return nodeengine.ConvergedAnswer{}, errors.New("this node's record says no mode yet: no declaration has said it adopted or converged") + } + out := nodeengine.ConvergedAnswer{State: st.Mode} + if st.ModeSince != nil { + out.Since = st.ModeSince.UTC().Format(time.RFC3339) + } + if st.Mode == store.ModeAdopted && st.Firewall != nil { + out.Found = st.Firewall.Kind + } + return out, nil +} diff --git a/internal/agent/composition.go b/internal/agent/composition.go index 16c78b3f..b80a2891 100644 --- a/internal/agent/composition.go +++ b/internal/agent/composition.go @@ -52,6 +52,15 @@ type CompositionView struct { // mark §6, lead answer A-239). Withheld []WithheldView `json:"withheld,omitempty"` WithheldUnknown string `json:"withheld-unknown,omitempty"` + // WithheldParts are the parts a compose kept because its read did not answer, each with why (design 08 control-verbs §4, + // H-A-321): for the packet filter's holder the part node-packet-filter.allowed, its filter file kept as it runs. + WithheldParts []WithheldPartView `json:"withheld-parts,omitempty"` +} + +// WithheldPartView is one part a compose kept because its read did not answer, and why. +type WithheldPartView struct { + Part string `json:"part"` + Why string `json:"why"` } // WithheldView is one marked subject withheld, and why. diff --git a/internal/bootstrap/apply.go b/internal/bootstrap/apply.go index f056c6d2..b9c1c218 100644 --- a/internal/bootstrap/apply.go +++ b/internal/bootstrap/apply.go @@ -81,10 +81,11 @@ func ApplyBundle(ctx context.Context, o Options, sys system.System, d *declarati // been flipped. updated.Genesis = &store.Genesis{Digest: apply.DigestOf(raw), At: time.Now().UTC(), Rewritten: true} if updated.Mode == "" { - updated.Mode = store.ModeConverged + mode := store.ModeConverged if o.Adopted { - updated.Mode = store.ModeAdopted + mode = store.ModeAdopted } + updated.SetMode(mode, time.Now()) } // Saved whichever way it went, for the reason `mesh-host` gives: what was applied before a diff --git a/internal/link/handacts.go b/internal/link/handacts.go index 3e0f0706..d902eb3f 100644 --- a/internal/link/handacts.go +++ b/internal/link/handacts.go @@ -68,6 +68,9 @@ const ( // ActProcessBuilds reads the build each process on this node was started with (design 47, *The fingerprint handover*); // it reads only; who may call it is the seat definition's (design 47 G §440, §447). ActProcessBuilds = nodeengine.VerbProcessBuilds + // ActConverged reads the node's convergence state: adopted or converged, since when, the found firewall's kind when + // adopted (design 33 control-verbs §10); read-only. + ActConverged = nodeengine.VerbConverged ) // The states of an act: asked, done and refused are also the seat's events. @@ -177,6 +180,8 @@ type HandActs struct { ApplyOrder func() (any, error) // ProcessBuilds answers the build each process of the node was started with, narrowed to a module when one is given. ProcessBuilds func(module string) (any, error) + // Converged answers the verb converged: the node's convergence state as the engine keeps it (design 33 control-verbs §10). + Converged func() (any, error) // ComposeCandidate composes a check's candidate (the indexer's candidate key) on this node in shadow and answers per // module, applying and writing nothing; with input, also the composition input it composed from (the verb // compose-candidate, ADR 0593 §7). @@ -278,6 +283,11 @@ func (h *HandActs) Call(c EngineCall) (any, error) { return nil, errors.New("this engine reads no process yet: its node agent has not started") } return h.ProcessBuilds(arg("module")) + case ActConverged: + if h.Converged == nil { + return nil, errors.New("this engine reads no convergence state yet: its node agent has not started") + } + return h.Converged() case ActSeatListAgain: if h.SeatListAgain == nil { return nil, errors.New("this engine reads no seat list yet: its node agent has not started") diff --git a/internal/selfcompose/filter.go b/internal/selfcompose/filter.go index 71b8e6ca..d24a5d24 100644 --- a/internal/selfcompose/filter.go +++ b/internal/selfcompose/filter.go @@ -74,6 +74,9 @@ func (c *Composer) filterOf(ctx context.Context, own meshmoduleassigner.Assignme func (c *Composer) holdsFilter(ctx context.Context, own meshmoduleassigner.Assignments) bool { for _, m := range own.Modules { if claims, known := c.Claims(ctx, m.Module, nodepacketfilter.Seat); claims && known { + c.mu.Lock() + c.filterHolder = m.Module + c.mu.Unlock() return true } } @@ -101,12 +104,12 @@ func notAnAllowance(allowances []nodepacketfilter.Allowance) string { return "" } -// LastWithheldParts is each part the last pass kept because its read did not answer, with why (H-A-321): the filter's -// allowed, named AllowedPart. Nil when none. -func (c *Composer) LastWithheldParts() map[string]string { +// LastWithheldParts is each part the last pass kept of module because its read did not answer, with why (H-A-321): of the +// holder of node-packet-filter, the filter's allowed, named AllowedPart. Nil when none. +func (c *Composer) LastWithheldParts(module string) map[string]string { c.mu.Lock() defer c.mu.Unlock() - if c.filter.Withheld == "" { + if c.filter.Withheld == "" || module != c.filterHolder { return nil } return map[string]string{AllowedPart: c.filter.Withheld} diff --git a/internal/selfcompose/selfcompose.go b/internal/selfcompose/selfcompose.go index 8ac1fbce..f177fd83 100644 --- a/internal/selfcompose/selfcompose.go +++ b/internal/selfcompose/selfcompose.go @@ -339,8 +339,9 @@ type Composer struct { // filter is what the last pass's compose of the packet filter was given (filterOf), which a candidate composed in shadow // is given too; allowedSaid says its withheld allowed was said in the journal, until it answers (design 08 // control-verbs §4). Guarded by mu. - filter resolution.Filter - allowedSaid bool + filter resolution.Filter + filterHolder string + allowedSaid bool } // Pass is how one pass went, as the node-engine's verb compose answers it. diff --git a/internal/selfcompose/versions_test.go b/internal/selfcompose/versions_test.go index 26b4cbed..76cf4bf8 100644 --- a/internal/selfcompose/versions_test.go +++ b/internal/selfcompose/versions_test.go @@ -171,6 +171,16 @@ func TestAModulesClaimsAreReadFromTheEntryOfItsWantsBuild(t *testing.T) { if got = c.filterOf(context.Background(), own); !strings.Contains(got.Withheld, `answered what is not its answer: allow.tcp.8000 has the until "tomorrow"`) { t.Errorf("an answer that is not allowed's gives %+v, want the part withheld", got) } + // H-A-321: the composition read of the holder names the part kept, and of another module none. + c.mu.Lock() + c.filter = got + c.mu.Unlock() + if parts := c.LastWithheldParts("nft"); len(parts) != 1 || parts[AllowedPart] != got.Withheld || AllowedPart != "node-packet-filter.allowed" { + t.Errorf("the holder's withheld parts are %v, want node-packet-filter.allowed with its why", parts) + } + if parts := c.LastWithheldParts("web"); parts != nil { + t.Errorf("another module's withheld parts are %v, want none", parts) + } if n := strings.Count(strings.Join(said, "\n"), "is withheld"); n != 1 { t.Errorf("the withheld part is said %d times over three unanswered composes, want once:\n%s", n, strings.Join(said, "\n")) } diff --git a/internal/store/store.go b/internal/store/store.go index 892f5c04..105c86c5 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -221,6 +221,9 @@ type State struct { // the mesh sends and at genesis from what the operator said, so a declaration that says the // other mode can be refused before it is applied (novox/hq issue 104). Mode string `json:"mode,omitempty"` + // ModeSince is when Mode last became what it is (SetMode): the node's convergence state the seat node-engine's verb + // converged answers (ADR 0168, design 33 control-verbs §10). Nil where no change of mode was recorded with its time. + ModeSince *time.Time `json:"mode_since,omitempty"` // FoundFirst is, by resource id, what a service's unit was found as by an apply of it that did // not finish — kept apart from Resources, because a record follows the fact and this apply's @@ -319,6 +322,17 @@ type Retired struct { Again int `json:"again,omitempty"` } +// SetMode records the node's mode, and when it became so when it changes (design 33 control-verbs §10); a mode said again +// keeps its time. +func (s *State) SetMode(mode string, at time.Time) { + if s.Mode == mode { + return + } + s.Mode = mode + at = at.UTC() + s.ModeSince = &at +} + // Modes a node can be in (novox/hq ADR 0100). const ( ModeAdopted = "adopted" diff --git a/module.json b/module.json index aeef6d1d..8f6929b1 100644 --- a/module.json +++ b/module.json @@ -36,7 +36,8 @@ "first-views", "first-view-again", "entry-again", - "process-builds" + "process-builds", + "converged" ] } ],