From 74dd8af6992562302c8205f751556d1e418aef91 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 01:03:06 +0100 Subject: [PATCH] M1: the gate prunes its state heads toward its cap at its own writes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit heads is written through the SDK's pruned state, which judges the fill each put answers and past prune-mark (70 %) prunes the oldest keys to prune-target (50 %); the gate serves mesh-delivery-gate_state_prune_now and mesh-delivery-gate_state_keep, each written in the hand-act log. Builds: design 47 H2 §812; H-A-380, H-A-386, H-A-411 (3) --- .../cmd/mesh-delivery-gate/heads.go | 23 ++++++++++++++++++- .../cmd/mesh-delivery-gate/main.go | 2 ++ modules/mesh-delivery-gate/module.json | 22 +++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/heads.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/heads.go index ea4d1d7bd..c2b80d4dd 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/heads.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/heads.go @@ -12,7 +12,9 @@ import ( "encoding/json" "errors" "fmt" + "os" "sort" + "sync" "time" "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" @@ -20,6 +22,8 @@ import ( "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg" stdio "git.novox.be/novox/mesh-sdk/go" "git.novox.be/novox/mesh-sdk/go/keys" + "git.novox.be/novox/mesh-sdk/go/stateobjects" + "git.novox.be/novox/mesh-sdk/go/views" ) // HeadUntaken is the finding of a head no merge call delivered; warning, the operator its resolver (H-A-81). @@ -61,10 +65,27 @@ func (kvHeads) Get(key string) (*HeldHead, error) { } func (kvHeads) Put(key string, v HeldHead) error { - _, err := stdio.State(seat.StateHeads).Put(key, v) + _, err := prunedHeads().Put(key, v) return err } +// prunedHeads is the state heads, pruned toward its cap at the gate's own writes (design 47 H2 §812; H-A-411 (3)): past +// prune-mark of its 8 MiB the oldest keys go down to prune-target, in one journal line. A setting that is no percentage +// is said, and the defaults hold. +var prunedHeads = sync.OnceValue(func() *stdio.PrunedState { + p, err := stdio.PruneSettings() + if err != nil { + fmt.Fprintf(os.Stderr, "the prune of heads keeps its defaults (%d %% to %d %%): %v\n", stdio.PruneMarkDefault, stdio.PruneTargetDefault, err) + p = stdio.Prune{Mark: stdio.PruneMarkDefault, Target: stdio.PruneTargetDefault} + } + return stdio.State(seat.StateHeads).Pruned(p) +}) + +// headsPruneTools are the gate's two prune tools over heads, each written in the hand-act log (H-A-380 (3)). +func headsPruneTools(acts views.HandActs) []stdio.Tool { + return stateobjects.PruneTools(Module, []stateobjects.Pruning{{Name: seat.StateHeads, State: prunedHeads()}}, acts) +} + func (kvHeads) Delete(key string) error { return stdio.State(seat.StateHeads).Delete(key) } func (s kvHeads) All() (map[string]HeldHead, error) { diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go index 7075dd84a..42dadf5a4 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go @@ -263,6 +263,8 @@ func tools(h *Holder, l *listening) []stdio.Tool { list = append(list, recordTools(h, meshhandactsclient.Recorder{Ask: stdio.Ask})...) list = append(list, sourceTools(h, meshhandactsclient.Recorder{Ask: stdio.Ask})...) list = append(list, headTools(h, meshhandactsclient.Recorder{Ask: stdio.Ask})...) + // The prune of heads by hand, now or kept from it (design 47 H2 §812, H-A-380 (3)). + list = append(list, headsPruneTools(meshhandactsclient.Recorder{Ask: stdio.Ask})...) // A verb that changes a delivery asks for a look at what it makes possible (react.go). for i := range list { run := list[i].Run diff --git a/modules/mesh-delivery-gate/module.json b/modules/mesh-delivery-gate/module.json index 7a8fe136f..37f784c26 100644 --- a/modules/mesh-delivery-gate/module.json +++ b/modules/mesh-delivery-gate/module.json @@ -433,7 +433,9 @@ "gate_source_again", "gate_source_seed", "gate_source_start", - "gate_times" + "gate_times", + "mesh-delivery-gate_state_keep", + "mesh-delivery-gate_state_prune_now" ], "config": { "record-retention": { @@ -464,6 +466,24 @@ "trusted": false, "runtime": true, "default": "3m" + }, + "prune-mark": { + "type": "number", + "description": "The fill of the gate's state heads, in percent of its cap, past which the gate 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 the gate's state heads takes it down to (design 47 H2 §812); below prune-mark.", + "trusted": false, + "runtime": true, + "minimum": 1, + "maximum": 100, + "default": 50 } }, "resources": [