networkmanager: the watcher's health is its unit's state

The sign-in process is judged by its unit being active, on the machine without the bus,
and NetworkManager's service keeps no state and no health again. The watcher exits
non-zero when it cannot subscribe once the system bus came back, so its unit shows
failing; uplink_health stays a tool that reads and no longer gives the names again.

Builds: design 08 sign-in-page §11, §13, §14, §23, §24, §25, §27; lead answer C-2c (hq 6752a5cf)
This commit is contained in:
jochen
2026-11-24 21:53:29 +01:00
parent 55a90d963e
commit 397e627b02
9 changed files with 59 additions and 80 deletions
+7 -4
View File
@@ -72,8 +72,7 @@ filtered to `mesh.seat.node-uplink.event.*.<node>`, their time in `at`.
Where a module holds `node-resolver` on this node (the assignments say which), the bundle calls its `uplink-names`
with the check address's host name, so NetworkManager's own check resolves through the network it tests: at its start,
when `check-address` changes, when its bus connection comes back, when the node-engine says that holder runs, and at
the health look when the resolver no longer holds the names. With no holder it calls nothing, and that is no failure.
when `check-address` changes, when its bus connection comes back and when the node-engine says that holder runs. With no holder it calls nothing, and that is no failure.
## Tools
@@ -83,6 +82,10 @@ the health look when the resolver no longer holds the names. With no holder it c
| `uplink_names_again` | call `uplink-names` now |
| `uplink_rating_again` | make the watcher subscribe again and act on the rating now |
| `uplink_publish_again` | publish the kept events now |
| `uplink_health` | the watcher's health: unhealthy while its socket does not answer, while it is not subscribed, or while the last `uplink-names` call stands failed |
| `uplink_health` | whether the reaction works: unhealthy while the watcher's socket does not answer, while it is not subscribed, or while the last `uplink-names` call stands failed; a tool to read, not a health check |
The watcher's health is judged only once the tool runner has reached the bus, since its health tool is the bundle's.
**The watcher's health is its unit's state** (`networkmanager-sign-in` active), judged on the machine without the bus,
so it holds behind a sign-in page. When the system bus comes back and the watcher cannot subscribe on it again, it
writes the reason to its journal and exits non-zero, so its unit shows failing and the service manager restarts it.
`uplink_health` is a tool, not a health check; the watcher not subscribed and a failed `uplink-names` call are also
shown by `uplink_sign_in` and written to the journal.
@@ -141,7 +141,7 @@ func TestAPathTheWatcherDoesNotKnowIsLeftAndSaidOnce(t *testing.T) {
return made
}
stop, done := make(chan struct{}), make(chan struct{})
go func() { w.run(stop); close(done) }()
go func() { _ = w.run(stop); close(done) }()
for _, p := range []string{filepath.Join(f.Dir, "other"), filepath.Join(f.Dir, "other"), filepath.Join(f.Dir, "sequence.new"),
filepath.Join(f.Dir, pendingName, "0000000002.json")} {
made <- p
@@ -64,10 +64,9 @@ func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
}
}
// The manifest declares the watcher's process as the account, with the health of its tool; the folder the two parts
// share, the account's alone; the event the bundle consumes and the verbs it invokes; and the five tools, the health
// tool among them, and NetworkManager's unit a check of kind unit beside the watcher's tool check (design 08
// sign-in-page §11, §12, §13, §27; lead answer C-2).
// The manifest declares the watcher's process as the account, its health its unit's state; the folder the two parts
// share, the account's alone; the event the bundle consumes and the verbs it invokes; and the five tools. NetworkManager's
// unit keeps no state and no health (design 08 sign-in-page §11, §12, §13, §27; lead answer C-2c).
func TestTheManifestDeclaresTheSignInParts(t *testing.T) {
raw, err := os.ReadFile(filepath.Join(moduleDir, "module.json"))
if err != nil {
@@ -116,11 +115,11 @@ func TestTheManifestDeclaresTheSignInParts(t *testing.T) {
h, _ := json.Marshal(p["health"])
if p["type"] != "process" || p["name"] != "networkmanager-sign-in" || p["artifact"] != "tools" ||
string(run) != `["./uplink-tools","watch"]` || p["user"] != "${machine:account}" ||
string(h) != `{"grace":"60s","interval":"60s","kind":"tool","looks":2,"timeout":"20s","tool":"uplink_health"}` {
string(h) != `{"kind":"unit"}` {
t.Errorf("the watcher is %v", p)
}
if svc, _ := json.Marshal(byID["service"]["health"]); string(svc) != `{"kind":"unit"}` || byID["service"]["state"] != nil {
t.Errorf("NetworkManager's unit carries the health %s, not a unit check beside the watcher's tool check", svc)
if byID["service"]["health"] != nil || byID["service"]["state"] != nil {
t.Errorf("NetworkManager's unit carries a state or a health: %v", byID["service"])
}
for _, id := range []string{"package", "config", "service"} {
if byID[id] == nil {
@@ -5,7 +5,6 @@ package main
import (
"fmt"
"slices"
"strings"
"git.novox.be/novox/mesh-networking/modules/mesh-connectivity-contracts/go/seats/noderesolver"
@@ -53,10 +52,10 @@ func (b *bundle) tools() []stdio.Tool {
"its moments: answers how many were published and how many still wait. (a)",
Run: func(map[string]any) (any, error) { return b.pub.publishKept("uplink_publish_again"), nil }},
{Name: "uplink_health",
Description: "Whether the sign-in reaction works, as the watcher process's health check (novox/hq ADR 0240): " +
"unhealthy while the watcher's socket does not answer, while the watcher is not subscribed on the system " +
"bus, or while the last uplink-names call stands failed, naming which; no holder of node-resolver is " +
"healthy. Where a holder runs and the resolver no longer holds the names last given, it gives them again. (r)",
Description: "Whether the sign-in reaction works: unhealthy while the watcher's socket does not answer, while " +
"the watcher is not subscribed on the system bus, or while the last uplink-names call stands failed, naming " +
"which; no holder of node-resolver is healthy. A tool to read, not the watcher's health check, which is its " +
"unit's state. (r)",
Run: func(map[string]any) (any, error) { return b.health(), nil }},
}
}
@@ -100,8 +99,7 @@ func (b *bundle) resolverRoutes() (noderesolver.RoutesAnswer, bool, error) {
return routes, true, err
}
// health is the watcher process's health, as its health tool answers it (§23). At this look, where a holder of
// node-resolver runs and its routes no longer hold the names last given, the names are given again (§13).
// health is uplink_health's answer, a tool of the bundle and not a node-engine check (§23; lead answer C-2c).
func (b *bundle) health() health.Answer {
var faults []string
var s watcherState
@@ -114,13 +112,6 @@ func (b *bundle) health() health.Answer {
if err != nil {
faults = append(faults, "names.json does not read: "+err.Error())
}
if call != nil && !call.Failed() && len(call.Names) > 0 {
if routes, held, err := b.resolverRoutes(); err == nil && held && !containsAll(routes.UplinkNames.Names, call.Names) {
journal("the resolver no longer holds %v: giving them again", call.Names)
given := b.names.give("the health look")
call = &given
}
}
if call != nil && call.Failed() {
faults = append(faults, "the last uplink-names call failed: "+call.Result)
}
@@ -133,12 +124,3 @@ func (b *bundle) health() health.Answer {
}
return health.Healthy(why + ".")
}
func containsAll(have, want []string) bool {
for _, w := range want {
if !slices.Contains(have, w) {
return false
}
}
return true
}
@@ -49,8 +49,8 @@ func runTool(t *testing.T, b *bundle, name string) any {
}
// The health tool is unhealthy while the watcher's socket does not answer, while the watcher is not subscribed and
// while the last uplink-names call stands failed, naming which; no holder is healthy. Where a holder runs and its
// routes no longer hold the names last given, the look gives them again (design 08 sign-in-page §13, §23, §25).
// while the last uplink-names call stands failed, naming which; no holder is healthy. It is a tool that reads and calls
// nothing on the bus: the names are not given again at a look (design 08 sign-in-page §13, §23, §25; C-2c).
func TestTheHealthToolSaysWhatIsWrong(t *testing.T) {
journalLines(t)
for _, c := range []struct {
@@ -97,8 +97,8 @@ func TestTheHealthToolSaysWhatIsWrong(t *testing.T) {
b, _ := aToolBundle(t, mesh, &subscribed, &asked)
b.folder.writeCheckAddress("http://check.example.net/")
b.names.give("the bundle's start")
if got := runTool(t, b, "uplink_health").(health.Answer); !got.Healthy || len(mesh.called()) != 2 {
t.Fatalf("the look did not give the missing names again: %+v, %d calls", got, len(mesh.called()))
if got := runTool(t, b, "uplink_health").(health.Answer); !got.Healthy || len(mesh.called()) != 1 {
t.Fatalf("the health tool answered %+v and called uplink-names %d times", got, len(mesh.called()))
}
}
@@ -194,8 +194,7 @@ func watch([]string) error {
}
w := newWatcher(f)
go serveSocket(l, w.askLoop)
w.run(nil)
return nil
return w.run(nil)
}
// askLoop hands one ask of the socket to the loop and waits for its answer.
@@ -206,8 +205,10 @@ func (w *Watcher) askLoop(ask string) (any, error) {
return r.answer, r.err
}
// run is the watcher's loop, until stop closes: it subscribes, then acts on what it hears, one thing at a time.
func (w *Watcher) run(stop <-chan struct{}) {
// run is the watcher's loop, until stop closes: it subscribes, then acts on what it hears, one thing at a time. It ends
// with an error when it cannot subscribe again once the system bus's socket came back, so the process exits non-zero
// and its unit shows failing, the watcher's health (design 08 sign-in-page §11; lead answer C-2c).
func (w *Watcher) run(stop <-chan struct{}) error {
if w.asks == nil {
w.asks = make(chan asked)
}
@@ -223,7 +224,7 @@ func (w *Watcher) run(stop <-chan struct{}) {
select {
case <-stop:
w.unsubscribe()
return
return nil
case s, ok := <-w.signals:
if !ok {
journal("the system bus connection dropped; subscribing again when its socket is there")
@@ -239,6 +240,10 @@ func (w *Watcher) run(stop <-chan struct{}) {
case <-w.socketAt:
w.socketAt = nil
w.subscribe()
if !w.state.Subscribed {
w.unsubscribe()
return errors.New("the system bus came back and the watcher could not subscribe on it")
}
case p := <-made:
w.strange(p)
case end := <-w.ends:
@@ -305,7 +305,7 @@ func TestTheWatcherSubscribesAgainAndRunsOnNoTimer(t *testing.T) {
w := aWatcher(t, sys)
stop := make(chan struct{})
done := make(chan struct{})
go func() { w.run(stop); close(done) }()
go func() { _ = w.run(stop); close(done) }()
defer func() { close(stop); <-done }()
state := func() watcherState {
s, err := w.askLoop(askState)
@@ -393,15 +393,15 @@ func TestTheWatcherHearsTheSystemBusSignals(t *testing.T) {
}
// The watcher dials the system bus again only at the file event that makes its socket and at rating-again, never in a
// loop: a bus that refuses it, at its start or after a drop, is not dialled again until one of the two (§14; note d).
// loop (§14; note d); and when the bus came back and it cannot subscribe on it, it ends with an error, so its process
// exits non-zero and its unit shows failing (§11; lead answer C-2c).
func TestTheWatcherRedialsOnlyAtTheSocketsEventAndRatingAgain(t *testing.T) {
journalLines(t)
sys := &fakeSystem{socket: make(chan struct{}), refuse: 1}
sys.set(guest(ratingFull))
w := aWatcher(t, sys)
stop, done := make(chan struct{}), make(chan struct{})
go func() { w.run(stop); close(done) }()
defer func() { close(stop); <-done }()
stop, done := make(chan struct{}), make(chan error, 1)
go func() { done <- w.run(stop) }()
state := func() watcherState {
s, _ := w.askLoop(askState)
return s.(watcherState)
@@ -413,32 +413,30 @@ func TestTheWatcherRedialsOnlyAtTheSocketsEventAndRatingAgain(t *testing.T) {
}
}
if d := dials(); d != 1 {
t.Fatalf("a refused bus was dialled %d times with no event", d)
t.Fatalf("a bus that refused the watcher at its start was dialled %d times with no event", d)
}
sys.socket <- struct{}{}
if s := state(); !s.Subscribed || dials() != 2 {
t.Fatalf("at the socket's event: %+v, %d dials", s, dials())
}
close(sys.last().signals)
state()
state()
if d := dials(); d != 2 {
t.Fatalf("a dropped connection was dialled again before the socket's event: %d dials", d)
}
if _, err := w.askLoop(askRatingAgain); err != nil || dials() != 3 || !state().Subscribed {
t.Fatalf("rating-again: %v, %d dials", err, dials())
}
close(sys.last().signals)
sys.mu.Lock()
sys.refuse = 1
sys.mu.Unlock()
sys.socket <- struct{}{}
state()
if d := dials(); d != 2 || state().Subscribed {
t.Fatalf("at the socket's event: %d dials", d)
}
state()
if d := dials(); d != 2 {
t.Fatalf("dialled again with no event: %d dials", d)
}
sys.socket <- struct{}{}
if s := state(); !s.Subscribed || dials() != 3 {
t.Fatalf("at the next socket event: %+v, %d dials", s, dials())
}
close(sys.last().signals)
state()
if d := dials(); d != 3 {
t.Fatalf("a dropped connection was dialled again before the socket's event: %d dials", d)
}
if _, err := w.askLoop(askRatingAgain); err != nil || dials() != 4 || !state().Subscribed {
t.Fatalf("rating-again: %v, %d dials", err, dials())
if err := <-done; err == nil || !strings.Contains(err.Error(), "could not subscribe") || dials() != 4 {
t.Fatalf("the bus came back refusing: the watcher ended with %v after %d dials", err, dials())
}
close(stop)
}
// The real wait fires at the file event that makes the system bus's socket, not for one that is merely there (note d).
@@ -211,7 +211,7 @@ func TestNetworkManagerWhole(t *testing.T) {
go serveSocket(l, w.askLoop)
stop, stopped := make(chan struct{}), make(chan struct{})
at.set(time.Date(2026, 11, 24, 9, 59, 0, 0, time.UTC))
go func() { w.run(stop); close(stopped) }()
go func() { _ = w.run(stop); close(stopped) }()
t.Cleanup(func() { close(stop); <-stopped })
told := func(summary string) {
t.Helper()
+2 -10
View File
@@ -81,10 +81,7 @@
"unit": "NetworkManager.service",
"reload-on": [
"config"
],
"health": {
"kind": "unit"
}
]
},
{
"id": "sign-in-state",
@@ -105,12 +102,7 @@
],
"user": "${machine:account}",
"health": {
"kind": "tool",
"tool": "uplink_health",
"interval": "60s",
"timeout": "20s",
"looks": 2,
"grace": "60s"
"kind": "unit"
}
}
]