From 8b5cc8be8d1cc2aa47da535a9b24cf4d7396f189 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 16 Nov 2026 22:28:40 +0100 Subject: [PATCH] nats: the tools bundle answers initialize again (keep days read when asked) bundleKeepDays read the config value snapshot-keep-days while allTools listed the tools, before stdio.Serve; a config read waits for the runtime's channel, which opens only once the bundle serves, so the bundle never answered initialize and node-tools served none of its tools (novox 2026-11-16 22:21 and 22:26, after the first build from main since A-112). The setting is now read when nats_snapshots is called. --- modules/nats/cmd/nats-tools/main.go | 6 ++++-- modules/nats/cmd/nats-tools/snapshots.go | 4 ++-- modules/nats/cmd/nats-tools/snapshots_test.go | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/nats/cmd/nats-tools/main.go b/modules/nats/cmd/nats-tools/main.go index d60eae4fc..9b43093f5 100644 --- a/modules/nats/cmd/nats-tools/main.go +++ b/modules/nats/cmd/nats-tools/main.go @@ -197,13 +197,15 @@ func allTools() []stdio.Tool { out = append(out, keeperHealthTool(StatusInState, HeldInState, jsz)) out = append(out, readTools(jsz, LiveMsgGet(LiveBus()))...) rs := RequestsInState() - out = append(out, snapshotListTool(rs, bundleKeepDays())...) + out = append(out, snapshotListTool(rs, bundleKeepDays)...) out = append(out, plansTool(PlansInState)) return append(out, requestTools(rs)...) } // bundleKeepDays is the setting snapshot-keep-days as this bundle's configuration holds it (design 47 G A-112), its -// default when the runtime gives none. +// default when the runtime gives none. It is read when a tool asks, never while the tools are listed: a config read +// waits for the runtime's channel, which opens only once the bundle serves, so a read before Serve never returns and +// the bundle never answers initialize. func bundleKeepDays() int { if raw, err := stdio.Config("snapshot-keep-days"); err == nil { var n int diff --git a/modules/nats/cmd/nats-tools/snapshots.go b/modules/nats/cmd/nats-tools/snapshots.go index a1d455588..08f4cfaea 100644 --- a/modules/nats/cmd/nats-tools/snapshots.go +++ b/modules/nats/cmd/nats-tools/snapshots.go @@ -324,7 +324,7 @@ func heldRequest(store keeper.Store) func(id string) (*keeper.Request, error) { } // snapshotListTool is nats_snapshots, which the tools bundle keeps beside the verbs the keeper's process answers. -func snapshotListTool(rs requestStore, keepDays int) []stdio.Tool { +func snapshotListTool(rs requestStore, keepDays func() int) []stdio.Tool { return []stdio.Tool{ {Name: "nats_snapshots", Description: "The keeper's snapshots of kept data taken before a drop or recreate, from its state requests: each one's request, module, local name, stream, size, digest, time, whether it is protected (restored only in place, never sent), whether it is expired (past snapshot-keep-days, removed at the keeper's next request) and whether it is recorded (a snapshot of before milestone G holds no digest and is sent or removed by hand only).", @@ -344,7 +344,7 @@ func snapshotListTool(rs requestStore, keepDays int) []stdio.Tool { continue } out = append(out, map[string]any{"request": r.ID, "module": r.Module, "local": r.Local, "stream": keeper.BusName(r.Module, r.Local), - "size": r.Size, "digest": r.Digest, "at": r.At, "protected": r.Protected, "expired": r.Expired(rs.Now(), keepDays), "recorded": r.Recorded()}) + "size": r.Size, "digest": r.Digest, "at": r.At, "protected": r.Protected, "expired": r.Expired(rs.Now(), keepDays()), "recorded": r.Recorded()}) } return map[string]any{"snapshots": out}, nil }}, diff --git a/modules/nats/cmd/nats-tools/snapshots_test.go b/modules/nats/cmd/nats-tools/snapshots_test.go index acd4ab909..4026fe5f6 100644 --- a/modules/nats/cmd/nats-tools/snapshots_test.go +++ b/modules/nats/cmd/nats-tools/snapshots_test.go @@ -222,7 +222,7 @@ func TestTheKeepersProcessAnswersTheSnapshotVerbs(t *testing.T) { t.Errorf("the hand acts %v: the caller of a call that named none is %s", acts, stdio.Unproven) } // nats_snapshots lists every snapshot, the expired and the unrecorded said. - out, err = snapshotListTool(rs, 90)[0].Run(nil) + out, err = snapshotListTool(rs, func() int { return 90 })[0].Run(nil) if err != nil { t.Fatal(err) }