From 9fa29ad801f30ff0cd7c239873349841f856f016 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 14 Nov 2026 11:33:57 +0100 Subject: [PATCH] Tool runner: serve a node-scoped seat's verb also with no machine, in a queue group A verb asked with no machine (the indexer's seed asks node-build-go's steps) is answered by any one holder, on the tool and the caller-named subject. Builds: lead answer A-393 (design 47 G) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h --- node-tools/internal/bus/bus.go | 6 +++ node-tools/internal/runtime/runtime.go | 26 +++++++++++- node-tools/internal/runtime/runtime_test.go | 44 +++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/node-tools/internal/bus/bus.go b/node-tools/internal/bus/bus.go index b0c0c04..c6d8e4c 100644 --- a/node-tools/internal/bus/bus.go +++ b/node-tools/internal/bus/bus.go @@ -682,6 +682,12 @@ func (c *Conn) HandleSubjectCalled(subject string, h CalledHandler) (func(), err return c.answerBoth(subject, "", h) } +// HandleSubjectCalledQueue is HandleSubjectCalled in one queue group: of every holder that serves the subject in the +// group, one answers (lead answer A-393: a node-scoped seat's verb asked with no machine). +func (c *Conn) HandleSubjectCalledQueue(subject, queue string, h CalledHandler) (func(), error) { + return c.answerBoth(subject, queue, h) +} + // answerBoth answers a subject and, when it is a tool's, the caller-named pattern beside it, in one queue. func (c *Conn) answerBoth(subject, queue string, h CalledHandler) (func(), error) { stop, err := c.answerCalledOn(subject, queue, h) diff --git a/node-tools/internal/runtime/runtime.go b/node-tools/internal/runtime/runtime.go index 5dda527..9cdcea8 100644 --- a/node-tools/internal/runtime/runtime.go +++ b/node-tools/internal/runtime/runtime.go @@ -787,7 +787,7 @@ func serveSeats(conn *bus.Conn, modules []string, current func() []registration, // Its callers checked, then through the approval gate, before the bundle (design 47 G §610, A-179; design 46 // 7-approval-mark §20). module, v := module, v - stop, err := conn.HandleSubjectCalled(v.Subject, func(caller string, body json.RawMessage) (any, error) { + handle := func(caller string, body json.RawMessage) (any, error) { if err := admitted(v.Seat, v.Verb, caller); err != nil { return nil, err } @@ -798,13 +798,26 @@ func serveSeats(conn *bus.Conn, modules []string, current func() []registration, } // A verb marked chunks: the bundle answers the whole file, the runner sends it in chunks (design 47 G A-257). return conn.AnswerChunked(v.Seat, v.Verb, body, answer) - }) + } + stop, err := conn.HandleSubjectCalled(v.Subject, handle) if err != nil { logf("[mesh-tools] cannot serve %s's %s on %s: %v", v.Seat, v.Verb, v.Subject, err) continue } stops = append(stops, stop) logf("[mesh-tools] serving %s's %s on %s, admitted where %s holds the seat", v.Seat, v.Verb, v.Subject, module) + // A verb of a node-scoped seat is also answered on the subject that names no machine, by any one holder, in + // one queue group per seat and verb (lead answer A-393). + if open, ok := anyHolderSubject(v, m.Node); ok && !have[open] { + have[open] = true + openStop, err := conn.HandleSubjectCalledQueue(open, "seat."+v.Seat+"."+v.Verb, handle) + if err != nil { + logf("[mesh-tools] cannot serve %s's %s on %s: %v", v.Seat, v.Verb, open, err) + continue + } + stops = append(stops, openStop) + logf("[mesh-tools] serving %s's %s on %s, in a queue group, for a call that names no machine", v.Seat, v.Verb, open) + } } } } @@ -821,6 +834,15 @@ func serveSeats(conn *bus.Conn, modules []string, current func() []registration, }, serve } +// anyHolderSubject is a node-scoped seat verb's subject without its machine, the one asked with no machine named; false +// where the verb's subject does not end in the machine (a seat held once). +func anyHolderSubject(v bus.SeatVerb, node string) (string, bool) { + if node == "" || !strings.HasSuffix(v.Subject, "."+v.Verb+"."+node) { + return "", false + } + return strings.TrimSuffix(v.Subject, "."+node), true +} + // consumers holds, per module the runtime serves, the one durable consumer its events arrive on and // the children its events are handed to (novox/hq ADR 0198). type consumers struct { diff --git a/node-tools/internal/runtime/runtime_test.go b/node-tools/internal/runtime/runtime_test.go index b8e8906..c8f24a1 100644 --- a/node-tools/internal/runtime/runtime_test.go +++ b/node-tools/internal/runtime/runtime_test.go @@ -312,3 +312,47 @@ func TestAnUntakenEventSaysWhoFailed(t *testing.T) { t.Errorf("the event is not named by its id: %q", got) } } + +// A node-scoped seat's verb asked with no machine is answered by a holder, by the tool form the SDK asks +// (lead answer A-393). +func TestANodeScopedSeatVerbIsAlsoAnsweredWithNoMachine(t *testing.T) { + mesh := mt.New(t) + mesh.Issue(t, mt.MembershipOf("theta", "anchor", false, map[string][]string{"node-shelf": {"list"}})) + nodeTools := connect(t, "node-tools", "anchor") + asker := connect(t, "console", "workstation") + regs := func() []registration { + return []registration{{module: "node-shelf", owner: "theta", tools: []launch.Tool{{Name: "list", + Run: func(string, json.RawMessage) (json.RawMessage, error) { return json.RawMessage(`{"shelf":["x"]}`), nil }}}}} + } + gated := func(_ approval.Call, tool launch.Tool, caller string) (any, error) { + return tool.Run(caller, nil) + } + nodeTools.Follow("theta") + stop, _ := serveSeats(nodeTools, []string{"theta"}, regs, gated, func(_, _, _ string) error { return nil }, + func(string) bool { return false }, nil, func(string) string { return "" }, (&mt.Logs{}).Logf) + defer stop() + for _, key := range []string{"seat:node-shelf.list@anchor", "seat:node-shelf.list"} { + t.Run(key, func(t *testing.T) { + mt.Until(t, func() error { + got, err := call(t, asker, key, map[string]any{}) + if err == nil { + same(t, got, `{"shelf":["x"]}`) + } + return err + }) + }) + } +} + +func TestAnyHolderSubject(t *testing.T) { + for _, c := range []struct{ subject, node, want string }{ + {"mesh.seat.node-build-go.tool.steps.shanks", "shanks", "mesh.seat.node-build-go.tool.steps"}, + {"mesh.seat.mesh-delivery.tool.show", "shanks", ""}, + {"mesh.seat.node-build-go.tool.steps.shanks", "", ""}, + } { + got, ok := anyHolderSubject(bus.SeatVerb{Seat: "s", Verb: "steps", Subject: c.subject}, c.node) + if got != c.want || ok != (c.want != "") { + t.Errorf("%s on %q: %q %v", c.subject, c.node, got, ok) + } + } +}