From 4adc35d5ce63a5e74bd50863f3b161a2b48fa7e2 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 02:13:04 +0100 Subject: [PATCH] H2 H-A-504: every have read gives the run, pipeline and want revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review round 1: sessionHaves.Read gave no run, pipeline or want revision, so on the live engine every have written over an apply (held, failed, waiting, not composed) dropped the want revision, and the next want counted as nothing applied. Read now maps the have value the same way as ReadAt, through one function. Builds: design 47 H2 §813 (1); H-A-504 fourth addendum --- cmd/mesh-host/nodeagent.go | 13 +++++++++---- cmd/mesh-host/recovery_integration_test.go | 12 ++++++++++++ internal/agent/agent_test.go | 22 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/cmd/mesh-host/nodeagent.go b/cmd/mesh-host/nodeagent.go index ebed8fdc..13e96beb 100644 --- a/cmd/mesh-host/nodeagent.go +++ b/cmd/mesh-host/nodeagent.go @@ -90,8 +90,15 @@ func (h sessionHaves) Read(ctx context.Context, module string) (agent.Have, bool if !ok { return agent.Have{}, false } + return haveOf(module, got), true +} + +// haveOf is a module's have value as the agent reads it: every read gives the run, the pipeline and the want revision it +// was applied from, so a have written over it (held, failed, waiting) keeps them (H-A-504 fourth addendum). +func haveOf(module string, got nodeengine.HaveByNodeModuleValue) agent.Have { 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 + Sealed: got.SealedAt, Wait: got.Wait, Run: got.Run, Pipeline: got.Pipeline, + WantRevision: uint64(max(got.WantRevision, 0))} } // ReadErr is Read telling a have absent from one the bus could not read (agent.HavesReadErr). @@ -114,9 +121,7 @@ func (h sessionHaves) ReadAt(ctx context.Context, module string) (agent.Have, ui if !ok || err != nil { return agent.Have{}, revision, false, err } - return agent.Have{Module: module, FP: got.Fp, Composed: got.Composed, Phase: string(got.Phase), Detail: got.Detail, - Sealed: got.SealedAt, Wait: got.Wait, Run: got.Run, Pipeline: got.Pipeline, - WantRevision: uint64(max(got.WantRevision, 0))}, revision, true, nil + return haveOf(module, got), revision, true, nil } // WriteAt writes a module's have only while its key is at the revision read (agent.HavesAt, H-A-480). diff --git a/cmd/mesh-host/recovery_integration_test.go b/cmd/mesh-host/recovery_integration_test.go index 4c8d2cdb..4267c4d1 100644 --- a/cmd/mesh-host/recovery_integration_test.go +++ b/cmd/mesh-host/recovery_integration_test.go @@ -21,6 +21,7 @@ import ( "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "github.com/nats-io/nats.go" "github.com/nats-io/nats.go/jetstream" + "github.com/novox/mesh-host/internal/agent" "github.com/novox/mesh-host/internal/buckets" "github.com/novox/mesh-host/internal/link" "github.com/novox/mesh-host/internal/nodegrant" @@ -134,6 +135,17 @@ func TestNatsTheRecoveryStepAsksHearsBoundsAndCatchesUpOverTheBus(t *testing.T) say("old", meshrecovery.RestoredEventOutcomeFailed) // said before anyone listens: the last message of the subject session := b.startSession() + // H-A-504 fourth addendum: a have written through the agent's haves and read back gives the run, the pipeline and the + // want revision it was applied from, by every read, so a have written over it keeps them. + hv := sessionHaves{session: session} + hv.Write(ctx, agent.Have{Module: "web", FP: "src2:" + strings.Repeat("a", 64), Composed: "sha256:" + strings.Repeat("b", 64), + Phase: "running", Run: "12", Pipeline: "main.12", WantRevision: 301924}) + within(t, 5*time.Second, "the have read back through the agent's haves lacks its run, pipeline or want revision", func() bool { + got, ok := hv.Read(ctx, "web") + at, _, okAt, err := hv.ReadAt(ctx, "web") + return ok && okAt && err == nil && got.Run == "12" && got.Pipeline == "main.12" && got.WantRevision == 301924 && + at.Run == got.Run && at.Pipeline == got.Pipeline && at.WantRevision == got.WantRevision + }) r := recoveryEnv(session, nil) // Design 47 H2 §775, H-A-364: over the same session, an ask of the seat is taken once in the state taken: the first time, // and never again within its bound. diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index 898cb803..d892c2f7 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -447,6 +447,28 @@ func testAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) { t.Errorf("%s: the have names want revision %d and run %q, want %d and %q", row.name, h.WantRevision, h.Run, next, row.run) } } + // H-A-504 fourth addendum: the want revision is written with every have, so a failed apply after one keeps the revision + // the module was applied from, and the next want is still ordered against it. + hf := b.haves.last("web") + hf.WantRevision = wantsRev() // the older row's earlier life ends: what was applied is at the latest write + b.haves.Write(context.Background(), hf) + applied := hf.WantRevision + b.mu.Lock() + b.failWith = "systemctl start web.service: exit status 1" + b.mu.Unlock() + fpf := fpOf("c") + ckf, crawf, digf := composition(t, "web", fpf, false, archive("a", d1)) + b.comps.put(ckf, crawf) + wkf, _ := wantFor(t, "web", fpf, digf, "") + rawf, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fpf, Run: "11"}) + b.wants.put(wkf, rawf) + b.idle() + if h := b.haves.last("web"); h.Phase != string(nodeengineclient.PhaseFailed) || h.WantRevision != applied || h.Run != "3" { + t.Errorf("the failed have after an apply: phase %s, want revision %d, run %q; want failed, %d and \"3\"", h.Phase, h.WantRevision, h.Run, applied) + } + b.mu.Lock() + b.failWith = "" + b.mu.Unlock() b.mu.Lock() said := strings.Join(b.said, "\n") b.mu.Unlock()