Design 47 H2: the kept call paced, take once, page by cursor, settings, class and caps, check-needs #209

Merged
mesh-tools merged 35 commits from feat/47-H2 into main 2026-11-22 03:50:59 +00:00
2 changed files with 58 additions and 3 deletions
Showing only changes of commit 3ad8ccbc06 - Show all commits
+34
View File
@@ -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
}
+24 -3
View File
@@ -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 {