* feat(gateway): give /status a real daemon-health surface Phase 2 of archie-core-wp9s. Phase 1 split the commands apart (health vs work) but left /status with one aggregate queue line and a static runtime block; it could not answer the questions an operator actually asks when something feels wrong. /status now reports, between the queue line and the runtime block: - Broker: the live state of this process's own NATS connection (eventbus/nats.Client.Connected), not a fresh dial -- a probe would report the probe's reachability, not the daemon's. - Containers: the pool's own active counter against the configured cap (Pool.Active/Cap), not a Docker listing, which would include containers this pool does not own. A zero cap means unlimited, so it is not shown as a ratio. - Channels: the channel manager's real lifecycle state, including a failed adapter's reason (the documented decision: read the existing manager rather than re-deriving health per adapter). - Chat model: last-known outcome of every chat-model call this process made, recorded once in sendChatTurn (the single choke point) and read back by /status. The second documented decision: never a live probe, so /status stays instant and reports what happened -- or says plainly that nothing has been attempted yet. - Last poll: when the most recent poll pass began, stamped on both poll paths (Run's single-identity loop and runIdentities' per-identity goroutines). A pass that hangs leaves the stamp stale, which is the signal; stamping completion would leave a wedged poller looking healthy. Truthful or absent: a section this process has no source for is omitted rather than rendered as a zero. The standalone Gateway owns no poll loop, pool or channel manager, so its /status reports broker and chat-model health only; aggregating across processes would need a new daemon RPC and is deliberately not built. Version stays out (/version owns it). /status and /tasks descriptions now describe what each command actually does on both published surfaces (Telegram menu/help and the shared specs), pinned by a test that also fails if the two surfaces drift. Sources are read through functions, not captured values: occupancy and channel state move, and the daemon is built after the gateways, so a source captured at construction would freeze /status on boot state. Left in place deliberately: the Runtime (provider/model) block, which Phase 1 flagged and which duplicates /model and /whoami. Removing it is a product call on a command Sam uses daily, not a mechanical follow-up. * docs(prds): record the two open /status health decisions as settled Both were flagged in PR #892 as needing the maintainer's call; both are now answered, and the PRD is the place a follow-up would look: - The Runtime (provider/model) block stays. It is the one line in /status the ticket's own rule says should not be there, but /status is read daily to see the active model at a glance, so the duplication is deliberate. Recorded as a settled product decision so it is not removed later as an oversight. - Health stays per-process. Pooling the daemon's and the Gateway's chat-model outcomes would need a new daemon<->gateway health RPC for one status line, and a per-process line is true where an aggregate would be a claim about a process the answering one cannot see. /agents' published description is still left to archie-core-mxls, unchanged.
93 lines
4.2 KiB
Go
93 lines
4.2 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/samcharles93/archie-core/internal/agentexec"
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
"github.com/samcharles93/archie-core/internal/tools"
|
|
)
|
|
|
|
// setupChatRuntime wires the model runtime, tool registry, persona registry,
|
|
// chat task creator/controller, default chat identity and the release-update
|
|
// service. The daemon and the standalone Gateway build through this one
|
|
// constructor so the two processes cannot diverge.
|
|
func (b *boot) setupChatRuntime(cfg config.Config) {
|
|
// ── LLM runtime ──────────────────────────────────────────────────
|
|
// Created before the router so the LLMResponder can be wired in for
|
|
// non-command message processing.
|
|
providers := executionProviders(cfg)
|
|
b.llm = agentexec.NewRuntime(providers)
|
|
b.toolReg = tools.NewRegistry()
|
|
chatModels := newChatModelManager(cfg.Models, cfg.Chat.Models, b.catalogModels)
|
|
chatModels.ApplyModelCatalog(b.catalog)
|
|
b.chatModels = chatModels
|
|
|
|
// ── Persona registry ─────────────────────────────────────────────
|
|
b.personas = gateway.NewPersonaRegistry(gateway.DefaultPersonas())
|
|
|
|
// ── Operator health surface ──────────────────────────────────────
|
|
// Built before the gateways because every turn runner and router built
|
|
// later carries both: the recorder is written by sendChatTurn, the source
|
|
// is read by /status. See newStatusHealth for why the source reads boot's
|
|
// fields lazily.
|
|
b.providerOutcomes = newProviderOutcomeRecorder()
|
|
b.statusHealth = newStatusHealth(b)
|
|
|
|
profiles, defaultChatIdentity := chatTaskProfiles(cfg)
|
|
var chatTasks gateway.TaskCreator
|
|
if len(profiles) > 0 {
|
|
chatTasks = gateway.NewStoreTaskCreatorForProfiles(
|
|
chatTaskWriterAdapter{enqueue: b.stateStore.EnqueueChatTask},
|
|
profiles,
|
|
)
|
|
}
|
|
b.chatTasks = chatTasks
|
|
b.defaultChatIdentity = defaultChatIdentity
|
|
b.chatController = gateway.NewStoreTaskController(chatTaskControllerAdapter{
|
|
taskByID: b.stateStore.TaskByID,
|
|
requeue: b.stateStore.Requeue,
|
|
transition: b.stateStore.Transition,
|
|
})
|
|
b.updateService = makeUpdateService(chatSetup{Cfg: config.NewHolder(cfg)})
|
|
}
|
|
|
|
// setupGatewayChat is the sole production constructor of the local contract.
|
|
// Frontends use its gRPC representation; only this service owns the router.
|
|
func (b *boot) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskActor) gateway.ChatContract {
|
|
b.setupChatRuntime(b.cfg)
|
|
cfg := b.cfg
|
|
router := gateway.NewRouter(b.stateStore, nil, "web")
|
|
router.Limiter = b.rateLimiter
|
|
router.Version = fmt.Sprintf("Archie\nGateway: %s\nRuntime: %s", gatewayVersion, runtimeVersion)
|
|
router.Models = b.chatModels
|
|
router.Personas = b.personas
|
|
router.Updates = b.updateService
|
|
router.InitSessions(b.chatSessionStore)
|
|
configureTaskCommands(router, b.chatTasks, b.chatController, chatTaskListerAdapter{tasks: b.stateStore.Tasks}, b.defaultChatIdentity)
|
|
router.Health = b.statusHealth
|
|
setup := chatSetup{
|
|
Cfg: config.NewHolder(cfg), LLM: b.llm, ChatModels: b.chatModels, ToolReg: b.toolReg,
|
|
Personas: b.personas, ChatTasks: b.chatTasks,
|
|
ChatTaskLister: chatTaskListerAdapter{tasks: b.stateStore.Tasks},
|
|
ChatTaskLogs: chatTaskLogReaderAdapter{tasks: b.stateStore.TaskByID, taskLogs: b.taskLogs},
|
|
ChatTaskActor: actor, ChatPRReviewer: b.prReviewer(),
|
|
DefaultChatIdentity: b.defaultChatIdentity,
|
|
Bus: b.bus, Log: b.log,
|
|
MemoryEngine: b.memoryStore(),
|
|
MemoryWriter: b.memoryWriter(),
|
|
// The Gateway executes the web chat's turns, so it is the process
|
|
// that must record their outcomes for /status.
|
|
ProviderOutcomes: b.providerOutcomes,
|
|
}
|
|
router.LLM, router.LLMStream = makeChatLLMResponder(ctx, "web", setup, b.chatSessionStore, router)
|
|
router.Titles = newChatTitleGenerator(setup)
|
|
router.Log = b.log
|
|
return &gateway.LocalChatAdapter{
|
|
Router: router, Sessions: b.chatSessionStore, Turns: gateway.NewTurns(b.log),
|
|
Models: b.chatModels, Personas: b.personas, TaskActor: actor,
|
|
}
|
|
}
|