From ecf597adce36b757d9e3656670d39525235145e6 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 11 Nov 2026 20:29:24 +0100 Subject: [PATCH] COND11 (in part): the keeper's ask bound and first-view bound are settings read at its start; the two hours wait on COND7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 G §557 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ --- .../cmd/mesh-conditions/asks.go | 16 ++++++--- .../cmd/mesh-conditions/keeper.go | 2 ++ .../cmd/mesh-conditions/main.go | 2 ++ .../cmd/mesh-conditions/settings.go | 36 +++++++++++++++++++ .../cmd/mesh-conditions/settings_test.go | 32 +++++++++++++++++ modules/mesh-conditions/module.json | 14 ++++++++ 6 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 modules/mesh-conditions/cmd/mesh-conditions/settings.go create mode 100644 modules/mesh-conditions/cmd/mesh-conditions/settings_test.go diff --git a/modules/mesh-conditions/cmd/mesh-conditions/asks.go b/modules/mesh-conditions/cmd/mesh-conditions/asks.go index f9868baa5..b9bff6d23 100644 --- a/modules/mesh-conditions/cmd/mesh-conditions/asks.go +++ b/modules/mesh-conditions/cmd/mesh-conditions/asks.go @@ -18,9 +18,17 @@ import ( stdio "git.novox.be/novox/mesh-sdk/go" ) -// AskedWithin is how long an observer has to state its findings after an ask. +// AskedWithin is how long an observer has to state its findings after an ask, when the setting says none (design 47 G §557). const AskedWithin = 5 * time.Minute +// askedWithin is the keeper's bound for an ask: its setting, AskedWithin when none. +func (k *Keeper) askedWithin() time.Duration { + if k.AskBound > 0 { + return k.AskBound + } + return AskedWithin +} + // The kind of the keeper's finding of an observer that stated nothing, and the prefix of its ask's key in `bounds`. const ( KindFindingsUnstated = "findings-unstated" @@ -62,7 +70,7 @@ func (k *Keeper) Ask(by, module string) (string, error) { if v.observer == "" || module != "" && v.observer != module || k.away[v.node] { continue } - v.Asks[ask] = now.Add(AskedWithin) + v.Asks[ask] = now.Add(k.askedWithin()) wait = append(wait, [2]string{v.observer, v.node}) } k.mu.Unlock() @@ -81,7 +89,7 @@ func (k *Keeper) Ask(by, module string) (string, error) { for _, w := range wait { k.saveView(w[0], w[1]) if err := k.Store.CreateTTL(BoundsState, askedKey(w[0], w[1], ask), map[string]any{"observer": w[0], "node": w[1], "ask": ask, - "until": now.Add(AskedWithin)}, AskedWithin); err != nil && !errors.Is(err, stdio.ErrChanged) { + "until": now.Add(k.askedWithin())}, k.askedWithin()); err != nil && !errors.Is(err, stdio.ErrChanged) { problems = append(problems, err.Error()) } } @@ -138,7 +146,7 @@ func (k *Keeper) AskPassed(bound string) error { now := k.Now().UTC() f := seat.FindingsByKeyValue{V: cc.FindingVersion, Key: unstatedKey(observer, node), Kind: KindFindingsUnstated, Subject: seat.Subject{Scope: cc.ScopeModule, ID: observer + "." + node, Machine: node}, - Severity: cc.Warning, Summary: fmt.Sprintf("%s on %s stated no findings within %s of the ask", observer, node, AskedWithin), + Severity: cc.Warning, Summary: fmt.Sprintf("%s on %s stated no findings within %s of the ask", observer, node, k.askedWithin()), Headline: observer + " on " + node + " did not state its findings", Explanation: "The keeper asked " + observer + " on " + node + " to state its findings and heard nothing; its conditions stand as they were.", Source: "findings-asked", Observer: Module, At: now, Evidence: []seat.Evidence{{At: now, Said: "ask " + ask + " unanswered"}}} diff --git a/modules/mesh-conditions/cmd/mesh-conditions/keeper.go b/modules/mesh-conditions/cmd/mesh-conditions/keeper.go index a8598441d..154773e4d 100644 --- a/modules/mesh-conditions/cmd/mesh-conditions/keeper.go +++ b/modules/mesh-conditions/cmd/mesh-conditions/keeper.go @@ -107,6 +107,8 @@ type Keeper struct { Homes map[string]Home // Bound is a delivery's hold bound; motion.DefaultDeliveryBound when zero (hold.go). Bound time.Duration + // AskBound is how long an observer has to state its findings after an ask (the setting ask-bound-seconds, §557); AskedWithin when zero. + AskBound time.Duration mu sync.Mutex findings map[string]map[string]seat.FindingsByKeyValue diff --git a/modules/mesh-conditions/cmd/mesh-conditions/main.go b/modules/mesh-conditions/cmd/mesh-conditions/main.go index a185af451..90fd771f6 100644 --- a/modules/mesh-conditions/cmd/mesh-conditions/main.go +++ b/modules/mesh-conditions/cmd/mesh-conditions/main.go @@ -193,6 +193,8 @@ func main() { v := NewViews(k) go func() { <-stdio.Served() + // The bounds are settings, read at the start once the runtime serves (design 47 G §557). + v.Bound = ReadSettings(k, stdio.Config) v.Start(context.Background()) Keep(k, v) }() diff --git a/modules/mesh-conditions/cmd/mesh-conditions/settings.go b/modules/mesh-conditions/cmd/mesh-conditions/settings.go new file mode 100644 index 000000000..b29fe7596 --- /dev/null +++ b/modules/mesh-conditions/cmd/mesh-conditions/settings.go @@ -0,0 +1,36 @@ +package main + +// The bounds the keeper times are settings read at its start, their defaults the design's values, so a whole test sets +// them in seconds and never waits on real time (design 47 G §557). + +import ( + "encoding/json" + "time" +) + +// The settings, in seconds. +const ( + SettingAskBound = "ask-bound-seconds" + SettingViewWaits = "view-waits-seconds" + defaultViewWaits = 5 * time.Minute +) + +// seconds reads one setting as a duration; def when the setting is unreadable, absent or not above zero. +func seconds(read func(key string) (json.RawMessage, error), key string, def time.Duration) time.Duration { + raw, err := read(key) + if err != nil { + logf("the setting %s cannot be read (%v); its default %s stands", key, err, def) + return def + } + var n float64 + if json.Unmarshal(raw, &n) != nil || n <= 0 { + return def + } + return time.Duration(n * float64(time.Second)) +} + +// ReadSettings sets the keeper's bounds and the first views' wait from the settings. +func ReadSettings(k *Keeper, read func(key string) (json.RawMessage, error)) (viewWaits time.Duration) { + k.AskBound = seconds(read, SettingAskBound, AskedWithin) + return seconds(read, SettingViewWaits, defaultViewWaits) +} diff --git a/modules/mesh-conditions/cmd/mesh-conditions/settings_test.go b/modules/mesh-conditions/cmd/mesh-conditions/settings_test.go new file mode 100644 index 000000000..9d9f48e82 --- /dev/null +++ b/modules/mesh-conditions/cmd/mesh-conditions/settings_test.go @@ -0,0 +1,32 @@ +package main + +import ( + "encoding/json" + "errors" + "testing" + "time" +) + +// Design 47 G §557: the bounds the keeper times are settings, their defaults the design's values. +func TestTheKeepersBoundsAreSettings(t *testing.T) { + for _, c := range []struct { + name string + read func(string) (json.RawMessage, error) + ask, view time.Duration + }{ + {"unset", func(string) (json.RawMessage, error) { return nil, errors.New("none") }, AskedWithin, defaultViewWaits}, + {"set in seconds", func(key string) (json.RawMessage, error) { + if key == SettingAskBound { + return json.RawMessage("2"), nil + } + return json.RawMessage("3"), nil + }, 2 * time.Second, 3 * time.Second}, + {"not above zero", func(string) (json.RawMessage, error) { return json.RawMessage("0"), nil }, AskedWithin, defaultViewWaits}, + } { + k := &Keeper{} + view := ReadSettings(k, c.read) + if k.askedWithin() != c.ask || view != c.view { + t.Errorf("%s: ask bound %s, view bound %s; want %s, %s", c.name, k.askedWithin(), view, c.ask, c.view) + } + } +} diff --git a/modules/mesh-conditions/module.json b/modules/mesh-conditions/module.json index 569f6071a..a59a68797 100644 --- a/modules/mesh-conditions/module.json +++ b/modules/mesh-conditions/module.json @@ -53,6 +53,20 @@ "key-ttl": true } ], + "config": { + "ask-bound-seconds": { + "type": "number", + "description": "How long an observer has to state its findings after an ask, in seconds, before the keeper raises findings-unstated for it: 300 is five minutes.", + "minimum": 1, + "default": 300 + }, + "view-waits-seconds": { + "type": "number", + "description": "How long a first view may stay unanswered, in seconds, before the keeper raises view-waits for it: 300 is five minutes.", + "minimum": 1, + "default": 300 + } + }, "own-secrets": { "broker": "${dir:state}/broker" },