B2: the builder serves the seat mesh-builds' drop and its queue's tools

A caller whose step ended by its bound could not stop the builder working on
its ask, and nobody could see what waited on the seat's work queue. The
builder now serves the seat's verb drop: an ask it runs is cancelled, one not
pulled yet is kept dropped in its state taken (dropped.<ask>, for
ask-taken-bound); both end the step could-not-run naming the drop and who
asked it. builder_asks reads the waiting asks through the runtime and the
taken ones and the drops from the state taken; builder_ask_drop asks the
seat's drop once the hand act is recorded.

Builds: design 47 H2 §777, §778; H-A-401, H-A-404, H-A-410
This commit is contained in:
2026-11-22 01:08:30 +01:00
parent 3a647a8e2d
commit 905a055a1e
11 changed files with 466 additions and 23 deletions
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"sync"
"sync/atomic"
"time"
@@ -17,6 +18,8 @@ import (
"git.novox.be/novox/mesh-sdk/go/buscompose"
"git.novox.be/novox/mesh-sdk/go/process"
"git.novox.be/novox/mesh-sdk/go/seatdef"
"mesh-delivery-builder/internal/build"
)
// **The seat mesh-builds takes its asks from a work queue and says ask-taken** (design 47 H2 §777, §775; ADR 0525 §1, §2,
@@ -32,9 +35,12 @@ const (
defaultAskTakenBound = 10 * time.Minute
)
// askTaker is the state taken (process.State.TakeOnce).
// askTaker is the state taken (process.State): an ask taken once by its id, and the drop of an ask not pulled yet kept
// under build.DroppedKey (H-A-404).
type askTaker interface {
TakeOnce(seat, ask string, bound time.Duration) (bool, error)
Get(key string) (*stdio.StateEntry, error)
CreateTTL(key string, value any, ttl time.Duration) (uint64, error)
}
// stepBuilder is build.Builder's BuildStep.
@@ -104,6 +110,17 @@ func (q *stepQueue) take(ctx context.Context, m queueMsg) {
q.logf("the ask %s (%s) was handed again while it runs here: its run answers it", id, run.Pipeline)
return
}
// An ask dropped before it was pulled ends could-not-run naming the drop, with no build (H-A-404).
if d := q.droppedAsk(id); d != nil {
work, cancel := context.WithCancelCause(ctx)
cancel(d)
ra := &runningAsk{run: run, taken: q.now(), cancel: cancel}
q.running[id] = ra
q.mu.Unlock()
q.logf("the ask %s (%s) was dropped before it was pulled: %s", id, run.Pipeline, d.Error())
go q.build(work, m, id, ra)
return
}
first, err := q.taken.TakeOnce(meshbuilds.Seat, id, q.takenBound)
if err != nil {
q.mu.Unlock()
@@ -159,6 +176,59 @@ func (q *stepQueue) build(ctx context.Context, m queueMsg, id string, ra *runnin
_ = m.Ack()
}
// droppedAsk is the drop kept for the ask id in the state taken, nil for none.
func (q *stepQueue) droppedAsk(id string) *build.Dropped {
e, err := q.taken.Get(build.DroppedKey(id))
if err != nil || e == nil {
return nil
}
var d build.Dropped
if json.Unmarshal(e.Value, &d) != nil {
return nil
}
return &d
}
// drop is the seat mesh-builds' verb drop (§778; H-A-401, H-A-404): the drop is kept in the state taken under
// build.DroppedKey for ask-taken-bound, so a pull of the ask within the bound ends it, and an ask that runs here is
// cancelled; both end the step could-not-run naming the drop and who asked it. held says whether it ran here.
func (q *stepQueue) drop(id, by, why string) (held bool, err error) {
if strings.TrimSpace(id) == "" || strings.TrimSpace(why) == "" {
return false, errors.New("give the ask's id and why it is dropped")
}
d := &build.Dropped{By: by, Why: why}
if _, err := q.taken.CreateTTL(build.DroppedKey(id), d, q.takenBound); err != nil && !errors.Is(err, stdio.ErrChanged) {
return false, fmt.Errorf("the drop of %s is not kept in the state %s: %w", id, process.TakenState, err)
}
q.mu.Lock()
ra := q.running[id]
q.mu.Unlock()
if ra != nil {
ra.cancel(d)
}
q.logf("the ask %s is dropped by %s: %s", id, by, why)
return ra != nil, nil
}
// dropVerb is the handler of the seat mesh-builds' verb drop: who drops it is the input's by, else the caller.
func dropVerb(q *stepQueue) process.SeatHandler {
return func(caller string, body json.RawMessage) (any, error) {
var in meshbuilds.DropInput
if err := json.Unmarshal(body, &in); err != nil {
return nil, fmt.Errorf("the arguments do not fit the verb drop: %w", err)
}
by := in.By
if by == "" {
by = caller
}
held, err := q.drop(in.ID, by, in.Why)
if err != nil {
return nil, err
}
return meshbuilds.DropAnswer{"held": held}, nil
}
}
// running answers the asks this builder runs now, by id.
func (q *stepQueue) runningAsks() map[string]runningAsk {
q.mu.Lock()