From 86380b66c1ea5d46319db3dd71c67a6ab57bc0cc Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 01:17:49 +0100 Subject: [PATCH] Write each node's declaration at the Version its engine reads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The composer is the node-engine's own build, so a newer composer could hand an older engine a field its strict decode refuses. The engine's record now states the declaration Version it reads, and the composer writes node X's declaration at the lower of its own Version and X's (1 when X states none), leaving out what that Version lacks: an engine reading 1 gets no drain-bound and runs on its own default. Builds: design 47 H2 §813 (12); H-A-416 (2), H-A-419; mesh-contracts feat/47-H2 e6ed560e (the record's declaration-reads) --- internal/compose/composed.go | 37 +++++++++++++++++++++++++++++ internal/compose/composed_test.go | 15 ++++++++++++ internal/compose/frombus/frombus.go | 1 + internal/compose/input.go | 3 +++ internal/link/have_test.go | 4 +++- internal/link/record.go | 3 +++ 6 files changed, 62 insertions(+), 1 deletion(-) diff --git a/internal/compose/composed.go b/internal/compose/composed.go index 9ba9dc16..b7a56b79 100644 --- a/internal/compose/composed.go +++ b/internal/compose/composed.go @@ -213,9 +213,11 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli } // What the tool runner's process runs as, whose slice of each held module the composed process keeps (H-A-306). var runsRuntime map[string]string + reads := 0 for i := range reading.Nodes { if reading.Nodes[i].Name == node { runsRuntime = reading.Nodes[i].RunsRuntime + reads = reading.Nodes[i].DeclarationReads } } var kept []json.RawMessage @@ -223,6 +225,10 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli foldedPaths := map[string]bool{} left := map[string]bool{} for _, raw := range envelope.Resources { + // Written at the lower of this composer's declaration Version and the one the node's engine reads (H-A-416 (2)). + if raw, err = AtDeclarationVersion(raw, reads); err != nil { + return nil, nil, nil, nil, err + } var head struct { ID string `json:"id"` Module string `json:"module"` @@ -836,3 +842,34 @@ func carry(kept []json.RawMessage, foldedPaths map[string]bool, runs *engcomp.Co } return out, foldedPaths, nil } + +// drainBoundVersion is the declaration Version a process's drain-bound came with (mesh-sdk declaration, H-A-388 (2)). +const drainBoundVersion = 2 + +// DeclarationVersionFor is the declaration Version a node's declaration is written at: the lower of this composer's +// own (declaration.Version) and the one its engine states it reads, 1 when it states none (design 47 H2 §813 (12), +// H-A-416 (2), H-A-419). +func DeclarationVersionFor(reads int) int { + if reads < 1 { + reads = 1 + } + return min(reads, declaration.Version) +} + +// AtDeclarationVersion is a resource as a node whose engine reads Version reads (DeclarationVersionFor): the fields that +// Version lacks left out, so an older engine never meets a field it refuses; a process's drain-bound then takes the +// engine's own default (H-A-416 (2)). +func AtDeclarationVersion(raw json.RawMessage, reads int) (json.RawMessage, error) { + if DeclarationVersionFor(reads) >= drainBoundVersion { + return raw, nil + } + var fields map[string]json.RawMessage + if err := json.Unmarshal(raw, &fields); err != nil { + return nil, err + } + if _, has := fields["drain-bound"]; !has { + return raw, nil + } + delete(fields, "drain-bound") + return json.Marshal(fields) +} diff --git a/internal/compose/composed_test.go b/internal/compose/composed_test.go index 595d38f2..2179aa48 100644 --- a/internal/compose/composed_test.go +++ b/internal/compose/composed_test.go @@ -241,6 +241,21 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) { env[catalogue.RuntimeToolModules], env[catalogue.RuntimeToolEnv], wantServed, words) } } + // Design 47 H2 §813 (12), H-A-416 (2), H-A-419: a node's declaration is written at the lower of the composer's Version + // and the one its engine states it reads: one stating 1, or none, gets Version 1 and no drain-bound; one stating 2 + // gets Version 2 with it. + t.Run("a declaration is written at the Version the node's engine reads", func(t *testing.T) { + process := json.RawMessage(`{"id":"node-tools.runtime","type":"process","drain-bound":30}`) + for _, row := range []struct { + reads, version int + drain bool + }{{0, 1, false}, {1, 1, false}, {2, 2, true}, {3, 2, true}} { + got, err := AtDeclarationVersion(process, row.reads) + if err != nil || DeclarationVersionFor(row.reads) != row.version || strings.Contains(string(got), "drain-bound") != row.drain { + t.Errorf("an engine reading %d: Version %d, %s (%v)", row.reads, DeclarationVersionFor(row.reads), got, err) + } + } + }) } // lead-47 2026-11-16: a held tool runner keeps the program it runs (Carried, runningProgram) after what the runtime serves diff --git a/internal/compose/frombus/frombus.go b/internal/compose/frombus/frombus.go index e5a59254..8d1def99 100644 --- a/internal/compose/frombus/frombus.go +++ b/internal/compose/frombus/frombus.go @@ -1260,6 +1260,7 @@ func nodeOf(rec nodeengine.NodeRecord, p meshmoduleassigner.Assignments) compose SealingKey: rec.SealingKey, OutwardLinks: rec.OutwardLinks, Networks: attachedOf(rec.Networks), NetworksSaid: rec.NetworksSaid, ServingKey: rec.ServingKey, Certificate: rec.Certificate, Contract: int(rec.Contract), Stated: rec.Contract > 0, + DeclarationReads: int(rec.DeclarationReads), } placeNode(&n, p) if len(rec.Capabilities) > 0 { diff --git a/internal/compose/input.go b/internal/compose/input.go index 1eb57312..d3c0b713 100644 --- a/internal/compose/input.go +++ b/internal/compose/input.go @@ -247,6 +247,9 @@ type Node struct { // Contract is the contract of its node-engine's newest statement (inv.HealthOf); Stated is whether it ever stated one. Contract int Stated bool + // DeclarationReads is the declaration Version its node-engine states it reads (nodeengine.NodeRecord.DeclarationReads, + // design 47 H2 §813 (12), H-A-416 (2), H-A-419); 0 when it states none, read as 1. + DeclarationReads int // InOwn is the modules it runs inside its own composition (`.node`), not by a composition of their own, since // no fingerprint of the new form names them where it runs them (novox/hq issue 1126): Compositions folds their // resources into the node's own, as the controller's composed writer does, unless fps gives one of the new form. diff --git a/internal/link/have_test.go b/internal/link/have_test.go index 74507602..5cea7449 100644 --- a/internal/link/have_test.go +++ b/internal/link/have_test.go @@ -19,6 +19,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/busretry" "git.novox.be/novox/mesh-sdk/go/catalogue" + "git.novox.be/novox/mesh-sdk/go/declaration" "github.com/nats-io/nats.go" ) @@ -372,7 +373,8 @@ func testTheNodeKeyCarriesTheNodesFacts(t *testing.T) { Certificate: "cert", Trusts: keys.Trusts, Capabilities: []string{"apt", "bus-state-calls", "ledger-calls", "systemd"}, OutwardLinks: []string{"eth0"}, NetworksSaid: true, Networks: []nodeengine.AttachedNetwork{{Link: "eth0", Network: "192.0.2.0/24"}}, Contract: NodeKeyContract, ManifestReads: statedReads(), // what it reads of a manifest: its contract's (ADR 0614 §4) and that it reads a want by version (H §772) - RunnerCapabilities: []string{"bus-state-calls", "ledger-calls"}, RunnerFingerprint: "sha256:runner"} + RunnerCapabilities: []string{"bus-state-calls", "ledger-calls"}, RunnerFingerprint: "sha256:runner", + DeclarationReads: declaration.Version} // H-A-416 (2), H-A-419: the declaration Version this engine reads if !nodeengineclient.SameNodeRecord(*got.Record, wantRecord) { t.Errorf("record = %+v, want %+v", *got.Record, wantRecord) } diff --git a/internal/link/record.go b/internal/link/record.go index e0e0ce46..1db4748c 100644 --- a/internal/link/record.go +++ b/internal/link/record.go @@ -11,6 +11,7 @@ import ( "time" "git.novox.be/novox/mesh-sdk/go/catalogue" + "git.novox.be/novox/mesh-sdk/go/declaration" ) // The node's record (novox/hq ADR 0555 §3, issue 1126): what the machine observes of itself, written in its own have key @@ -154,5 +155,7 @@ func recordOf(node string, r Report, keys RecordKeys) *nodeengine.NodeRecord { if r.Health != nil { rec.Contract = int64(r.Health.Contract) } + // The declaration Version this engine reads, by which a composer writes this node's declaration (H-A-416 (2), H-A-419). + rec.DeclarationReads = declaration.Version return rec }