From d3d9ff5183e591145bb1876ae3cefedde8221864 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 01:39:49 +0100 Subject: [PATCH] M1: the build modules and the registry say their class and name every store's cap; detected-steps is pruned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each of the four is core. Every state that named no cap names one, from its live fill read 2026-11-22 01:4x CET (mesh-broker show, nats_streams on novox): mesh-build-go steps 16.0 MiB (16,783,695 bytes) -> 128 MiB; mesh-build-node steps 2.35 MiB (2,463,833 bytes) -> 16 MiB; every other state under 2 MiB -> 8 MiB (largest: distribution holds 1,844,287 bytes, mesh-build-go detected-steps 868,554, distribution transfers 846,359, findings 668,161, idle 401,736, mesh-build-go pauses 254,366). The Go build module's finding-events is 8 MiB for 7 days. The objects stores already name their caps; none keeps a log. The Go and Node build modules prune their state detected-steps (each key an artifact's steps as detected, detected again when gone) at their own writes, past prune-mark 70 % down to prune-target 50 %, and serve _state_prune_now and _state_keep; no other state of the four is prunable (each is truth: running steps, pauses, keys, toolchains, findings, holds, transfers, windows, mirrors, taken asks). Builds: design 47 H2 §812, §820; H-A-411 (1), (2), (3), H-A-437 --- .../internal/holder/holder_test.go | 14 +++++ modules/distribution/module.json | 29 ++++++++--- .../cmd/mesh-build-go/asks_test.go | 15 ++++++ .../cmd/mesh-build-go/detected.go | 35 +++++++++++++ .../cmd/mesh-build-go/forge_test.go | 11 ++-- .../mesh-build-go/cmd/mesh-build-go/main.go | 2 +- .../cmd/mesh-build-go/module_test.go | 2 +- .../mesh-build-go/cmd/mesh-build-go/tools.go | 1 + modules/mesh-build-go/module.json | 51 ++++++++++++++++--- .../cmd/mesh-build-image/forge_test.go | 5 +- .../cmd/mesh-build-image/manifest_test.go | 6 ++- modules/mesh-build-image/module.json | 9 ++-- .../cmd/mesh-build-node/detected.go | 35 +++++++++++++ .../cmd/mesh-build-node/forge_test.go | 3 +- .../cmd/mesh-build-node/main.go | 2 +- .../cmd/mesh-build-node/manifest_test.go | 25 ++++++++- .../cmd/mesh-build-node/module_test.go | 2 +- .../cmd/mesh-build-node/tools.go | 1 + modules/mesh-build-node/module.json | 33 +++++++++--- 19 files changed, 242 insertions(+), 39 deletions(-) create mode 100644 modules/mesh-build-go/cmd/mesh-build-go/detected.go create mode 100644 modules/mesh-build-node/cmd/mesh-build-node/detected.go diff --git a/modules/distribution/internal/holder/holder_test.go b/modules/distribution/internal/holder/holder_test.go index 069f08745..aa76a8bcb 100644 --- a/modules/distribution/internal/holder/holder_test.go +++ b/modules/distribution/internal/holder/holder_test.go @@ -929,10 +929,24 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) { Name string `json:"name"` Port int `json:"port"` } `json:"listens"` + Class string `json:"class"` + State []struct { + Name string `json:"name"` + MaxMiB int `json:"max-mib"` + } `json:"state"` } if err := json.Unmarshal(raw, &m); err != nil { t.Fatal(err) } + // Design 47 H2 H-A-411 (2): a core module, and every state names its cap, 8 MiB. + if m.Class != "core" { + t.Errorf("class %q, want core", m.Class) + } + for _, st := range m.State { + if st.MaxMiB != 8 { + t.Errorf("the state %s names max-mib %d, want 8", st.Name, st.MaxMiB) + } + } // The reservation is asked through the seat mesh-builds, so the manifest takes no package of the builder (design 47 §381). if len(m.Packages) != 0 { t.Errorf("packages %v: want none", m.Packages) diff --git a/modules/distribution/module.json b/modules/distribution/module.json index 501826bf4..6941af2d1 100644 --- a/modules/distribution/module.json +++ b/modules/distribution/module.json @@ -1,6 +1,7 @@ { "module": "distribution", "version": "0.1", + "class": "core", "provides": [ { "name": "artifact-store", @@ -249,15 +250,31 @@ } ], "state": [ - "transfers", + { + "name": "transfers", + "max-mib": 8 + }, { "name": "idle", - "key-ttl": true + "key-ttl": true, + "max-mib": 8 + }, + { + "name": "holds", + "max-mib": 8 + }, + { + "name": "windows", + "max-mib": 8 + }, + { + "name": "mirrors", + "max-mib": 8 + }, + { + "name": "findings", + "max-mib": 8 }, - "holds", - "windows", - "mirrors", - "findings", { "name": "taken", "key-ttl": true, diff --git a/modules/mesh-build-go/cmd/mesh-build-go/asks_test.go b/modules/mesh-build-go/cmd/mesh-build-go/asks_test.go index 955b8925a..5dcf5bfe7 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/asks_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/asks_test.go @@ -13,6 +13,8 @@ import ( sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun" + stdio "git.novox.be/novox/mesh-sdk/go" + "git.novox.be/novox/mesh-sdk/go/catalogue" ) const askCommit = "0123456789abcdef0123456789abcdef01234567" @@ -156,6 +158,19 @@ func TestManifestClaimsTheGoBuildSeatAndReadsItsCapacity(t *testing.T) { } `json:"config"` } _ = json.Unmarshal(raw, &doc) + // Design 47 H2 H-A-411 (2), (3): a core module; its state detected-steps is pruned at its own writes, with the two prune + // tools and the settings prune-mark (70 %) and prune-target (50 %). + if m.Class != catalogue.ClassCore { + t.Errorf("class = %q, want %s", m.Class, catalogue.ClassCore) + } + for _, tool := range []string{ModuleName + "_state_prune_now", ModuleName + "_state_keep"} { + if !slices.Contains(m.Tools, tool) { + t.Errorf("tools = %v lack %s", m.Tools, tool) + } + } + if mark, target := string(doc.Config[stdio.PruneMarkSetting].Default), string(doc.Config[stdio.PruneTargetSetting].Default); mark != "70" || target != "50" { + t.Errorf("prune-mark %s and prune-target %s, want 70 and 50", mark, target) + } // Issue 1806's follow-up: the cores a step needs is a setting of its own, in the settings file, with the SDK's default. if cores := string(doc.Config[steprun.CoresPerStepSetting].Default); cores != fmt.Sprint(steprun.DefaultCoresPerStep[sdkstep.AskGo]) { t.Errorf("the cores-per-step default = %s, want %g", cores, steprun.DefaultCoresPerStep[sdkstep.AskGo]) diff --git a/modules/mesh-build-go/cmd/mesh-build-go/detected.go b/modules/mesh-build-go/cmd/mesh-build-go/detected.go new file mode 100644 index 000000000..4bf0beabe --- /dev/null +++ b/modules/mesh-build-go/cmd/mesh-build-go/detected.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "os" + "sync" + + seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" + + "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" + stdio "git.novox.be/novox/mesh-sdk/go" + "git.novox.be/novox/mesh-sdk/go/stateobjects" +) + +// ModuleName is this module's name, which its prune tools are named for (stateobjects.PruneTools). +const ModuleName = "mesh-build-go" + +// prunedDetected is the state detected-steps, pruned toward its cap at this module's own writes (design 47 H2 §812; +// H-A-411 (2), (3)): past prune-mark of its 8 MiB the oldest keys go down to prune-target, in one journal line. Each key +// is an artifact's steps as detected, which the verb steps detects again when its key is gone. A setting that is no +// percentage is said, and the defaults hold. +var prunedDetected = sync.OnceValue(func() *stdio.PrunedState { + p, err := stdio.PruneSettings() + if err != nil { + fmt.Fprintf(os.Stderr, "the prune of %s keeps its defaults (%d %% to %d %%): %v\n", seat.StateDetectedSteps, stdio.PruneMarkDefault, stdio.PruneTargetDefault, err) + p = stdio.Prune{Mark: stdio.PruneMarkDefault, Target: stdio.PruneTargetDefault} + } + return stdio.State(seat.StateDetectedSteps).Pruned(p) +}) + +// pruneTools are the module's two prune tools over detected-steps, each written in the hand-act log (H-A-380 (3)). +func pruneTools() []stdio.Tool { + return stateobjects.PruneTools(ModuleName, []stateobjects.Pruning{{Name: seat.StateDetectedSteps, State: prunedDetected()}}, + meshhandactsclient.Recorder{Ask: stdio.Ask}) +} diff --git a/modules/mesh-build-go/cmd/mesh-build-go/forge_test.go b/modules/mesh-build-go/cmd/mesh-build-go/forge_test.go index 2e17a639b..8b6fbd31d 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/forge_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/forge_test.go @@ -153,20 +153,21 @@ func TestManifestRequiresForgeAccountKeepsKeysAndTakesFilesFromTemplates(t *test kept := map[string]any{"name": "kept-builds", "storage": "object-store", "template": "objects", "options": map[string]any{"max-mib": float64(1024)}} // steps: a step's end over what step-ended carries inline, in the steps state's objects store (design 47 G A-254, A-313; // H2 H-A-412 addendum), read by the verb answer. - steps := map[string]any{"name": "steps", "storage": "key-value", "template": "state", "options": map[string]any{"ttl-seconds": float64(172800), "objects-max-mib": float64(256)}} + steps := map[string]any{"name": "steps", "storage": "key-value", "template": "state", "options": map[string]any{"ttl-seconds": float64(172800), "objects-max-mib": float64(256), "max-mib": float64(128)}} // outputs: a run's test output, read by the verb output (design 47 H2 §791, §820: 1 GiB, 7 days). outputs := map[string]any{"name": "outputs", "storage": "object-store", "template": "objects", "options": map[string]any{"max-mib": float64(1024), "max-age-days": float64(7)}} - detected := map[string]any{"name": "detected-steps", "storage": "key-value", "template": "state", "options": map[string]any{"history": float64(1)}} + detected := map[string]any{"name": "detected-steps", "storage": "key-value", "template": "state", "options": map[string]any{"history": float64(1), "max-mib": float64(8)}} // The findings are asked in requires as a part that is no foundation part asks them (design 47 G §529, A-30). - findings := map[string]any{"name": "findings", "storage": "key-value", "template": "state"} + findings := map[string]any{"name": "findings", "storage": "key-value", "template": "state", "options": map[string]any{"max-mib": float64(8)}} findingEvents := map[string]any{"name": "finding-events", "storage": "stream", "template": "events", "options": map[string]any{ - "events": []any{"finding-written.*", "finding-cleared.*", "findings-stated.*"}, "max-age-days": float64(7), "max-mib": float64(16)}} + "events": []any{"finding-written.*", "finding-cleared.*", "findings-stated.*"}, "max-age-days": float64(7), "max-mib": float64(8)}} if want := []any{steps, detected, outputs, kept, "artifact-store", "forge-account", "go-toolchain", "go-package-registry", "node-tools", findings, findingEvents}; !reflect.DeepEqual(m.Requires, want) { t.Errorf("requires = %v, want %v", m.Requires, want) } keeps := false for _, s := range m.State { - if s == "keys" { + // Design 47 H2 H-A-411 (2): every state names its cap, 8 MiB. + if e, _ := s.(map[string]any); e["name"] == "keys" && e["max-mib"] == float64(8) { keeps = true } } diff --git a/modules/mesh-build-go/cmd/mesh-build-go/main.go b/modules/mesh-build-go/cmd/mesh-build-go/main.go index 9566774a1..6fe0401ab 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/main.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/main.go @@ -44,7 +44,7 @@ func main() { Toolchains: stdio.State(seat.StateToolchains).Put, SayToolchain: stdio.SeatPublish, Steps: stdio.State(seat.StateSteps).Put, - Detected: stdio.State(seat.StateDetectedSteps).Put, + Detected: prunedDetected().Put, ReadDetected: readOf(stdio.State(seat.StateDetectedSteps)).Get, ForgetDetected: stdio.State(seat.StateDetectedSteps).Delete, RecordAct: handActRecorder, diff --git a/modules/mesh-build-go/cmd/mesh-build-go/module_test.go b/modules/mesh-build-go/cmd/mesh-build-go/module_test.go index fa17102e2..94e7d4549 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/module_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/module_test.go @@ -116,7 +116,7 @@ func TestAGoThatCannotBeRunRefusesEveryStepAndHealthIsUnhealthy(t *testing.T) { {Name: "short_probe", Run: run}, }, m.StepTools()...) for _, tool := range m.Tools(steps) { - if tool.Name == StatusTool || tool.Name == HealthTool || tool.Name == StepReadTool || tool.Name == StepsReadTool || tool.Name == ToolchainsReadTool || tool.Name == ReleaseTool || tool.Name == KeptTool || tool.Name == KeptDropTool || tool.Name == StepEndTool { + if strings.HasPrefix(tool.Name, ModuleName+"_state_") || tool.Name == StatusTool || tool.Name == HealthTool || tool.Name == StepReadTool || tool.Name == StepsReadTool || tool.Name == ToolchainsReadTool || tool.Name == ReleaseTool || tool.Name == KeptTool || tool.Name == KeptDropTool || tool.Name == StepEndTool { continue } var reason string diff --git a/modules/mesh-build-go/cmd/mesh-build-go/tools.go b/modules/mesh-build-go/cmd/mesh-build-go/tools.go index 73047dc8d..9a5ef62c8 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/tools.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/tools.go @@ -45,6 +45,7 @@ func (m *Module) Tools(steps []StepTool) []stdio.Tool { tools = append(tools, m.ReadTools()...) tools = append(tools, steprun.StepEndTool(StepEndTool, m.Node, m.stepScan(), m.Held)) tools = append(tools, m.releaseTool()) + tools = append(tools, pruneTools()...) tools = append(tools, m.keptTools()...) return append(tools, stdio.Tool{Name: StatusTool, diff --git a/modules/mesh-build-go/module.json b/modules/mesh-build-go/module.json index 9714631ce..2de4a290b 100644 --- a/modules/mesh-build-go/module.json +++ b/modules/mesh-build-go/module.json @@ -1,6 +1,7 @@ { "module": "mesh-build-go", "version": "0.1", + "class": "core", "packages": { "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds": "0.1", "git.novox.be/novox/mesh-catalog/modules/ssh-client/sshkeys": "0.1" @@ -13,9 +14,18 @@ "user-namespaces" ], "state": [ - "toolchains", - "keys", - "pauses" + { + "name": "toolchains", + "max-mib": 8 + }, + { + "name": "keys", + "max-mib": 8 + }, + { + "name": "pauses", + "max-mib": 8 + } ], "claims": [ { @@ -75,6 +85,24 @@ "trusted": false, "runtime": true, "default": "15s,60s" + }, + "prune-mark": { + "type": "number", + "description": "The fill of mesh-build-go's state detected-steps, in percent of its cap, past which the module prunes it at its own write, oldest first (design 47 H2 §812): below the bus module's raise mark of 75 %.", + "trusted": false, + "runtime": true, + "minimum": 1, + "maximum": 100, + "default": 70 + }, + "prune-target": { + "type": "number", + "description": "The fill, in percent of the cap, a prune of mesh-build-go's state detected-steps takes it down to (design 47 H2 §812); below prune-mark.", + "trusted": false, + "runtime": true, + "minimum": 1, + "maximum": 100, + "default": 50 } }, "tools": [ @@ -91,7 +119,9 @@ "build_go_step_end", "build_go_toolchains", "build_go_status", - "build_go_health" + "build_go_health", + "mesh-build-go_state_keep", + "mesh-build-go_state_prune_now" ], "requires": [ { @@ -100,7 +130,8 @@ "template": "state", "options": { "ttl-seconds": 172800, - "objects-max-mib": 256 + "objects-max-mib": 256, + "max-mib": 128 } }, { @@ -108,7 +139,8 @@ "storage": "key-value", "template": "state", "options": { - "history": 1 + "history": 1, + "max-mib": 8 } }, { @@ -136,7 +168,10 @@ { "name": "findings", "storage": "key-value", - "template": "state" + "template": "state", + "options": { + "max-mib": 8 + } }, { "name": "finding-events", @@ -149,7 +184,7 @@ "findings-stated.*" ], "max-age-days": 7, - "max-mib": 16 + "max-mib": 8 } } ], diff --git a/modules/mesh-build-image/cmd/mesh-build-image/forge_test.go b/modules/mesh-build-image/cmd/mesh-build-image/forge_test.go index 0e188a830..84d6c2982 100644 --- a/modules/mesh-build-image/cmd/mesh-build-image/forge_test.go +++ b/modules/mesh-build-image/cmd/mesh-build-image/forge_test.go @@ -146,7 +146,7 @@ func TestForgeFilesRenderFromTheBoundValuesInTheModulesOwnHome(t *testing.T) { func TestManifestRequiresForgeAccountKeepsKeysAndTakesFilesFromTemplates(t *testing.T) { m := readForgeManifest(t) // steps: a step's end over what step-ended carries inline, in the steps state's objects store (design 47 G A-254, A-313). - steps := map[string]any{"name": "steps", "storage": "key-value", "template": "state", "options": map[string]any{"ttl-seconds": float64(172800), "objects-max-mib": float64(256)}} + steps := map[string]any{"name": "steps", "storage": "key-value", "template": "state", "options": map[string]any{"ttl-seconds": float64(172800), "objects-max-mib": float64(256), "max-mib": float64(8)}} // outputs: a run's test output, read by the verb output (design 47 H2 §791, §820: 1 GiB, 7 days). outputs := map[string]any{"name": "outputs", "storage": "object-store", "template": "objects", "options": map[string]any{"max-mib": float64(1024), "max-age-days": float64(7)}} if want := []any{steps, outputs, "forge-account", "rootless-image-build", "node-tools"}; !reflect.DeepEqual(m.Requires, want) { @@ -154,7 +154,8 @@ func TestManifestRequiresForgeAccountKeepsKeysAndTakesFilesFromTemplates(t *test } keeps := false for _, s := range m.State { - if s == "keys" { + // Design 47 H2 H-A-411 (2): every state names its cap, 8 MiB. + if e, _ := s.(map[string]any); e["name"] == "keys" && e["max-mib"] == float64(8) { keeps = true } } diff --git a/modules/mesh-build-image/cmd/mesh-build-image/manifest_test.go b/modules/mesh-build-image/cmd/mesh-build-image/manifest_test.go index d345b6396..82008d5a4 100644 --- a/modules/mesh-build-image/cmd/mesh-build-image/manifest_test.go +++ b/modules/mesh-build-image/cmd/mesh-build-image/manifest_test.go @@ -113,6 +113,10 @@ func TestWorkAndStoreDirectoriesLieOutsideTheHome(t *testing.T) { // and the registry's address is bound into a file of the home that the program reads. func TestManifestKeepsItsStatesClaimsItsBuildSeatAndDeclaresItsHealthTool(t *testing.T) { m := readManifest(t) + // Design 47 H2 H-A-411 (2): a core module. + if m.Class != catalogue.ClassCore { + t.Errorf("class = %q, want %s", m.Class, catalogue.ClassCore) + } // Design 47 G A-488a, A-488b: its runtime follows the seat list, so the module consumes the seat's two events (which makes its // durable consumer) and invokes the verb that reads the list. for _, ev := range []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"} { @@ -238,7 +242,7 @@ func TestManifestRequiresTheStepsStateWithItsObjectsStore(t *testing.T) { t.Fatal(err) } for _, want := range []map[string]any{ - {"name": "steps", "storage": "key-value", "template": "state", "options": map[string]any{"ttl-seconds": float64(172800), "objects-max-mib": float64(256)}}, + {"name": "steps", "storage": "key-value", "template": "state", "options": map[string]any{"ttl-seconds": float64(172800), "objects-max-mib": float64(256), "max-mib": float64(8)}}, {"name": "outputs", "storage": "object-store", "template": "objects", "options": map[string]any{"max-mib": float64(1024), "max-age-days": float64(7)}}, } { if !slices.ContainsFunc(doc.Requires, func(r any) bool { return reflect.DeepEqual(r, any(want)) }) { diff --git a/modules/mesh-build-image/module.json b/modules/mesh-build-image/module.json index ae2a83de5..4ef6ba7b6 100644 --- a/modules/mesh-build-image/module.json +++ b/modules/mesh-build-image/module.json @@ -1,6 +1,7 @@ { "module": "mesh-build-image", "version": "0.1", + "class": "core", "packages": { "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds": "0.1", "git.novox.be/novox/mesh-catalog/modules/ssh-client/sshkeys": "0.1" @@ -13,9 +14,9 @@ "user-namespaces" ], "state": [ - "keys", - "pauses", - {"name": "mirror-waits", "ttl-seconds": 172800} + {"name": "keys", "max-mib": 8}, + {"name": "pauses", "max-mib": 8}, + {"name": "mirror-waits", "ttl-seconds": 172800, "max-mib": 8} ], "claims": [ { @@ -64,7 +65,7 @@ "build_image_health" ], "requires": [ - {"name": "steps", "storage": "key-value", "template": "state", "options": {"ttl-seconds": 172800, "objects-max-mib": 256}}, + {"name": "steps", "storage": "key-value", "template": "state", "options": {"ttl-seconds": 172800, "objects-max-mib": 256, "max-mib": 8}}, {"name": "outputs", "storage": "object-store", "template": "objects", "options": {"max-mib": 1024, "max-age-days": 7}}, "forge-account", "rootless-image-build", diff --git a/modules/mesh-build-node/cmd/mesh-build-node/detected.go b/modules/mesh-build-node/cmd/mesh-build-node/detected.go new file mode 100644 index 000000000..c295130e3 --- /dev/null +++ b/modules/mesh-build-node/cmd/mesh-build-node/detected.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "os" + "sync" + + seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode" + + "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" + stdio "git.novox.be/novox/mesh-sdk/go" + "git.novox.be/novox/mesh-sdk/go/stateobjects" +) + +// ModuleName is this module's name, which its prune tools are named for (stateobjects.PruneTools). +const ModuleName = "mesh-build-node" + +// prunedDetected is the state detected-steps, pruned toward its cap at this module's own writes (design 47 H2 §812; +// H-A-411 (2), (3)): past prune-mark of its 8 MiB the oldest keys go down to prune-target, in one journal line. Each key +// is an artifact's steps as detected, which the verb steps detects again when its key is gone. A setting that is no +// percentage is said, and the defaults hold. +var prunedDetected = sync.OnceValue(func() *stdio.PrunedState { + p, err := stdio.PruneSettings() + if err != nil { + fmt.Fprintf(os.Stderr, "the prune of %s keeps its defaults (%d %% to %d %%): %v\n", seat.StateDetectedSteps, stdio.PruneMarkDefault, stdio.PruneTargetDefault, err) + p = stdio.Prune{Mark: stdio.PruneMarkDefault, Target: stdio.PruneTargetDefault} + } + return stdio.State(seat.StateDetectedSteps).Pruned(p) +}) + +// pruneTools are the module's two prune tools over detected-steps, each written in the hand-act log (H-A-380 (3)). +func pruneTools() []stdio.Tool { + return stateobjects.PruneTools(ModuleName, []stateobjects.Pruning{{Name: seat.StateDetectedSteps, State: prunedDetected()}}, + meshhandactsclient.Recorder{Ask: stdio.Ask}) +} diff --git a/modules/mesh-build-node/cmd/mesh-build-node/forge_test.go b/modules/mesh-build-node/cmd/mesh-build-node/forge_test.go index 26f8dfabb..f9ade8758 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/forge_test.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/forge_test.go @@ -150,7 +150,8 @@ func TestManifestRequiresForgeAccountKeepsKeysAndTakesFilesFromTemplates(t *test } keeps := false for _, s := range m.State { - if s == "keys" { + // Design 47 H2 H-A-411 (2): every state names its cap, 8 MiB. + if e, _ := s.(map[string]any); e["name"] == "keys" && e["max-mib"] == float64(8) { keeps = true } } diff --git a/modules/mesh-build-node/cmd/mesh-build-node/main.go b/modules/mesh-build-node/cmd/mesh-build-node/main.go index b41d596b0..920a97dc8 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/main.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/main.go @@ -51,7 +51,7 @@ func main() { SayToolchain: stdio.SeatPublish, Steps: stdio.State(seat.StateSteps).Put, ReadSteps: readOf(stdio.State(seat.StateSteps)), - Detected: stdio.State(seat.StateDetectedSteps).Put, + Detected: prunedDetected().Put, ReadDetected: readOf(stdio.State(seat.StateDetectedSteps)).Get, ForgetDetected: stdio.State(seat.StateDetectedSteps).Delete, RecordAct: handActRecorder, diff --git a/modules/mesh-build-node/cmd/mesh-build-node/manifest_test.go b/modules/mesh-build-node/cmd/mesh-build-node/manifest_test.go index 91fb3ac2b..8310d9478 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/manifest_test.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/manifest_test.go @@ -10,6 +10,7 @@ import ( "strings" "testing" + stdio "git.novox.be/novox/mesh-sdk/go" "git.novox.be/novox/mesh-sdk/go/catalogue" ) @@ -121,10 +122,30 @@ func TestManifestKeepsItsStatesClaimsItsBuildSeatAndDeclaresItsHealthTool(t *tes if len(m.Claims) != 1 || m.Claims[0].Name != Seat || !slices.Equal(m.Claims[0].Serves, []string{"current", "drop", "pause", "resume", "steps", "kept-artifact", "output", "answer"}) { t.Errorf("claims = %v, want the seat %s alone", m.Claims, Seat) } + // Design 47 H2 H-A-411 (2), (3): a core module; its state detected-steps is pruned at its own writes, with the two prune + // tools and the settings prune-mark (70 %) and prune-target (50 %). + if m.Class != catalogue.ClassCore { + t.Errorf("class = %q, want %s", m.Class, catalogue.ClassCore) + } + for _, tool := range []string{ModuleName + "_state_prune_now", ModuleName + "_state_keep"} { + if !slices.Contains(m.Tools, tool) { + t.Errorf("tools = %v lack %s", m.Tools, tool) + } + } + raw, _ := os.ReadFile(filepath.Join(moduleDir, "module.json")) + var doc struct { + Config map[string]struct { + Default json.RawMessage `json:"default"` + } `json:"config"` + } + _ = json.Unmarshal(raw, &doc) + if mark, target := string(doc.Config[stdio.PruneMarkSetting].Default), string(doc.Config[stdio.PruneTargetSetting].Default); mark != "70" || target != "50" { + t.Errorf("prune-mark %s and prune-target %s, want 70 and 50", mark, target) + } if !slices.Contains(m.Tools, HealthTool) { t.Errorf("tools = %v lack %s", m.Tools, HealthTool) } - raw, _ := os.ReadFile(filepath.Join(moduleDir, "module.json")) + raw, _ = os.ReadFile(filepath.Join(moduleDir, "module.json")) if !strings.Contains(string(raw), `"tool": "`+HealthTool+`"`) { t.Errorf("runtime-health does not name %s", HealthTool) } @@ -305,7 +326,7 @@ func TestManifestRequiresTheStepsStateWithItsObjectsStore(t *testing.T) { t.Fatal(err) } for _, want := range []map[string]any{ - {"name": "steps", "storage": "key-value", "template": "state", "options": map[string]any{"ttl-seconds": float64(172800), "objects-max-mib": float64(256)}}, + {"name": "steps", "storage": "key-value", "template": "state", "options": map[string]any{"ttl-seconds": float64(172800), "objects-max-mib": float64(256), "max-mib": float64(16)}}, {"name": "outputs", "storage": "object-store", "template": "objects", "options": map[string]any{"max-mib": float64(1024), "max-age-days": float64(7)}}, } { if !slices.ContainsFunc(doc.Requires, func(r any) bool { return reflect.DeepEqual(r, any(want)) }) { diff --git a/modules/mesh-build-node/cmd/mesh-build-node/module_test.go b/modules/mesh-build-node/cmd/mesh-build-node/module_test.go index a04ed8e4f..99b460230 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/module_test.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/module_test.go @@ -117,7 +117,7 @@ func TestANodeThatCannotBeRunRefusesEveryStepAndHealthIsUnhealthy(t *testing.T) {Name: "short_probe", Run: run}, }, (&Module{}).StepTools()...) for _, tool := range m.Tools(steps) { - if tool.Name == StatusTool || tool.Name == HealthTool || tool.Name == StepReadTool || tool.Name == StepsReadTool || tool.Name == ToolchainsReadTool || tool.Name == ReleaseTool || tool.Name == StepEndTool { + if strings.HasPrefix(tool.Name, ModuleName+"_state_") || tool.Name == StatusTool || tool.Name == HealthTool || tool.Name == StepReadTool || tool.Name == StepsReadTool || tool.Name == ToolchainsReadTool || tool.Name == ReleaseTool || tool.Name == StepEndTool { continue } var reason string diff --git a/modules/mesh-build-node/cmd/mesh-build-node/tools.go b/modules/mesh-build-node/cmd/mesh-build-node/tools.go index 604a034e3..ee0e9beaf 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/tools.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/tools.go @@ -43,6 +43,7 @@ func (m *Module) Tools(steps []StepTool) []stdio.Tool { tools = append(tools, m.ReadTools()...) tools = append(tools, steprun.StepEndTool(StepEndTool, m.Node, m.stepScan(), m.Held)) tools = append(tools, m.releaseTool()) + tools = append(tools, pruneTools()...) return append(tools, stdio.Tool{Name: StatusTool, Description: "What the Node build module is on this machine: the Node version its recipe builds with and the one installed, " + diff --git a/modules/mesh-build-node/module.json b/modules/mesh-build-node/module.json index e998f5ed2..d3b769eb2 100644 --- a/modules/mesh-build-node/module.json +++ b/modules/mesh-build-node/module.json @@ -1,6 +1,7 @@ { "module": "mesh-build-node", "version": "0.1", + "class": "core", "packages": { "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds": "0.1", "git.novox.be/novox/mesh-catalog/modules/ssh-client/sshkeys": "0.1" @@ -13,9 +14,9 @@ "user-namespaces" ], "state": [ - "toolchains", - "keys", - "pauses" + {"name": "toolchains", "max-mib": 8}, + {"name": "keys", "max-mib": 8}, + {"name": "pauses", "max-mib": 8} ], "claims": [ { @@ -53,6 +54,24 @@ "trusted": false, "runtime": true, "default": "15s,60s" + }, + "prune-mark": { + "type": "number", + "description": "The fill of mesh-build-node's state detected-steps, in percent of its cap, past which the module prunes it at its own write, oldest first (design 47 H2 §812): below the bus module's raise mark of 75 %.", + "trusted": false, + "runtime": true, + "minimum": 1, + "maximum": 100, + "default": 70 + }, + "prune-target": { + "type": "number", + "description": "The fill, in percent of the cap, a prune of mesh-build-node's state detected-steps takes it down to (design 47 H2 §812); below prune-mark.", + "trusted": false, + "runtime": true, + "minimum": 1, + "maximum": 100, + "default": 50 } }, "tools": [ @@ -65,11 +84,13 @@ "build_node_step_end", "build_node_toolchains", "build_node_status", - "build_node_health" + "build_node_health", + "mesh-build-node_state_keep", + "mesh-build-node_state_prune_now" ], "requires": [ - {"name": "steps", "storage": "key-value", "template": "state", "options": {"ttl-seconds": 172800, "objects-max-mib": 256}}, - {"name": "detected-steps", "storage": "key-value", "template": "state", "options": {"history": 1}}, + {"name": "steps", "storage": "key-value", "template": "state", "options": {"ttl-seconds": 172800, "objects-max-mib": 256, "max-mib": 16}}, + {"name": "detected-steps", "storage": "key-value", "template": "state", "options": {"history": 1, "max-mib": 8}}, {"name": "outputs", "storage": "object-store", "template": "objects", "options": {"max-mib": 1024, "max-age-days": 7}}, "artifact-store", "forge-account",