From 62dce9fec7a4d4c776de246d130333d30cb8ba4f Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 9 Nov 2026 22:53:21 +0100 Subject: [PATCH] =?UTF-8?q?T1:=20the=20seat=20settle=20applies=20a=20delay?= =?UTF-8?q?ed=20nak=20with=20the=20bus's=20own=20delay=20(ADR=200664=20?= =?UTF-8?q?=C2=A71,=20issue=201748)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ --- node-tools/internal/bus/seat_pull.go | 20 ++++++++++++++++++- node-tools/internal/bus/seat_pull_test.go | 15 ++++++++++++++ node-tools/internal/runtime/runtime.go | 14 ++++++++++--- .../internal/runtime/seat_traffic_test.go | 11 ++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/node-tools/internal/bus/seat_pull.go b/node-tools/internal/bus/seat_pull.go index de013ba..d0e4625 100644 --- a/node-tools/internal/bus/seat_pull.go +++ b/node-tools/internal/bus/seat_pull.go @@ -147,11 +147,27 @@ const ( SettleNak = "nak" // handed back, to be delivered again at once SettleTerm = "term" // dropped SettleProgress = "progress" // still being worked: its acknowledgement wait starts again + // SettleNakAfter hands the message back to be delivered again after a delay: the bus's own redelivery, so no part + // keeps a timer for a step given again (novox/hq ADR 0664 ยง1; issue 1748). SeatSettleAfter gives it. + SettleNakAfter = "nak-after" ) // SeatSettle gives the message module pulled under id its fate. A message pulled for another module, or settled // already, is refused. func (c *Conn) SeatSettle(module, id, fate string) error { + return c.settle(module, id, fate, 0) +} + +// SeatSettleAfter hands the message module pulled under id back to be delivered again after delay (SettleNakAfter), +// counting one more delivery. A delay of 0 or below is refused and settles nothing. +func (c *Conn) SeatSettleAfter(module, id string, delay time.Duration) error { + if delay <= 0 { + return fmt.Errorf("a message given again after a delay needs a delay above 0, not %s", delay) + } + return c.settle(module, id, SettleNakAfter, delay) +} + +func (c *Conn) settle(module, id, fate string, delay time.Duration) error { seatPulls.mu.Lock() p, ok := seatPulls.held[id] if ok && p.module != module { @@ -173,9 +189,11 @@ func (c *Conn) SeatSettle(module, id, fate string) error { return p.msg.Term() case SettleProgress: return p.msg.InProgress() + case SettleNakAfter: + return p.msg.NakWithDelay(delay) } seatPulls.mu.Lock() seatPulls.held[id] = p // an unknown fate settles nothing seatPulls.mu.Unlock() - return fmt.Errorf("a pulled message's fate is ack, nak, term or progress, not %q", fate) + return fmt.Errorf("a pulled message's fate is ack, nak, nak-after, term or progress, not %q", fate) } diff --git a/node-tools/internal/bus/seat_pull_test.go b/node-tools/internal/bus/seat_pull_test.go index 0aa53e6..c43c98d 100644 --- a/node-tools/internal/bus/seat_pull_test.go +++ b/node-tools/internal/bus/seat_pull_test.go @@ -58,6 +58,21 @@ func TestAHolderPullsOneMessageWhenItHasRoom(t *testing.T) { if err != nil || again == nil || string(again.Body) != `{"id":"a2"}` || again.Delivered != 2 { t.Fatalf("the message handed back = %+v, %v", again, err) } + // Issue 1748: a message settled with a delay is not given again at once, is after it, one delivery higher; a delay + // of 0 settles nothing. + if err := conn.SeatSettleAfter("messenger", again.ID, 0); err == nil { + t.Error("a delay of 0 was accepted") + } + if err := conn.SeatSettleAfter("messenger", again.ID, 300*time.Millisecond); err != nil { + t.Fatal(err) + } + if early, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 0); err != nil || early != nil { + t.Fatalf("a message given again after a delay came at once: %+v, %v", early, err) + } + late, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 2*time.Second) + if err != nil || late == nil || late.Delivered != 3 { + t.Fatalf("the message given again after its delay = %+v, %v", late, err) + } if _, err := conn.SeatPull("telegram", "SEAT_OPERATOR_CHANNEL_worker", 0); err == nil || !strings.Contains(err.Error(), "membership lists") { t.Errorf("a channel pulled the router's work: %v", err) } diff --git a/node-tools/internal/runtime/runtime.go b/node-tools/internal/runtime/runtime.go index 4680aa4..84580ef 100644 --- a/node-tools/internal/runtime/runtime.go +++ b/node-tools/internal/runtime/runtime.go @@ -1256,8 +1256,10 @@ type seatAsked struct { Bucket string `json:"bucket"` Key string `json:"key"` // WaitMS is how long a pull waits for a message (none when 0); Fate what a settle gives one (issue 1887 A11). - WaitMS int `json:"wait_ms"` - Fate string `json:"fate"` + WaitMS int `json:"wait_ms"` + // DelayMS is how long a settle with the fate nak-after waits before the bus gives the message again. + DelayMS int64 `json:"delay_ms"` + Fate string `json:"fate"` } // Seat answers a bundle's seat traffic, each as the module and only as far as its membership lists: @@ -1300,7 +1302,13 @@ func (b *moduleBus) Seat(verb string, params json.RawMessage, handOn func(string } return json.Marshal(p) case "settle": - if err := conn.SeatSettle(b.module, asked.ID, asked.Fate); err != nil { + settle := func() error { return conn.SeatSettle(b.module, asked.ID, asked.Fate) } + if asked.Fate == bus.SettleNakAfter { + settle = func() error { + return conn.SeatSettleAfter(b.module, asked.ID, time.Duration(asked.DelayMS)*time.Millisecond) + } + } + if err := settle(); err != nil { return nil, err } return json.RawMessage(`{}`), nil diff --git a/node-tools/internal/runtime/seat_traffic_test.go b/node-tools/internal/runtime/seat_traffic_test.go index 9857a32..357e6f8 100644 --- a/node-tools/internal/runtime/seat_traffic_test.go +++ b/node-tools/internal/runtime/seat_traffic_test.go @@ -202,6 +202,17 @@ func TestABundlePullsAndSettlesThroughItsModulesBus(t *testing.T) { if _, err := elsewhere.Seat("settle", json.RawMessage(`{"id":"`+p.ID+`","fate":"ack"}`), nil); err == nil { t.Fatal("another module settled the pulled ask") } + // Issue 1748: a settle with the fate nak-after and no delay settles nothing; with a delay the ask comes again. + if _, err := building.Seat("settle", json.RawMessage(`{"id":"`+p.ID+`","fate":"nak-after"}`), nil); err == nil { + t.Fatal("a delayed nak without a delay was accepted") + } + if _, err := building.Seat("settle", json.RawMessage(`{"id":"`+p.ID+`","fate":"nak-after","delay_ms":100}`), nil); err != nil { + t.Fatal(err) + } + raw, err = building.Seat("pull", json.RawMessage(`{"worker":"SEAT_NODE_BUILD_GO_DELIVERY_worker","wait_ms":2000}`), nil) + if err != nil || json.Unmarshal(raw, &p) != nil || p.Delivered != 2 { + t.Fatalf("the ask given again after its delay = %s, %v", raw, err) + } if _, err := building.Seat("settle", json.RawMessage(`{"id":"`+p.ID+`","fate":"ack"}`), nil); err != nil { t.Fatal(err) }