fix(webui): count every chat front-end in the published projection
GitHub #821 reported two dashboard behaviours degrading in the extracted UI
process because webui.Server.Cfg is nil there. Half of it was already closed:
19062a7 ("take configuration off the dashboard server", on main since
2026-09-12) moved the daemon's ConfigView renderer off webui.Server, gave
ConfigView a chat section carrying show_tool_calls, the operator name and a
channel flag, and pointed chatShowToolCalls and handleSetup at the projection.
The chat page and the checklist do read published values now.
The channel flag was still wrong. It was derived from telegram and the webhook
gateway only, while the daemon's own channel status manager lists three
front-ends and counts the inbound mail gateway as one. An email-only
deployment therefore read as configured on /api/channels and unconfigured on
the setup checklist at the same time, and the checklist told the operator to
connect a channel they already had.
Fix at the producer: config.ChatConfig gains FrontEnds, the single definition
of "this front-end is configured", enumerating telegram, email and the webhook
gateway. Both the published projection (ChannelConfigured) and the daemon's
channel descriptors (status.NewManager) now derive from it, so the two surfaces
cannot drift apart again. A front-end added to [chat] is counted by both or
neither. Whitespace-only values are not configured: an env var name of " "
resolves to nothing and " " cannot be listened on.
The setup checklist stays. It renders each step as a title, a detail and a done
mark with no control behind it, so it answers "what is this deployment
missing?" rather than promising to fix it; the process that cannot apply setup
never offered to. Removing it would delete the one surface that distinguishes a
fresh deployment from a finished one, and the values it reads already cross the
boundary in ConfigView at no cost to the daemon. The write path stays descoped
for Phase 3 (docs/prds/ui-service-boundary.md, /api/config (write) row): the
checklist reports configuration, it does not change it.
docs/prds/ui-service-boundary.md records that judgement and corrects the
"Real-process evidence" paragraph, which claimed the channel flag covered every
chat channel.
This commit is contained in:
1 parent
2ef5327cd8
commit
55a4ac201b
7 files changed
+400
-16
No files matched your search
@@ -294,8 +294,27 @@ and the `/api/setup` checklist (the panel was omitted rather than rendered).
|
||||
Both are closed by `archie-core-ml30`: `ConfigView` gained a `chat` section
|
||||
carrying `show_tool_calls`, the operator name, and whether any chat channel is
|
||||
configured, and both surfaces now read the projection rather than a live
|
||||
holder. The end-to-end suite asserts the checklist renders from the published
|
||||
snapshot.
|
||||
holder. The end-to-end suite drives the real binary and streams a turn, so the
|
||||
`show_tool_calls` assertion is made on the frames a browser receives.
|
||||
|
||||
The checklist stays. The question raised when it was republished -- is a
|
||||
read-only setup report wanted in a process that cannot apply the setup it
|
||||
reports? -- resolves in favour of keeping it, because the panel never promised
|
||||
to apply anything. It renders each step as a title, a detail and a done mark
|
||||
with no control behind it, so it answers "what is this deployment missing?"
|
||||
rather than "fix it here", and the page that CAN act on it (the Configuration
|
||||
page) is where an operator goes next, in the daemon's own words. Removing it
|
||||
would delete the one surface that distinguishes a fresh deployment from a
|
||||
finished one for no gain, since the values it reads already cross the boundary
|
||||
in `ConfigView` and the read path costs the daemon nothing. The write path
|
||||
remains descoped (see `/api/config` (write) in the route table): the checklist
|
||||
reports configuration, it does not change it.
|
||||
|
||||
`archie-core-ml30` published the channel flag from two of the three chat
|
||||
front-ends, so an email-only deployment read as configured on `/api/channels`
|
||||
and unconfigured on the checklist at the same time (GitHub #821). Both now
|
||||
derive from `config.ChatConfig.FrontEnds`, the single definition of a configured
|
||||
front-end, and a test pins the two surfaces to the same answer.
|
||||
|
||||
## Non-goals and open work
|
||||
|
||||
|
||||
@@ -384,6 +384,35 @@ func (b *boot) loadCatalog(ctx context.Context, cfgPath string) {
|
||||
b.log.Info("model catalog loaded", "providers", len(catalog.Providers), "models", len(b.catalogModels))
|
||||
}
|
||||
|
||||
// channelDescriptors projects the configured chat front-ends into the
|
||||
// dashboard's channel-status descriptors.
|
||||
//
|
||||
// Configured comes from config.ChatConfig.FrontEnds so this list and the
|
||||
// configuration projection published for the extracted UI process cannot
|
||||
// disagree about whether a front-end is set up (GitHub #821). ReloadSupported
|
||||
// and Detail stay here because they are channel-lifecycle facts about the bot
|
||||
// the daemon runs, not configuration: only Telegram can be reloaded in place
|
||||
// today, and its allowlist caveat is about who the running bot answers.
|
||||
func channelDescriptors(chat config.ChatConfig) []status.Descriptor {
|
||||
frontEnds := chat.FrontEnds()
|
||||
descriptors := make([]status.Descriptor, 0, len(frontEnds))
|
||||
for _, frontEnd := range frontEnds {
|
||||
descriptor := status.Descriptor{
|
||||
ID: frontEnd.ID,
|
||||
Name: frontEnd.Name,
|
||||
Configured: frontEnd.Configured,
|
||||
}
|
||||
if frontEnd.ID == "telegram" {
|
||||
descriptor.ReloadSupported = frontEnd.Configured
|
||||
if frontEnd.Configured && len(chat.Telegram.AllowedUserIDs) == 0 {
|
||||
descriptor.Detail = "Token set, but the allowlist is empty -- the bot answers nobody."
|
||||
}
|
||||
}
|
||||
descriptors = append(descriptors, descriptor)
|
||||
}
|
||||
return descriptors
|
||||
}
|
||||
|
||||
// setupObservability builds the event bus, channel manager and dashboard
|
||||
// server. Every event is logged to SQLite (stamped with its row id) and
|
||||
// then fanned out to live dashboard connections.
|
||||
@@ -392,15 +421,7 @@ func (b *boot) setupObservability(ctx context.Context) {
|
||||
bus := events.NewBus()
|
||||
b.bus = bus
|
||||
b.addCleanup(func() { bus.Close() })
|
||||
telegramDetail := ""
|
||||
if (cfg.Chat.Telegram.Token != (secret.SecretRef{}) || cfg.Chat.Telegram.TokenEnv != "") && len(cfg.Chat.Telegram.AllowedUserIDs) == 0 {
|
||||
telegramDetail = "Token set, but the allowlist is empty -- the bot answers nobody."
|
||||
}
|
||||
b.channelManager = status.NewManager([]status.Descriptor{
|
||||
{ID: "telegram", Name: "Telegram", Configured: cfg.Chat.Telegram.Token != (secret.SecretRef{}) || cfg.Chat.Telegram.TokenEnv != "", ReloadSupported: cfg.Chat.Telegram.Token != (secret.SecretRef{}) || cfg.Chat.Telegram.TokenEnv != "", Detail: telegramDetail},
|
||||
{ID: "email", Name: "Email", Configured: cfg.Chat.Email.ListenAddr != ""},
|
||||
{ID: "webhook", Name: "Webhook gateway", Configured: cfg.Chat.WebhookAddr != ""},
|
||||
})
|
||||
b.channelManager = status.NewManager(channelDescriptors(cfg.Chat))
|
||||
b.cfgHolder = config.NewHolder(cfg)
|
||||
b.web = &webui.Server{Log: log.With("component", "webui"), Channels: b.channelManager, Skills: skillCatalogAdapter{b.cfgHolder}}
|
||||
// The watchdog leaves its verdict in a file on this host, so the daemon
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package archied
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/webui"
|
||||
)
|
||||
|
||||
// TestPublishedProjectionAgreesWithTheChannelManagerOnConfiguredChannels: the
|
||||
// daemon answers "is a chat channel configured" twice -- once through the
|
||||
// channel status manager it exposes on /api/channels, and once through the
|
||||
// ChatView.ChannelConfigured boolean it publishes for the dashboard's setup
|
||||
// checklist. Those two answers are read by different pages of the same
|
||||
// extracted process, so a deployment that the manager calls configured must
|
||||
// not be told by the checklist to connect a channel it already has. Both sides
|
||||
// now derive from one definition (config.ChatConfig.FrontEnds); this test is
|
||||
// what keeps them from being re-decided separately.
|
||||
func TestPublishedProjectionAgreesWithTheChannelManagerOnConfiguredChannels(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg config.Config
|
||||
}{
|
||||
{name: "nothing configured", cfg: config.Config{}},
|
||||
{
|
||||
name: "telegram token",
|
||||
cfg: config.Config{Chat: config.ChatConfig{
|
||||
Telegram: config.TelegramConfig{TokenEnv: "TELEGRAM_TOKEN"},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "telegram token through the secret engine",
|
||||
cfg: config.Config{Chat: config.ChatConfig{
|
||||
Telegram: config.TelegramConfig{Token: config.SecretRef{Engine: "builtin", Key: "telegram"}},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "webhook gateway",
|
||||
cfg: config.Config{Chat: config.ChatConfig{WebhookAddr: "127.0.0.1:9099"}},
|
||||
},
|
||||
{
|
||||
name: "inbound mail gateway",
|
||||
cfg: config.Config{Chat: config.ChatConfig{Email: config.EmailConfig{ListenAddr: "127.0.0.1:2525"}}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "state.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = st.Close() })
|
||||
|
||||
b := &boot{
|
||||
cfg: tc.cfg,
|
||||
log: slog.New(slog.DiscardHandler),
|
||||
stateStore: st,
|
||||
cfgHolder: config.NewHolder(tc.cfg),
|
||||
}
|
||||
b.setupObservability(t.Context())
|
||||
|
||||
// What the dashboard's /api/channels page reads.
|
||||
managerSaysConfigured := false
|
||||
for _, descriptor := range b.channelManager.Snapshot() {
|
||||
if descriptor.Configured {
|
||||
managerSaysConfigured = true
|
||||
}
|
||||
}
|
||||
|
||||
// What the dashboard's setup checklist reads, through the
|
||||
// same round trip a reading process performs.
|
||||
document, err := json.Marshal(webui.BuildConfigView(b.configViewInput(t.Context())))
|
||||
if err != nil {
|
||||
t.Fatalf("render the published projection: %v", err)
|
||||
}
|
||||
var published webui.ConfigView
|
||||
if err := json.Unmarshal(document, &published); err != nil {
|
||||
t.Fatalf("decode the published projection: %v", err)
|
||||
}
|
||||
|
||||
if published.Chat.ChannelConfigured != managerSaysConfigured {
|
||||
t.Errorf("published Chat.ChannelConfigured = %v, but the channel manager reports a configured front-end = %v (%+v)",
|
||||
published.Chat.ChannelConfigured, managerSaysConfigured, published.Chat)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package config
|
||||
|
||||
import "strings"
|
||||
|
||||
// ChatFrontEnd is one conversational front-end [chat] can enable.
|
||||
//
|
||||
// It carries the answer to "is this front-end configured", and nothing else:
|
||||
// which process starts it, whether it can be reloaded, and what an operator
|
||||
// reads about it are channel-lifecycle facts that belong to the daemon, not to
|
||||
// configuration. ID is the stable identifier every surface keys on (the
|
||||
// dashboard's channel list, the channel reload route).
|
||||
type ChatFrontEnd struct {
|
||||
ID string
|
||||
Name string
|
||||
Configured bool
|
||||
}
|
||||
|
||||
// FrontEnds reports every conversational front-end this configuration enables,
|
||||
// in the order the dashboard lists them.
|
||||
//
|
||||
// This is the single definition of "a chat channel is configured". It exists
|
||||
// because that question used to be answered twice from the same config and the
|
||||
// two answers drifted: the daemon's channel status manager counted the inbound
|
||||
// mail gateway, and the dashboard projection published for the extracted UI
|
||||
// process did not, so an email-only deployment read as configured on
|
||||
// /api/channels and unconfigured on the setup checklist at the same time
|
||||
// (GitHub #821). Front-ends are enumerated once here so a front-end added to
|
||||
// [chat] cannot be counted by one surface and missed by the other.
|
||||
//
|
||||
// A whitespace-only value is not configured on any front-end: an env var name
|
||||
// of " " resolves to nothing, and an address of " " cannot be listened on.
|
||||
func (c ChatConfig) FrontEnds() []ChatFrontEnd {
|
||||
return []ChatFrontEnd{
|
||||
{
|
||||
ID: "telegram",
|
||||
Name: "Telegram",
|
||||
Configured: c.Telegram.Token != (SecretRef{}) || strings.TrimSpace(c.Telegram.TokenEnv) != "",
|
||||
},
|
||||
{
|
||||
ID: "email",
|
||||
Name: "Email",
|
||||
Configured: strings.TrimSpace(c.Email.ListenAddr) != "",
|
||||
},
|
||||
{
|
||||
ID: "webhook",
|
||||
Name: "Webhook gateway",
|
||||
Configured: strings.TrimSpace(c.WebhookAddr) != "",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// AnyFrontEndConfigured reports whether at least one conversational front-end
|
||||
// has credentials. The setup checklist asks this as a yes/no question; every
|
||||
// other consumer wants the per-front-end detail FrontEnds returns.
|
||||
func (c ChatConfig) AnyFrontEndConfigured() bool {
|
||||
for _, frontEnd := range c.FrontEnds() {
|
||||
if frontEnd.Configured {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestChatConfigFrontEnds is the single definition of "a chat front-end is
|
||||
// configured". Two surfaces read it -- the daemon's channel status manager and
|
||||
// the configuration projection published for the extracted UI process -- so a
|
||||
// front-end counted by one and missed by the other is a dashboard that
|
||||
// contradicts itself (GitHub #821).
|
||||
func TestChatConfigFrontEnds(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
chat ChatConfig
|
||||
want map[string]bool
|
||||
}{
|
||||
{
|
||||
name: "nothing configured",
|
||||
chat: ChatConfig{},
|
||||
want: map[string]bool{"telegram": false, "email": false, "webhook": false},
|
||||
},
|
||||
{
|
||||
name: "telegram bot token from the environment",
|
||||
chat: ChatConfig{Telegram: TelegramConfig{TokenEnv: "TELEGRAM_TOKEN"}},
|
||||
want: map[string]bool{"telegram": true, "email": false, "webhook": false},
|
||||
},
|
||||
{
|
||||
name: "telegram bot token through the secret engine",
|
||||
chat: ChatConfig{Telegram: TelegramConfig{Token: SecretRef{Engine: "builtin", Key: "telegram"}}},
|
||||
want: map[string]bool{"telegram": true, "email": false, "webhook": false},
|
||||
},
|
||||
{
|
||||
name: "inbound mail gateway",
|
||||
chat: ChatConfig{Email: EmailConfig{ListenAddr: "127.0.0.1:2525"}},
|
||||
want: map[string]bool{"telegram": false, "email": true, "webhook": false},
|
||||
},
|
||||
{
|
||||
name: "webhook gateway",
|
||||
chat: ChatConfig{WebhookAddr: "127.0.0.1:9099"},
|
||||
want: map[string]bool{"telegram": false, "email": false, "webhook": true},
|
||||
},
|
||||
{
|
||||
name: "every front-end at once",
|
||||
chat: ChatConfig{
|
||||
Telegram: TelegramConfig{TokenEnv: "TELEGRAM_TOKEN"},
|
||||
Email: EmailConfig{ListenAddr: "127.0.0.1:2525"},
|
||||
WebhookAddr: "127.0.0.1:9099",
|
||||
},
|
||||
want: map[string]bool{"telegram": true, "email": true, "webhook": true},
|
||||
},
|
||||
{
|
||||
// Whitespace is not a value: an env var name of " " resolves
|
||||
// to nothing and " " cannot be listened on.
|
||||
name: "whitespace-only values are not configured",
|
||||
chat: ChatConfig{
|
||||
Telegram: TelegramConfig{TokenEnv: " "},
|
||||
Email: EmailConfig{ListenAddr: " "},
|
||||
WebhookAddr: "\t",
|
||||
},
|
||||
want: map[string]bool{"telegram": false, "email": false, "webhook": false},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := map[string]bool{}
|
||||
for _, frontEnd := range tc.chat.FrontEnds() {
|
||||
if frontEnd.ID == "" || frontEnd.Name == "" {
|
||||
t.Errorf("front-end %+v is missing an identifier or a name", frontEnd)
|
||||
}
|
||||
if _, seen := got[frontEnd.ID]; seen {
|
||||
t.Errorf("front-end %q listed twice", frontEnd.ID)
|
||||
}
|
||||
got[frontEnd.ID] = frontEnd.Configured
|
||||
}
|
||||
if len(got) != len(tc.want) {
|
||||
t.Fatalf("FrontEnds() = %+v, want one entry per front-end %+v", got, tc.want)
|
||||
}
|
||||
for id, want := range tc.want {
|
||||
if got[id] != want {
|
||||
t.Errorf("front-end %q configured = %v, want %v", id, got[id], want)
|
||||
}
|
||||
}
|
||||
|
||||
var anyConfigured bool
|
||||
for _, configured := range got {
|
||||
anyConfigured = anyConfigured || configured
|
||||
}
|
||||
if got, want := tc.chat.AnyFrontEndConfigured(), anyConfigured; got != want {
|
||||
t.Errorf("AnyFrontEndConfigured() = %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -391,13 +391,15 @@ func BuildConfigView(in ConfigViewInput) ConfigView {
|
||||
return view
|
||||
}
|
||||
|
||||
// chatChannelConfigured reports whether any conversational front-end has
|
||||
// credentials. The setup checklist needs the answer, not the tokens, so the
|
||||
// chatChannelConfigured reports whether any conversational front-end is
|
||||
// configured. The setup checklist needs the answer, not the tokens, so the
|
||||
// projection carries the boolean.
|
||||
//
|
||||
// The definition lives in config.ChatConfig.FrontEnds, not here: the daemon's
|
||||
// channel status manager answers the same question on /api/channels, and
|
||||
// deciding it twice is how the two answers drifted apart (GitHub #821).
|
||||
func chatChannelConfigured(chat config.ChatConfig) bool {
|
||||
return chat.Telegram.Token != (config.SecretRef{}) ||
|
||||
strings.TrimSpace(chat.Telegram.TokenEnv) != "" ||
|
||||
strings.TrimSpace(chat.WebhookAddr) != ""
|
||||
return chat.AnyFrontEndConfigured()
|
||||
}
|
||||
|
||||
// RemoteConfigView reads the projection the configuration owner published.
|
||||
|
||||
@@ -95,6 +95,101 @@ func TestSetupChecklistRendersFromTheProjection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetupChecklistChatChannelStepCountsEveryFrontEnd: the checklist's
|
||||
// "Connect a chat channel" step asks whether ANY conversational front-end is
|
||||
// configured, so the projection it reads has to answer that question for every
|
||||
// front-end the daemon serves. The daemon's own channel inventory lists three
|
||||
// (telegram, the webhook gateway and the inbound mail gateway -- see
|
||||
// bootstrap.go's status.NewManager), and an email-only deployment is a
|
||||
// configured deployment: the mail gateway feeds the same gateway.Router as the
|
||||
// other two. Deriving the answer from two of the three told an email operator
|
||||
// to connect a channel they already had.
|
||||
func TestSetupChecklistChatChannelStepCountsEveryFrontEnd(t *testing.T) {
|
||||
const stepTitle = "Connect a chat channel"
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg config.Config
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "nothing configured",
|
||||
cfg: config.Config{},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "telegram token env",
|
||||
cfg: config.Config{Chat: config.ChatConfig{
|
||||
Telegram: config.TelegramConfig{TokenEnv: "TELEGRAM_TOKEN"},
|
||||
}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "telegram token through the secret engine",
|
||||
cfg: config.Config{Chat: config.ChatConfig{
|
||||
Telegram: config.TelegramConfig{Token: config.SecretRef{Engine: "builtin", Key: "telegram"}},
|
||||
}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "webhook gateway",
|
||||
cfg: config.Config{Chat: config.ChatConfig{
|
||||
WebhookAddr: "127.0.0.1:9099",
|
||||
}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "inbound mail gateway",
|
||||
cfg: config.Config{Chat: config.ChatConfig{
|
||||
Email: config.EmailConfig{ListenAddr: "127.0.0.1:2525"},
|
||||
}},
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
srv.ConfigSource = publishedSource(t, tc.cfg)
|
||||
|
||||
got := getSetup(t, srv)
|
||||
found := false
|
||||
for _, step := range got.Steps {
|
||||
if step.Title != stepTitle {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if step.Done != tc.want {
|
||||
t.Errorf("step %q done = %v, want %v (config: %+v)", stepTitle, step.Done, tc.want, tc.cfg.Chat)
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("no %q step in %+v", stepTitle, got.Steps)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// publishedSource renders cfg the way the daemon does -- through
|
||||
// webui.BuildConfigView -- and hands the server the marshalled document, which
|
||||
// is how the reading process actually receives it. Rendering here rather than
|
||||
// hand-writing a ConfigView keeps these tests honest about the producer: a
|
||||
// field BuildConfigView forgets is one the dashboard cannot see.
|
||||
func publishedSource(t *testing.T, cfg config.Config) ConfigViewSource {
|
||||
t.Helper()
|
||||
document, err := json.Marshal(BuildConfigView(ConfigViewInput{Config: cfg}))
|
||||
if err != nil {
|
||||
t.Fatalf("render the published projection: %v", err)
|
||||
}
|
||||
return func(context.Context) (ConfigView, bool, error) {
|
||||
var view ConfigView
|
||||
if err := json.Unmarshal(document, &view); err != nil {
|
||||
return ConfigView{}, false, err
|
||||
}
|
||||
return view, true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetupChecklistOmittedWithoutAProjection: no configuration to read means
|
||||
// the panel is omitted, not guessed at from zeroes.
|
||||
func TestSetupChecklistOmittedWithoutAProjection(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user