assigner: assigner_why says why a want is what it is: the pass step that decided it and what it read (tools rule)
This commit is contained in:
@@ -56,6 +56,8 @@ type passer struct {
|
||||
// skipped are the added modules whose absence from a candidate's added was said (skippedAdd), and the trunk entries whose
|
||||
// release is not heard (unheardRelease), once each.
|
||||
skipped map[string]bool
|
||||
// whys is, by key, the why of a want this process last wrote, the time aside (why.go).
|
||||
whys map[string]string
|
||||
// findings is the assigner's findings bucket (its said conditions, ADR 0564 §2).
|
||||
findings assign.Findings
|
||||
// calls is the wait of the kept manifest-reads calls (enginereads.ReadsCalls, ADR 0668 §3), made at the first pass.
|
||||
@@ -230,6 +232,9 @@ func (p *passer) pass(ctx context.Context) {
|
||||
p.deliveredAgain(ctx)
|
||||
if p.graph == nil || !p.graph.full { // a full assignment graph store keeps the last revision and writes no new want (design 47 G §181)
|
||||
p.wants(ctx)
|
||||
p.sayPass(ctx, "judged")
|
||||
} else {
|
||||
p.sayPass(ctx, "the assignment graph store is full: no want is written (design 47 G §181)")
|
||||
}
|
||||
p.puts(ctx)
|
||||
p.nodeWants(ctx)
|
||||
@@ -331,7 +336,9 @@ func (p *passer) wants(ctx context.Context) {
|
||||
}
|
||||
if fp != "" && !p.ends.mayWant(name, fp, branches, wantedOf[name]) {
|
||||
if !runnerFirstStart(name, manifests, p.w.runningNow()) {
|
||||
p.sayNoWant(name, g.nodes, wantedOf[name], assign.Outcome{Rules: noPipelineRules(g.nodes, name, fp, branches)})
|
||||
none := assign.Outcome{Rules: noPipelineRules(g.nodes, name, fp, branches)}
|
||||
p.sayNoWant(name, g.nodes, wantedOf[name], none)
|
||||
p.sayWhy(ctx, name, g.nodes, wantWhy{Branch: g.branch, Fp: fp, Step: whyNoPipeline}, wantedOf[name], &none, nil)
|
||||
return
|
||||
}
|
||||
// The first start of the pipeline runner (design 47 G A-428): no runner runs to pass its pipeline, so its want is
|
||||
@@ -346,6 +353,7 @@ func (p *passer) wants(ctx context.Context) {
|
||||
}
|
||||
// A dependent's new version waits for its dependency's newest released version to be delivered (§376, A-189).
|
||||
if p.holdForDelivery(ctx, name, fp, g.branch, g.nodes) {
|
||||
p.sayWhy(ctx, name, g.nodes, wantWhy{Branch: g.branch, Fp: fp, Step: whyDelivery, Words: p.saidDeliveryWaits()[name].Wait.On}, wantedOf[name], nil, nil)
|
||||
return
|
||||
}
|
||||
m := assign.Module{Name: name, FP: fp, Manifest: manifests[name], Needs: trunk[name].Needs, Chosen: chosenOf(chosen, name), Provisions: provisionsOf(name), Answering: answering(manifests, nodes), Offered: offered(manifests), Nodes: nodesOf[name], Now: time.Now(), Puts: puts[name], FormNeeds: p.w.buildNeeds(name, fp),
|
||||
@@ -404,6 +412,7 @@ func (p *passer) wants(ctx context.Context) {
|
||||
actingOf, orderOf := p.actingOf(name, released), p.orderActing(name, released, unread, func() assign.Nodes { return nodes })
|
||||
m.Acting = func(node string) []assign.ActingEdge { return append(actingOf(node), orderOf(node)...) }
|
||||
out := assign.Wants(m, nodes, wantedOf[name], last)
|
||||
p.sayWhy(ctx, name, m.Nodes, wantWhy{Branch: g.branch, Fp: fp, Step: whyRules}, wantedOf[name], &out, &m)
|
||||
p.sayParts(name, m, nodes, out, wantedOf[name])
|
||||
for _, node := range m.Nodes {
|
||||
for _, prov := range m.MissingProvisions(node) {
|
||||
|
||||
@@ -353,6 +353,9 @@ func writtenTools(st store) []stdio.Tool {
|
||||
sort.Strings(ks)
|
||||
out := map[string]End{}
|
||||
for _, k := range ks {
|
||||
if strings.HasPrefix(k, whyPrefix) {
|
||||
continue // a want's why (why.go), read by assigner_why
|
||||
}
|
||||
raw, _, ok, err := st.get(writtenState, k)
|
||||
if err != nil || !ok {
|
||||
continue
|
||||
|
||||
@@ -426,6 +426,7 @@ func serveTools() error {
|
||||
// What each node's engine reads, as the assigner uses it (ADR 0618 §3): its own state engine-reads, asked again through it.
|
||||
tools = append(tools, enginereads.Tool(engineReadsTool, "the assigner", enginereads.KeptState(stdio.State(engineReadsState)), false, time.Now))
|
||||
tools = append(tools, writtenTools(runtimeStore{})...)
|
||||
tools = append(tools, whyTools(runtimeStore{})...)
|
||||
tools = append(tools, pinsTools(runtimeStore{}, stdio.Ask)...)
|
||||
tools = append(tools, askAgainTools(runtimeStore{}, stdio.Ask, time.Now)...)
|
||||
return stdio.Serve("", tools)
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
)
|
||||
|
||||
// Why a want is what it is (lead-47 2026-11-15, the tools rule: novox's want of the indexer stood unwritten for a day and nothing
|
||||
// said why). Each pass writes, in the state written beside the pipeline ends, one key `why.<node>.<module>`: the step of the pass
|
||||
// that decided the want and what it read there. A key whose time stands still says the pass no longer judges that module.
|
||||
// assigner_why reads them.
|
||||
|
||||
// whyPrefix starts every key of a want's why in the state written; a pipeline end's key starts with a module's name.
|
||||
const whyPrefix = "why."
|
||||
|
||||
// whyTool is the tool that reads them.
|
||||
const whyTool = "assigner_why"
|
||||
|
||||
// The steps of the pass that decide a want.
|
||||
const (
|
||||
whyNoPipeline = "no-passed-pipeline" // the trunk's fingerprint passed no pipeline on the branch, and no want names it
|
||||
whyDelivery = "waits-for-delivery" // a dependency's newest released version is not delivered yet
|
||||
whyRules = "rules" // the six rules judged it
|
||||
)
|
||||
|
||||
// wantWhy is one key's value.
|
||||
type wantWhy struct {
|
||||
At time.Time `json:"at"`
|
||||
Branch string `json:"branch,omitempty"`
|
||||
// Fp is the fingerprint the trunk's entry names, the one the pass judged.
|
||||
Fp string `json:"fp,omitempty"`
|
||||
Step string `json:"step"`
|
||||
// Before is the want that stood before the pass, After the one the pass wrote (none: it kept Before).
|
||||
Before *mwc.Want `json:"before,omitempty"`
|
||||
After *mwc.Want `json:"after,omitempty"`
|
||||
// Rule is the rule holding the node back from Fp, with its words.
|
||||
Rule string `json:"rule,omitempty"`
|
||||
// What the rules read of the module.
|
||||
Built, BuildFailed, Held, Granted, Released, Kept bool `json:",omitempty"`
|
||||
BuildError string `json:"build-error,omitempty"`
|
||||
Acting []string `json:"acting,omitempty"`
|
||||
Words string `json:"words,omitempty"`
|
||||
}
|
||||
|
||||
func whyKey(node, module string) string { return whyPrefix + node + "." + module }
|
||||
|
||||
// sayWhy writes the why of module on each of nodes, once per change (the time aside): every put is a change its watchers hear.
|
||||
func (p *passer) sayWhy(ctx context.Context, module string, nodes []string, w wantWhy, before map[string]mwc.Want, out *assign.Outcome, m *assign.Module) {
|
||||
kv := p.kvs[writtenBucket()]
|
||||
if kv == nil {
|
||||
return
|
||||
}
|
||||
if p.whys == nil {
|
||||
p.whys = map[string]string{}
|
||||
}
|
||||
for _, node := range nodes {
|
||||
one := w
|
||||
one.At = time.Now().UTC()
|
||||
if b, ok := before[node]; ok {
|
||||
one.Before = &b
|
||||
}
|
||||
if out != nil {
|
||||
if a, ok := out.Wants[node]; ok {
|
||||
one.After = &a
|
||||
}
|
||||
if h, ok := out.Rules[node]; ok {
|
||||
one.Rule = h.Reason()
|
||||
}
|
||||
}
|
||||
if m != nil {
|
||||
one.Built, one.BuildFailed, one.BuildError, one.Held, one.Granted, one.Released, one.Kept = m.Built, m.BuildFailed, m.BuildError, m.Held, m.Granted, m.Released, m.Kept
|
||||
if m.Acting != nil {
|
||||
for _, e := range m.Acting(node) {
|
||||
one.Acting = append(one.Acting, e.Step+" "+e.Node+"/"+e.Part+"@"+shortHex(e.Fp)+" (seat "+e.Seat+")")
|
||||
}
|
||||
}
|
||||
}
|
||||
same := one
|
||||
same.At = time.Time{}
|
||||
cmp, _ := json.Marshal(same)
|
||||
key := whyKey(node, module)
|
||||
if p.whys[key] == string(cmp) {
|
||||
continue
|
||||
}
|
||||
raw, err := json.Marshal(one)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, err := kv.Put(ctx, key, raw); err != nil {
|
||||
p.logf("the why of %s on %s is not written: %v", module, node, err)
|
||||
continue
|
||||
}
|
||||
p.whys[key] = string(cmp)
|
||||
}
|
||||
}
|
||||
|
||||
// whyTools is the tool assigner_why: every want's why, or those of one module or one node.
|
||||
func whyTools(st store) []stdio.Tool {
|
||||
return []stdio.Tool{{Name: whyTool, Description: "why a want is what it is: per node and module, the step of the assigner's last pass that decided the want (no passed pipeline, waits for a dependency's delivery, or the six rules with the rule holding it back), the fingerprint the trunk names, the want before and the one written, and what the rules read (built, held, granted, acting waits). A time that stands still says the pass no longer judges that module. Arguments: module and node narrow it.",
|
||||
Input: schema(map[string]string{"module": "a module's name", "node": "a node's name"}, nil),
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
ks, err := st.keys(writtenState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
module, node := arg(args, "module"), arg(args, "node")
|
||||
sort.Strings(ks)
|
||||
out := map[string]wantWhy{}
|
||||
for _, k := range ks {
|
||||
rest, ok := strings.CutPrefix(k, whyPrefix)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
n, mod, _ := strings.Cut(rest, ".")
|
||||
if (module != "" && mod != module) || (node != "" && n != node) {
|
||||
continue
|
||||
}
|
||||
raw, _, ok, err := st.get(writtenState, k)
|
||||
if err != nil || !ok {
|
||||
continue
|
||||
}
|
||||
var w wantWhy
|
||||
if json.Unmarshal(raw, &w) == nil {
|
||||
out[rest] = w
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}}}
|
||||
}
|
||||
|
||||
// sayPass writes, under `why.pass`, whether the last pass judged the wants at all, once per change of its words.
|
||||
func (p *passer) sayPass(ctx context.Context, words string) {
|
||||
kv := p.kvs[writtenBucket()]
|
||||
if kv == nil {
|
||||
return
|
||||
}
|
||||
if p.whys == nil {
|
||||
p.whys = map[string]string{}
|
||||
}
|
||||
if p.whys[whyPrefix+"pass"] == words {
|
||||
return
|
||||
}
|
||||
raw, _ := json.Marshal(wantWhy{At: time.Now().UTC(), Step: words})
|
||||
if _, err := kv.Put(ctx, whyPrefix+"pass", raw); err == nil {
|
||||
p.whys[whyPrefix+"pass"] = words
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,7 @@
|
||||
"assigner_seat_list_again",
|
||||
"assigner_ask_again",
|
||||
"assigner_written",
|
||||
"assigner_why",
|
||||
"assigner_pins",
|
||||
"assigner_unpin",
|
||||
"assigner_delivered_again"
|
||||
|
||||
Reference in New Issue
Block a user