C-1: a node's holdings are said as holdings-changed, and again when asked

The licence manager follows the nodes' holdings by an event and asks for them with
holdings.asked, instead of reading the agent module's state (ADR 0596 §2). The state
holdings stays the module's own.

Builds: design 39 bus-and-switch §23

Claude-Session: https://claude.ai/code/session_01NcbgfHb9d4T9nq5Q6WqdiJ
This commit is contained in:
2026-11-11 23:09:22 +01:00
parent e85cf002a4
commit 4179be7a56
5 changed files with 121 additions and 11 deletions
+27 -8
View File
@@ -20,6 +20,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"sync"
"time"
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
@@ -567,15 +568,24 @@ func run(p Paths, view *ServerView, configView *ConfigView) {
// every change of the credentials file, polled, because the file is replaced by rename and a watch on
// the old inode would go quiet. Fingerprints and expiries only.
holdings := stdio.State("holdings")
reported := ""
report := func() {
var sayMu sync.Mutex
sayer := &HoldingsSayer{
Put: func(h Holdings) error { _, err := holdings.Put(p.Node, h); return err },
Emit: func(h Holdings) error { return stdio.Emit(HoldingsChanged, h) },
}
sayHoldings := func(again bool) {
sayMu.Lock()
defer sayMu.Unlock()
now := HoldingsOf(p)
raw, _ := json.Marshal(now)
if string(raw) == reported {
return
}
persist("reporting what this node holds", func() error { _, err := holdings.Put(p.Node, now); return err }, func(int) {
reported = string(raw)
said := false
persist("reporting what this node holds", func() error {
var err error
said, err = sayer.Say(now, again)
return err
}, func(int) {
if !said {
return
}
account := "no account"
if now.Identity != nil && now.Identity.EmailAddress != "" {
account = now.Identity.EmailAddress
@@ -593,6 +603,15 @@ func run(p Paths, view *ServerView, configView *ConfigView) {
say("%s", line)
})
}
report := func() { sayHoldings(false) }
// The licence manager asks every node to say what it holds again (§23): after its carry-over, at its start and on
// its resync.
go persist("hearing the licence manager ask what this node holds", func() error {
return stdio.Subscribe(HoldingsAsked, func(stdio.Envelope) error {
go sayHoldings(true)
return nil
})
}, func(n int) { say("hearing %s%s", HoldingsAsked, refusals(n)) })
// What this node should hold (ADR 0206): the manager's `bindings` key for this node; a newer
// generation is fetched with the seat's `current`, sealed to this module's key.