From 3ad8ccbc06dc87602bfac5fc890de431e6c439fa Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 00:56:35 +0100 Subject: [PATCH] S16 QueueWaiting: a holder reads its own seat queue's waiting asks through the runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A holder's asks tool answers what waits on its seat's queue; the queue is its own store, so the read is the owner's, one shared form asked of the tool runner as mesh/queue.waiting. Builds: design 47 H2 §777, H-A-410 --- go/seat.go | 34 ++++++++++++++++++++++++++++++++++ go/state_history_test.go | 27 ++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/go/seat.go b/go/seat.go index c5a373b1..c903143f 100644 --- a/go/seat.go +++ b/go/seat.go @@ -264,3 +264,37 @@ func subjectMatches(pattern, subject string) bool { } return len(p) == len(s) } + +// WaitingAsk is one ask waiting in a seat's work queue, as the runtime reads it without taking it (design 47 H2 §777, +// H-A-410): the ask's id, the module that asked it and its age in seconds. +type WaitingAsk struct { + ID string `json:"id"` + Module string `json:"module"` + AgeSeconds float64 `json:"age_seconds"` +} + +// Waiting is the asks waiting in a seat's work queue, oldest first as the queue holds them; Capped says the runtime cut +// them at 768 KB. +type Waiting struct { + Asks []WaitingAsk `json:"asks"` + Capped bool `json:"capped"` +} + +// QueueWaiting is the asks waiting in the work queue of seat, this holder's own queue, which a holder's asks tool answers +// (design 47 H2 §777, H-A-410): asked of the runtime as mesh/queue.waiting, which reads the queue's waiting messages +// without taking them. A refusal is the runtime's error. +func QueueWaiting(seat string) (Waiting, error) { + c, err := live() + if err != nil { + return Waiting{}, err + } + raw, err := c.ask("mesh/queue.waiting", map[string]any{"seat": seat}, seatTimeout) + if err != nil { + return Waiting{}, err + } + var w Waiting + if err := json.Unmarshal(raw, &w); err != nil { + return Waiting{}, fmt.Errorf("the runtime answered the waiting asks of %s in no form this reads: %w", seat, err) + } + return w, nil +} diff --git a/go/state_history_test.go b/go/state_history_test.go index d490531d..8b34c95c 100644 --- a/go/state_history_test.go +++ b/go/state_history_test.go @@ -38,7 +38,7 @@ func historying(t *testing.T, answer func(message) map[string]any, run func()) [ if json.Unmarshal(lines.Bytes(), &m) != nil { continue } - if strings.HasPrefix(m.Method, "mesh/state.") { + if strings.HasPrefix(m.Method, "mesh/state.") || strings.HasPrefix(m.Method, "mesh/queue.") { amu.Lock() asked = append(asked, m) amu.Unlock() @@ -143,13 +143,23 @@ func TestHistoryIsEveryKeptValueOldestFirst(t *testing.T) { } // Info asks mesh/state.info with the state alone and hands back the bucket's fill against its caps, as the tool -// runner answers it (design 47 G §623); a refusal is the runtime's error. +// runner answers it (design 47 G §623); a refusal is the runtime's error. QueueWaiting asks mesh/queue.waiting with the +// seat alone and hands back its waiting asks and whether they were cut (design 47 H2 §777, H-A-410). func TestInfoIsTheBucketsFillAgainstItsCaps(t *testing.T) { var got *StateInfo var refused error + var waiting Waiting + var waitingRefused error asked := historying(t, func(m message) map[string]any { var p map[string]any _ = json.Unmarshal(m.Params, &p) + if m.Method == "mesh/queue.waiting" { + if p["seat"] != "mesh-wants" || len(p) != 1 { + return map[string]any{"error": map[string]any{"code": -32000, "message": "issued no queue of that seat"}} + } + return map[string]any{"result": map[string]any{"asks": []map[string]any{{"id": "main.9", "module": "mesh-delivery-pipeline", + "age_seconds": 42}, {"id": "main.10", "module": "mesh-delivery-pipeline", "age_seconds": 1.5}}, "capped": true}} + } if p["state"] != "issues" { return map[string]any{"error": map[string]any{"code": -32000, "message": "issues was issued no state"}} } @@ -164,8 +174,19 @@ func TestInfoIsTheBucketsFillAgainstItsCaps(t *testing.T) { if i, refused = State("elsewhere.issues").Info(); i != nil { t.Errorf("a refused info handed back %v", i) } + if waiting, err = QueueWaiting("mesh-wants"); err != nil { + t.Errorf("waiting: %v", err) + } + _, waitingRefused = QueueWaiting("node-build-go") }) - if len(asked) != 2 || asked[0].Method != "mesh/state.info" { + if w := waiting; !w.Capped || len(w.Asks) != 2 || w.Asks[0] != (WaitingAsk{ID: "main.9", Module: "mesh-delivery-pipeline", AgeSeconds: 42}) || + w.Asks[1].AgeSeconds != 1.5 { + t.Errorf("the waiting asks are %+v", w) + } + if waitingRefused == nil || !strings.Contains(waitingRefused.Error(), "issued no queue") { + t.Errorf("a refused waiting read answered %v", waitingRefused) + } + if len(asked) != 4 || asked[0].Method != "mesh/state.info" || asked[2].Method != "mesh/queue.waiting" { t.Fatalf("asked %+v", asked) } if got == nil || got.Bytes != 300 || got.MaxBytes != 1000 || got.Keys != 4 || got.Bucket != "issues_issues" || !got.KeyTTL {