COND11 (in part): the keeper's ask bound and first-view bound are settings read at its start; the two hours wait on COND7

Builds: design 47 G §557

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
2026-11-11 20:32:33 +01:00
parent 811b59b454
commit ecf597adce
6 changed files with 98 additions and 4 deletions
@@ -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"}}}
@@ -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
@@ -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)
}()
@@ -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)
}
@@ -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)
}
}
}
+14
View File
@@ -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"
},