Design 47 H1: the tool runner hears every event and serves every seat's verbs #78

Merged
mesh-tools merged 11 commits from feat/47-H1-tool-runner into main 2026-11-20 07:13:08 +00:00
6 changed files with 106 additions and 4 deletions
Showing only changes of commit 2f9690fe80 - Show all commits
+2 -1
View File
@@ -90,7 +90,8 @@ func main() {
Build: os.Getenv(runtime.FingerprintWord), Hear: hearOne(conn)})
// A failed read or write of the state approvals is made again at the next membership change the runner hears (A-157).
conn.OnMembership(func(bus.Membership) { go gate.StateAgain() })
opts = append(opts, runtime.WithGate(gate), runtime.WithSeatDefinitions(definitionsOf(seatList)))
opts = append(opts, runtime.WithGate(gate), runtime.WithSeatDefinitions(definitionsOf(seatList)),
runtime.WithSeatDefinitionsAgain(rereadOf(seatList)))
// A run still unrecorded is asked again at each start and when the hand-act seat's holder is heard again (lead answer A-157).
if stopBounds, err := gate.WatchBounds(); err != nil {
log.Printf("[mesh-tools] the gate's bound keys are not watched (%v): an unanswered hand-act is said in the log only", err)
+17
View File
@@ -66,6 +66,12 @@ func startSeatListOn(b seatlist.Bus, bound <-chan time.Time, logf func(string, .
select {
case <-reader.Ready():
catalogue.UseSeats(reader.Seats())
// a first read that ended without an answer is no failure of the reader, which holds the bootstrap and waits for the seat's
// next event: so it is said here, where nothing else would say it (the runner then reads again where a bundle asks a verb
// its definitions do not name)
if st := reader.Status(); !st.Heard {
logf("node-tools: the first read of the seat list ended without an answer (%s); the runner serves with the bootstrapped seats and reads again when a bundle asks a verb they do not name", st.LastError)
}
case <-bound:
logf("node-tools: the seat list is not read yet; the runner serves with the bootstrapped seats and reads on")
}
@@ -82,3 +88,14 @@ func definitionsOf(reader *seatlist.Reader) func() map[string]seatdef.Definition
return reader.Definitions()
}
}
// rereadOf is how the runner reads the seat list again where a verb is not named by the definitions it holds; it reads nothing
// while the reader did not start.
func rereadOf(reader *seatlist.Reader) func() error {
return func() error {
if reader == nil {
return fmt.Errorf("the seat list reader did not start")
}
return reader.Reload()
}
}
+2 -2
View File
@@ -32,7 +32,7 @@ func TestTheRunnerWaitsForTheFirstReadOfTheSeatListOnlyToItsBound(t *testing.T)
wantSaid string
wantReady bool
}{
{"the first read ends before the bound", true, "", true},
{"the first read ends before the bound, unanswered", true, "the first read of the seat list ended without an answer", true},
{"the bound passes with the seat silent", false, "the seat list is not read yet", false},
} {
t.Run(row.name, func(t *testing.T) {
@@ -57,7 +57,7 @@ func TestTheRunnerWaitsForTheFirstReadOfTheSeatListOnlyToItsBound(t *testing.T)
if ended != row.wantReady {
t.Errorf("first read ended = %v, want %v", ended, row.wantReady)
}
if got := strings.Join(said, ";"); !strings.Contains(got, row.wantSaid) || (row.wantSaid == "" && got != "") {
if got := strings.Join(said, ";"); !strings.Contains(got, row.wantSaid) {
t.Errorf("said %q, want %q", got, row.wantSaid)
}
if !row.release {
@@ -2,6 +2,7 @@ package runtime
import (
"encoding/json"
"errors"
"strings"
"testing"
"time"
@@ -150,6 +151,40 @@ func TestTheSubjectThatNamesNoCallerStillWorksAndNamesNone(t *testing.T) {
t.Error("a runner that holds no seat definitions asks no chunks")
}
})
// A seat verb a bundle asks that the definitions held do not name is read again once, never taken for one that sends no chunks:
// the holder refuses an ask that carries no call, and the bundle saw only that refusal (the compositions of 2026-11-19).
t.Run("AVerbTheListDoesNotNameIsReadAgainAndNeverAskedWithoutItsCall", func(t *testing.T) {
stale := map[string]seatdef.Definition{"mesh-wants": {Verbs: []seatdef.Verb{{Name: "revision"}}}}
fresh := map[string]seatdef.Definition{"mesh-wants": {Verbs: []seatdef.Verb{{Name: "revision"}, {Name: "input", Chunks: true}}}}
for _, row := range []struct {
name string
again func(held *map[string]seatdef.Definition) error
want bool
wantErr string
wantRead int
}{
{"a read that names it", func(h *map[string]seatdef.Definition) error { *h = fresh; return nil }, true, "", 1},
{"a read that fails", func(h *map[string]seatdef.Definition) error { return errors.New("the seat does not answer") }, false, "does not answer", 1},
{"a read that still does not name it", func(h *map[string]seatdef.Definition) error { return nil }, false, "does not name the verb seat:mesh-wants.input", 1},
} {
t.Run(row.name, func(t *testing.T) {
held, reads := stale, 0
c := &consumers{definitions: func() map[string]seatdef.Definition { return held }, reread: func() error { reads++; return row.again(&held) }}
got, err := c.chunkedAsked("seat:mesh-wants.input")
if got != row.want || reads != row.wantRead || (row.wantErr == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), row.wantErr)) {
t.Errorf("chunkedAsked = %v, %v after %d reads, want %v, %q after %d", got, err, reads, row.want, row.wantErr, row.wantRead)
}
})
}
held := fresh
c := &consumers{definitions: func() map[string]seatdef.Definition { return held }, reread: func() error { t.Error("a verb the list names is not read again"); return nil }}
if got, err := c.chunkedAsked("seat:mesh-wants.input@g14"); !got || err != nil {
t.Errorf("a named chunked verb: %v, %v", got, err)
}
if got, err := (&consumers{}).chunkedAsked("seat:mesh-wants.input"); got || err != nil {
t.Errorf("a runner that holds no definitions asks no chunks: %v, %v", got, err)
}
})
// **The tool runner answers a held seat's marked verb by caller and serves the seat's `approvals`** (design 47 G §677; lead
// answers A-265, A-271), with zsh's node-login-shell `execute` as the case: the marked verb reaches the gate with the caller
// its subject names, and `approvals` is answered from the runner's own record of the calls its gate holds, with the
+43
View File
@@ -1,6 +1,7 @@
package runtime
import (
"fmt"
"strings"
"git.novox.be/novox/mesh-sdk/go/approval"
@@ -75,6 +76,48 @@ func (r *runner) unservedMarks(module string, regs []launch.Registration) []stri
return r.events.gate.Unserved(module, r.fingerprintOf(module), registered)
}
// WithSeatDefinitionsAgain gives the runner the way to read the seat list again (the seat list reader's Reload): a seat verb a bundle asks
// that the definitions held do not name is looked up again after it, never taken for a verb that sends no chunks.
func WithSeatDefinitionsAgain(again func() error) Option {
return func(c *consumers) { c.reread = again }
}
// chunkedAsked is chunked for a verb a bundle asks, where the answer decides whether the runner chooses the `call` the holder
// requires (AskAsChunked): a seat verb the definitions held do not name is not taken for one that sends no chunks, since the
// holder then refuses an ask that carries no call and the bundle sees only that refusal. The seat list is read again once, and
// a verb it still does not name is an error that says why. A runner that holds no definitions (nil) asks no chunks.
func (c *consumers) chunkedAsked(key string) (bool, error) {
if c.definitions == nil || !strings.HasPrefix(key, "seat:") {
return false, nil
}
name, _, _ := strings.Cut(key, "@")
seat, verb, ok := strings.Cut(strings.TrimPrefix(name, "seat:"), ".")
if !ok {
return false, nil
}
find := func() (chunks, found bool) {
for _, v := range c.definitions()[seat].Verbs {
if v.Name == verb {
return v.Chunks, true
}
}
return false, false
}
if chunks, found := find(); found {
return chunks, nil
}
var why string
if c.reread != nil {
if err := c.reread(); err != nil {
why = ": reading the seat list again failed: " + err.Error()
}
if chunks, found := find(); found {
return chunks, nil
}
}
return false, fmt.Errorf("the seat list this runner holds does not name the verb %s, so it cannot tell whether the verb sends its answer in chunks (the ask is not sent)%s", key, why)
}
// chunked says whether key names a seat's verb whose definition says `chunks` (design 47 G A-249): its answer is received in
// chunks by the runner, whose call hands the bundle the whole.
func (c *consumers) chunked(key string) bool {
+7 -1
View File
@@ -871,6 +871,8 @@ type consumers struct {
gate Gate
// definitions are the seat definitions a seat verb's callers are read from (gate.go); nil admits every caller.
definitions func() map[string]seatdef.Definition
// reread reads the seat list again (gate.go, chunkedAsked); nil reads nothing.
reread func() error
}
type moduleEvents struct {
@@ -1000,7 +1002,11 @@ func (b *moduleBus) Ask(params json.RawMessage) (json.RawMessage, error) {
body = map[string]any{}
}
ask := b.all.conn.AskAs
if b.all.chunked(asked.Key) {
chunks, err := b.all.chunkedAsked(asked.Key)
if err != nil {
return nil, err
}
if chunks {
ask = b.all.conn.AskAsChunked // the runner receives the chunks of the answer; the bundle receives none (design 47 G A-249)
}
answered, err := ask(b.module, asked.Key, body)