Keep what discovery heard when a round hears nothing, and fetch only changed announcements (issue 554)
mesh/merge-gate pass: builds mesh-tools, node-tools → ace, g14, novox, shanks; no bus step; every machine composes with the change as it did without (4 of …
mesh/repo-check pass: THE CHANGE ALTERS ITS OWN CHECK (merge-check.sh): main's version judged it; the change's judges the pull requests after it merges; it…
mesh/delivery delivered

A round in which no PING reached the laptop's console within the 750 ms window
was taken as the mesh's answer that nothing is there, and replaced the index:
every seat and module call was refused for five seconds at a time. Discovery
now waits up to its patience for a first PING, a round that heard nothing is
not kept, a runtime not heard this round is resolved from what it announced
last (said with its age), and a round that misses runtimes is logged once.
A PING carries a digest of what the instance serves, so an unchanged
announcement is not pulled again every round (some 880 kB to the laptop).
This commit is contained in:
jochen
2026-10-12 13:56:50 +02:00
parent 09c5f809cb
commit 424a7eec82
11 changed files with 678 additions and 45 deletions
+128 -10
View File
@@ -134,6 +134,42 @@ type index struct {
// Replaces is what each verb and tool replaces, from the controller's records (novox/hq ADR 0245):
// `seat:<seat>.<verb>` and `<module>.<tool>`.
Replaces map[string][]string
// Earlier is every runtime not heard this round whose last answer, within RuntimeForgotten, this
// index holds instead (novox/hq issue 554), by runtimeKey: when it was heard.
Earlier map[string]time.Time
// Stale is every module on a machine (`mod:<module>@<node>`) and every seat's holder
// (`seat:<seat>@<node>`) this index knows only from an earlier answer: from whom, and when.
Stale map[string]staleFrom
}
// staleFrom is where an address known only from an earlier round of discovery was heard.
type staleFrom struct {
Runtime string
Machine string
At time.Time
}
// say is the sentence a call or a description carries for it.
func (f staleFrom) say() string {
who := f.Runtime
if f.Machine != "" {
who += " on " + f.Machine
}
return fmt.Sprintf("found from what %s announced %s ago: it did not answer the latest round of discovery",
who, time.Since(f.At).Round(time.Second))
}
// earlier is a runtime's last answer, used for a round that did not hear it.
type earlier struct {
Heard announce.Heard
At time.Time
}
func endpointKey(e announce.Endpoint) string {
if e.Kind == announce.KindSeat {
return "seat:" + e.Seat + "@" + e.Node
}
return "mod:" + e.Module + "@" + e.Node
}
// unheard is one runtime discovery did not hear in full, and why.
@@ -237,7 +273,11 @@ type recordedMachine struct {
// indexOn asks the mesh what it holds (novox/hq ADR 0197): what answers, from every runtime's own
// announcement on the bus — one `$SRV.INFO` request — and what should, from the controller's records
// read as JSON. Nothing is inferred from a roster and nothing is parsed from print.
func indexOn(conn *bus.Conn) (*index, error) {
//
// `held` is what the console holds already, so an instance whose announcement is unchanged is not
// asked for it again; `before` is the last answer of every runtime this round did not hear, which the
// index holds instead, marked with its age (novox/hq issue 554).
func indexOn(conn *bus.Conn, held announce.Known, before func(announce.Discovery) []earlier) (*index, error) {
var wg sync.WaitGroup
var nodesOut, modulesOut string
var toolsAnswer json.RawMessage
@@ -252,19 +292,44 @@ func indexOn(conn *bus.Conn) (*index, error) {
toolsAnswer = got.Result
}
}()
d, err := announce.Gather(conn)
d, err := announce.Gather(conn, held)
wg.Wait()
if err != nil {
return nil, err
}
var endpoints []announce.Endpoint
fresh := map[string]bool{}
for _, h := range d.Heard {
endpoints = append(endpoints, announce.Endpoints(h.Info)...)
for _, e := range announce.Endpoints(h.Info) {
fresh[endpointKey(e)] = true
endpoints = append(endpoints, e)
}
}
// **A runtime not heard this round is not gone** (novox/hq issue 554): a round in which no answer
// crossed the laptop's link in time replaced a full index with an empty one, and every seat and
// module call was refused. What it announced last, within RuntimeForgotten, stands — said with its age.
stale := map[string]staleFrom{}
earlierAt := map[string]time.Time{}
if before != nil {
for _, b := range before(d) {
earlierAt[runtimeKey(b.Heard.Info.Name, b.Heard.Info.ID)] = b.At
for _, e := range announce.Endpoints(b.Heard.Info) {
k := endpointKey(e)
if fresh[k] {
continue
}
if _, have := stale[k]; !have {
stale[k] = staleFrom{Runtime: b.Heard.Info.Name, Machine: b.Heard.Machine(), At: b.At}
}
endpoints = append(endpoints, e)
}
}
}
x, announced, machines := indexOfEndpoints(endpoints)
l := x.Listing
x.Discovery = d
x.Stale, x.Earlier = stale, earlierAt
for _, s := range d.Silent {
x.Unheard = append(x.Unheard, unheard{Runtime: s.Name, Machine: s.Machine,
Why: fmt.Sprintf("it answered PING; what it serves did not arrive within %s", announce.Patience)})
@@ -325,6 +390,10 @@ func containsHolder(hs []holder, h holder) bool {
func (s *Surface) index() (*index, error) { return s.indexAsked(false) }
// indexAsked is what the mesh answered, asked again when `fresh` or when the kept answer is old.
//
// **A round that heard nothing is not kept** (novox/hq issue 554): the index it gives holds what every
// runtime announced last, marked with its age, and the next question asks again rather than living
// with it for IndexKept.
func (s *Surface) indexAsked(fresh bool) (*index, error) {
s.mu.Lock()
if !fresh && s.idx != nil && time.Since(s.idxAt) <= IndexKept {
@@ -333,13 +402,17 @@ func (s *Surface) indexAsked(fresh bool) (*index, error) {
return x, nil
}
s.mu.Unlock()
x, err := indexOn(s.conn)
x, err := indexOn(s.conn, s.held, s.before)
if err != nil {
return nil, err
}
s.mu.Lock()
s.remember(x)
s.idx, s.idxAt = x, time.Now()
s.sayRound(x)
s.idx = x
if !x.Discovery.Empty() {
s.idxAt = time.Now()
}
s.mu.Unlock()
return x, nil
}
@@ -450,6 +523,26 @@ type target struct {
Node string
Tool Tool
Seat bool
// Stale is set when the target is known only from an earlier round of discovery (novox/hq issue 554).
Stale *staleFrom
}
// staleOf is where a target was heard, when every place it answers is known only from an earlier round.
func (x *index) staleOf(keys []string) *staleFrom {
if len(keys) == 0 || len(x.Stale) == 0 {
return nil
}
var first *staleFrom
for _, k := range keys {
f, ok := x.Stale[k]
if !ok {
return nil
}
if first == nil {
first = &f
}
}
return first
}
// resolve turns an address into exactly one target, or says why it cannot.
@@ -487,12 +580,17 @@ func resolve(x *index, address string) (target, error) {
return target{}, fmt.Errorf("%s is held once per machine: write <node>/%s — it is held on %s",
prefix, rest, orNobody(nodesOf(s.Holders)))
}
return target{Address: node + "/" + rest, Key: "seat:" + rest + "@" + node, Name: rest, Node: node, Tool: *verb, Seat: true}, nil
return target{Address: node + "/" + rest, Key: "seat:" + rest + "@" + node, Name: rest, Node: node, Tool: *verb, Seat: true,
Stale: x.staleOf([]string{"seat:" + prefix + "@" + node})}, nil
}
if node != "" {
return target{}, fmt.Errorf("%s is held once for the whole mesh: write %s, without a machine", prefix, rest)
}
return target{Address: rest, Key: "seat:" + rest, Name: rest, Tool: *verb, Seat: true}, nil
var holders []string
for _, h := range s.Holders {
holders = append(holders, "seat:"+prefix+"@"+h.Node)
}
return target{Address: rest, Key: "seat:" + rest, Name: rest, Tool: *verb, Seat: true, Stale: x.staleOf(holders)}, nil
}
m := x.Modules[prefix]
@@ -509,6 +607,11 @@ func resolve(x *index, address string) (target, error) {
return target{}, fmt.Errorf("nothing that answered discovery is called %s, but not every runtime answered: %s — "+
"%s may be theirs. Ask again in a moment; mesh_runtimes shows which runtimes answered", prefix, sayUnheard(x.Unheard), prefix)
}
if x.Discovery.Empty() {
return target{}, fmt.Errorf("nothing answered discovery at all within %s, not even PING, and this console holds no "+
"earlier answer: whether anything is called %s is not known. Ask again in a moment; mesh_runtimes shows which "+
"runtimes answered", x.Discovery.Waited.Round(time.Millisecond), prefix)
}
return target{}, fmt.Errorf("nothing in the mesh is called %s: no seat, and no module that answers tools. "+
"mesh_search finds a tool by words", prefix)
}
@@ -521,7 +624,11 @@ func resolve(x *index, address string) (target, error) {
return target{}, fmt.Errorf("%s keeps state on each machine it runs on, so a call names the machine: "+
"write <node>/%s — it runs on %s", prefix, rest, orNobody(m.On))
}
return target{Address: rest, Key: rest, Name: rest, Tool: *tool}, nil
var on []string
for _, n := range m.On {
on = append(on, "mod:"+prefix+"@"+n)
}
return target{Address: rest, Key: rest, Name: rest, Tool: *tool, Stale: x.staleOf(on)}, nil
}
if len(m.On) > 0 && !contains(m.On, node) {
if us := x.unheardOn(node); len(us) > 0 || contains(x.Recorded[prefix], node) {
@@ -534,7 +641,8 @@ func resolve(x *index, address string) (target, error) {
}
return target{}, fmt.Errorf("%s does not run on %s; it runs on %s", prefix, node, orNobody(m.On))
}
return target{Address: node + "/" + rest, Key: rest + "@" + node, Name: rest, Node: node, Tool: *tool}, nil
return target{Address: node + "/" + rest, Key: rest + "@" + node, Name: rest, Node: node, Tool: *tool,
Stale: x.staleOf([]string{"mod:" + prefix + "@" + node})}, nil
}
// unheardOnAny is what is unheard on any of these machines.
@@ -861,6 +969,9 @@ func (s *Surface) discover(name string, args map[string]any) map[string]any {
if r := x.Replaces[key]; len(r) > 0 {
described["instead_of"] = r
}
if t.Stale != nil {
described["found"] = t.Stale.say()
}
return answerText(described)
case verbCall:
@@ -880,12 +991,19 @@ func (s *Surface) discover(name string, args map[string]any) map[string]any {
got, err = callTool(s.conn, t.Key, callArgs, nil, x.Listing)
}
if err != nil {
return failure(whyItFailed(t.Address, err))
why := whyItFailed(t.Address, err)
if t.Stale != nil {
why += " (" + t.Stale.say() + ")"
}
return failure(why)
}
content := []map[string]any{{"type": "text", "text": pretty(got.Result)}}
if got.Node != "" {
content = append(content, map[string]any{"type": "text", "text": "answered by " + got.Node})
}
if t.Stale != nil {
content = append(content, map[string]any{"type": "text", "text": t.Stale.say()})
}
return map[string]any{"content": content}
}
return failure("no discovery verb " + name)
+1 -1
View File
@@ -62,7 +62,7 @@ func toolKey(name string, seats Seats) string {
// toolsOn is the flat catalogue (MESH_CONSOLE_FLAT=1): what announced itself on the bus, every
// tool and seat verb, and the assignments with tools that did not (novox/hq ADR 0197).
func toolsOn(conn *bus.Conn) (*Listing, error) {
x, err := indexOn(conn)
x, err := indexOn(conn, nil, nil)
if err != nil {
return nil, err
}
@@ -0,0 +1,151 @@
package console
import (
"encoding/json"
"fmt"
"strings"
"sync"
"testing"
"time"
"github.com/novox/mesh-tools/node-tools/internal/announce"
mt "github.com/novox/mesh-tools/node-tools/internal/meshtest"
)
// novox/hq issue 554, reproduced: the laptop's console heard every runtime, then a round in which
// nothing answered discovery in time — and every seat and module call was refused ("it answered
// discovery 2s ago, not now") for the five seconds that round was kept, again and again. Now a call
// is resolved against what the runtime announced last, says how old that is, and reaches the tool; the
// empty round is logged once, is not kept, and the next question asks again.
func TestACallAfterARoundThatHeardNothingUsesWhatWasHeardBefore(t *testing.T) {
keptWas, patienceWas := IndexKept, announce.Patience
IndexKept, announce.Patience = 0, 1200*time.Millisecond
t.Cleanup(func() { IndexKept, announce.Patience = keptWas, patienceWas })
mt.New(t)
// The tools answer on their own connection; discovery is answered on another, which goes quiet.
tools := connect(t, "node-tools", "laptop")
stopTool, err := tools.HandleSubject("mesh.mod.slack.tool.slack_check.laptop", func(json.RawMessage) (any, error) {
return map[string]any{"ok": true}, nil
})
if err != nil {
t.Fatal(err)
}
t.Cleanup(stopTool)
stopSeat, err := tools.HandleSubject("mesh.seat.issue-tracker.tool.list", func(json.RawMessage) (any, error) {
return map[string]any{"issues": []int{554}}, nil
})
if err != nil {
t.Fatal(err)
}
t.Cleanup(stopSeat)
tools.Flush()
endpoints := []announce.Endpoint{
{Kind: announce.KindTool, Module: "slack", Tool: "slack_check", Node: "laptop", Subject: "mesh.mod.slack.tool.slack_check.laptop"},
{Kind: announce.KindSeat, Module: "issue-tracker", Seat: "issue-tracker", Tool: "list", Scope: "mesh", Node: "laptop",
Schema: json.RawMessage(`{}`), Subject: "mesh.seat.issue-tracker.tool.list"},
}
announcing := connect(t, "node-tools", "laptop")
stopAnnounce, err := announce.Serve(announcing, announce.Service{Name: "node-tools", ID: "laptop",
Metadata: map[string]string{"node": "laptop"}}, func() []announce.Endpoint { return endpoints })
if err != nil {
t.Fatal(err)
}
announcing.Flush()
console := connect(t, "node-tools", "laptop-console")
var mu sync.Mutex
var logged []string
console.Logf = func(f string, a ...any) {
mu.Lock()
defer mu.Unlock()
logged = append(logged, fmt.Sprintf(f, a...))
}
said := func(words string) int {
mu.Lock()
defer mu.Unlock()
n := 0
for _, l := range logged {
if strings.Contains(l, words) {
n++
}
}
return n
}
surface := NewSurface(console, "laptop.node-tools")
up, err := Serve(surface, "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer up.Close()
endpoint := "http://" + up.Address + "/mcp"
if got, isErr := call(t, endpoint, "mesh_call", map[string]any{"address": "laptop/slack.slack_check"}); isErr || strings.Contains(got, "announced") {
t.Fatalf("while discovery hears the runtime: %s", got)
}
// Discovery goes quiet: no PING arrives at all.
stopAnnounce()
announcing.Flush()
for _, address := range []string{"laptop/slack.slack_check", "issue-tracker.list"} {
got, isErr := call(t, endpoint, "mesh_call", map[string]any{"address": address})
if isErr || !strings.Contains(got, "found from what node-tools on laptop announced") ||
!strings.Contains(got, "ago: it did not answer the latest round of discovery") {
t.Errorf("%s after a round that heard nothing: %s", address, got)
}
}
if got, isErr := call(t, endpoint, "mesh_describe", map[string]any{"address": "issue-tracker.list"}); isErr || !strings.Contains(got, `"found"`) {
t.Errorf("describe after a round that heard nothing: %s", got)
}
if n := said("discovery heard nothing at all"); n != 1 {
t.Errorf("the empty round was logged %d time(s), want once: %v", n, logged)
}
// A runtime really gone: the call is sent on what it announced, and fails with the bus's own refusal,
// saying where the address was found.
stopTool()
tools.Flush()
if got, isErr := call(t, endpoint, "mesh_call", map[string]any{"address": "laptop/slack.slack_check"}); !isErr ||
!strings.Contains(got, "nothing serves") || !strings.Contains(got, "found from what node-tools on laptop announced") {
t.Errorf("a gone runtime's tool: %s", got)
}
surface.mu.Lock()
kept := surface.idx != nil && !surface.idx.Discovery.Empty() && time.Since(surface.idxAt) < time.Second
surface.mu.Unlock()
if kept {
t.Error("a round that heard nothing was kept as the answer")
}
// Discovery answers again: the calls are plain again, and that is logged once.
stopAgain, err := announce.Serve(announcing, announce.Service{Name: "node-tools", ID: "laptop",
Metadata: map[string]string{"node": "laptop"}}, func() []announce.Endpoint { return endpoints })
if err != nil {
t.Fatal(err)
}
t.Cleanup(stopAgain)
announcing.Flush()
if got, isErr := call(t, endpoint, "mesh_call", map[string]any{"address": "issue-tracker.list"}); isErr || strings.Contains(got, "announced") {
t.Errorf("once discovery hears the runtime again: %s", got)
}
if n := said("discovery hears every runtime again"); n != 1 {
t.Errorf("the recovery was logged %d time(s): %v", n, logged)
}
}
// An address known only from an earlier answer says how old it is; one heard fresh on its machine is
// plain, even where the same module is known only from an earlier answer on another.
func TestAnAddressKnownOnlyFromAnEarlierAnswerSaysHowOld(t *testing.T) {
at := time.Now().Add(-20 * time.Second)
x := &index{Modules: map[string]*moduleInfo{"slack": {Module: "slack", On: []string{"laptop"},
Tools: []Tool{{Module: "slack", Name: "slack_check"}}}}, Recorded: map[string][]string{},
Stale: map[string]staleFrom{"mod:slack@laptop": {Runtime: "node-tools", Machine: "laptop", At: at}},
Discovery: announce.Discovery{Pinged: 0}}
got, err := resolve(x, "laptop/slack.slack_check")
if err != nil || got.Stale == nil || !strings.Contains(got.Stale.say(), "announced 20s ago") {
t.Fatalf("%+v %v", got, err)
}
// A module heard fresh on one machine and only earlier on another: the fresh one is plain.
x.Modules["slack"].On = []string{"desk", "laptop"}
if got, err := resolve(x, "desk/slack.slack_check"); err != nil || got.Stale != nil {
t.Errorf("a fresh machine's module marked stale: %+v %v", got, err)
}
}
+2
View File
@@ -52,6 +52,8 @@ type Surface struct {
idxAt time.Time
// runtimes is every runtime discovery has heard, as it last heard it (mesh_runtimes).
runtimes map[string]*runtimeSeen
// roundSaid is what the last round logged was missing, so a round is logged once (novox/hq issue 554).
roundSaid string
// Flat announces the whole catalogue, as the console did before ADR 0195: for a person reading
// it or a client that wants it. Off by default; MESH_CONSOLE_FLAT=1 turns it on.
Flat bool
+125 -3
View File
@@ -7,7 +7,9 @@ package console
import (
"fmt"
"log"
"sort"
"strings"
"time"
"github.com/novox/mesh-tools/node-tools/internal/announce"
@@ -31,6 +33,11 @@ type runtimeSeen struct {
Shortened string
Answered bool // in the latest round
Why string // why not, when it did not
// Reused is true when its PING said its announcement was unchanged, so it was not fetched again.
Reused bool
// Last is its last whole answer: what a round that does not hear it uses instead, and what an
// unchanged digest stands for (novox/hq issue 554).
Last announce.Heard
}
func runtimeKey(name, id string) string { return name + "/" + id }
@@ -50,7 +57,108 @@ func seenOf(h announce.Heard, at time.Time) *runtimeSeen {
}
}
return &runtimeSeen{Name: h.Info.Name, ID: h.Info.ID, Machine: h.Machine(), LastHeard: at, Took: h.Took,
Bytes: h.Bytes, Modules: len(modules), Tools: len(tools), SeatVerbs: len(verbs), Shortened: h.Shortened, Answered: true}
Bytes: h.Bytes, Modules: len(modules), Tools: len(tools), SeatVerbs: len(verbs), Shortened: h.Shortened, Answered: true,
Reused: h.Reused, Last: h}
}
// held is the answer this console holds for an instance at this digest (announce.Known): an instance
// whose announcement is unchanged is not asked for it again (novox/hq issue 554).
func (s *Surface) held(name, id, digest string) (announce.Heard, bool) {
s.mu.Lock()
defer s.mu.Unlock()
r := s.runtimes[runtimeKey(name, id)]
if r == nil || r.Last.Digest == "" || r.Last.Digest != digest || r.Last.Info.Name == "" {
return announce.Heard{}, false
}
h := r.Last
h.Took, h.Reused = 0, false
return h, true
}
// before is the last answer of every runtime this round did not hear, heard within RuntimeForgotten
// and not since restarted under another instance (novox/hq issue 554).
func (s *Surface) before(d announce.Discovery) []earlier {
heard := map[string]bool{}
running := map[string]bool{}
for _, h := range d.Heard {
heard[runtimeKey(h.Info.Name, h.Info.ID)] = true
if m := h.Machine(); m != "" {
running[h.Info.Name+"@"+m] = true
}
}
s.mu.Lock()
defer s.mu.Unlock()
var out []earlier
for k, r := range s.runtimes {
if heard[k] || r.Last.Info.Name == "" || r.LastHeard.IsZero() || time.Since(r.LastHeard) > RuntimeForgotten {
continue
}
if r.Machine != "" && running[r.Name+"@"+r.Machine] {
continue // restarted: the new instance answered
}
out = append(out, earlier{Heard: r.Last, At: r.LastHeard})
}
sort.Slice(out, func(i, j int) bool {
return runtimeKey(out[i].Heard.Info.Name, out[i].Heard.Info.ID) < runtimeKey(out[j].Heard.Info.Name, out[j].Heard.Info.ID)
})
return out
}
// sayRound logs a round of discovery that did not hear every runtime — once, when what it missed
// changes, and once when every runtime is heard again — so the next case leaves evidence in the
// journal (novox/hq issue 554). Called with s.mu held, after remember.
func (s *Surface) sayRound(x *index) {
d := x.Discovery
var missed []string
for _, u := range x.Unheard {
who := u.Runtime
if u.Machine != "" {
who += " on " + u.Machine
}
missed = append(missed, who)
}
sort.Strings(missed)
shape := strings.Join(missed, ", ")
if d.Empty() {
shape = "empty|" + shape
}
if shape == s.roundSaid {
return
}
s.roundSaid = shape
reused := 0
for _, h := range d.Heard {
if h.Reused {
reused++
}
}
logf := log.Printf
if s.conn != nil && s.conn.Logf != nil {
logf = s.conn.Logf
}
window := fmt.Sprintf("waited %s (window %s, patience %s)", d.Waited.Round(time.Millisecond), announce.Window, announce.Patience)
held := ""
if len(x.Earlier) > 0 {
held = fmt.Sprintf("; what %d of them announced earlier is used, with its age", len(x.Earlier))
}
switch {
case d.Empty():
logf("[mesh-tools] discovery heard nothing at all: no PING arrived; %s; not heard: %s%s; asking again at the next question",
window, orNone(missed), held)
case len(missed) > 0:
logf("[mesh-tools] discovery did not hear every runtime: %d PING answer(s), %d announcement(s) (%d unchanged, not fetched); %s; not heard: %s%s",
d.Pinged, len(d.Heard), reused, window, shape, held)
default:
logf("[mesh-tools] discovery hears every runtime again: %d PING answer(s), %d announcement(s) (%d unchanged, not fetched); %s",
d.Pinged, len(d.Heard), reused, window)
}
}
func orNone(xs []string) string {
if len(xs) == 0 {
return "none heard before either"
}
return strings.Join(xs, ", ")
}
// remember records a round of discovery and adds to the index every runtime heard lately that did not
@@ -101,14 +209,25 @@ func (s *Surface) remember(x *index) {
continue
}
r.Answered = false
used := ""
if at, ok := x.Earlier[k]; ok {
used = fmt.Sprintf("; what it announced %s ago is used", time.Since(at).Round(time.Second))
}
if why, ok := silent[k]; ok {
r.Why = why
if used != "" {
for i := range x.Unheard {
if x.Unheard[i].Runtime == r.Name && x.Unheard[i].Machine == r.Machine && x.Unheard[i].Why == why {
x.Unheard[i].Why += used
}
}
}
continue // already in the index's unheard
}
r.Why = "it did not answer this round of discovery"
if time.Since(r.LastHeard) <= RuntimeForgotten {
x.Unheard = append(x.Unheard, unheard{Runtime: r.Name, Machine: r.Machine,
Why: fmt.Sprintf("it answered discovery %s ago, not now", time.Since(r.LastHeard).Round(time.Second))})
Why: fmt.Sprintf("it answered discovery %s ago, not now%s", time.Since(r.LastHeard).Round(time.Second), used)})
}
}
for _, u := range x.Discovery.Silent {
@@ -157,6 +276,9 @@ func (s *Surface) runtimesAnswer() map[string]any {
if r.Shortened != "" {
entry["shortened, how"] = r.Shortened
}
if r.Reused && r.Answered {
entry["announcement"] = "unchanged (its PING's digest), so not fetched again; took is its PING's"
}
}
if r.Answered {
onMachine[r.Machine] = true
@@ -184,7 +306,7 @@ func (s *Surface) runtimesAnswer() map[string]any {
return answerText(map[string]any{
"asked": x.Discovery.At.Format(time.RFC3339),
"waited": x.Discovery.Waited.Round(time.Millisecond).String(),
"window": fmt.Sprintf("at least %s; up to %s for a runtime that answered PING", announce.Window, announce.Patience),
"window": fmt.Sprintf("at least %s; up to %s for a runtime that answered PING, or until one does", announce.Window, announce.Patience),
"answered": answered,
"not heard": notHeard,
})
+11 -7
View File
@@ -23,18 +23,22 @@ func slowRuntime(t *testing.T, conn *bus.Conn, node string, lag time.Duration, e
t.Fatal(err)
}
t.Cleanup(stop)
stop, err = conn.Raw("$SRV.INFO", func(string, []byte) []byte {
// Asked of every service, and of this instance by name and id — as discovery asks it (issue 554).
info := func(string, []byte) []byte {
if lag < 0 {
return nil
}
time.Sleep(lag)
body, _ := json.Marshal(announce.Info(announce.Service{Name: id.Name, ID: id.ID, Metadata: id.Metadata}, endpoints))
return body
})
if err != nil {
t.Fatal(err)
}
t.Cleanup(stop)
for _, subject := range []string{"$SRV.INFO", "$SRV.INFO." + id.Name + "." + id.ID} {
stop, err := conn.Raw(subject, info)
if err != nil {
t.Fatal(err)
}
t.Cleanup(stop)
}
conn.Flush()
}
@@ -175,7 +179,7 @@ func TestARuntimeHeardBeforeAndNotNowIsNamed(t *testing.T) {
s.remember(before)
now := &index{Modules: map[string]*moduleInfo{"nextcloud-client": {Module: "nextcloud-client", On: []string{"desktop"},
Tools: []Tool{{Module: "nextcloud-client", Name: "nextcloud_check"}}}}, Recorded: map[string][]string{},
Discovery: announce.Discovery{At: time.Now().UTC()}}
Discovery: announce.Discovery{At: time.Now().UTC(), Pinged: 1}} // desktop's runtime answered
s.remember(now)
if len(now.Unheard) != 1 || now.Unheard[0].Machine != "laptop" {
t.Fatalf("unheard: %+v", now.Unheard)
@@ -190,7 +194,7 @@ func TestARuntimeHeardBeforeAndNotNowIsNamed(t *testing.T) {
t.Errorf("%v", err)
}
// Nobody unheard: the plain answers stand.
quiet := &index{Modules: now.Modules, Recorded: map[string][]string{}}
quiet := &index{Modules: now.Modules, Recorded: map[string][]string{}, Discovery: now.Discovery}
if _, err := resolve(quiet, "laptop/nextcloud-client.nextcloud_check"); err == nil || !strings.Contains(err.Error(), "does not run on laptop; it runs on desktop") {
t.Errorf("%v", err)
}