steprun: an ask on its last delivery is ended, every end is acknowledged, an unwritten end is given back (A-489a)

Builds: design 47 G §24, §25; lead answers A-489, A-489a

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-19 15:38:16 +01:00
parent 16feb56fd4
commit 92196dde3a
7 changed files with 144 additions and 36 deletions
+53 -20
View File
@@ -32,6 +32,8 @@ type Pulled struct {
Subject string
// Delivered is how many times the bus has handed it over, this time included.
Delivered uint64
// Sequence is its sequence in the stream (0 for a source that has none), which the journal names for an ask that cannot be read.
Sequence uint64
// Ack ends it: it is never delivered again. InProgress tells the bus it is still being worked, restarting its
// acknowledgement wait. Nak hands it back to be delivered again at once (to this node or another). Term drops it.
Ack, InProgress, Nak, Term func() error
@@ -580,7 +582,8 @@ func (p *Puller) decline(msg *Pulled, ask sdkstep.StepAsk, lacks []string) {
return
}
p.logf("the ask %s is declined on %s: it needs %s, and this node lacks %s", ask.ID, p.Node, strings.Join(ask.Needs, ", "), strings.Join(lacks, ", "))
_ = msg.Term()
p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, "this node lacks "+strings.Join(lacks, ", "))
_ = msg.Ack() // A-489a: its end is written
p.mu.Lock()
if p.declined == nil {
p.declined = map[string]bool{}
@@ -602,7 +605,7 @@ func (p *Puller) declineRun(msg *Pulled, ask sdkstep.StepAsk, key string, step s
return
}
p.logf("the ask %s is declined on %s: %s", ask.ID, p.Node, d.Text)
_ = msg.Term()
_ = msg.Ack() // A-489a: its end is written (run() says it)
p.mu.Lock()
if p.declined == nil {
p.declined = map[string]bool{}
@@ -637,8 +640,8 @@ func (p *Puller) refuseUnread(msg *Pulled, why error) {
}
}
}
p.logf("an ask dropped: %v", why)
_ = msg.Term()
p.logf("an ask dropped, no id to answer it by, acknowledged with this line as its only record (stream sequence %d): %v", msg.Sequence, why)
_ = msg.Ack() // A-489a
}
func withKind(msg *Pulled, kind string) *Pulled {
@@ -648,6 +651,37 @@ func withKind(msg *Pulled, kind string) *Pulled {
return msg
}
// priorRuns is how many runs of the ask started before this delivery: its step key's (Puller.Prior), else the bus's delivery
// count less this one. The bus's count also counts an ask given back before it ran, which is no run.
func (p *Puller) priorRuns(msg *Pulled, ask sdkstep.StepAsk) int {
if p.Prior != nil {
if akey, kerr := sdkstep.StepKeyOf(keyAsker(msg), p.Node, ask.ID); kerr == nil {
return p.Prior(akey)
}
}
return int(msg.Delivered) - 1
}
// endUnrun ends an ask that is run no more (A-489, A-489a): poison when runs of it started and none ended, out of its
// deliveries when none did. Its step ends and its step-ended is said, and only then it is acknowledged; an end that could not
// be written gives it back, never acknowledged.
func (p *Puller) endUnrun(msg *Pulled, ask sdkstep.StepAsk, key string, step sdkstep.Step, prior int) {
var why error
if prior > 0 {
why = fmt.Errorf("the ask was taken %d times and no run of it ended: each took its build node down or died with it, so it is run no more (poison)", prior)
} else {
why = fmt.Errorf("the ask is on its last delivery (%d) and no run of it started: it is out of its deliveries and run no more", msg.Delivered)
}
p.logf("the ask %s is ended on %s: %v", ask.ID, p.Node, why)
if _, ferr := finish(p.Put, p.KeepOutput, key, step, nil, why, p.Logf); ferr != nil {
p.logf("the end of the ask %s could not be written on %s, so it is given back: %v", ask.ID, p.Node, ferr)
_ = msg.Nak()
return
}
p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, why.Error())
_ = msg.Ack()
}
// take starts one ask: it decodes it, refuses one that is not of this seat, and runs it as a step under its own id.
func (p *Puller) take(ctx context.Context, msg *Pulled) {
kind := msg.Kind
@@ -662,6 +696,18 @@ func (p *Puller) take(ctx context.Context, msg *Pulled) {
p.refuseUnread(msg, err)
return
}
if msg.Delivered >= sdkstep.AskMaxDeliver {
// Its last delivery (A-489a): the bus gives it no more, so it is ended here, run or not, never given back.
prior := p.priorRuns(msg, ask)
step, key, err := beginRun(p.Put, keyAsker(msg), p.Node, ask.Kind+" ask", ask.ID, buildrun.AskWhat(askRead(ask)), prior+1)
if err != nil {
p.logf("the ask %s is on its last delivery and cannot start its end on %s: %v", ask.ID, p.Node, err)
_ = msg.Nak()
return
}
p.endUnrun(msg, ask, key, step, prior)
return
}
if why, judged := p.askerRefusal(msg, ask); !judged {
p.giveBack(msg, ask)
return
@@ -677,14 +723,7 @@ func (p *Puller) take(ctx context.Context, msg *Pulled) {
p.decline(msg, ask, lacks)
return
}
// The run this is: the runs of the ask that started before it, from its step key, and one more. The bus's delivery count
// also counts an ask given back before it ran (a seat list not read yet, a start that failed), which is no run.
prior := int(msg.Delivered) - 1
if p.Prior != nil {
if akey, kerr := sdkstep.StepKeyOf(keyAsker(msg), p.Node, ask.ID); kerr == nil {
prior = p.Prior(akey)
}
}
prior := p.priorRuns(msg, ask)
step, key, err := beginRun(p.Put, keyAsker(msg), p.Node, ask.Kind+" ask", ask.ID, buildrun.AskWhat(askRead(ask)), prior+1)
if err != nil {
p.logf("the ask %s cannot start on %s: %v", ask.ID, p.Node, err)
@@ -692,13 +731,7 @@ func (p *Puller) take(ctx context.Context, msg *Pulled) {
return
}
if prior >= sdkstep.AskRuns {
// Run AskRuns times and never ended: each run took its node down or died with it. It is run no more, and said
// (issue 1907): the asker's key fails with why.
why := fmt.Errorf("the ask was taken %d times and no run of it ended: each took its build node down or died with it, so it is run no more (poison)", prior)
p.logf("the ask %s is ended on %s: %v", ask.ID, p.Node, why)
_, _ = finish(p.Put, p.KeepOutput, key, step, nil, why, p.Logf) // run no more either way: the asker's bound says it then
p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, why.Error()) // and its asker, a pipeline's runner too, hears it
_ = msg.Ack() // A-489
p.endUnrun(msg, ask, key, step, prior)
return
}
module := ""
@@ -781,7 +814,7 @@ func (p *Puller) run(ctx context.Context, msg *Pulled, ask sdkstep.StepAsk, key
var dec *Declining
if errors.As(err, &dec) && ctx.Err() == nil {
p.declineRun(msg, ask, key, step, dec)
p.sayEnded(msg, ask, sdkstep.OutcomeCouldNotRun, dec.Text, nil, "")
p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, dec.Text)
return
}
if ctx.Err() != nil {