From 851cb78b04236c9a11f98c0251e95ade14e32a44 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 13 Nov 2026 13:16:11 +1100 Subject: [PATCH] fix(chat): a failed turn reads as a plain sentence, shown as an error --- internal/gateway/turn_failure.go | 21 +++++++++++---------- internal/gateway/turn_failure_test.go | 2 +- internal/webui/chat.go | 5 ++--- internal/webui/chat_errors_test.go | 2 +- ui/src/chat/ChatBubble.vue | 12 +++++++++++- ui/src/chat/ChatTranscript.vue | 3 +++ ui/src/chat/state.ts | 19 +++++++++++++------ 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/internal/gateway/turn_failure.go b/internal/gateway/turn_failure.go index 19964d5bb..3e3938fa2 100644 --- a/internal/gateway/turn_failure.go +++ b/internal/gateway/turn_failure.go @@ -7,24 +7,25 @@ import ( "github.com/samcharles93/ai-sdk/chat" ) -// turnFailureText is what a chat reader sees when a turn fails. The cause -// carries provider bodies, URLs and wrapping that belong in the log, which -// failTurn writes, not in front of whoever is chatting. +// turnFailureText is what a chat reader sees when a turn fails: one complete +// sentence they can act on, shown as the reply itself. The cause carries +// provider bodies, URLs and wrapping that belong in the log, which failTurn +// writes, not in front of whoever is chatting. func turnFailureText(err error) string { switch { case errors.Is(err, chat.ErrRateLimited): - return "the model provider is refusing requests (rate limit or spending cap). Try again later, or switch model with /model." + return "The model provider is refusing requests right now (rate limit or spending cap). Try again later, or pick another model with /model." case errors.Is(err, chat.ErrAuthFailed): - return "the model provider rejected Archie's credentials. Check the provider key in settings." + return "The model provider rejected Archie's credentials. An admin needs to check the provider key in Settings." case errors.Is(err, chat.ErrProviderUnavailable): - return "the model provider is unavailable. Try again in a moment." + return "The model provider is unavailable. Try again in a moment." case errors.Is(err, chat.ErrContextLength): - return "this conversation is too long for the model. Start a new chat, or shorten it with /compress." + return "This conversation is too long for the model. Start a new chat, or shorten this one with /compress." case errors.Is(err, chat.ErrUnsupportedContent): - return "the model can't read one of the attachments. Remove it, or switch model with /model." + return "The model can't read one of the attachments. Remove it, or pick another model with /model." case errors.Is(err, context.DeadlineExceeded): - return "the model took too long to answer. Try again." + return "The model took too long to answer. Try again." default: - return "something went wrong on Archie's side. Try again; the gateway log has the cause." + return "Archie couldn't reply. Try again in a moment." } } diff --git a/internal/gateway/turn_failure_test.go b/internal/gateway/turn_failure_test.go index 1eead81aa..e6678d07f 100644 --- a/internal/gateway/turn_failure_test.go +++ b/internal/gateway/turn_failure_test.go @@ -22,7 +22,7 @@ func TestStreamedTurnFailureHidesCause(t *testing.T) { }{ {name: "spending cap", cause: chat.ErrRateLimited, want: "rate limit or spending cap"}, {name: "bad key", cause: chat.ErrAuthFailed, want: "credentials"}, - {name: "unknown", cause: errors.New("dial tcp 10.0.0.1:5432: refused"), want: "gateway log"}, + {name: "unknown", cause: errors.New("dial tcp 10.0.0.1:5432: refused"), want: "Archie couldn't reply"}, } { t.Run(tc.name, func(t *testing.T) { raw := fmt.Errorf(`llm chat stream: gemini: status 429: {"message":"https://ai.studio/spend"}: %w`, tc.cause) diff --git a/internal/webui/chat.go b/internal/webui/chat.go index c36619cbe..70729e170 100644 --- a/internal/webui/chat.go +++ b/internal/webui/chat.go @@ -176,9 +176,8 @@ func (a *chatAPI) chatReady(w http.ResponseWriter) (*ChatService, bool) { // chatFailureText is what the browser sees when a chat backend call fails. // The cause can carry SQL, gRPC status details or host paths, so failChat -// logs it server-side and sends this sentence instead, in the same plain -// wording the gateway gives chat readers for a failed turn. -const chatFailureText = "something went wrong on Archie's side. Try again; the server log has the cause." +// logs it server-side and sends this sentence instead. +const chatFailureText = "Something went wrong. Try again in a moment." // failChat logs the real cause with the request's trace and answers with the // plain sentence. A nil logger is tolerated, as tests build servers without one. diff --git a/internal/webui/chat_errors_test.go b/internal/webui/chat_errors_test.go index f82d44dd7..9ad674fec 100644 --- a/internal/webui/chat_errors_test.go +++ b/internal/webui/chat_errors_test.go @@ -23,7 +23,7 @@ var errInternal = errors.New(internalDetail) // plainChatFailure is the sentence the browser must see instead; spelled out // here so the test also compiles, and fails, against the unsanitised handlers. -const plainChatFailure = "something went wrong on Archie's side. Try again; the server log has the cause." +const plainChatFailure = "Something went wrong. Try again in a moment." // failingChat fails the contract methods its fields name, so one fake covers // every chat endpoint. diff --git a/ui/src/chat/ChatBubble.vue b/ui/src/chat/ChatBubble.vue index 7b93846aa..77e6cdbcd 100644 --- a/ui/src/chat/ChatBubble.vue +++ b/ui/src/chat/ChatBubble.vue @@ -1,4 +1,5 @@