fix: address the Greptile findings on the merged PRs (#902)
* fix: address the Greptile findings on the merged PRs Four valid review findings from PRs #892, #893, #898 and #899, which were merged without the comments being read. - Config.Clone left the new diff-cap pointers aliased (#899, mine). Clone deep-copies every reference field, including the *bool beside it, so a clone could write the cap through to the published snapshot. Both the top-level field and the identity overrides are copied, with the clone test extended to cover them. - providerOutcomeRecorder.record could report an older call as the latest (#892). The completion time is taken before the lock, so two concurrent calls can reach the lock in the opposite order to their completion and the unconditional store overwrote the newer outcome. It now keeps the newer, via a recordAt seam that makes the reordering testable. - Curator model calls bypassed the recorder (#892). curatorLLMRunner calls the runtime directly, so a daemon whose only recent model traffic was curator work reported "no calls attempted yet" while the provider was demonstrably reachable. It records at its own adapter, and sendChatTurn's "single choke point" comment is corrected to say there are two. - A provider error reached /status raw (#892), unlike channel details, so a multiline or oversized error broke the one-line-per-fact layout. Both now share one bounded formatter. Found while fixing the curator path: agentexec.NewRuntime returns nil when no provider is configured, and a nil *runtime.Runtime panics on its first method call, so a curator asking for a completion took the daemon down. It now returns an error, and records nothing -- a local misconfiguration is not a provider call. Not fixed, filed instead: the shared lastPollAt masking a stuck identity, the container max-uptime callback resurrecting teardown bookkeeping, the dashboard dropping a served-only status filter on cold load, and the route registry test's line-by-line parser. * fix(build): drop goimports from the gate's formatter set `task check` spent 136 of its 167 seconds in `task fmt`, and 134 of those 136 in one formatter: goimports alone over the tree. golangci-lint's goimports formatter calls imports.Process once per file, which builds a fresh x/tools ProcessEnv each time, so internal/imports.getFixesWithSource re-reads modindex.Read($GOMODCACHE) per file. On this machine that index is 62.7 MiB / 2,081,070 lines (an 11 GiB module cache), and modindex's in-process memo does not take effect: 3 files read 187.9 MiB back, 15 files open the payload 15 times. That is ~53 GiB of I/O and CSV parsing per run, and it is linear at ~155 ms per file (122 files -> 18.8s, 864 -> 133.8s). Pointing the index cache elsewhere drops the same command to 3.9s. The same analyzer runs under `golangci-lint run`, so a cold cache pays it again: 169s cold with goimports, 31s without -- which is what CI and archied's own PR gate see, since only `fmt` never caches locally. Removing it costs no enforcement. gofumpt and gci remain, `task lint` still reports formatter drift as an issue, and the whole-tree fmt is now 2.2s with the tree byte-identical. What is given up is goimports' convenience of adding and removing import lines, which compile errors already cover. The examples/secret-engines exclusion stays: gofumpt and gci leave those Yaegi programs alone today, but the exclusion is the stated invariant that a formatter must not rewrite the imports of files it cannot type-check, and TestFormattersExcludeInterpretedSecretEngines holds it. Its comment no longer pins the reason to the formatter that was dropped. * fix(gateway): stop /status promising and mis-reporting health it cannot see Two findings from the cloud review of #892. Title generation no longer records chat-model health. It runs detached after a first turn under its own 30s bound and its error is swallowed by the caller, but it shared the process-wide outcome recorder, so a title that merely timed out overwrote the health line with "failed" -- reporting a broken provider on the strength of a call no user was waiting for. The /status command description no longer claims "workers" and "channels". Neither can render: newStatusHealth reads the container pool and the poll loop from boot, but the only production router.Health assignment is in setupGatewayChat, which runs solely in the archie-gateway process, where neither exists; channels is nil since the Messaging Service took the front-ends. Only the broker and chat-model lines actually appear, so that is what the help text now says. The underlying split -- daemon owns the facts, Gateway owns the Router -- is filed rather than patched here: it needs either a cross-process health contract or a ratified two-section /status, not a quick wire-up.
This commit is contained in:
1 parent
0efd812387
commit
16e3b84048
13 files changed
+225
-25
No files matched your search
+4
-4
@@ -116,7 +116,6 @@ linters:
|
||||
formatters:
|
||||
enable:
|
||||
- gofumpt
|
||||
- goimports
|
||||
- gci
|
||||
settings:
|
||||
gofumpt:
|
||||
@@ -131,9 +130,10 @@ formatters:
|
||||
custom-order: true
|
||||
exclusions:
|
||||
generated: strict
|
||||
# These are Yaegi programs shipped as examples. goimports cannot type-check
|
||||
# files excluded by //go:build ignore and deletes their genuinely used
|
||||
# internal/secret import, leaving the interpreter unable to load them.
|
||||
# These Yaegi programs sit behind //go:build ignore, so a formatter cannot
|
||||
# type-check them: rewriting their imports deletes the genuinely used
|
||||
# internal/secret import and the interpreter can no longer load them.
|
||||
# Excluded from every formatter so adding one cannot reintroduce that.
|
||||
paths:
|
||||
- ^examples/secret-engines/(age|sops|vault)\.go$
|
||||
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ tasks:
|
||||
cmds:
|
||||
- go fix ./...
|
||||
# This must use the same engine and configuration as task lint. Running
|
||||
# standalone gofumpt cannot reproduce goimports or gci's custom import
|
||||
# grouping, so it can leave a tree that the gate rejects.
|
||||
# standalone gofumpt cannot reproduce gci's custom import grouping, so it
|
||||
# can leave a tree that the gate rejects.
|
||||
- golangci-lint fmt
|
||||
|
||||
proto:install:
|
||||
|
||||
@@ -995,7 +995,7 @@ func (b *boot) setupCurators(ctx context.Context) {
|
||||
// Conversations backs the session-memory curator; b.chatSessionStore
|
||||
// is opened by openChatSessions before setupCurators.
|
||||
Conversations: sessioncurator.NewAdapter(b.chatSessionStore),
|
||||
LLM: curatorLLMRunner{rt: b.llm},
|
||||
LLM: curatorLLMRunner{rt: b.llm, outcomes: b.providerOutcomes},
|
||||
// b.chatModels.ActiveModel() is the same source sendChatTurn uses
|
||||
// for a real chat turn (telegram_setup.go) -- not
|
||||
// b.defaultChatIdentity, which names a task-routing identity, not
|
||||
|
||||
@@ -238,10 +238,11 @@ func chatRepoEnv(cfg config.Config, identity string) []gateway.RepoEnv {
|
||||
}
|
||||
|
||||
// sendChatTurn runs one chat-model call and records its outcome for /status'
|
||||
// chat-model line. Recording happens in this one wrapper because every
|
||||
// chat-model call in this process passes through it: recording at the call
|
||||
// sites instead would let a path make a call and leave the reported
|
||||
// last-known outcome stale, which is a /status that lies about the provider.
|
||||
// chat-model line. Every chat turn passes through here, so one wrapper covers
|
||||
// the whole chat path; curator work is the other model caller in this process
|
||||
// and records at its own adapter (curatorLLMRunner). Anything that reaches the
|
||||
// runtime without recording leaves /status reporting a stale last-known
|
||||
// outcome, which is a /status that lies about the provider.
|
||||
func sendChatTurn(ctx context.Context, llm *runtime.Runtime, chatModel string, options core.GenerateOptions, turn gateway.TurnStream, outcomes *providerOutcomeRecorder) (string, error) {
|
||||
text, err := runChatTurn(ctx, llm, chatModel, options, turn)
|
||||
// record tolerates a nil recorder: a setup built without one (tests, a
|
||||
@@ -374,7 +375,6 @@ type chatTitleGenerator struct {
|
||||
log *slog.Logger
|
||||
llm *runtime.Runtime
|
||||
chatModels gateway.ModelManager
|
||||
outcomes *providerOutcomeRecorder
|
||||
}
|
||||
|
||||
// newChatTitleGenerator wires an LLM-backed title generator for a chat
|
||||
@@ -384,7 +384,7 @@ func newChatTitleGenerator(s chatSetup) gateway.TitleGenerator {
|
||||
if s.LLM == nil || s.ChatModels == nil {
|
||||
return nil
|
||||
}
|
||||
return &chatTitleGenerator{log: s.Log, llm: s.LLM, chatModels: s.ChatModels, outcomes: s.ProviderOutcomes}
|
||||
return &chatTitleGenerator{log: s.Log, llm: s.LLM, chatModels: s.ChatModels}
|
||||
}
|
||||
|
||||
func (g *chatTitleGenerator) GenerateTitle(ctx context.Context, sessionID, firstMessage string) (string, error) {
|
||||
@@ -394,8 +394,15 @@ func (g *chatTitleGenerator) GenerateTitle(ctx context.Context, sessionID, first
|
||||
}
|
||||
// No tools: a title is a single completion. The active model is read
|
||||
// at call time so a /model switch applies to titles too.
|
||||
//
|
||||
// Deliberately records no outcome for /status. A title is cosmetic,
|
||||
// generated in a detached goroutine under its own 30s bound
|
||||
// (gateway.titleGenerationTimeout), and its error is swallowed by the
|
||||
// caller. Sharing the process-wide recorder let a title that merely timed
|
||||
// out overwrite the chat-model health line with "failed", reporting a
|
||||
// broken provider on the strength of a call no user was waiting for.
|
||||
text, err := sendChatTurn(ctx, g.llm, g.chatModels.ActiveModel(),
|
||||
core.GenerateOptions{Messages: messages, MaxSteps: 1}, nil, g.outcomes)
|
||||
core.GenerateOptions{Messages: messages, MaxSteps: 1}, nil, nil)
|
||||
if err != nil {
|
||||
if g.log != nil {
|
||||
g.log.Error("session title generation failed", "session", sessionID, "err", err)
|
||||
|
||||
@@ -547,14 +547,29 @@ func (s curatorEventSink) Emit(kind, detail string, data map[string]any) {
|
||||
// single completion are a bigger decision than this adapter makes.
|
||||
type curatorLLMRunner struct {
|
||||
rt *runtime.Runtime
|
||||
// outcomes records this call for /status alongside sendChatTurn's. A
|
||||
// curator call is a model call this process made, and it does not pass
|
||||
// through sendChatTurn, so without this a daemon whose only recent model
|
||||
// traffic was curator work reports "no calls attempted yet" while the
|
||||
// provider is demonstrably reachable -- or worse, keeps showing a much
|
||||
// older chat outcome as current.
|
||||
outcomes *providerOutcomeRecorder
|
||||
}
|
||||
|
||||
func (r curatorLLMRunner) Chat(ctx context.Context, req curator.ChatRequest) (curator.ChatResult, error) {
|
||||
// agentexec.NewRuntime returns nil when no provider is configured, and a
|
||||
// nil *runtime.Runtime panics on the first method call. A curator asking
|
||||
// for a completion on a daemon with no providers is a misconfiguration,
|
||||
// not a reason to take the process down.
|
||||
if r.rt == nil {
|
||||
return curator.ChatResult{}, fmt.Errorf("curator chat: no model runtime is configured")
|
||||
}
|
||||
msgs := make([]chat.Message, 0, len(req.Messages))
|
||||
for _, m := range req.Messages {
|
||||
msgs = append(msgs, chat.Message{Role: chat.Role(m.Role), Content: m.Content})
|
||||
}
|
||||
res, err := r.rt.Chat(ctx, req.Model, core.GenerateOptions{Messages: msgs, MaxSteps: max(req.MaxSteps, 1)})
|
||||
r.outcomes.record(req.Model, err)
|
||||
if err != nil {
|
||||
return curator.ChatResult{}, err
|
||||
}
|
||||
|
||||
@@ -39,15 +39,31 @@ func newProviderOutcomeRecorder() *providerOutcomeRecorder { return &providerOut
|
||||
// when it succeeded. A nil recorder records nothing -- call paths built
|
||||
// without one (tests, minimal setups) must not panic.
|
||||
func (r *providerOutcomeRecorder) record(model string, err error) {
|
||||
r.recordAt(model, err, time.Now().UTC())
|
||||
}
|
||||
|
||||
// recordAt stores one call's outcome, keeping whichever is most recent.
|
||||
//
|
||||
// The completion time is taken by the caller, before the lock, so it reports
|
||||
// when the call actually finished rather than when this goroutine won the
|
||||
// mutex. That ordering is not the same as the lock's: two concurrent calls can
|
||||
// reach the lock in the opposite order to their completion, and an
|
||||
// unconditional store would then leave /status reporting an older call as the
|
||||
// latest one. Keeping the newer of the two is what makes the reported outcome
|
||||
// true regardless of scheduling.
|
||||
func (r *providerOutcomeRecorder) recordAt(model string, err error, at time.Time) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
outcome := gateway.ChatModelOutcome{Model: model, At: time.Now().UTC()}
|
||||
outcome := gateway.ChatModelOutcome{Model: model, At: at}
|
||||
if err != nil {
|
||||
outcome.Err = err.Error()
|
||||
}
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if r.attempted && outcome.At.Before(r.outcome.At) {
|
||||
return
|
||||
}
|
||||
r.outcome = outcome
|
||||
r.attempted = true
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/agentexec"
|
||||
"github.com/samcharles93/archie-core/internal/channels/status"
|
||||
"github.com/samcharles93/archie-core/internal/daemon"
|
||||
"github.com/samcharles93/archie-core/internal/domain/curator"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
@@ -463,3 +464,111 @@ func TestRouterWithHealthAnswersStatus(t *testing.T) {
|
||||
t.Errorf("reply = %q, want the wired broker line", reply)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRecordKeepsTheLatestOutcomeUnderReordering is the regression case for a
|
||||
// /status chat-model line that reports an older call as the latest. The
|
||||
// completion time is taken before the lock, so two concurrent calls can reach
|
||||
// the lock in the opposite order to their completion; an unconditional store
|
||||
// then overwrites the newer outcome with the older one.
|
||||
func TestRecordKeepsTheLatestOutcomeUnderReordering(t *testing.T) {
|
||||
r := &providerOutcomeRecorder{}
|
||||
newer := time.Now().UTC()
|
||||
older := newer.Add(-time.Minute)
|
||||
|
||||
// The later call completes and stores first, as it would when the earlier
|
||||
// call is descheduled between stamping and locking.
|
||||
r.recordAt("openai/gpt-5.6", nil, newer)
|
||||
r.recordAt("openai/gpt-4o", errors.New("401 Unauthorized"), older)
|
||||
|
||||
got, attempted := r.LastChatModelOutcome()
|
||||
if !attempted {
|
||||
t.Fatal("LastChatModelOutcome reports no attempt after two records")
|
||||
}
|
||||
if got.Model != "openai/gpt-5.6" || got.Err != "" {
|
||||
t.Fatalf("outcome = %+v, want the newer successful call to survive", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRecordStoresTheFirstOutcomeWhateverItsAge pins that the ordering guard
|
||||
// does not swallow the first record, whose timestamp has nothing to compare
|
||||
// against.
|
||||
func TestRecordStoresTheFirstOutcomeWhateverItsAge(t *testing.T) {
|
||||
r := &providerOutcomeRecorder{}
|
||||
r.recordAt("openai/gpt-4o", nil, time.Now().UTC().Add(-time.Hour))
|
||||
|
||||
if _, attempted := r.LastChatModelOutcome(); !attempted {
|
||||
t.Fatal("the first recorded outcome was dropped")
|
||||
}
|
||||
}
|
||||
|
||||
// TestCuratorRunnerRefusesWithoutARuntime pins that a curator asking for a
|
||||
// completion on a daemon with no configured provider gets an error. The
|
||||
// runtime constructor returns nil in that case, and a nil *runtime.Runtime
|
||||
// panics on its first method call, which would take the daemon down. Nothing
|
||||
// is recorded: no provider call was attempted, and saying one failed would be
|
||||
// a /status that blames the provider for a local misconfiguration.
|
||||
func TestCuratorRunnerRefusesWithoutARuntime(t *testing.T) {
|
||||
recorder := &providerOutcomeRecorder{}
|
||||
runner := curatorLLMRunner{outcomes: recorder}
|
||||
|
||||
if _, err := runner.Chat(context.Background(), curator.ChatRequest{Model: "openai/gpt-4o"}); err == nil {
|
||||
t.Fatal("Chat with no runtime returned no error")
|
||||
}
|
||||
if _, attempted := recorder.LastChatModelOutcome(); attempted {
|
||||
t.Error("a local misconfiguration was recorded as a provider call")
|
||||
}
|
||||
}
|
||||
|
||||
// TestCuratorRunnerRecordsItsOutcome pins that curator model calls reach
|
||||
// /status. They do not pass through sendChatTurn, so before this a daemon
|
||||
// whose only recent model traffic was curator work reported "no calls
|
||||
// attempted yet" while the provider was demonstrably reachable.
|
||||
func TestCuratorRunnerRecordsItsOutcome(t *testing.T) {
|
||||
recorder := &providerOutcomeRecorder{}
|
||||
// A provider pointed at a closed local port fails fast without touching
|
||||
// the network. The outcome is what matters here: a failed provider call is
|
||||
// exactly what /status must not miss.
|
||||
rt := agentexec.NewRuntime(map[string]agentexec.Provider{
|
||||
"openai": {Class: "openai", BaseURL: "http://127.0.0.1:1", APIKeyEnv: "ARCHIE_TEST_MISSING_KEY"},
|
||||
})
|
||||
if rt == nil {
|
||||
t.Fatal("NewRuntime returned nil for a configured provider")
|
||||
}
|
||||
runner := curatorLLMRunner{rt: rt, outcomes: recorder}
|
||||
|
||||
_, err := runner.Chat(context.Background(), curator.ChatRequest{Model: "openai/gpt-4o"})
|
||||
if err == nil {
|
||||
t.Fatal("Chat against a closed port returned no error")
|
||||
}
|
||||
|
||||
got, attempted := recorder.LastChatModelOutcome()
|
||||
if !attempted {
|
||||
t.Fatal("curator call was not recorded; /status would report no calls attempted")
|
||||
}
|
||||
if got.Model != "openai/gpt-4o" || got.Err == "" {
|
||||
t.Fatalf("outcome = %+v, want the failed curator call", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestTitleGenerationDoesNotRecordChatModelHealth is the regression case for
|
||||
// /status blaming the provider for a cosmetic failure. Title generation runs
|
||||
// detached after a first turn under its own 30s bound and its error is
|
||||
// swallowed by the caller, so a title that merely timed out must not become
|
||||
// the process-wide "Chat model: failed" that an operator reads as an outage.
|
||||
func TestTitleGenerationDoesNotRecordChatModelHealth(t *testing.T) {
|
||||
recorder := &providerOutcomeRecorder{}
|
||||
rt := agentexec.NewRuntime(map[string]agentexec.Provider{
|
||||
"openai": {Class: "openai", BaseURL: "http://127.0.0.1:1", APIKeyEnv: "ARCHIE_TEST_MISSING_KEY"},
|
||||
})
|
||||
if rt == nil {
|
||||
t.Fatal("NewRuntime returned nil for a configured provider")
|
||||
}
|
||||
gen := &chatTitleGenerator{llm: rt, chatModels: newChatModelManager(map[string]string{"chat": "openai/gpt-4o"}, nil, nil)}
|
||||
|
||||
if _, err := gen.GenerateTitle(context.Background(), "s1", "hello"); err == nil {
|
||||
t.Fatal("GenerateTitle against a closed port returned no error")
|
||||
}
|
||||
if _, attempted := recorder.LastChatModelOutcome(); attempted {
|
||||
t.Error("a failed title proposal was recorded as chat-model health")
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ type commandSpec struct {
|
||||
// published command menu and /help. Keeping the discoverability surfaces
|
||||
// together prevents a newly registered command from being omitted from help.
|
||||
var gatewayCommandSpecs = []commandSpec{
|
||||
{Command: "status", Description: "Show daemon health: broker, workers, channels, provider", Usage: "/status"},
|
||||
{Command: "status", Description: "Show health: queue depth, broker, and the last chat-model call", Usage: "/status"},
|
||||
{Command: "tasks", Description: "Show your tasks: state, stage, age, parked reason", Usage: "/tasks"},
|
||||
{Command: "version", Description: "Show installed Archie versions", Usage: "/version"},
|
||||
{Command: "update", Description: "Check for Archie updates", Usage: "/update"},
|
||||
|
||||
@@ -11,12 +11,14 @@ import (
|
||||
func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) {
|
||||
enabled := true
|
||||
orig := Config{
|
||||
Models: map[string]string{"builder": "m"},
|
||||
ModelLimits: map[string]ModelLimits{"m": {ContextWindow: 128_000}},
|
||||
Repos: []Repo{{Gate: [][]string{{"task", "check"}}, Protect: []string{"p"}}},
|
||||
Models: map[string]string{"builder": "m"},
|
||||
ModelLimits: map[string]ModelLimits{"m": {ContextWindow: 128_000}},
|
||||
Repos: []Repo{{Gate: [][]string{{"task", "check"}}, Protect: []string{"p"}}},
|
||||
DiffCapLines: new(400),
|
||||
Identities: []IdentityConfig{{
|
||||
Models: map[string]string{"planner": "m2"},
|
||||
Repos: []Repo{{Gate: [][]string{{"go", "vet"}}}},
|
||||
Models: map[string]string{"planner": "m2"},
|
||||
DiffCapLines: new(50),
|
||||
Repos: []Repo{{Gate: [][]string{{"go", "vet"}}}},
|
||||
}},
|
||||
Dispatch: Dispatch{Labels: map[string]string{"q": "archie:q"}},
|
||||
Tools: ToolsConfig{
|
||||
@@ -51,6 +53,8 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) {
|
||||
got.Extra["custom"] = 2
|
||||
got.Bindings.PreviousEncryptionKeys[0] = SecretRef{Engine: "env", Key: "changed"}
|
||||
*got.Tools.WebFetch.Enabled = false
|
||||
*got.DiffCapLines = 1
|
||||
*got.Identities[0].DiffCapLines = 2
|
||||
got.Image.Hosted["openai"] = ImageHostedProvider{Enabled: false}
|
||||
got.Image.Local["sdxl"] = ImageLocalProvider{Enabled: false}
|
||||
got.Services[ServiceNameState] = ServiceConnection{Target: "changed"}
|
||||
@@ -85,6 +89,12 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) {
|
||||
if orig.Bindings.PreviousEncryptionKeys[0].Key != "K0" {
|
||||
t.Error("Bindings.PreviousEncryptionKeys is shared")
|
||||
}
|
||||
if orig.DiffCap() != 400 {
|
||||
t.Errorf("DiffCapLines pointer is shared: orig.DiffCap() = %d, want 400", orig.DiffCap())
|
||||
}
|
||||
if got := orig.Identities[0].DiffCapLines; got == nil || *got != 50 {
|
||||
t.Errorf("Identities[0].DiffCapLines pointer is shared: got %v, want 50", got)
|
||||
}
|
||||
if !*orig.Tools.WebFetch.Enabled {
|
||||
t.Error("WebFetch.Enabled pointer is shared")
|
||||
}
|
||||
|
||||
@@ -695,10 +695,22 @@ func (c Config) Clone() Config {
|
||||
v := *c.Tools.WebFetch.Enabled
|
||||
c.Tools.WebFetch.Enabled = &v
|
||||
}
|
||||
c.DiffCapLines = cloneIntPtr(c.DiffCapLines)
|
||||
c.Extra = maps.Clone(c.Extra)
|
||||
return c
|
||||
}
|
||||
|
||||
// cloneIntPtr copies an optional int so a clone cannot write through to the
|
||||
// original. Optional ints carry a real meaning in their zero value (see
|
||||
// DiffCapLines), which is why they are pointers in the first place.
|
||||
func cloneIntPtr(v *int) *int {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
n := *v
|
||||
return &n
|
||||
}
|
||||
|
||||
func cloneRepos(repos []Repo) []Repo {
|
||||
if repos == nil {
|
||||
return nil
|
||||
@@ -723,6 +735,7 @@ func cloneIdentities(ids []IdentityConfig) []IdentityConfig {
|
||||
id.Providers = maps.Clone(id.Providers)
|
||||
id.Dispatch.Labels = cloneStringMap(id.Dispatch.Labels)
|
||||
id.Repos = cloneRepos(id.Repos)
|
||||
id.DiffCapLines = cloneIntPtr(id.DiffCapLines)
|
||||
out[i] = id
|
||||
}
|
||||
return out
|
||||
|
||||
@@ -20,7 +20,7 @@ type CommandSpec struct {
|
||||
}
|
||||
|
||||
var localCommandSpecs = []CommandSpec{
|
||||
{Command: "/status", Description: "Show daemon health: broker, workers, channels, provider", Usage: "/status"},
|
||||
{Command: "/status", Description: "Show health: queue depth, broker, and the last chat-model call", Usage: "/status"},
|
||||
{Command: "/tasks", Description: "Show your tasks: state, stage, age, parked reason", Usage: "/tasks"},
|
||||
{Command: "/model", Description: "Choose a provider and model", Usage: "/model [provider/model]"},
|
||||
{Command: "/spawn", Description: "Create a tracked task", Usage: "/spawn <title>"},
|
||||
|
||||
@@ -156,7 +156,10 @@ func formatChannels(channels []ChannelHealth) string {
|
||||
// multi-line error cannot break the chat reply's layout, and bounds its
|
||||
// length. A failed adapter is the case where an operator most needs the
|
||||
// reason, so this trims rather than drops it.
|
||||
func channelDetail(detail string) string {
|
||||
// boundedDetail flattens and caps a detail so one line of /status stays one
|
||||
// line. A provider error carries whatever the provider sent back, which for an
|
||||
// HTML error page or a echoed request body is neither short nor single-line.
|
||||
func boundedDetail(detail string) string {
|
||||
flattened := strings.Join(strings.Fields(detail), " ")
|
||||
runes := []rune(flattened)
|
||||
if len(runes) <= maxChannelDetail {
|
||||
@@ -165,6 +168,8 @@ func channelDetail(detail string) string {
|
||||
return string(runes[:maxChannelDetail]) + "…"
|
||||
}
|
||||
|
||||
func channelDetail(detail string) string { return boundedDetail(detail) }
|
||||
|
||||
func formatChatModel(health ChatModelHealth, now time.Time) string {
|
||||
if !health.Attempted {
|
||||
// The decision behind this line: /status never probes the provider.
|
||||
@@ -183,9 +188,9 @@ func formatChatModel(health ChatModelHealth, now time.Time) string {
|
||||
case outcome.Err == "":
|
||||
return fmt.Sprintf("ok %s%s", age, model)
|
||||
case age == "":
|
||||
return fmt.Sprintf("failed%s: %s", model, outcome.Err)
|
||||
return fmt.Sprintf("failed%s: %s", model, boundedDetail(outcome.Err))
|
||||
default:
|
||||
return fmt.Sprintf("failed %s%s: %s", age, model, outcome.Err)
|
||||
return fmt.Sprintf("failed %s%s: %s", age, model, boundedDetail(outcome.Err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,3 +240,28 @@ func TestHandleStatusReadsTheWiredHealthSource(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestFormatChatModelBoundsTheProviderError pins that a provider error cannot
|
||||
// break /status' one-line-per-fact layout. The error is whatever the provider
|
||||
// returned, which for an HTML error page is neither short nor single-line, and
|
||||
// unlike a channel detail it was passed through raw.
|
||||
func TestFormatChatModelBoundsTheProviderError(t *testing.T) {
|
||||
now := time.Now()
|
||||
health := ChatModelHealth{
|
||||
Attempted: true,
|
||||
Outcome: ChatModelOutcome{
|
||||
Model: "openai/gpt-5.6",
|
||||
At: now.Add(-time.Minute),
|
||||
Err: "502 Bad Gateway\n<html>\n<head><title>502</title></head>\n" + strings.Repeat("body text ", 40),
|
||||
},
|
||||
}
|
||||
|
||||
got := formatChatModel(health, now)
|
||||
if strings.ContainsAny(got, "\n\r") {
|
||||
t.Fatalf("formatChatModel() = %q, want a single line", got)
|
||||
}
|
||||
if len([]rune(got)) > maxChannelDetail+80 {
|
||||
t.Fatalf("formatChatModel() is %d runes, want it bounded near maxChannelDetail (%d)",
|
||||
len([]rune(got)), maxChannelDetail)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user