G's grants already carry a state's max-mib onto its bucket (Bucket.MaxBytes, §469); main's second copy of that cap in BucketStreamConfig and Composed is dropped for G's, and main's tests (the declared cap row, the held bucket raised) are kept. The checker keeps G's version 0.1 (§368) with main's compositions max-mib 256. Builds: design 47 G §469, §368; A-277 (since mesh-delivery #206 the grants part carries max-mib) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
532 lines
31 KiB
Go
532 lines
31 KiB
Go
// Command mesh-delivery-checker-tools serves the checker's read tools (novox/hq ADR 0484 clause 13, issue 1686): the runtime
|
|
// launches it for a call, it reads the checker's verdicts and kept states through the checker's state and reads, and the
|
|
// indexer's candidates and modules through the indexer's read tools. It writes only the tries (the try's tools) and, asking a check again by hand, one verdict. The checker is the other program: it serves no tool (ADR 0437 §4).
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"mesh-delivery-checker/internal/check"
|
|
|
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
|
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
|
"git.novox.be/novox/mesh-sdk/go/views"
|
|
)
|
|
|
|
// reads counts the values this call read from the bus: the runtime launches the tools for one call, so the count is the call's.
|
|
var reads atomic.Int64
|
|
|
|
// cutAnswer says in the answer that it was cut, and how to narrow it.
|
|
func cutAnswer(answer map[string]any, cut string) map[string]any {
|
|
if cut != "" {
|
|
answer["cut"], answer["note"] = true, cut
|
|
}
|
|
return answer
|
|
}
|
|
|
|
// logged runs every tool with one line to stderr per call: the tool, the values it read and the time it took.
|
|
func logged(tools []stdio.Tool) []stdio.Tool {
|
|
for i := range tools {
|
|
name, run := tools[i].Name, tools[i].Run
|
|
tools[i].Run = func(args map[string]any) (any, error) {
|
|
reads.Store(0)
|
|
start := time.Now()
|
|
out, err := run(args)
|
|
fmt.Fprintf(os.Stderr, "[mesh-delivery-checker-tools] %s read %d values in %s (error: %v)\n", name, reads.Load(), time.Since(start).Round(time.Millisecond), err)
|
|
return out, err
|
|
}
|
|
}
|
|
return tools
|
|
}
|
|
|
|
func read(s stdio.KeptState) check.StateRead {
|
|
return check.StateRead{Keys: s.Keys, Get: func(key string) (json.RawMessage, error) {
|
|
reads.Add(1)
|
|
e, err := s.Get(key)
|
|
if err != nil || e == nil {
|
|
return nil, err
|
|
}
|
|
return e.Value, nil
|
|
}}
|
|
}
|
|
|
|
// ownerRead is a state of another module read through that module's ordinary read tool (views.ReadTool), asked through ask
|
|
// (stdio.Ask, or a test's): its keys with no argument, one key's value with key. Another module's data is asked through its
|
|
// tools, never read from its bus state (novox/hq ADR 0596); the manifest invokes the tool, and the owner answers every reader
|
|
// that invokes it. Each read is asked when it is read: the owner's state is the truth, and the tools keep no copy.
|
|
func ownerRead(ask func(string, any) (json.RawMessage, error), tool string) check.StateRead {
|
|
call := func(args map[string]any, into any) error {
|
|
reads.Add(1)
|
|
raw, err := ask(tool, args)
|
|
if err != nil {
|
|
return fmt.Errorf("%s does not answer: %w", tool, err)
|
|
}
|
|
answer, said, ok := buscalls.Unwrap(raw)
|
|
if !ok {
|
|
return fmt.Errorf("%s answered: %s", tool, said)
|
|
}
|
|
if err := json.Unmarshal(answer, into); err != nil {
|
|
return fmt.Errorf("%s answered what does not decode: %w", tool, err)
|
|
}
|
|
return nil
|
|
}
|
|
return check.StateRead{
|
|
Keys: func() ([]string, error) {
|
|
var a views.ReadAnswer
|
|
if err := call(map[string]any{}, &a); err != nil {
|
|
return nil, err
|
|
}
|
|
return a.Keys, nil
|
|
},
|
|
Get: func(key string) (json.RawMessage, error) {
|
|
var a views.KeyAnswer
|
|
if err := call(map[string]any{"key": key}, &a); err != nil {
|
|
return nil, err
|
|
}
|
|
if !a.Found {
|
|
return nil, nil
|
|
}
|
|
return a.Value, nil
|
|
}}
|
|
}
|
|
|
|
// The indexer's read tools the tools ask for its candidates and modules (the manifest's invokes).
|
|
const (
|
|
indexerCandidatesTool = check.IndexerModule + ".indexer_read_candidates"
|
|
indexerModulesTool = check.IndexerModule + ".indexer_read_modules"
|
|
)
|
|
|
|
// runsOf says which commit the mesh runs of a module from the indexer's modules state, as the checker's own record of it does
|
|
// (the commit the module's record was computed at); "" when the record is not readable.
|
|
type runsOf struct{ modules check.StateRead }
|
|
|
|
func (r runsOf) CommitOf(module string) string {
|
|
if r.modules.Get == nil {
|
|
return ""
|
|
}
|
|
raw, err := r.modules.Get(module)
|
|
if err != nil || len(raw) == 0 {
|
|
return ""
|
|
}
|
|
m, err := meshcatalogclient.DecodeModule(raw)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return m.Commit
|
|
}
|
|
|
|
// stateStore is a state the tools write: the tries.
|
|
type stateStore struct {
|
|
check.StateRead
|
|
create func(key string, value []byte) error
|
|
entry func(key string) (json.RawMessage, uint64, error)
|
|
update func(key string, value []byte, revision uint64) error
|
|
}
|
|
|
|
func (s stateStore) Entry(key string) (json.RawMessage, uint64, error) { return s.entry(key) }
|
|
func (s stateStore) Update(key string, value []byte, revision uint64) error {
|
|
return s.update(key, value, revision)
|
|
}
|
|
|
|
func (s stateStore) Keys() ([]string, error) { return s.StateRead.Keys() }
|
|
func (s stateStore) Get(key string) (json.RawMessage, error) { return s.StateRead.Get(key) }
|
|
func (s stateStore) Create(key string, value []byte) error { return s.create(key, value) }
|
|
|
|
// Trying is what the try's tools work on: the tries, and the gate's trunk heads.
|
|
type Trying struct {
|
|
Tries check.TryStore
|
|
Ender check.TryEnder
|
|
Trunks func() (map[string]string, error)
|
|
Now func() time.Time
|
|
}
|
|
|
|
// TryTools are the try's tools (ADR 0501 §5): ask one, read one, and end one by hand (issue 734). mesh-controller's try calls them.
|
|
func TryTools(tr Trying) []stdio.Tool {
|
|
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return s }
|
|
return []stdio.Tool{
|
|
{Name: check.TryTool,
|
|
Description: "Try a delivery group, or one pushed head, before its pull requests are opened (try a group, group try, try several repositories): " +
|
|
"name the members, each a repository and the exact commit asked (never the branch's head now, so a push after the ask changes nothing of what is tried), " +
|
|
"or one repository and its head for a try of one member (the seat verb try of mesh-delivery-checker takes the same members, ADR 0637 §6). The checker judges it by the code a group's pull-request check runs, so the two cannot drift: " +
|
|
"each member merged onto its trunk's head, the unit and the integration level of every member through the build modules, the manifest validator over " +
|
|
"the members' manifests, the module graph, and the composition on every placed node. Every failure is named (each member, level, test, manifest and node), not " +
|
|
"the first. A try owes the forge nothing (no status, no Approve asked) and writes no verdict of a pull request; what its passing levels prove is kept, so a pull request's " +
|
|
"check of the same heads on the same trunk runs only what the try did not pass. A try narrowed to a level or to some tests judges only those, no manifest and no composition, and keeps nothing of tests. " +
|
|
"Answers the try's id at once; " + check.TryReadTool + " reads where it stands, " + check.TryEndTool + " ends it by hand. A try of the same commits that waits or runs is the answer to a second ask " +
|
|
"(whatever the order of the members); at most 4 run on a build node, and 8 wait for one, mesh-wide. A repository the checker checks no level of (one whose trunk the gate does not name) " +
|
|
"is refused. A try whose ask no build node took within the step bound ends as error; its ask stays in the build seat's stream and may still run later, judged by nobody (issue 734).",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"members": map[string]any{"type": "array", "description": "the group: one repository at most once, each at the exact commit asked and the trunk commit it is merged onto",
|
|
"items": map[string]any{"type": "object", "required": []string{"repository", "head"}, "properties": map[string]any{
|
|
"repository": map[string]any{"type": "string", "description": "<owner>/<name>"},
|
|
"head": map[string]any{"type": "string", "description": "the full commit to try, 40 or 64 hex digits"},
|
|
"trunk": map[string]any{"type": "string", "description": "the trunk commit to merge it onto, or the trunk's branch for its head now; the trunk's head when absent"}}}},
|
|
"repository": map[string]any{"type": "string", "description": "<owner>/<name>, for a try of one member (instead of members)"},
|
|
"head": map[string]any{"type": "string", "description": "the full commit to try, 40 or 64 hex digits (with repository)"},
|
|
"trunk": map[string]any{"type": "string", "description": "the trunk commit to merge it onto, or the trunk's branch for its head now; the trunk's head when absent (with repository)"},
|
|
"tests": map[string]any{"type": "string", "description": "a go test -run pattern: only those tests run, and nothing is kept"},
|
|
"level": map[string]any{"type": "string", "enum": []string{"unit", "integration"}, "description": "only this level; both when absent"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
if tr.Tries == nil || tr.Trunks == nil {
|
|
return nil, fmt.Errorf("the tries state cannot be written here")
|
|
}
|
|
trunks, err := tr.Trunks()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the trunk heads cannot be read: %w", err)
|
|
}
|
|
now := time.Now
|
|
if tr.Now != nil {
|
|
now = tr.Now
|
|
}
|
|
var members []check.TryAskMember
|
|
if raw, ok := args["members"]; ok {
|
|
list, isList := raw.([]any)
|
|
if !isList {
|
|
return nil, fmt.Errorf("members is a list of {repository, head, trunk}")
|
|
}
|
|
for _, item := range list {
|
|
m, isMap := item.(map[string]any)
|
|
if !isMap {
|
|
return nil, fmt.Errorf("a member is {repository, head, trunk}")
|
|
}
|
|
members = append(members, check.TryAskMember{Repository: str(m, "repository"), Head: str(m, "head"), Trunk: str(m, "trunk")})
|
|
}
|
|
}
|
|
id, err := check.AskTry(tr.Tries, trunks, check.TryAsk{Repository: str(args, "repository"), Head: str(args, "head"),
|
|
Trunk: str(args, "trunk"), Tests: str(args, "tests"), Level: str(args, "level"), Members: members}, now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]any{"id": id}, nil
|
|
}},
|
|
{Name: check.TryReadTool,
|
|
Description: "Where a try (of a group or of one head) stands, read whole, as stored: queued, running, or its end (pass, fail, or error when it could not run, or " +
|
|
"when its manifests and composition could not be judged), with what was said of it, every member's commit and the trunk commit it was merged onto, the time it took, " +
|
|
"every failure one line each (members, levels, tests, manifests, the composition per node), the levels' tests run and kept, the composition on every placed node, " +
|
|
"the notes of the check (manifests judged, module graph, kept verdicts); while it runs, each ask it put as soon as it is put, " +
|
|
"with the node that took it, its state and the phase its step says (fetch and merge, a level's digest, lint, tests) and since when. Read-only.",
|
|
Input: map[string]any{"type": "object", "required": []string{"id"}, "properties": map[string]any{
|
|
"id": map[string]any{"type": "string", "description": "the try's id, try-<digits>"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
if tr.Tries == nil {
|
|
return nil, fmt.Errorf("the tries state cannot be read here")
|
|
}
|
|
return check.ReadTry(tr.Tries, str(args, "id"))
|
|
}},
|
|
{Name: check.TryEndTool,
|
|
Description: "End a try of a group (or of one head) that waits or runs, as error, by hand: say why (kept in what it says). Its place among the 4 is free at once, " +
|
|
"the checker stops waiting for its asks, and the next " + check.TryTool + " of its head asks anew with a new id. For a try whose ask " +
|
|
"was lost (no step runs for it in checker_status); the checker ends one by itself when the build seat gives its ask up, or no node " +
|
|
"takes it within the step bound. A try that ended already is refused.",
|
|
Input: map[string]any{"type": "object", "required": []string{"id", "why"}, "properties": map[string]any{
|
|
"id": map[string]any{"type": "string", "description": "the try's id, try-<digits>"},
|
|
"why": map[string]any{"type": "string", "description": "why it is ended, in words"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
if tr.Ender == nil {
|
|
return nil, fmt.Errorf("the tries state cannot be written here")
|
|
}
|
|
now := time.Now
|
|
if tr.Now != nil {
|
|
now = tr.Now
|
|
}
|
|
t, err := check.EndTry(tr.Ender, str(args, "id"), str(args, "why"), now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]any{"id": t.ID, "state": t.State, "said": t.Said}, nil
|
|
}},
|
|
}
|
|
}
|
|
|
|
// OpenTriesTools is the tool that lists the tries that wait or run, each with its members at their commits, and whether it is
|
|
// a whole try (the indexer writes the candidate of a whole try's group): the read a part uses at its start to find the tries
|
|
// whose start event it missed, instead of reading the checker's state.
|
|
func OpenTriesTools(tr Trying) []stdio.Tool {
|
|
return []stdio.Tool{{Name: check.TriesTool,
|
|
Description: "The tries that wait or run now (a try of a group or of one head; try.started and try.ended on the checker's stream say the same), each with its id, state, its members at their exact commits and " +
|
|
"trunk commits, and whether it is a whole try (not narrowed to a level or to tests, so it is composed and its manifests judged). For a part that " +
|
|
"missed the checker's try.started or try.ended event (the indexer at its start); checker_try_read reads one try whole. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
|
Run: func(map[string]any) (any, error) {
|
|
if tr.Tries == nil {
|
|
return nil, fmt.Errorf("the tries state cannot be read here")
|
|
}
|
|
open, err := check.OpenTries(tr.Tries)
|
|
return map[string]any{"tries": open}, err
|
|
}}}
|
|
}
|
|
|
|
// Seat is the seat the checker holds (novox/hq ADR 0547 §10, issue 774); its verbs are served as tools named <seat>.<verb>.
|
|
const Seat = "mesh-delivery-checker"
|
|
|
|
// SeatTryTools are the try's tools as the seat's verbs: try, try-read and try-end, run by the same code as checker_try,
|
|
// checker_try_read and checker_try_end, so the answer is the same. The module tools stay beside them.
|
|
func SeatTryTools(tr Trying) []stdio.Tool {
|
|
verbs := map[string]string{check.TryTool: "try", check.TryReadTool: "try-read", check.TryEndTool: "try-end"}
|
|
var out []stdio.Tool
|
|
for _, t := range TryTools(tr) {
|
|
t.Name = Seat + "." + verbs[t.Name]
|
|
out = append(out, t)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// SeatInputTools are the seat's verb input (check.InputVerb): a checking program's input as the checker keeps it, asked by
|
|
// the Go build module that runs the program (buildstep.RunInput.Read), never read from the checker's state by it.
|
|
func SeatInputTools(r check.Reader) []stdio.Tool {
|
|
return []stdio.Tool{{Name: Seat + "." + meshdeliverychecker.VerbInput,
|
|
Description: "A checking program's input the checker keeps, by the sha256 of its exact bytes, as a run ask names it: the digest " +
|
|
"and the bytes, base64. A digest it keeps no input of, or bytes that read back as another digest, is an error. Read-only.",
|
|
Input: map[string]any{"type": "object", "required": []string{"digest"}, "properties": map[string]any{
|
|
"digest": map[string]any{"type": "string", "description": "the input's sha256, 64 lowercase hex digits"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
digest, _ := args["digest"].(string)
|
|
return r.Input(digest)
|
|
}}}
|
|
}
|
|
|
|
// Tools are the read tools over the checker's states.
|
|
func Tools(r check.Reader) []stdio.Tool {
|
|
return []stdio.Tool{
|
|
{Name: check.VerdictsReadTool,
|
|
Description: "The verdicts the checker holds, each as stored under verdicts.<group>.<heads>: its state, every failure it names one line each (every member's failed tests, refused steps and conflicts, the manifests' refusals and the composition), the tests run, kept and skipped per level, the time of each part, the trunk heads it judged against, the composition and which checking program judged it (judged: its build and the heads it read), with the full " +
|
|
"report of the status each pull request carries (the line the forge shows is cut at 140 characters, this is not). With a group, that group's only. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"group": map[string]any{"type": "string", "description": "the delivery group's branch name"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
group, _ := args["group"].(string)
|
|
vs, cut, err := r.Verdicts(group)
|
|
return cutAnswer(map[string]any{"verdicts": vs}, cut), err
|
|
}},
|
|
{Name: check.PullReadTool,
|
|
Description: "The verdict that judges one pull request, every failure it names one line each (all of them, not only the first the status line shows), which checking program judged it (judged: its build, its key and the heads it read), and the full report of its status mesh/check. Read-only.",
|
|
Input: map[string]any{"type": "object", "required": []string{"repository", "number"}, "properties": map[string]any{
|
|
"repository": map[string]any{"type": "string", "description": "<owner>/<name>"},
|
|
"number": map[string]any{"type": "integer", "description": "the pull request's number"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
repository, _ := args["repository"].(string)
|
|
n, _ := args["number"].(float64)
|
|
return r.Pull(repository, int(n))
|
|
}},
|
|
{Name: check.KeptReadTool,
|
|
Description: "The kept verdicts of passing packages, each as stored under kept.<level>.<digest>: the package, its tests, the time they took, the toolchain " +
|
|
"and when it was kept. With a level, that level's; with a level and a digest, that one. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"level": map[string]any{"type": "string", "enum": []string{"unit", "integration"}, "description": "the level"},
|
|
"digest": map[string]any{"type": "string", "description": "the package's digest, with a level"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
level, _ := args["level"].(string)
|
|
digest, _ := args["digest"].(string)
|
|
kept, cut, err := r.Kept(level, digest)
|
|
return cutAnswer(map[string]any{"kept": kept}, cut), err
|
|
}},
|
|
{Name: check.InputsReadTool,
|
|
Description: "The checking program's inputs the checker keeps, each under the sha256 of its exact bytes (inputs.<digest>, kept a day): " +
|
|
"the facts of a check its verdict is asked of, or the heads its seat list is asked of. With a digest, that input as kept; " +
|
|
"without, every digest and its size. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"digest": map[string]any{"type": "string", "description": "the input's sha256, as a run ask names it"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
digest, _ := args["digest"].(string)
|
|
inputs, cut, err := r.Inputs(digest)
|
|
return cutAnswer(map[string]any{"inputs": inputs}, cut), err
|
|
}},
|
|
{Name: check.PreviewsReadTool,
|
|
Description: "The merge previews the checker holds, each as stored under previews.<repository>.<head>.<trunk>: the merge commit, per module directory " +
|
|
"its tree, manifest digest and lock hashes, or the files in conflict. With a repository, that repository's; with a head (7 or more characters) " +
|
|
"only that head's. Keys that are no preview key are listed as unreadable. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"repository": map[string]any{"type": "string", "description": "<owner>/<name>"},
|
|
"head": map[string]any{"type": "string", "description": "a pull request head commit, or a prefix of at least 7 characters"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
repository, _ := args["repository"].(string)
|
|
head, _ := args["head"].(string)
|
|
if head != "" && len(head) < 7 {
|
|
return nil, fmt.Errorf("the head %q is too short: give at least 7 characters", head)
|
|
}
|
|
ps, bad, cut, err := r.Previews(repository, head)
|
|
return cutAnswer(map[string]any{"previews": ps, "unreadable": bad}, cut), err
|
|
}},
|
|
{Name: check.StatusReadTool,
|
|
Description: "What runs: the steps in flight on the build modules by node, the candidates without a verdict for their heads, " +
|
|
"and the candidates whose check is owed by kind (waiting_by_kind: new, nodes, and trunk, a re-judge pulled after the other two). A key a " +
|
|
"build module left running (started past the step bound, or its build module not running on its node) is listed apart under " +
|
|
"left_running with why, and not counted. Nothing holds the checker and it has no capacity of its own: a check is an ask on the " +
|
|
"build seats' streams, whose backlog the delivery view shows (novox/hq ADR 0525). No merge holds a check off (novox/hq ADR 0661). could_not_run names each check " +
|
|
"that could not run because a part of the mesh was not heard: the part, since when, the running that asked it again, and whether it " +
|
|
"is the finding check-could-not-run (an hour unasked); it is asked again when that part runs. " +
|
|
"dead_letters says whether the checker hears the asks the build seats give up on (issue 734), and why not: " +
|
|
"deaf, a try or check whose ask is given up waits until its bound. builds_not_ended names, of each running check, the builder's builds of " +
|
|
"its candidate's changed modules that are neither done nor failed: the check waits on them before it composes, within its build-wait-bound " +
|
|
"(novox/hq ADR 0603 §10); a failed one fails the check: rebuild it with the builder's builder_build_again, and the check asks itself again when the build is done. Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
|
Run: func(map[string]any) (any, error) { return r.Status() }},
|
|
}
|
|
}
|
|
|
|
// RequestTools is the tool that reads the composition requests the checker sent to nodes (issue 1921).
|
|
func RequestTools(r check.StateRead) []stdio.Tool {
|
|
return []stdio.Tool{{Name: check.RequestsReadTool,
|
|
Description: "The composition request a check sent to a node: the composer's whole input for that node (the node-engine's composition input, the case's " +
|
|
"manifests and verdicts, the seat list), kept exactly as sent so a session reproduces the check's composition (the composer run by hand over the same " +
|
|
"request gives the check's answer). Kept in the checker's state compositions, per check key (group.heads, the 12-digit heads hash) and node, " +
|
|
"0.7 to 0.8 MB each (kept compressed, in pieces that each fit the state's 256 KiB value), for 3 days (the state's ttl-seconds), the state holding at most 256 MiB (max-mib, which mesh-grants raises a held bucket to). With a check and a node, that request whole; with a check, " +
|
|
"the nodes it kept one for; with neither, every kept request, each with its size, digest and when it was kept. Read-only; " + check.RequestsDropTool + " drops a check's.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"check": map[string]any{"type": "string", "description": "the check's key, <group>.<heads hash>, as the verdict and composition name it"},
|
|
"node": map[string]any{"type": "string", "description": "the node the request was sent for, with a check"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
key, _ := args["check"].(string)
|
|
node, _ := args["node"].(string)
|
|
return check.ReadRequests(r, key, node)
|
|
}}}
|
|
}
|
|
|
|
// RequestDropTools is the tool that drops a check's kept composition requests by hand, which frees the state when it is
|
|
// full (tools-are-how-a-module-is-spoken-to): it records the hand act through the seat mesh-hand-acts first.
|
|
func RequestDropTools(s check.StateDrop, acts views.HandActs) []stdio.Tool {
|
|
return []stdio.Tool{{Name: check.RequestsDropTool,
|
|
Description: "Drop the composition requests the checker kept for one check (" + check.RequestsReadTool + " lists them): every node's, and the pieces " +
|
|
"no other kept request names. The hand act is recorded through the seat mesh-hand-acts first, and a drop whose act could not be recorded is not made. " +
|
|
"Answers the nodes and pieces dropped. Use it when a check's words say its request could not be kept in the state compositions because it is full; " +
|
|
"the state itself drops a request 3 days after it was kept.",
|
|
Input: map[string]any{"type": "object", "required": []string{"check", "why"}, "properties": map[string]any{
|
|
"check": map[string]any{"type": "string", "description": "the check's key, <group>.<heads hash>, whose kept requests are dropped"},
|
|
"why": map[string]any{"type": "string", "description": "why they are dropped, in words; recorded as the hand act"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
key, _ := args["check"].(string)
|
|
why, _ := args["why"].(string)
|
|
return check.DropRequests(s, key, why, func(what string) error {
|
|
return acts.RecordHandAct(views.HandAct{What: what, Why: why, Verb: check.RequestsDropTool})
|
|
})
|
|
}}}
|
|
}
|
|
|
|
// RecoveryTools are the tools that steer a check by hand (tools-are-how-a-module-is-spoken-to): ask a check again whose
|
|
// wait judged nothing (the lost check of 2026-10-28). They write the checker's verdicts through w.
|
|
func RecoveryTools(r check.Reader, w check.VerdictEntry) []stdio.Tool {
|
|
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return s }
|
|
return []stdio.Tool{{Name: check.AskAgainTool,
|
|
Description: "Ask a candidate's check again by hand, whose verdict stays running while nothing runs for it (" + check.StatusReadTool + " names it " +
|
|
"under lost): its verdict is ended as asked again, saying why, and the checker, which hears its verdicts, stops the wait that judged nothing " +
|
|
"and asks the check anew, whole. Refused for a group with no candidate, a verdict that is not running or a failure whose failing steps did not all end on a transport fault (a pass, or any other failure, stands until a push or " +
|
|
"a trunk move), and while a step of its pull requests can still run on a build module (its end judges it). The checker reads a step that " +
|
|
"ended while its watch was deaf by itself at the next step end of its build module; this is for what that does not reach.",
|
|
Input: map[string]any{"type": "object", "required": []string{"group", "why"}, "properties": map[string]any{
|
|
"group": map[string]any{"type": "string", "description": "the delivery group's branch name"},
|
|
"why": map[string]any{"type": "string", "description": "why it is asked again, in words; kept in the verdict it ends"}}},
|
|
Run: func(args map[string]any) (any, error) {
|
|
return r.AskAgain(w, str(args, "group"), str(args, "why"))
|
|
}}}
|
|
}
|
|
|
|
// stepBound is the checker's step bound as the checker reads it (MESH_CHECKER_STEP_BOUND), its default when unset or not a
|
|
// duration.
|
|
func stepBound() time.Duration {
|
|
if d, err := time.ParseDuration(os.Getenv("MESH_CHECKER_STEP_BOUND")); err == nil && d > 0 {
|
|
return d
|
|
}
|
|
return check.DefaultStepBound
|
|
}
|
|
|
|
// seatListAgainCallers are who may ask the seat list again by hand (design 47 G §204).
|
|
var seatListAgainCallers = []string{stdio.AnyPerson, "node-tools", "mesh-healers"}
|
|
|
|
// holderOf is a seat's holder as the seat that places modules answers it (seatlist.HolderOf, design 47 G A-126): false while the
|
|
// seat has none or the answer cannot be read.
|
|
func holderOf(seat string) (string, bool) {
|
|
module, err := seatlist.HolderOf(stdio.Ask, seat)
|
|
return module, err == nil
|
|
}
|
|
|
|
func main() {
|
|
// The build modules are no names (design 47 G A-82): the build seats on the seat list, each held by the module the seat
|
|
// that places modules names for it; the seat list and its two tools are wired once by mesh-sdk (§204).
|
|
gate := seatlist.NewPart("checker", seatListAgainCallers)
|
|
go func() {
|
|
<-stdio.Served()
|
|
gate.Follow(seatlist.StdioBus(), nil, func(f string, a ...any) { fmt.Fprintf(os.Stderr, "[mesh-delivery-checker-tools] "+f+"\n", a...) })
|
|
}()
|
|
seats := buildrun.NewBuildSeats(func() map[string]seatdef.Definition {
|
|
if rd := gate.Reader(); rd != nil {
|
|
return rd.Definitions()
|
|
}
|
|
return nil
|
|
}, holderOf)
|
|
r := check.Reader{VerdictState: read(stdio.State("verdicts")), KeptState: read(stdio.State("kept")), CandidateState: ownerRead(stdio.Ask, indexerCandidatesTool),
|
|
PreviewState: read(stdio.State("previews")), InputState: read(stdio.State(check.InputsStateName)),
|
|
StepStates: func() map[string]check.StateRead {
|
|
out := map[string]check.StateRead{}
|
|
for _, m := range seats.All() {
|
|
if m.Module != "" && m.Toolchain != "" {
|
|
out[m.Module] = read(stdio.State(m.Module + ".steps"))
|
|
}
|
|
}
|
|
return out
|
|
},
|
|
HaveState: read(stdio.State("node-engine.have")), StepBound: stepBound(),
|
|
CouldNotRunState: read(stdio.State(check.CouldNotRunState)), HearingState: read(stdio.State(buildrun.HearingState)),
|
|
AskState: read(stdio.State(check.AsksState)), BuildState: read(stdio.State("mesh-delivery-builder.builds"))}
|
|
r.Runs = runsOf{ownerRead(stdio.Ask, indexerModulesTool)} // the node-engine at the commit the mesh runs, as the checker reads it
|
|
tries := stdio.State(check.TriesState)
|
|
trunks := func() (map[string]string, error) {
|
|
raw, err := stdio.Ask(check.TrunkVerb, meshcatalog.RevisionInput{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return check.TrunkHeads(raw)
|
|
}
|
|
r.Trunks = trunks
|
|
store := stateStore{StateRead: read(tries), create: func(key string, value []byte) error {
|
|
_, err := tries.Create(key, json.RawMessage(value))
|
|
return err
|
|
}, entry: func(key string) (json.RawMessage, uint64, error) {
|
|
reads.Add(1)
|
|
e, err := tries.Get(key)
|
|
if err != nil || e == nil {
|
|
return nil, 0, err
|
|
}
|
|
return e.Value, e.Revision, nil
|
|
}, update: func(key string, value []byte, revision uint64) error {
|
|
_, err := tries.Update(key, json.RawMessage(value), revision)
|
|
return err
|
|
}}
|
|
trying := Trying{Tries: store, Ender: store, Trunks: trunks}
|
|
verdicts := stdio.State("verdicts")
|
|
written := stateStore{entry: func(key string) (json.RawMessage, uint64, error) {
|
|
reads.Add(1)
|
|
e, err := verdicts.Get(key)
|
|
if err != nil || e == nil {
|
|
return nil, 0, err
|
|
}
|
|
return e.Value, e.Revision, nil
|
|
}, update: func(key string, value []byte, revision uint64) error {
|
|
_, err := verdicts.Update(key, json.RawMessage(value), revision)
|
|
return err
|
|
}}
|
|
tools := append(append(append(append(Tools(r), TryTools(trying)...), OpenTriesTools(trying)...), SeatTryTools(trying)...), RecoveryTools(r, written)...)
|
|
// checker_first_views and checker_first_view_again: where the checker's first views of the indexer's and the assigner's
|
|
// states stand, and asking one again by hand (ADR 0615, DLV-M2).
|
|
tools = append(tools, views.StatusTools(check.CheckerModule, "checker_first_views", "checker_first_view_again", stdio.State(views.StatusState), meshhandactsclient.Recorder{Ask: stdio.Ask}, time.Now)...)
|
|
tools = append(tools, gate.Tools()...)
|
|
tools = append(tools, SeatInputTools(r)...)
|
|
tools = append(tools, RequestTools(read(stdio.State(check.RequestsStateName)))...)
|
|
requests := stdio.State(check.RequestsStateName)
|
|
tools = append(tools, RequestDropTools(check.StateDrop{StateRead: read(requests), Delete: requests.Delete}, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
|
|
if err := stdio.Serve("", logged(tools)); err != nil {
|
|
fmt.Fprintf(os.Stderr, "[mesh-delivery-checker-tools] %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|