webui.Server declared Cfg *config.Holder with eight read sites, none of
which ran in the UI process: composition leaves it nil there. The field
survived because the daemon kept a webui.Server it never served, using it
to render the published ConfigView snapshot and to hold the readiness
probes (archie-core-ml30).
Split at the producer. LocalConfigView becomes webui.BuildConfigView, a
pure function over a ConfigViewInput the configuration owner assembles;
the DTO and its schema stay where the UI renders them. The daemon builds
that input from its own state (boot.configViewInput) and publishes the
result. Readiness reads the daemon's Holder, channel manager and chat
contract, and the registry it produces is a daemon field, not a field on
a server with no listener. Boot now owns one Holder instead of seeding a
second and replacing it in buildDaemon; operator retry caps read it too,
so they follow a reload rather than a boot-time snapshot.
Server loses Cfg, ConfigProvenance, LastReload, ConfigOverrides and
SetProvenance. The nil-guarded branches they fed went with them, each
checked first against what the UI process actually serves:
- chat.show_tool_calls and the /api/setup checklist were degraded, not
dead. ConfigView gains a chat section carrying show_tool_calls, the
operator name and whether a channel is configured, and both surfaces
read the projection. The end-to-end suite asserts the checklist renders
from the published snapshot.
- /api/logs takes its path as a process-local option. The history is on
the daemon's disk, so a dashboard elsewhere cannot read it by learning
the path; that route still needs a contract.
- handleChannels drops its config-derived fallback, superseded by the
status manager, which already carries the descriptions and detail.
- trustForwardedHeaders keeps only the process's own setting, which the
UI process already sets.
- resolveForge keeps the published-projection path it already had.
ConfigView.Editable moves to handleConfig, decided by whether this
process holds UpdateConfig. It describes the writer, not the document, so
the write contract (archie-core-j28m) makes the page editable by wiring
one field. The write handlers and their seams stay for it.
overlay.Store gains Keys: Snapshot nests dotted keys for decoding, so the
overridden-key list was publishing section names ("budgets") where the
dashboard marks and resets rows by stored key ("budgets.max_steps").
Multi-identity forge links move to archie-core-pv6t: forgeConfigForTask
resolved a task's forge from config.Config, had no reachable caller once
the holder was gone, and belongs in the projection rather than the
rendering package.
127 lines
4.3 KiB
Go
127 lines
4.3 KiB
Go
// readiness.go wires the operator readiness probes (internal/domain/health)
|
|
// to their real subsystem dependencies and hands the assembled registry to the
|
|
// dashboard's /health/detailed surface. It is the composition-root bridge:
|
|
// each probe gets the narrowest real input it needs, never the daemon.
|
|
package archied
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/channels/status"
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/health"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
|
|
"github.com/samcharles93/archie-core/internal/webui"
|
|
)
|
|
|
|
// setupReadinessProbes assembles the readiness probes over the daemon's own
|
|
// subsystems. It must be called after setupObservability (so the config
|
|
// Holder and channel manager exist) and after the chat wiring (so b.chat
|
|
// exposes the contract).
|
|
//
|
|
// The probes read the daemon's state directly rather than through a
|
|
// webui.Server: the daemon serves /health/detailed on its own listener and
|
|
// has served no dashboard since the UI process cutover (archie-core-ml30).
|
|
func (b *boot) setupReadinessProbes() {
|
|
cfg := b.cfg
|
|
probes := []health.Probe{
|
|
readiness.NewStoreProbe(b.stateStore),
|
|
readiness.NewConfigProbe(b.cfgHolder.Get, configuration.Validate),
|
|
readiness.NewDiskProbe(diskProbePath(cfg)),
|
|
readiness.NewModelProbe(b.chatModels.ActiveModel, b.chatModels.Models, modelReachProbe(cfg, b.chatModels.ActiveModel)),
|
|
readiness.NewGatewayProbe(
|
|
func() []readiness.ChannelState { return channelStates(b.channelManager) },
|
|
func(ctx context.Context) int { return sessionCount(ctx, b.chat) },
|
|
),
|
|
}
|
|
b.healthRegistry = health.NewRegistry(probes...)
|
|
}
|
|
|
|
// channelStates projects a channel lifecycle snapshot into the readiness
|
|
// probe's view, so the probe does not depend on the channels package's
|
|
// concrete type.
|
|
func channelStates(m *status.Manager) []readiness.ChannelState {
|
|
if m == nil {
|
|
return nil
|
|
}
|
|
snapshot := m.Snapshot()
|
|
states := make([]readiness.ChannelState, 0, len(snapshot))
|
|
for _, s := range snapshot {
|
|
states = append(states, readiness.ChannelState{
|
|
ID: s.ID,
|
|
Configured: s.Configured,
|
|
State: string(s.State),
|
|
})
|
|
}
|
|
return states
|
|
}
|
|
|
|
// sessionCount returns the number of gateway sessions. An unwired chat
|
|
// surface returns 0 rather than reporting a false failure.
|
|
func sessionCount(ctx context.Context, chat *webui.ChatService) int {
|
|
if chat == nil || chat.Contract == nil {
|
|
return 0
|
|
}
|
|
snapshot, err := chat.Contract.Snapshot(ctx)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
return len(snapshot.Sessions)
|
|
}
|
|
|
|
// diskProbePath resolves the filesystem the readiness disk probe inspects:
|
|
// the store database directory first (the data that must fit on disk), then
|
|
// the working directory, then the process cwd.
|
|
func diskProbePath(cfg config.Config) string {
|
|
switch {
|
|
case cfg.DBPath != "":
|
|
return filepath.Dir(cfg.DBPath)
|
|
case cfg.WorkDir != "":
|
|
return cfg.WorkDir
|
|
default:
|
|
return "."
|
|
}
|
|
}
|
|
|
|
// modelReachProbe returns a live reachability check for the active model. It
|
|
// resolves the active model's provider and, when the provider has a custom
|
|
// base URL, performs a short-timeout HTTP request to it: any response
|
|
// (including 401/404) proves the endpoint is reachable, while a network error
|
|
// or an unconfigured provider reports unreachable. A provider using its SDK
|
|
// default endpoint is assumed reachable, because no custom endpoint exists to
|
|
// probe.
|
|
func modelReachProbe(cfg config.Config, active func() string) func(context.Context) error {
|
|
return func(ctx context.Context) error {
|
|
model := active()
|
|
provider, _, _ := strings.Cut(model, "/")
|
|
if provider == "" {
|
|
return fmt.Errorf("active model %q has no provider", model)
|
|
}
|
|
p, ok := cfg.Providers[provider]
|
|
if !ok {
|
|
return fmt.Errorf("provider %q not configured", provider)
|
|
}
|
|
if p.BaseURL == "" {
|
|
return nil
|
|
}
|
|
reqCtx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
|
defer cancel()
|
|
req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, p.BaseURL, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_ = resp.Body.Close()
|
|
return nil
|
|
}
|
|
}
|