From 84843e619ae3bff16eef605c3b5ecb6407a8d1c1 Mon Sep 17 00:00:00 2001 From: Hugo Dutka Date: Fri, 12 Jun 2026 14:47:34 +0200 Subject: [PATCH] fix(coderd): disable chat worker in TestPostChatMessagesBusyInterrupt (#26331) Addresses https://github.com/coder/internal/issues/1584 --- coderd/coderd.go | 8 +++++++- coderd/coderdtest/coderdtest.go | 14 +++++++++----- coderd/exp_chats_chatstate_test.go | 4 +++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/coderd/coderd.go b/coderd/coderd.go index 0605e57829..537d024e77 100644 --- a/coderd/coderd.go +++ b/coderd/coderd.go @@ -258,6 +258,9 @@ type Options struct { // ChatProviderAPIKeys overrides deployment-derived provider keys. // Test harnesses use this to route chat models to local providers. ChatProviderAPIKeys *chatprovider.ProviderAPIKeys + // ChatWorkerDisabled skips starting the chat daemon's background + // worker. + ChatWorkerDisabled bool UpdateAgentMetrics func(ctx context.Context, labels prometheusmetrics.AgentMetricLabels, metrics []*agentproto.Stats_Metric) StatsBatcher workspacestats.Batcher @@ -839,7 +842,10 @@ func New(options *Options) *API { OIDCTokenSource: oidcMCPSrc, NotificationsEnqueuer: options.NotificationsEnqueuer, Auditor: &api.Auditor, - }).Start() + }) + if !options.ChatWorkerDisabled { + api.chatDaemon.Start() + } gitSyncLogger := options.Logger.Named("gitsync") refresher := gitsync.NewRefresher( api.resolveGitProvider, diff --git a/coderd/coderdtest/coderdtest.go b/coderd/coderdtest/coderdtest.go index 0a34b5fcb2..0babe14dfa 100644 --- a/coderd/coderdtest/coderdtest.go +++ b/coderd/coderdtest/coderdtest.go @@ -154,11 +154,14 @@ type Options struct { IncludeProvisionerDaemon bool ChatdInstructionLookupTimeout time.Duration ChatProviderAPIKeys *chatprovider.ProviderAPIKeys - ProvisionerDaemonVersion string - ProvisionerDaemonTags map[string]string - MetricsCacheRefreshInterval time.Duration - AgentStatsRefreshInterval time.Duration - DeploymentValues *codersdk.DeploymentValues + // ChatWorkerDisabled skips starting the chat daemon's background + // worker. Used in tests. + ChatWorkerDisabled bool + ProvisionerDaemonVersion string + ProvisionerDaemonTags map[string]string + MetricsCacheRefreshInterval time.Duration + AgentStatsRefreshInterval time.Duration + DeploymentValues *codersdk.DeploymentValues // Set update check options to enable update check. UpdateCheckOptions *updatecheck.Options @@ -594,6 +597,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can AgentInactiveDisconnectTimeout: testutil.WaitShort, ChatdInstructionLookupTimeout: options.ChatdInstructionLookupTimeout, ChatProviderAPIKeys: options.ChatProviderAPIKeys, + ChatWorkerDisabled: options.ChatWorkerDisabled, AccessURL: accessURL, AppHostname: options.AppHostname, AppHostnameRegex: appHostnameRegex, diff --git a/coderd/exp_chats_chatstate_test.go b/coderd/exp_chats_chatstate_test.go index 485b5d21b7..5b78886e4d 100644 --- a/coderd/exp_chats_chatstate_test.go +++ b/coderd/exp_chats_chatstate_test.go @@ -172,7 +172,9 @@ func TestPostChatMessagesBusyInterrupt(t *testing.T) { t.Parallel() ctx := testutil.Context(t, testutil.WaitLong) - client := newChatClient(t) + client := newChatClient(t, func(o *coderdtest.Options) { + o.ChatWorkerDisabled = true + }) firstUser := coderdtest.CreateFirstUser(t, client.Client) _ = createChatModelConfig(t, client)