H-A-146: forget a resolution whose fetch failed, so versions is asked again

The engine kept a want's version resolved to a digest for its process's life
even when the artifact store's fetch of that digest failed (404, or bytes not
of the digest), so a fix of the store's answer never reached the node without
a restart. A failed fetch now forgets every resolution naming that digest, says
"resolution of <module> <version> forgotten: <why>" in the journal and holds
the module; the seats' verb versions is asked again at the module's next want,
at the next compose by hand, and after resolveAgain (the bound a failed lookup
already has). A resolution whose fetch succeeded is kept.

Builds: design 47 H H-A-146, G A-430a
This commit is contained in:
2026-11-20 16:31:20 +01:00
parent 0b388fa675
commit dc95fb5673
4 changed files with 137 additions and 4 deletions
+81
View File
@@ -2,11 +2,16 @@ package selfcompose
import (
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"strings"
"sync"
"testing"
"time"
"github.com/novox/mesh-host/internal/agent"
"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"
@@ -130,3 +135,79 @@ func TestAModulesClaimsAreReadFromTheEntryOfItsWantsBuild(t *testing.T) {
t.Errorf("a module with no want has no manifest read: claims %v, known %v", claims, known)
}
}
// Design 47 H, the lead's answer H-A-146 (A-430a: the bytes are fetched by the digest the versions answer gives): a resolution
// whose fetch failed is forgotten and said so in the journal; the seats' verb versions is asked again at the module's next want, at
// the next compose by hand, and after a bound while the module is held, never before; a resolution whose fetch succeeded is kept.
func aResolutionWhoseFetchFailedIsForgotten(t *testing.T) {
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64)
body := []byte("the files")
sum := sha256.Sum256(body)
good := "sha256:" + hex.EncodeToString(sum[:])
wrong := "sha256:" + strings.Repeat("e", 64) // the store's answer of the manifest's digest where the blob's was due
entry := meshcatalog.CatalogEntry{Module: "mail", Fp: fp, Manifest: map[string]any{"module": "mail", "version": "1"},
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
}{
"a fetch that succeeded keeps its resolution": {answer: good, then: "bound"},
"a 404, the next pass within the bound": {answer: wrong, fetch: errors.New("404 Not Found"), forgets: true},
"a 404, then the module's next want": {answer: wrong, fetch: errors.New("404 Not Found"), then: "want", asked: true, forgets: true},
"a 404, then a compose by hand": {answer: wrong, fetch: errors.New("404 Not Found"), then: "compose", asked: true, forgets: true},
"a 404, then the bound while it is held": {answer: wrong, fetch: errors.New("404 Not Found"), then: "bound", asked: true, forgets: true},
"bytes that are not of the digest": {answer: wrong, then: "want", asked: true, forgets: 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 }}
calls := 0
env.Registry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) {
calls++
return json.RawMessage(`{"versions":[{"digest":"` + row.answer + `","version":"1.2.3"}]}`), nil
})
env.Fetch = func(context.Context, string) ([]byte, error) { return body, row.fetch }
env.Entry = EntryCall(func(context.Context, string, string, any) (json.RawMessage, error) {
return nil, errors.New("not asked")
})
c := New(env)
c.wants["mail"] = want
c.keptEnt[fp] = keptEntry{entry: entry}
parts, _ := c.partsOf("mail", entry, want)
_, err := reader{c: c}.Archive(context.Background(), referenceOf("mail", "files", parts["mail:files"]), parts["mail:files"])
if (err != nil) != row.forgets {
t.Errorf("%s: the fetch: %v", name, err)
}
switch row.then {
case "want":
raw, _ := json.Marshal(want)
c.takeWant(agent.Update{Key: meshwants.WantsByWantNodeModuleKey("desk", "mail"), Value: raw})
case "compose":
c.watching.Store(true)
ended, cancel := context.WithCancel(context.Background())
cancel()
c.ComposeNow(ended)
case "bound":
now = now.Add(resolveAgain)
}
before := calls
again, missing := c.partsOf("mail", entry, want)
if asked := calls > before; asked != row.asked {
t.Errorf("%s: versions asked again %v, want %v", name, asked, row.asked)
}
if row.forgets && !row.asked && (again != nil || !strings.Contains(missing, "forgotten")) {
t.Errorf("%s: parts %v, missing %q: want the module held, saying the resolution was forgotten", name, again, missing)
}
if !row.forgets && again["mail:files"] != good {
t.Errorf("%s: parts %v: want the resolution kept", name, again)
}
line := "resolution of mail 1.2.3 forgotten: "
if got := strings.Contains(strings.Join(said, "\n"), line); got != row.forgets {
t.Errorf("%s: said %q; want %q said: %v", name, said, line, row.forgets)
}
}
}