assigner: a run's start and its wait run on the assigner's own context (issue 1984, review round 1)

The composition and validate runs were started on the context of the
step that started them, so a supersede or a drop of that step ended the
wait for a package's publish silently, while other steps share the run:
it then waited, woken by nothing, until its bound ended it "no published
version" though the package stood published. The start, its wait and
its run ask now run on the assigner's own context (compositionRun.own),
as the take-up's do.

Tests: TestTheCompositionStepRunsOneAskPerMachine, the wait's rows gain
"superseded": a second step joins the waiting runs, the starting step's
context ends, the runs stay waiting with both readers, and at the
publish the second step reads them composed with the pin;
TestTheValidateStepRefusesAManifestProblemAndACycle, revision 14: the
validate run waiting for mesh-sdk's publish outlives its starting step
and ends passed after the publish. Both failed first (no end within
10 s) with the start on the step's context.

Builds: design 47 H2 H-A-630 (3) (hq 1cdfa6ff); H-A-628 (3) (hq cea6404c); H-A-629 (3) (hq 8aa70271)
This commit is contained in:
2026-11-23 23:11:32 +01:00
parent 051e104f1b
commit dc2ddb871a
5 changed files with 66 additions and 8 deletions
@@ -84,6 +84,9 @@ type compositionRun struct {
away func(machine string) bool away func(machine string) bool
// put puts a run ask on the build seat's check queue under the assigner's name. // put puts a run ask on the build seat's check queue under the assigner's name.
put func(ctx context.Context, a buildstep.StepAsk) error put func(ctx context.Context, a buildstep.StepAsk) error
// own is the assigner's own context: a run's start, and its wait for a package's publish, run on it as the take-up's do, never
// on the starting step's, which a supersede or a drop ends while other steps share the run (design 47 H2 H-A-630 (3)).
own context.Context
// reads shares the catalog reads among steps (compositionreads.go); sleep waits between two tries of a read (nil: a timer). // reads shares the catalog reads among steps (compositionreads.go); sleep waits between two tries of a read (nil: a timer).
reads *compositionReads reads *compositionReads
sleep func(ctx context.Context, d time.Duration) error sleep func(ctx context.Context, d time.Duration) error
@@ -134,7 +137,7 @@ func (r *compositionRun) run(ctx context.Context, id string, step meshwants.Step
continue continue
} }
if j.started { if j.started {
go r.start(ctx, j.key, j.run, prep, id) go r.start(r.own, j.key, j.run, prep, id) // on the assigner's own context (H-A-630 (3))
} }
keys = append(keys, j.key) keys = append(keys, j.key)
} }
@@ -201,7 +201,7 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *
s.runs = newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf) s.runs = newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf)
s.r = &compositionRun{runs: s.runs, s.r = &compositionRun{runs: s.runs,
inputs: &compositionInputs{machines: func(string, string) []string { return []string{"ace", "g14", "shanks"} }, callFile: engines, bound: time.Second}, inputs: &compositionInputs{machines: func(string, string) []string { return []string{"ace", "g14", "shanks"} }, callFile: engines, bound: time.Second},
keeper: keeper, reads: &compositionReads{}, call: call, away: away, now: time.Now, logf: t.Logf, keeper: keeper, reads: &compositionReads{}, call: call, away: away, own: context.Background(), now: time.Now, logf: t.Logf,
trunk: func() (mcc.Half, bool) { trunk: func() (mcc.Half, bool) {
return mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{"engine": engine(trunkEngine, commitE1)}}, true return mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{"engine": engine(trunkEngine, commitE1)}}, true
}, },
@@ -304,8 +304,9 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
// with the time its wait began, its bound bound.<run key> armed for package-wait-minutes, the step saying fetch naming the // with the time its wait began, its bound bound.<run key> armed for package-wait-minutes, the step saying fetch naming the
// package; at the publish heard each reads published again and puts its run ask with the pin, `waits` and the bound gone, the // package; at the publish heard each reads published again and puts its run ask with the pin, `waits` and the bound gone, the
// step saying run; past the bound each ends could not run naming the package and the bound, no run ask put. H-A-630 (2): a // step saying run; past the bound each ends could not run naming the package and the bound, no run ask put. H-A-630 (2): a
// bind of the consumer, the publish said while it was not bound, wakes each to read it published. // bind of the consumer, the publish said while it was not bound, wakes each to read it published. H-A-630 (3): the starting
for _, how := range []string{"published", "bind", "past its bound"} { // step superseded leaves the runs another step shares waiting, and that step reads them composed after the publish.
for _, how := range []string{"published", "bind", "superseded", "past its bound"} {
publish := how != "past its bound" publish := how != "past its bound"
u := newRunStand(t, "src2:e1", "src2:e1", "d1") u := newRunStand(t, "src2:e1", "src2:e1", "d1")
u.publishedAt = nil u.publishedAt = nil
@@ -323,7 +324,9 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
} }
phase := &stepPhase{} phase := &stepPhase{}
done := make(chan stepOutcome, 1) done := make(chan stepOutcome, 1)
go func() { done <- u.r.run(context.WithValue(context.Background(), phaseKey{}, phase), "ask-step", step) }() first, supersede := context.WithCancel(context.WithValue(context.Background(), phaseKey{}, phase))
defer supersede()
go func() { done <- u.r.run(first, "ask-step", step) }()
journal.await(t, "waits for package git.novox.be/novox/x/go, named with no version in the node-engine's entry src2:e", 2) journal.await(t, "waits for package git.novox.be/novox/x/go, named with no version in the node-engine's entry src2:e", 2)
journal.await(t, "the composition step of m says fetch: the composition run", 1) journal.await(t, "the composition step of m says fetch: the composition run", 1)
if got := phase.get(); got != meshwants.StepProgressEventPhaseFetch { if got := phase.get(); got != meshwants.StepProgressEventPhaseFetch {
@@ -352,6 +355,24 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
kv.expire(runBoundPrefix + key) kv.expire(runBoundPrefix + key)
u.runs.expired(runBoundPrefix + key) u.runs.expired(runBoundPrefix + key)
} }
case "superseded":
second := make(chan stepOutcome, 1)
go func() {
second <- u.r.run(context.WithValue(context.Background(), phaseKey{}, &stepPhase{}), "ask-step-2", step)
}()
journal.await(t, "the composition step of m says fetch: the composition run", 2) // the second step reads the waiting runs
supersede()
<-done
for _, key := range keys {
if run, _, _, _ := u.runs.read(key); run.Ended != nil || run.Waits == nil || len(run.Readers) != 2 {
t.Errorf("the starting step superseded, the run %s holds ended %v, waits %+v, readers %d; want it waiting for its two readers", key, run.Ended, run.Waits, len(run.Readers))
}
}
done = second
u.mu.Lock()
u.publishedAt = map[string]string{"src2:x1": "0.1.9"}
u.mu.Unlock()
u.runs.heardPublished("x:go")
case "bind": case "bind":
hub := &eventsOf{handle: map[string]func(jetstream.Msg){}} hub := &eventsOf{handle: map[string]func(jetstream.Msg){}}
if err := hearPublished(hub, u.runs, t.Logf); err != nil { if err := hearPublished(hub, u.runs, t.Logf); err != nil {
@@ -687,7 +687,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
return err return err
} }
run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFileKept, bound: askBound}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept, callFile: bus.CallFileKept, run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFileKept, bound: askBound}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept, callFile: bus.CallFileKept,
trunk: trunkOf(iv, w.trunkName), newest: iv.newestOf(), watched: iv.watchedOf, assigned: w.assignedOn, assignment: w.assignmentOf, findings: findings, running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf} trunk: trunkOf(iv, w.trunkName), newest: iv.newestOf(), watched: iv.watchedOf, assigned: w.assignedOn, assignment: w.assignmentOf, findings: findings, running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), own: ctx, ask: bus.CallFile, now: time.Now, logf: logger.Printf}
// The seat's work queue (design 47 H2 §777): pulled through its one worker, each ask taken once in the state taken. // The seat's work queue (design 47 H2 §777): pulled through its one worker, each ask taken once in the state taken.
takenBound, err := askTakenBound() takenBound, err := askTakenBound()
if err != nil { if err != nil {
@@ -75,7 +75,7 @@ func (r *compositionRun) validate(ctx context.Context, id string, step meshwants
return couldNotRun("the validate run " + key + " is not joined: " + err.Error()) return couldNotRun("the validate run " + key + " is not joined: " + err.Error())
} }
if j.started { if j.started {
go r.startValidate(ctx, key, j.run, step) go r.startValidate(r.own, key, j.run, step) // on the assigner's own context (H-A-630 (3))
} }
return r.readValidate(ctx, key, step) return r.readValidate(ctx, key, step)
} }
@@ -48,6 +48,9 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
13: {unpinned, entry("web", "d-web-2"), entry("db", "d-db"), {Module: "mesh-sdk", Fp: "src2:sdk1", 13: {unpinned, entry("web", "d-web-2"), entry("db", "d-db"), {Module: "mesh-sdk", Fp: "src2:sdk1",
Artifacts: []meshcatalog.Artifact{{Ref: "mesh-sdk:go", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}}}}}, Artifacts: []meshcatalog.Artifact{{Ref: "mesh-sdk:go", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}}}}},
} }
revisions[14] = revisions[13] // H-A-630 (3): its validate run waits for mesh-sdk's publish
var sdkMu sync.Mutex
sdkUnpublished := false
// base is the newest kept revision below n, as the take-in names it; none below the first. Revision 12 names 7 with 8 to 11 // base is the newest kept revision below n, as the take-in names it; none below the first. Revision 12 names 7 with 8 to 11
// never kept, so a case before read as the number minus one could not run (H-A-154). // never kept, so a case before read as the number minus one could not run (H-A-154).
base := func(n int64) (b int64) { base := func(n int64) (b int64) {
@@ -86,6 +89,11 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
if in != (builds.PublishedInput{Module: "mesh-sdk", Artifact: "mesh-sdk:go", Fingerprint: "src2:sdk1"}) { if in != (builds.PublishedInput{Module: "mesh-sdk", Artifact: "mesh-sdk:go", Fingerprint: "src2:sdk1"}) {
return nil, errors.New("published asked of another build") return nil, errors.New("published asked of another build")
} }
sdkMu.Lock()
defer sdkMu.Unlock()
if sdkUnpublished {
return json.Marshal(builds.PublishedAnswer{})
}
return json.Marshal(builds.PublishedAnswer{Published: true, Version: "0.1.36"}) return json.Marshal(builds.PublishedAnswer{Published: true, Version: "0.1.36"})
} }
return nil, errors.New("no such verb " + key) return nil, errors.New("no such verb " + key)
@@ -111,7 +119,7 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
var requests []composer.Request var requests []composer.Request
keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now) keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now)
runs := newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf) runs := newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf)
r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: call, callFile: callFile, now: time.Now, logf: t.Logf, r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: call, callFile: callFile, own: context.Background(), now: time.Now, logf: t.Logf,
put: func(_ context.Context, a buildstep.StepAsk) error { put: func(_ context.Context, a buildstep.StepAsk) error {
body, err := keeper.body(a.Run.Input.Digest) body, err := keeper.body(a.Run.Input.Digest)
if err != nil { if err != nil {
@@ -237,4 +245,30 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
} else if got := asks[3].Packages; len(got) != 2 || got["git.novox.be/novox/mesh-sdk/go"] != "v0.1.36" || got["git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"] != "v0.1.4" { } else if got := asks[3].Packages; len(got) != 2 || got["git.novox.be/novox/mesh-sdk/go"] != "v0.1.36" || got["git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"] != "v0.1.4" {
t.Errorf("the validator is built against the pins %v; want mesh-sdk/go at v0.1.36 from published beside its entry's", got) t.Errorf("the validator is built against the pins %v; want mesh-sdk/go at v0.1.36 from published beside its entry's", got)
} }
// H-A-630 (3): the validate run waits for mesh-sdk's publish on the assigner's own context, so the step that started it, ended
// meanwhile, leaves it waiting: at the publish it is put and ends passed for the movers that read it.
sdkMu.Lock()
sdkUnpublished = true
sdkMu.Unlock()
journal := newLogLines()
r.logf = journal.logf
starting, stop := context.WithCancel(ctx)
left := make(chan stepOutcome, 1)
go func() { left <- r.validate(starting, "ask-left", step("web", 14)) }()
journal.await(t, "waits for package git.novox.be/novox/mesh-sdk/go", 1)
stop()
if o := <-left; o.Outcome != meshwants.StepEndedOutcomeCouldNotRun {
t.Errorf("the starting step stopped ended %+v", o)
}
sdkMu.Lock()
sdkUnpublished = false
sdkMu.Unlock()
runs.heardPublished("mesh-sdk:go")
key, _ := validateKeyOf(step("web", 14))
run := runs.awaitEach(ctx, []string{key}, nil)[key]
mu.Lock()
defer mu.Unlock()
if run.Ended == nil || run.Outcome != meshwants.CompositionRunOutcomePassed || len(asks) != 5 || asks[4].Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.36" {
t.Errorf("the validate run its starting step left ended %v %s %q with %d validator asks, want it put after the publish and passed", run.Ended, run.Outcome, run.Said, len(asks))
}
} }