Read the seat mesh-placement's state through the sdk's PlacementKeys in mesh-conditions, mesh-config, mesh-provisioner, mesh-vault and mesh-self-check, so they read its keys per module and node and the form before alike while it is delivered (issue 774, research 072 row 37)

This commit is contained in:
2026-10-31 09:27:15 +01:00
parent 21fddffc6e
commit 85c336f260
23 changed files with 235 additions and 150 deletions
@@ -31,29 +31,26 @@ const (
ScopeMachine = health.ScopeMachine
)
// placements is every node's placement, by node.
// placements is every node's placement, by node, from the state's keys in either form: a node key and its module keys,
// or the form before, `placement.<node>` (delivery.PlacementsOf; research 072 row 37).
func (c *Checker) placements() (map[string]delivery.Placement, error) {
keys, err := c.Store.Keys(PlacementRead)
if err != nil {
return nil, fmt.Errorf("the placement cannot be read: %w", err)
}
out := map[string]delivery.Placement{}
values := map[string][]byte{}
for _, k := range keys {
raw, ok, err := c.Store.Get(PlacementRead, k)
if err != nil {
return nil, fmt.Errorf("the placement of %s cannot be read: %w", k, err)
return nil, fmt.Errorf("the placement's key %s cannot be read: %w", k, err)
}
if !ok {
continue
if ok {
values[k] = raw
}
var p delivery.Placement
if err := json.Unmarshal(raw, &p); err != nil {
return nil, fmt.Errorf("the placement of %s is not readable: %w", k, err)
}
if p.Node == "" {
p.Node = k
}
out[p.Node] = p
}
out, err := delivery.PlacementsOf(values)
if err != nil {
return nil, fmt.Errorf("the placement is not readable: %w", err)
}
return out, nil
}
@@ -260,8 +260,12 @@ func machines() *memStore {
node, address, endpoint string
online bool
}{{"novox", "10.10.0.1/16", "203.0.113.5:51820", true}, {"ace", "10.10.0.2/16", "", true}, {"g14", "10.10.0.3/16", "", false}} {
_ = s.Put(PlacementRead, p.node, delivery.Placement{V: 1, Node: p.node,
Decided: delivery.NodeDecided{Address: p.address, Endpoint: p.endpoint, Hub: p.endpoint != ""}})
pl := delivery.Placement{V: 1, Node: p.node,
Decided: delivery.NodeDecided{Address: p.address, Endpoint: p.endpoint, Hub: p.endpoint != ""}}
if p.node == "ace" {
pl.Modules = []delivery.PlacedModule{{Module: "sshd"}} // a module key beside the node key
}
place(s, pl)
_ = s.Put(PresenceRead, p.node, delivery.Presence{V: 1, Online: p.online})
key, _ := delivery.SeatHoldersKey(BannedSeat, p.node)
_ = s.Put(SeatHoldersRead, key, delivery.SeatHolders{V: 1, Seat: BannedSeat, Scope: "node", Node: p.node,
@@ -270,6 +274,31 @@ func machines() *memStore {
return s
}
// place writes a node's placement as the seat does, its node key and a key per module (research 072 row 37); g14's in
// the form before, `placement.g14`, which the probes still read while the change is delivered.
func place(s *memStore, p delivery.Placement) {
if p.Node == "g14" {
raw, _ := delivery.EncodePlacement(p)
_ = s.Put(PlacementRead, "placement.g14", json.RawMessage(raw))
return
}
values, _ := delivery.PlacementValues(p)
for k, raw := range values {
_ = s.Put(PlacementRead, k, json.RawMessage(raw))
}
}
// placed is every node's placement the store holds.
func placed(s *memStore) map[string]delivery.Placement {
keys, _ := s.Keys(PlacementRead)
values := map[string][]byte{}
for _, k := range keys {
values[k], _, _ = s.Get(PlacementRead, k)
}
out, _ := delivery.PlacementsOf(values)
return out
}
// filling is a store holding the self-check's written fill finding of a stream: the condition open.
func filling(stream string) *memStore {
s := newStore()
@@ -285,11 +314,9 @@ func filling(stream string) *memStore {
func agents(verdicts map[string]string) *memStore {
s := machines()
for node, v := range verdicts {
raw, _, _ := s.Get(PlacementRead, node)
var p delivery.Placement
_ = json.Unmarshal(raw, &p)
p := placed(s)[node]
p.Decided.AgentAccount = "agent"
_ = s.Put(PlacementRead, node, p)
place(s, p)
h := delivery.NodeHealth{V: 1, Node: node, Contract: 13}
switch v {
case "":
@@ -303,7 +330,7 @@ func agents(verdicts map[string]string) *memStore {
h.Root = []delivery.RootVerdict{{Account: "agent", Module: "claude-code", Resource: "claude-code.agent", State: v,
Reason: "can become root without a person: a sudo rule"}}
}
raw, _ = delivery.EncodeNodeHealth(h)
raw, _ := delivery.EncodeNodeHealth(h)
_ = s.Put(HealthRead, node, json.RawMessage(raw))
}
return s