E4b: keep the run a module was applied from in its have

The engine kept the applied run in its memory only, so a restarted engine
applied an older run's want again. The have, the record of what the engine
applied, carries the run (the node-engine seat's form 2): the engine reads
it from the have before it applies a want that carries one, a write that
names none keeps the last have's, and every have is written at the seat's
form.

Builds: design 47 H2 §813 (1); H-A-355, H-A-384 (2), H-A-388 (1)
This commit is contained in:
2026-11-22 00:19:47 +01:00
parent fea6836f9e
commit f4f5615bfb
6 changed files with 67 additions and 22 deletions
+2 -2
View File
@@ -109,7 +109,7 @@ func (h sessionHaves) ReadErr(ctx context.Context, module string) (agent.Have, b
return agent.Have{}, false, err return agent.Have{}, false, err
} }
return agent.Have{Module: module, FP: got.Fp, Composed: got.Composed, Phase: string(got.Phase), Detail: got.Detail, return agent.Have{Module: module, FP: got.Fp, Composed: got.Composed, Phase: string(got.Phase), Detail: got.Detail,
Sealed: got.SealedAt, Wait: got.Wait}, true, nil Sealed: got.SealedAt, Wait: got.Wait, Run: got.Run}, true, nil
} }
func (h sessionHaves) Write(ctx context.Context, x agent.Have) { func (h sessionHaves) Write(ctx context.Context, x agent.Have) {
@@ -126,7 +126,7 @@ func (h sessionHaves) Write(ctx context.Context, x agent.Have) {
} }
h.session.NoteModule(ctx, link.ModuleFact{Module: x.Module, FP: x.FP, Composed: x.Composed, Phase: phase, h.session.NoteModule(ctx, link.ModuleFact{Module: x.Module, FP: x.FP, Composed: x.Composed, Phase: phase,
Failed: phase == string(nodeengineclient.PhaseFailed), Detail: shorten(x.Detail), Judgement: x.Judgement, Waits: x.Waits, Failed: phase == string(nodeengineclient.PhaseFailed), Detail: shorten(x.Detail), Judgement: x.Judgement, Waits: x.Waits,
BuildAlone: x.BuildAlone, Kept: x.Kept, Sealed: x.Sealed, PullWait: x.PullWait, Wait: x.Wait}) BuildAlone: x.BuildAlone, Kept: x.Kept, Sealed: x.Sealed, PullWait: x.PullWait, Wait: x.Wait, Run: x.Run})
} }
func (h sessionHaves) Removed(ctx context.Context, module string) { func (h sessionHaves) Removed(ctx context.Context, module string) {
+34 -14
View File
@@ -78,6 +78,10 @@ type Have struct {
PullWait *nodeengine.PullWait PullWait *nodeengine.PullWait
// Wait is the hold or wait the have says, in the recovery wait with its ask-at and act (design 47 G §560). // Wait is the hold or wait the have says, in the recovery wait with its ask-at and act (design 47 G §560).
Wait *nodeengine.Wait Wait *nodeengine.Wait
// Run is the composition run the module was applied from, its pipeline sequence in decimal (design 47 H2 §813 (1),
// H-A-384 (2), H-A-388; nodeengine.HaveByNodeModuleValue.Run): kept in the have, so a restarted engine applies no
// older run again. A write that names none keeps the one the module's last have said (writeHave).
Run string
} }
// Haves is the node's have bucket as the agent uses it. // Haves is the node's have bucket as the agent uses it.
@@ -250,9 +254,6 @@ type Agent struct {
// applied is the composition each module was last applied from: a revision a want named from the key's history is // applied is the composition each module was last applied from: a revision a want named from the key's history is
// not the key's latest value, and what it holds is still held out of the others' applies. // not the key's latest value, and what it holds is still held out of the others' applies.
applied map[string]compNow applied map[string]compNow
// appliedRun is, of each module applied from a want that carried run, that run: the composition run's pipeline sequence
// in decimal (design 47 H2 §813 (1), H-A-355). A want whose run is not newer is not applied again.
appliedRun map[string]string
// had is, for each module whose have names a composition the bucket keeps (its latest value or a revision), that // had is, for each module whose have names a composition the bucket keeps (its latest value or a revision), that
// composition, read once at the start (loadHad): what runs of a module the agent has not taken yet, ahead of the kept // composition, read once at the start (loadHad): what runs of a module the agent has not taken yet, ahead of the kept
// declaration (issue 924). // declaration (issue 924).
@@ -345,7 +346,7 @@ func New(env Env) *Agent {
if env.Say == nil { if env.Say == nil {
env.Say = func(string) {} env.Say = func(string) {}
} }
return &Agent{env: env, wants: map[string]wantNow{}, comps: map[string]compNow{}, running: map[string]nodeengine.HaveByNodeModuleValue{}, applied: map[string]compNow{}, appliedRun: map[string]string{}, had: map[string]compNow{}, keptData: map[string]bool{}, return &Agent{env: env, wants: map[string]wantNow{}, comps: map[string]compNow{}, running: map[string]nodeengine.HaveByNodeModuleValue{}, applied: map[string]compNow{}, had: map[string]compNow{}, keptData: map[string]bool{},
attempt: map[string]attempt{}, checked: map[string]bool{}, prior: map[string]bool{}, said: map[string]string{}, waited: map[string]string{}, notComposed: map[string]notComposedMark{}, attempt: map[string]attempt{}, checked: map[string]bool{}, prior: map[string]bool{}, said: map[string]string{}, waited: map[string]string{}, notComposed: map[string]notComposedMark{},
pulls: map[string]*pullWait{}, settledAt: map[string]time.Time{}, settledSeq: map[string]int{}, pulls: map[string]*pullWait{}, settledAt: map[string]time.Time{}, settledSeq: map[string]int{},
retry: make(chan []string, 8), reconcile: make(chan []string, 64), failedAgain: make(chan string, 8), tries: map[string]int{}, again: make(chan againAsk, 64), retry: make(chan []string, 8), reconcile: make(chan []string, 64), failedAgain: make(chan string, 8), tries: map[string]int{}, again: make(chan againAsk, 64),
@@ -737,11 +738,17 @@ func (a *Agent) writeHave(ctx context.Context, h Have) {
h.Kept = a.kept[h.Module] h.Kept = a.kept[h.Module]
a.mu.Unlock() a.mu.Unlock()
} }
if h.Composed == "" && h.Module != NodeModule { if (h.Composed == "" || h.Run == "") && h.Module != NodeModule {
if last, ok := a.env.Haves.Read(ctx, h.Module); ok && last.Composed != "" { if last, ok := a.env.Haves.Read(ctx, h.Module); ok {
h.FP, h.Composed = last.FP, last.Composed if h.Composed == "" && last.Composed != "" {
if h.Sealed == nil { h.FP, h.Composed = last.FP, last.Composed
h.Sealed = last.Sealed if h.Sealed == nil {
h.Sealed = last.Sealed
}
}
// The run the module was applied from stays in its have until an apply from another run (H-A-384 (2)).
if h.Run == "" {
h.Run = last.Run
} }
} }
} }
@@ -1515,6 +1522,22 @@ func (a *Agent) settleOne(ctx context.Context, module string) {
} else { } else {
a.mu.Unlock() a.mu.Unlock()
} }
// Design 47 H2 §813 (1), H-A-384 (2): the run the module was applied from is its have's, never this engine's memory, so
// a restarted engine applies no older run again. Read only for a want that carries one.
appliedRun := ""
if w.Want.Run != "" {
h, found, unread := a.readHave(ctx, module)
if unread {
a.mu.Lock()
a.sayOnce("run-unread:"+module+":"+w.Want.Run, fmt.Sprintf("the want of %s carries run %s, and its have, which says "+
"the run it was applied from, cannot be read: nothing is applied until it reads", module, w.Want.Run))
a.mu.Unlock()
return
}
if found {
appliedRun = h.Run
}
}
a.mu.Lock() a.mu.Lock()
r, runs := a.running[module] r, runs := a.running[module]
// A module whose last apply failed runs no composition whole, whatever it ran before (ranFailed). // A module whose last apply failed runs no composition whole, whatever it ran before (ranFailed).
@@ -1548,7 +1571,7 @@ func (a *Agent) settleOne(ctx context.Context, module string) {
a.mu.Unlock() a.mu.Unlock()
return // failed already for exactly these keys: retried by the next change of either return // failed already for exactly these keys: retried by the next change of either
} }
if was := a.appliedRun[module]; !runIsNewer(w.Want.Run, was) { if was := appliedRun; !runIsNewer(w.Want.Run, was) {
// Design 47 H2 §813 (1), H-A-355: one writer per composition key, and the engine applies again only a newer write. // Design 47 H2 §813 (1), H-A-355: one writer per composition key, and the engine applies again only a newer write.
a.sayOnce("run:"+module+":"+w.Want.Run, fmt.Sprintf("the want of %s carries run %s, and the engine applied it from run %s, "+ a.sayOnce("run:"+module+":"+w.Want.Run, fmt.Sprintf("the want of %s carries run %s, and the engine applied it from run %s, "+
"which is not older: nothing is applied", module, w.Want.Run, was)) "which is not older: nothing is applied", module, w.Want.Run, was))
@@ -1841,9 +1864,6 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
a.running[module] = nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: dig, Phase: nodeengineclient.PhaseRunning} a.running[module] = nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: dig, Phase: nodeengineclient.PhaseRunning}
a.applied[module] = comp a.applied[module] = comp
run := w.Want.Run run := w.Want.Run
if run != "" {
a.appliedRun[module] = run
}
a.mu.Unlock() a.mu.Unlock()
if run != "" { if run != "" {
a.env.Say(fmt.Sprintf("applied %s from run %s", what, run)) a.env.Say(fmt.Sprintf("applied %s from run %s", what, run))
@@ -1852,7 +1872,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
if a.env.Settled != nil { if a.env.Settled != nil {
a.env.Settled(module) a.env.Settled(module)
} }
a.writeHave(ctx, Have{Module: module, FP: fp, Composed: dig, Phase: string(nodeengineclient.PhaseRunning), Detail: res.Detail}) a.writeHave(ctx, Have{Module: module, FP: fp, Composed: dig, Phase: string(nodeengineclient.PhaseRunning), Detail: res.Detail, Run: run})
a.catchUp(ctx, module, catchUps) a.catchUp(ctx, module, catchUps)
} }
+21 -1
View File
@@ -368,10 +368,30 @@ func TestAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) {
t.Errorf("a want of run %s after run 7: applied %d times, want %d", row.run, got, row.applied) t.Errorf("a want of run %s after run 7: applied %d times, want %d", row.run, got, row.applied)
} }
} }
// H-A-384 (2), H-A-388: the run is kept in the have, never in memory: the have names run 8, and a have an earlier life of
// the engine wrote at run 20 holds a want of run 10 back, though this one applied run 8 last.
if h := b.haves.last("web"); h.Run != "8" {
t.Errorf("the have names run %q after run 8 was applied", h.Run)
}
h := b.haves.last("web")
h.Run = "20"
b.haves.Write(context.Background(), h)
before = len(b.appliedList())
fpr := fpOf("9")
ckr, crawr, digr := composition(t, "web", fpr, false, archive("a", d1))
b.comps.put(ckr, crawr)
wkr, _ := wantFor(t, "web", fpr, digr, "")
rawr, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fpr, Run: "10"})
b.wants.put(wkr, rawr)
b.idle()
if got := len(b.appliedList()) - before; got != 0 {
t.Errorf("a want of run 10 after a have of run 20: applied %d times, want none", got)
}
b.mu.Lock() b.mu.Lock()
said := strings.Join(b.said, "\n") said := strings.Join(b.said, "\n")
b.mu.Unlock() b.mu.Unlock()
for _, want := range []string{"from run 7", "from run 8", "carries run 5, and the engine applied it from run 7"} { for _, want := range []string{"from run 7", "from run 8", "carries run 5, and the engine applied it from run 7",
"carries run 10, and the engine applied it from run 20"} {
if !strings.Contains(said, want) { if !strings.Contains(said, want) {
t.Errorf("the journal does not say %q:\n%s", want, said) t.Errorf("the journal does not say %q:\n%s", want, said)
} }
+2
View File
@@ -413,6 +413,8 @@ func (q *Session) writeHaves(ctx context.Context, bus Bus) {
h.PullWait = f.PullWait h.PullWait = f.PullWait
} }
h.Wait = f.Wait h.Wait = f.Wait
// The seat's form 2 carries the run the module was applied from (H-A-388).
h.Run, h.Form = f.Run, nodeengine.Form
h.Health = s.healthOf(module, f) h.Health = s.healthOf(module, f)
if h.Detail == "" { if h.Detail == "" {
h.Detail = s.wordsOf(module, h.Health) h.Detail = s.wordsOf(module, h.Health)
+6 -5
View File
@@ -256,11 +256,12 @@ func TestAnAppliedModuleIsWrittenRunningAndAFailedOneFailed(t *testing.T) {
} }
} }
// 1132/AC5: a have equal to the bucket's value is not written; a different one is written over the last revision. // 1132/AC5: a have equal to the bucket's value is not written; a different one is written over the last revision. Each
// is written at the seat's form (H-A-388).
func TestAHaveIsWrittenOnlyWhenItDiffers(t *testing.T) { func TestAHaveIsWrittenOnlyWhenItDiffers(t *testing.T) {
l := newHaveLink() l := newHaveLink()
l.put(t, "n1.a", nodeengine.HaveByNodeModuleValue{V: sdkkeys.Version, Build: "b-1", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}) l.put(t, "n1.a", nodeengine.HaveByNodeModuleValue{V: sdkkeys.Version, Form: nodeengine.Form, Build: "b-1", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
l.put(t, "n1.b", nodeengine.HaveByNodeModuleValue{V: sdkkeys.Version, Build: "b-0", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}) l.put(t, "n1.b", nodeengine.HaveByNodeModuleValue{V: sdkkeys.Version, Form: nodeengine.Form, Build: "b-0", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
q, _ := aHaveQueue(l) q, _ := aHaveQueue(l)
q.SayFacts(context.Background(), appliedModules()) q.SayFacts(context.Background(), appliedModules())
if l.kv["n1.a"].rev != 1 { if l.kv["n1.a"].rev != 1 {
@@ -711,8 +712,8 @@ func TestARefusedRemovalIsWrittenByTheNextPass(t *testing.T) {
// before: one of them the new declaration lacks is written removed, one that is not in the bucket is not created. // before: one of them the new declaration lacks is written removed, one that is not in the bucket is not created.
func TestARestartedNodeEngineWritesTheRemovalFromTheReportsBefore(t *testing.T) { func TestARestartedNodeEngineWritesTheRemovalFromTheReportsBefore(t *testing.T) {
l := newHaveLink() l := newHaveLink()
l.put(t, "n1.a", nodeengine.HaveByNodeModuleValue{V: sdkkeys.Version, Build: "b-1", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}) l.put(t, "n1.a", nodeengine.HaveByNodeModuleValue{V: sdkkeys.Version, Form: nodeengine.Form, Build: "b-1", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
l.put(t, "n1.b", nodeengine.HaveByNodeModuleValue{V: sdkkeys.Version, Build: "b-2", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}) l.put(t, "n1.b", nodeengine.HaveByNodeModuleValue{V: sdkkeys.Version, Form: nodeengine.Form, Build: "b-2", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
q, _ := aHaveQueue(l) // fresh: nothing written by this process q, _ := aHaveQueue(l) // fresh: nothing written by this process
r := onlyA() r := onlyA()
r.Before = []string{"a", "b", "c"} r.Before = []string{"a", "b", "c"}
+2
View File
@@ -649,4 +649,6 @@ type ModuleFact struct {
PullWait *nodeengine.PullWait PullWait *nodeengine.PullWait
// Wait is the hold or wait the module has, with the ask-at and act of a recovery wait (nodeengine.HaveByNodeModuleValue.Wait, design 47 G §560). // Wait is the hold or wait the module has, with the ask-at and act of a recovery wait (nodeengine.HaveByNodeModuleValue.Wait, design 47 G §560).
Wait *nodeengine.Wait Wait *nodeengine.Wait
// Run is the composition run the module was applied from (nodeengine.HaveByNodeModuleValue.Run, design 47 H2 §813 (1), H-A-388).
Run string
} }