From 7ade318cfac9034cb32ee7ee17d85cdb60780e2f Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 19 Nov 2026 23:07:09 +0100 Subject: [PATCH] =?UTF-8?q?mesh-config:=20one=20deadline=20timer=20for=20t?= =?UTF-8?q?he=20earliest=20real=20deadline,=20its=20floor=20a=20setting=20?= =?UTF-8?q?(issue=201982;=20ADR=200681=20=C2=A71;=20A-490l)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The one timer left is set for the earliest of three deadlines: a waiting proposal's end, an unanswered retirement's second ask, and a rename window's seven-day held finding, which is now judged at its deadline (JudgeHeldWindows) so it comes in a quiet mesh too. Its floor is the module's setting deadline-floor-seconds (default 60), not a constant. Tests: an integration test counts asks by key and fails on any `seat:git.*` over the whole run (ADR 0681, How it is checked, clause 1); a unit test shows an approved proposal records a hand act naming no pull request; another that a stored proposal naming a pull request is refused on approval, saying why. Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- modules/mesh-config/cmd/mesh-config/main.go | 24 ++++++++- .../mesh-config/cmd/mesh-config/proposals.go | 14 +++++- .../cmd/mesh-config/proposals_test.go | 39 +++++++++++++++ .../cmd/mesh-config/quiet_integration_test.go | 6 ++- .../mesh-config/cmd/mesh-config/quiet_test.go | 49 +++++++++++++++++++ .../mesh-config/cmd/mesh-config/renames.go | 14 ++++++ .../cmd/mesh-config/whole_integration_test.go | 21 +++++++- modules/mesh-config/module.json | 13 ++++- 8 files changed, 173 insertions(+), 7 deletions(-) diff --git a/modules/mesh-config/cmd/mesh-config/main.go b/modules/mesh-config/cmd/mesh-config/main.go index 3c05a9130..15d4d8df5 100644 --- a/modules/mesh-config/cmd/mesh-config/main.go +++ b/modules/mesh-config/cmd/mesh-config/main.go @@ -268,6 +268,23 @@ func hearing(c *Config) { }() } +// DeadlineFloorKey is this module's setting for the least wait of its one deadline timer, in seconds (module.json `config`). +const DeadlineFloorKey = "deadline-floor-seconds" + +// DefaultDeadlineFloor is the floor when the setting cannot be read. +const DefaultDeadlineFloor = time.Minute + +// floorOf is the floor a setting's value names: its seconds, or the default for a value that is not a positive number. +func floorOf(raw json.RawMessage, err error) time.Duration { + var seconds float64 + if err != nil || json.Unmarshal(raw, &seconds) != nil || seconds < 1 { + return DefaultDeadlineFloor + } + return time.Duration(seconds * float64(time.Second)) +} + +func deadlineFloor() time.Duration { return floorOf(stdio.Config(DeadlineFloorKey)) } + // deciding reads the router's record of every waiting ask once at start, which finds an answer said while this module was // down, and then when the router says an ask ended (hearing's `decided` subscription calls Decide itself) or the next // deadline of a waiting proposal or retirement passes: one timer for the earliest, set again whenever a proposal or a @@ -282,6 +299,9 @@ func deciding(c *Config, rearm chan struct{}) { for _, s := range said { logf("[mesh-config] %s", s) } + if err := c.JudgeHeldWindows(); err != nil { + logf("[mesh-config] the held windows cannot be judged: %v", err) + } } decide() for { @@ -290,8 +310,8 @@ func deciding(c *Config, rearm chan struct{}) { <-rearm continue } - // Not sooner than a minute: a deadline that passed and was not settled (an ask the router refused) is tried again, not spun on. - timer := time.NewTimer(max(time.Until(at), time.Minute)) + // Not sooner than the floor: a deadline that passed and was not settled (an ask the router refused) is tried again, not spun on. + timer := time.NewTimer(max(time.Until(at), deadlineFloor())) select { case <-timer.C: decide() diff --git a/modules/mesh-config/cmd/mesh-config/proposals.go b/modules/mesh-config/cmd/mesh-config/proposals.go index 33895c2f8..f821555bb 100644 --- a/modules/mesh-config/cmd/mesh-config/proposals.go +++ b/modules/mesh-config/cmd/mesh-config/proposals.go @@ -871,7 +871,8 @@ func (c *Config) HeardEnd(w oc.Warrant) []string { // NextDeadline is when a waiting proposal or retirement is next judged for want of an answer: a proposal with no record // at the router ends an hour after its ask lapses (Decide), and a retirement left unanswered is asked once more after -// HeldFinding. The earliest of them; false when nothing waits on a time. +// HeldFinding, and an open rename window's held finding comes after HeldFinding too (lead answer A-490l). The earliest of +// them; false when nothing waits on a time. func (c *Config) NextDeadline() (time.Time, bool) { c.mu.Lock() defer c.mu.Unlock() @@ -895,6 +896,17 @@ func (c *Config) NextDeadline() (time.Time, bool) { } } } + // An open rename window reaches its held finding after HeldFinding (renames.go): its deadline, while it lies ahead. + if renames, err := c.readRenames(); err == nil { + now := c.now() + for _, r := range renames { + for _, node := range r.Open() { + if d := r.Nodes[node].Since.Add(HeldFinding); d.After(now) { + earlier(d) + } + } + } + } return at, !at.IsZero() } diff --git a/modules/mesh-config/cmd/mesh-config/proposals_test.go b/modules/mesh-config/cmd/mesh-config/proposals_test.go index da09744a5..af8c99587 100644 --- a/modules/mesh-config/cmd/mesh-config/proposals_test.go +++ b/modules/mesh-config/cmd/mesh-config/proposals_test.go @@ -590,3 +590,42 @@ func TestAnOwnersListOfNamesWithDigitsIsProposed(t *testing.T) { t.Fatalf("the owners were not put to the operator: %+v, asked on %v", a, r.subjects) } } + +// **An approved proposal records a hand act that names no pull request** (ADR 0681 clause 1: nothing it records as a hand act is a +// held value). +func TestAnApprovedProposalsHandActNamesNoPullRequest(t *testing.T) { + c, m, r := aProposingMesh(t) + a := propose(t, c, Call{Key: "font-size", Value: 12.0, Node: "g14"}) + r.choose(t, a.Proposal, OptionApprove, nil) + m.handActs = nil + if said, err := c.Decide(); err != nil || len(said) == 0 { + t.Fatalf("decide: %v, %v", said, err) + } + if len(m.handActs) == 0 { + t.Fatal("the approval recorded no hand act") + } + for _, act := range m.handActs { + if strings.Contains(strings.ToLower(act), "pull") || strings.Contains(act, "#") { + t.Errorf("a hand act names a pull request: %q", act) + } + } +} + +// A stored proposal that names a pull request is refused on its approval, saying why, and nothing is set (lead answer A-490l). +func TestAStoredProposalNamingAPullRequestIsRefusedOnApproval(t *testing.T) { + c, m, r := aProposingMesh(t) + a := propose(t, c, Call{Key: "font-size", Value: 12.0, Node: "g14"}) + p := storedProposal(t, m, a.Proposal) + p.Pull = "novox/mesh-catalog#7" + if err := m.Put(ProposalsState, p.ID, p); err != nil { + t.Fatal(err) + } + r.choose(t, a.Proposal, OptionApprove, nil) + said, _ := c.Decide() + if got := storedProposal(t, m, a.Proposal); got.State == ProposalApproved || len(said) == 0 || !strings.Contains(strings.Join(said, " "), "pull request") { + t.Errorf("said %v, proposal %+v", said, got) + } + if _, ok := storedValue(t, m, "node.g14.font-size"); ok { + t.Error("a value was set on a proposal that names a pull request") + } +} diff --git a/modules/mesh-config/cmd/mesh-config/quiet_integration_test.go b/modules/mesh-config/cmd/mesh-config/quiet_integration_test.go index 335e23949..3070fd7e9 100644 --- a/modules/mesh-config/cmd/mesh-config/quiet_integration_test.go +++ b/modules/mesh-config/cmd/mesh-config/quiet_integration_test.go @@ -92,14 +92,16 @@ func TestConfigWholeAsksTheBusForNothingWhileNoInputChanges(t *testing.T) { t.Fatal(err) } - // No input changes: the delivery says it delivered, a node-engine says what it reads, and the catalog says a manifest was accepted that no retirement waits on. Each is heard and none is a pass: - // nothing is asked of the bus. (The module has no timer: no minute, five or otherwise, asks it anything.) + // No input changes: the delivery says it delivered and a node-engine says what it reads, with no rename window open and no retirement + // waiting. Each is heard and none is a pass: nothing is asked of the bus. (The module has no polling timer; its one deadline + // timer is set for a real deadline, and none is near.) before, putsBefore := p.snapshot() for i := 0; i < 20; i++ { p.event("mesh-delivery-view.delivered", map[string]any{"revision": "r"}) p.event("node-engine.manifest-reads-changed", map[string]any{"node": "g14"}) } after, putsAfter := p.snapshot() + p.noGitAsk() if n := asked(before, after, "mesh/state.get", "mesh/state.keys", "mesh/state.watch", "mesh/state.put", "mesh/state.create", "mesh/state.update", "mesh/state.delete", "mesh/ask"); n != 0 || len(putsAfter) != len(putsBefore) { t.Errorf("40 events that move nothing asked %d requests of the bus (%v); wrote %v", n, after, putsAfter[len(putsBefore):]) diff --git a/modules/mesh-config/cmd/mesh-config/quiet_test.go b/modules/mesh-config/cmd/mesh-config/quiet_test.go index d5e25c429..1995523e3 100644 --- a/modules/mesh-config/cmd/mesh-config/quiet_test.go +++ b/modules/mesh-config/cmd/mesh-config/quiet_test.go @@ -5,6 +5,7 @@ package main import ( "encoding/json" + "errors" "strings" "sync" "testing" @@ -271,3 +272,51 @@ func TestTheVerbKnowsNoPullRequest(t *testing.T) { } } } + +// The deadline timer's floor is the setting deadline-floor-seconds, the default for a value that is not a positive number. +func TestTheDeadlineFloorIsTheSettingOrItsDefault(t *testing.T) { + for _, c := range []struct { + raw string + err error + want time.Duration + }{ + {`5`, nil, 5 * time.Second}, {`0`, nil, DefaultDeadlineFloor}, {`"x"`, nil, DefaultDeadlineFloor}, + {``, errors.New("not declared"), DefaultDeadlineFloor}, {`90`, nil, 90 * time.Second}, + } { + if got := floorOf(json.RawMessage(c.raw), c.err); got != c.want { + t.Errorf("floor of %q (%v) = %v, want %v", c.raw, c.err, got, c.want) + } + } +} + +// **A rename window held seven days comes as a finding in a quiet mesh** (lead answer A-490l): the deadline is the window's +// seventh day, the finding is written at it with no resolution pass, and a window that is not yet seven days old writes none. +func TestAHeldWindowIsAFindingAtItsDeadlineWithNoPass(t *testing.T) { + c, m, _, clock := aRenamingMesh(t) + m.declare(t, "player", newPlayer) + if _, err := c.Reconcile(); err != nil { + t.Fatal(err) + } + at, ok := c.NextDeadline() + if !ok || !at.Equal(clock.Add(HeldFinding)) { + t.Fatalf("deadline %v, %v; want the window's seventh day %v", at, ok, clock.Add(HeldFinding)) + } + if err := c.JudgeHeldWindows(); err != nil || len(findingsOf(t, m, FindingWindowHeld)) != 0 { + t.Fatalf("a young window wrote a finding (%v)", err) + } + *clock = at + cs := &countingStore{memStore: m, reads: map[string]int{}} + c.Store = cs + if err := c.JudgeHeldWindows(); err != nil { + t.Fatal(err) + } + if fs := findingsOf(t, m, FindingWindowHeld); len(fs) != 2 { + t.Errorf("findings %+v, want one for each node holding the window", fs) + } + if got := cs.readsExcept(RenamesState); len(got) != 0 { + t.Errorf("judging the held windows read %v", got) + } + if _, ok := c.NextDeadline(); ok { + t.Error("a deadline is still set once the finding is written") + } +} diff --git a/modules/mesh-config/cmd/mesh-config/renames.go b/modules/mesh-config/cmd/mesh-config/renames.go index 64417796f..f82a03879 100644 --- a/modules/mesh-config/cmd/mesh-config/renames.go +++ b/modules/mesh-config/cmd/mesh-config/renames.go @@ -487,6 +487,20 @@ func (c *Config) RenameClose(module, to, node, why string) (any, error) { return map[string]any{"closed": node, "open": r.Open()}, nil } +// JudgeHeldWindows writes the finding of each window held open past HeldFinding, and clears one that is not, from the renames +// kept: run at start and at the deadline the next window reaches (NextDeadline), so the finding comes in a quiet mesh too (lead +// answer A-490l); it reads no source and asks nothing. +func (c *Config) JudgeHeldWindows() error { + c.mu.Lock() + defer c.mu.Unlock() + renames, err := c.readRenames() + if err != nil { + return err + } + c.sweepRenameFindings(&Sources{Renames: renames}, c.now()) + return nil +} + // sweepRenameFindings writes a finding for each window held open past HeldFinding, naming the node, and clears one // whose window closed. func (c *Config) sweepRenameFindings(s *Sources, now time.Time) { diff --git a/modules/mesh-config/cmd/mesh-config/whole_integration_test.go b/modules/mesh-config/cmd/mesh-config/whole_integration_test.go index f004ff88c..a32671dc3 100644 --- a/modules/mesh-config/cmd/mesh-config/whole_integration_test.go +++ b/modules/mesh-config/cmd/mesh-config/whole_integration_test.go @@ -83,6 +83,7 @@ type player struct { catRev int64 // calls counts what the module asked of the runtime, by method (and by key for an ask); puts are the keys it wrote, "/". calls map[string]int + asks map[string]int // the asks of tools and seat verbs, by key puts []string // stop ends the module this player runs: the restart of a module is the old process gone and a new one started. stop func() @@ -368,6 +369,9 @@ func (p *player) handle(m wire) { Body json.RawMessage `json:"body"` } _ = json.Unmarshal(m.Params, &q) + p.mu.Lock() + p.asks[q.Key]++ + p.mu.Unlock() p.answer(m.ID, p.asked(q.Key, q.Body), nil) default: p.answer(m.ID, nil, errors.New("nats: no responders available for request")) @@ -687,7 +691,7 @@ func start(t *testing.T, bin string, js jetstream.JetStream, router *standIn, ha cmd.Stderr = os.Stderr p := &player{t: t, ctx: ctx, js: js, router: router, in: stdin, pending: map[string]chan wire{}, haves: haves, readers: readers, owned: map[string]*ownedState{}, catalog: map[string]catalog.CatalogEntry{}, byFp: map[string]catalog.CatalogEntry{}, - calls: map[string]int{}} + calls: map[string]int{}, asks: map[string]int{}} for _, f := range followed { p.own(f.Read) } @@ -882,6 +886,21 @@ func TestConfigWholeRenamesAndRetiresAgainstTheBus(t *testing.T) { p2.conforms(EventRetiring, &meshconfig.RetiringHolderEvent{}, meshconfig.HolderSubjectRetiring) p2.conforms(EventRetired, &meshconfig.RetiredHolderEvent{}, meshconfig.HolderSubjectRetired) eventually(t, "the retirement is dropped", func() bool { _, ok := p2.get(RetiringState, "radio.band"); return !ok }) + p.noGitAsk() + p2.noGitAsk() +} + +// noGitAsk fails when the module asked the seat git for anything over the whole run (ADR 0681 clause 1: it calls no +// `seat:git.pull`, and no other verb of the seat git is its). +func (p *player) noGitAsk() { + p.t.Helper() + p.mu.Lock() + defer p.mu.Unlock() + for key, n := range p.asks { + if strings.HasPrefix(key, "seat:git.") { + p.t.Errorf("the module asked %s %d times: it holds no value for a pull request", key, n) + } + } } // streamCarries says whether the module's manifest names event among its own streams' events. diff --git a/modules/mesh-config/module.json b/modules/mesh-config/module.json index c6d12e565..c54954179 100644 --- a/modules/mesh-config/module.json +++ b/modules/mesh-config/module.json @@ -125,5 +125,16 @@ "max-age-days": 7, "max-mib": 16 } - ] + ], + "config": { + "deadline-floor-seconds": { + "type": "number", + "description": "the least wait, in seconds, of mesh-config's one deadline timer: it is set for the earliest real deadline it holds (a waiting proposal's end, an unanswered retirement's second ask, a rename window's seven-day held finding) and never sooner than this after a look, so a deadline passed and not settled is tried again, not spun on (lead answer A-490l, ADR 0681).", + "minimum": 1, + "maximum": 3600, + "trusted": false, + "default": 60, + "runtime": true + } + } }