Runner: widens-read-bound and revisions-kept are the module's settings (A-472a)

Declared in module.json's config and written to state files as test-step-bound is; runner_cancel keeps its note.

Builds: design 47 G A-472a
This commit is contained in:
2026-11-17 14:59:25 +01:00
parent 871f75acd3
commit 3f51d83147
5 changed files with 112 additions and 10 deletions
@@ -143,7 +143,12 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
Say: func(event string, f seat.Fill) error { return say("mesh.seat."+seat.Seat+".event."+event, f) }}
hearer.Fills = fills
// A pipeline's end names what its change widens (§71, A-207), computed by this running runner from the catalog and the grants part.
hearer.Widens = widenerOf(calls.Call, logger.Printf).Widens
readBound, revisionsKept, err := widensSettings(getenv)
if err != nil {
return err
}
logger.Printf("widens: each read bound %s, %d catalog revisions kept", readBound, revisionsKept)
hearer.Widens = widenerOf(calls.Call, readBound, revisionsKept, logger.Printf).Widens
hearer.LogLast = stepLog{ctx: ctx, js: js, module: cred.Module}.Last
hearer.Where = routerRecordOf(cred.Module, calls.Call, calls.Ask)
hearer.Failures = &pipeline.Failures{Findings: rv.Findings, Observer: cred.Module, Author: commitAuthor(calls.Call), Logf: logger.Printf}
@@ -20,13 +20,13 @@ import (
// `revision` for the candidate and the branch's newest, the holders from the seat holders' one reading, and the grants part's
// `grants-for`; no other verb.
//
// A pipeline's end is said without waiting on another part (A-472): each read is bounded to readBound and says in the journal how
// A pipeline's end is said without waiting on another part (A-472): each read is bounded to its widens-read-bound and says in the journal how
// long it took, and a failed or cut one is said there and in the widening's could-not-run; a catalog revision, which never
// changes, is kept once read.
func widenerOf(call func(key string, body any) (json.RawMessage, error), logf func(string, ...any)) *pipeline.Widener {
call = boundedCalls(call, readBound, time.After, logf)
func widenerOf(call func(key string, body any) (json.RawMessage, error), bound time.Duration, kept int, logf func(string, ...any)) *pipeline.Widener {
call = boundedCalls(call, bound, time.After, logf)
return &pipeline.Widener{
Revision: catalogRevision(call, newRevisionCache(revisionsKept)),
Revision: catalogRevision(call, newRevisionCache(kept)),
Holder: func(s string) (string, error) { return seatlist.HolderOf(call, s) },
GrantsFor: func(branch string, source int64) (meshgrants.GrantsFor, error) {
return grantsFor(call, branch, source)
@@ -34,13 +34,40 @@ func widenerOf(call func(key string, body any) (json.RawMessage, error), logf fu
}
}
// The settings widens-read-bound and revisions-kept (A-472a), each written by the manifest into a file the environment names.
const (
// readBound is how long one read of widens waits for its answer (A-472): a few seconds, never the call's 30.
readBound = 5 * time.Second
// revisionsKept is how many catalog revisions the runner keeps once read; a revision of the catalog graph is some 1.4 MB.
revisionsKept = 6
envWidensReadBound = "MESH_RUNNER_WIDENS_READ_BOUND_FILE"
envRevisionsKept = "MESH_RUNNER_REVISIONS_KEPT_FILE"
// defaultReadBound is how long one read of widens waits for its answer: a few seconds, never the call's 30.
defaultReadBound = 5 * time.Second
// defaultRevisionsKept is how many catalog revisions the runner keeps once read; a revision of the catalog graph is some 1.4 MB.
defaultRevisionsKept = 6
)
// widensSettings reads widens-read-bound, a Go duration, and revisions-kept, a whole number, from their files; one whose file
// is missing or empty is its default, one that is neither a positive duration nor a positive number is an error naming the file.
func widensSettings(getenv func(string) string) (time.Duration, int, error) {
bound, kept := defaultReadBound, defaultRevisionsKept
v, err := settingText(getenv(envWidensReadBound))
if err != nil {
return 0, 0, err
}
if v != "" {
if bound, err = time.ParseDuration(v); err != nil || bound <= 0 {
return 0, 0, fmt.Errorf("%s holds %q, which is not a positive duration", getenv(envWidensReadBound), v)
}
}
if v, err = settingText(getenv(envRevisionsKept)); err != nil {
return 0, 0, err
}
if v != "" {
if kept, err = strconv.Atoi(v); err != nil || kept < 1 {
return 0, 0, fmt.Errorf("%s holds %q, which is not a positive whole number", getenv(envRevisionsKept), v)
}
}
return bound, kept, nil
}
// boundedCalls bounds each call to bound, said in logf with its duration, and a failed or cut one in words that name the call;
// a call that outlives its bound ends on its own at the connection's timeout, its answer dropped.
func boundedCalls(call func(string, any) (json.RawMessage, error), bound time.Duration, after func(time.Duration) <-chan time.Time,
@@ -3,6 +3,8 @@ package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
@@ -94,3 +96,39 @@ func TestBoundedCallsCutAReadThatDoesNotAnswer(t *testing.T) {
t.Fatalf("fast: %v, said %v", err, said)
}
}
// widens-read-bound and revisions-kept are read from the files the manifest writes; a missing file is the default, a content
// that is no positive duration or number an error naming the file (A-472a).
func TestWidensSettings(t *testing.T) {
dir := t.TempDir()
write := func(name, content string) string {
p := filepath.Join(dir, name)
if err := os.WriteFile(p, []byte(content), 0o600); err != nil {
t.Fatal(err)
}
return p
}
for _, c := range []struct {
name string
files map[string]string
bound time.Duration
kept int
ok bool
}{
{"defaults", nil, 5 * time.Second, 6, true},
{"set", map[string]string{envWidensReadBound: "2s\n", envRevisionsKept: "3\n"}, 2 * time.Second, 3, true},
{"no duration", map[string]string{envWidensReadBound: "5"}, 0, 0, false},
{"no number", map[string]string{envRevisionsKept: "0"}, 0, 0, false},
} {
t.Run(c.name, func(t *testing.T) {
env := map[string]string{}
for k, v := range c.files {
env[k] = write(c.name+k, v)
}
bound, kept, err := widensSettings(func(k string) string { return env[k] })
if (err == nil) != c.ok || bound != c.bound || kept != c.kept {
t.Fatalf("%s %d, %v", bound, kept, err)
}
})
}
}
@@ -198,7 +198,7 @@ func runSettingsOf(raw []byte) bool {
if json.Unmarshal(raw, &m) != nil {
return false
}
want := map[string]string{"test-runs-cap-mib": "number", "test-runs-kept": "string", "test-step-bound": "string", "run-untaken-bound": "string"}
want := map[string]string{"test-runs-cap-mib": "number", "test-runs-kept": "string", "test-step-bound": "string", "run-untaken-bound": "string", "widens-read-bound": "string", "revisions-kept": "number"}
if len(m.Config) != len(want) || m.Config["test-runs-cap-mib"]["maximum"] != float64(64) || m.Config["test-runs-cap-mib"]["default"] != float64(16) {
return false
}
@@ -108,6 +108,20 @@
"trusted": false,
"default": "30m"
},
"widens-read-bound": {
"type": "string",
"description": "how long one read of a pipeline end's widens (the catalog's revision, the seat holders, the grants part) waits for its answer before it is cut and said could not run, a Go duration such as 5s (design 47 G A-472, A-472a).",
"trusted": false,
"default": "5s"
},
"revisions-kept": {
"type": "number",
"description": "how many catalog revisions the runner keeps once read, each some 1.4 MB, so a pipeline end does not read them again (design 47 G A-472, A-472a).",
"minimum": 1,
"maximum": 32,
"trusted": false,
"default": 6
},
"run-untaken-bound": {
"type": "string",
"description": "how long a test run's ask may wait untaken after the run's start before the run ends could not run, a Go duration such as 24h (design 47 G section 725, A-466s, A-469x).",
@@ -236,6 +250,22 @@
"mode": "0600",
"content": "${config:run-untaken-bound}"
},
{
"id": "widens-read-bound",
"type": "file",
"path": "${dir:state}/widens-read-bound",
"owner": "mesh-delivery-pipeline",
"mode": "0600",
"content": "${config:widens-read-bound}"
},
{
"id": "revisions-kept",
"type": "file",
"path": "${dir:state}/revisions-kept",
"owner": "mesh-delivery-pipeline",
"mode": "0600",
"content": "${config:revisions-kept}"
},
{
"id": "pipeline",
"type": "process",
@@ -249,6 +279,8 @@
"MESH_RUNNER_TEST_RUNS_CAP_FILE": "${dir:state}/test-runs-cap-mib",
"MESH_RUNNER_TEST_RUNS_KEPT_FILE": "${dir:state}/test-runs-kept",
"MESH_RUNNER_TEST_STEP_BOUND_FILE": "${dir:state}/test-step-bound",
"MESH_RUNNER_WIDENS_READ_BOUND_FILE": "${dir:state}/widens-read-bound",
"MESH_RUNNER_REVISIONS_KEPT_FILE": "${dir:state}/revisions-kept",
"MESH_RUNNER_RUN_UNTAKEN_BOUND_FILE": "${dir:state}/run-untaken-bound"
},
"user": "mesh-delivery-pipeline",