Design 47 H1: the bound after which a failed resolution is asked again is the setting resolve-again-minutes (H-A-146, principle 11) #243

Merged
mesh-tools merged 1 commits from fix/47-H1-engine-resolve-again into main 2026-11-20 19:56:48 +00:00
8 changed files with 87 additions and 15 deletions
+1 -1
View File
@@ -1222,7 +1222,7 @@ func composerEnv(session *link.Session, node string, say func(string), hooks com
Hear: session.Hear,
// And a moved module's templates archive, in the artifact store, as every archive is fetched (issue 1126).
Fetch: apply.Fetch,
Running: hooks.running, Unseal: hooks.unseal, Refused: hooks.refused, Held: hooks.held, Kept: hooks.kept, EntryNotFound: hooks.entryNotFound, EntryUnanswered: hooks.entryUnanswered, EntryAsks: entryAsks(),
Running: hooks.running, Unseal: hooks.unseal, Refused: hooks.refused, Held: hooks.held, Kept: hooks.kept, EntryNotFound: hooks.entryNotFound, EntryUnanswered: hooks.entryUnanswered, EntryAsks: entryAsks(), ResolveAgain: resolveAgainBound(),
VaultAuthority: hooks.vaultAuthority, Certify: hooks.certify}
if hooks.seatList != nil {
env.SeatList, env.SeatListChanged = hooks.seatList.reader, hooks.seatList.changed
+17
View File
@@ -94,4 +94,21 @@ func TestTheViewWaitsBoundIsTheManifestsSetting(t *testing.T) {
if got := viewWaitsBound(); got != 5*time.Minute {
t.Errorf("no file gives %v", got)
}
// H-A-146, principle 11: the bound after which a failed resolution is asked again is the file `resolve-again-minutes` feeds,
// one minute when it holds nothing usable (1 to 60).
wasAgain := resolveAgainFile
defer func() { resolveAgainFile = wasAgain }()
for content, want := range map[string]time.Duration{"7\n": 7 * time.Minute, "60": time.Hour, "61": time.Minute, "": time.Minute, "0": time.Minute, "x": time.Minute} {
resolveAgainFile = filepath.Join(t.TempDir(), "w")
if err := os.WriteFile(resolveAgainFile, []byte(content), 0o644); err != nil {
t.Fatal(err)
}
if got := resolveAgainBound(); got != want {
t.Errorf("the file %q gives %v, want %v", content, got, want)
}
}
resolveAgainFile = filepath.Join(t.TempDir(), "missing")
if got := resolveAgainBound(); got != time.Minute {
t.Errorf("no file gives %v", got)
}
}
+19
View File
@@ -20,6 +20,7 @@ import (
"git.novox.be/novox/mesh-sdk/go/views"
"github.com/novox/mesh-host/internal/link"
"github.com/novox/mesh-host/internal/seatwait"
"github.com/novox/mesh-host/internal/selfcompose"
)
// The node-engine reads the seat list as every part does (novox/hq ADR 0635 §1, ADR 0636): through the seat mesh-catalog,
@@ -281,6 +282,24 @@ func viewWaitsBound() time.Duration {
return time.Duration(n) * time.Minute
}
// resolveAgainFile is the file the manifest declares with the content ${config:resolve-again-minutes} (design 47 H, H-A-146;
// principle 11), read at the engine's start as recoveryWaitFile is.
var resolveAgainFile = "/var/lib/mesh-host/resolve-again-minutes"
// resolveAgainBound is how long a failed resolution of a want's version stands before the registry seats' verb versions is asked
// again: the file's minutes (1 to 60), selfcompose.DefaultResolveAgain when the file is missing, empty or not such a number.
func resolveAgainBound() time.Duration {
raw, err := os.ReadFile(resolveAgainFile)
if err != nil {
return selfcompose.DefaultResolveAgain
}
n, err := strconv.Atoi(strings.TrimSpace(string(raw)))
if err != nil || n < 1 || n > 60 {
return selfcompose.DefaultResolveAgain
}
return time.Duration(n) * time.Minute
}
// entryAsksFile is the file the manifest declares with the content ${config:entry-asks} (design 47 H, H-A-60), read at the
// engine's start as recoveryWaitFile is.
var entryAsksFile = "/var/lib/mesh-host/entry-asks"
+3
View File
@@ -73,6 +73,9 @@ type Env struct {
// EntryAsks is the setting `entry-asks`: how often an entry whose ask failed in transport is asked again before it is
// unanswered; meshcatalogclient.DefaultEntryAsks when 0 (design 47 H, H-A-60).
EntryAsks int
// ResolveAgain is the setting `resolve-again-minutes`: how long a failed resolution of a want's version stands before the
// seats' verb versions is asked again; DefaultResolveAgain when 0 (design 47 H, H-A-146; principle 11).
ResolveAgain time.Duration
// Watch follows one bucket's keys matching pattern, as the agent's watches do.
Watch func(ctx context.Context, bucket, pattern string) (<-chan agent.Update, error)
// Get reads one key's latest value; nil and no error when there is none.
+15 -6
View File
@@ -25,8 +25,17 @@ import (
// manifest's `from` pins. A want that names parts (a build no version is known of) is read by its parts as before. A lookup that
// fails is said in the journal, naming the module, the version and the seat, and the module is held whole: never composed partly.
// resolveAgain is how long a failed lookup stands before it is asked again; a pass is asked then.
const resolveAgain = time.Minute
// DefaultResolveAgain is how long a failed lookup stands before it is asked again when the setting `resolve-again-minutes` gives
// nothing (Env.ResolveAgain 0); a pass is asked then (H-A-146 "after a bound"; principle 11: a bound is a setting with a default).
const DefaultResolveAgain = time.Minute
// resolveAgain is how long a failed lookup stands before it is asked again: the setting, or DefaultResolveAgain.
func (c *Composer) resolveAgain() time.Duration {
if c.env.ResolveAgain > 0 {
return c.env.ResolveAgain
}
return DefaultResolveAgain
}
// versionsVerb is the verb a lookup asks.
const versionsVerb = "versions"
@@ -107,7 +116,7 @@ func (c *Composer) resolve(module string, e meshcatalog.CatalogEntry, w meshwant
c.mu.Lock()
r, ok := c.resolved[key]
c.mu.Unlock()
if ok && (r.failed == "" || now.Sub(r.at) < resolveAgain) {
if ok && (r.failed == "" || now.Sub(r.at) < c.resolveAgain()) {
return r.parts, r.failed
}
parts, failed := c.lookUp(module, e, w)
@@ -124,7 +133,7 @@ func (c *Composer) resolve(module string, e meshcatalog.CatalogEntry, w meshwant
c.resolved[key] = versionParts{parts: parts, failed: failed, at: now}
c.mu.Unlock()
if failed != "" {
time.AfterFunc(resolveAgain, c.askRehand)
time.AfterFunc(c.resolveAgain(), c.askRehand)
return nil, failed
}
return parts, ""
@@ -146,7 +155,7 @@ func (c *Composer) forgetFetched(digest, why string) {
continue
}
line := fmt.Sprintf("resolution of %s %s forgotten: %s", k.module, k.version, why)
c.resolved[k] = versionParts{failed: line + "; the seats' verb versions is asked again at its next want, at the next compose or in " + resolveAgain.String(),
c.resolved[k] = versionParts{failed: line + "; the seats' verb versions is asked again at its next want, at the next compose or in " + c.resolveAgain().String(),
at: now, forgotten: true}
lines = append(lines, line)
}
@@ -156,7 +165,7 @@ func (c *Composer) forgetFetched(digest, why string) {
c.env.Say(line)
}
if len(lines) > 0 {
time.AfterFunc(resolveAgain, c.askRehand)
time.AfterFunc(c.resolveAgain(), c.askRehand)
}
}
+15 -8
View File
@@ -149,12 +149,13 @@ func aResolutionWhoseFetchFailedIsForgotten(t *testing.T) {
Artifacts: []meshcatalog.Artifact{{Ref: "mail:files", Kind: "archive"}}}
want := meshwants.WantsByWantNodeModuleValue{Fp: fp, Version: "1.2.3", Self: true}
for name, row := range map[string]struct {
answer string // the digest versions answers
fetch error // the store's answer to the fetch
then string // what follows the fetch: "" (a pass within the bound), want, compose, bound
asked bool // versions is asked again
forgets bool // the journal says it forgot
failed bool // the fetch fails though nothing is forgotten
answer string // the digest versions answers
fetch error // the store's answer to the fetch
then string // what follows the fetch: "" (a pass within the bound), want, compose, bound
asked bool // versions is asked again
forgets bool // the journal says it forgot
failed bool // the fetch fails though nothing is forgotten
again time.Duration // the setting resolve-again-minutes; 0 is its default
}{
"a fetch that succeeded keeps its resolution": {answer: good, then: "bound"},
"a 404, the next pass within the bound": {answer: wrong, fetch: notFound{}, forgets: true},
@@ -162,13 +163,17 @@ func aResolutionWhoseFetchFailedIsForgotten(t *testing.T) {
"a 404, then a compose by hand": {answer: wrong, fetch: notFound{}, then: "compose", asked: true, forgets: true},
"a 404, then the bound while it is held": {answer: wrong, fetch: notFound{}, then: "bound", asked: true, forgets: true},
"bytes that are not of the digest": {answer: wrong, then: "want", asked: true, forgets: true},
// Principle 11: the bound is the setting resolve-again-minutes, one minute by default.
"a 404, a minute within a setting of five": {answer: wrong, fetch: notFound{}, then: "minute", forgets: true, again: 5 * time.Minute},
"a 404, then the setting's bound of five": {answer: wrong, fetch: notFound{}, then: "bound", asked: true, forgets: true, again: 5 * time.Minute},
// H-A-150: a fetch nothing answered for keeps its resolution, and the module is not held for it.
"a bus that did not answer keeps it": {answer: good, fetch: errors.New("nats: timeout"), failed: true},
"a store away keeps it": {answer: good, fetch: storeAway{}, failed: true},
} {
now := time.Date(2026, 11, 20, 16, 0, 0, 0, time.UTC)
var said []string
env := Env{Node: "desk", Say: func(line string) { said = append(said, line) }, Now: func() time.Time { return now }}
env := Env{Node: "desk", Say: func(line string) { said = append(said, line) }, Now: func() time.Time { return now },
ResolveAgain: row.again}
calls := 0
env.Registry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) {
calls++
@@ -196,7 +201,9 @@ func aResolutionWhoseFetchFailedIsForgotten(t *testing.T) {
cancel()
c.ComposeNow(ended)
case "bound":
now = now.Add(resolveAgain)
now = now.Add(max(row.again, DefaultResolveAgain))
case "minute":
now = now.Add(time.Minute)
}
before := calls
again, missing := c.partsOf("mail", entry, want)
+14
View File
@@ -105,6 +105,13 @@
"minimum": 1,
"default": 5
},
"resolve-again-minutes": {
"type": "number",
"description": "How long the node-engine holds a module whose want's version it could not resolve to its artifacts' digests, or whose resolution it forgot after a failed fetch, before it asks the registry seats' verb versions again, in minutes (design 47 H, H-A-146).",
"minimum": 1,
"maximum": 60,
"default": 1
},
"entry-asks": {
"type": "number",
"description": "How often the node-engine asks the catalog half's entry of a build again after an ask that failed to reach the holder, before the entry is unanswered and the finding entry-unanswered is written (design 47 H, H-A-60).",
@@ -160,6 +167,13 @@
"mode": "0644",
"content": "${config:entry-asks}\n"
},
{
"id": "resolve-again",
"type": "file",
"path": "/var/lib/mesh-host/resolve-again-minutes",
"mode": "0644",
"content": "${config:resolve-again-minutes}\n"
},
{
"id": "view-waits",
"type": "file",
+3
View File
@@ -92,6 +92,9 @@ func TestTheManifestConsumesTheBackupEvent(t *testing.T) {
if !strings.Contains(string(raw), `"content": "${config:entry-asks}\n"`) || m.Config["entry-asks"].Default != float64(5) {
t.Errorf("module.json declares no file with the content ${config:entry-asks} or its default is not 5 (design 47 H, H-A-60)")
}
if !strings.Contains(string(raw), `"content": "${config:resolve-again-minutes}\n"`) || m.Config["resolve-again-minutes"].Default != float64(1) {
t.Errorf("module.json declares no file with the content ${config:resolve-again-minutes} or its default is not 1 (design 47 H, H-A-146)")
}
if m.Config["recovery-wait-minutes"].Default != float64(90) {
t.Errorf("config recovery-wait-minutes is %+v, want default 90", m.Config["recovery-wait-minutes"])
}