From 2e5c7d99c2babcb66e757a4ec297e3503ab85d5d Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Thu, 23 Apr 2026 13:18:18 +0100 Subject: [PATCH] fix(coderd/x/chatd): fix flaky TestSpawnComputerUseAgentInheritsContext (#24666) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes flaky `TestSpawnComputerUseAgentInheritsContext`. - The test inserts an Anthropic provider directly into the DB after `CreateChat` has already been called - The server's background goroutine may have already cached the provider list (OpenAI only) via `configCache.EnabledProviders()` with a 10s TTL - The direct DB insert bypasses the pubsub event that production uses to invalidate the cache - `isAnthropicConfigured()` returns the stale cached result, making `computer_use` appear unavailable - Fix: call `server.configCache.InvalidateProviders()` after the insert, mirroring what production does via pubsub CI failure: https://github.com/coder/coder/actions/runs/24829197096/job/72673070101?pr=24648 > 🤖 --- coderd/x/chatd/subagent_context_internal_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/coderd/x/chatd/subagent_context_internal_test.go b/coderd/x/chatd/subagent_context_internal_test.go index 5acdc1efaf..6d5a6e4513 100644 --- a/coderd/x/chatd/subagent_context_internal_test.go +++ b/coderd/x/chatd/subagent_context_internal_test.go @@ -477,6 +477,12 @@ func TestSpawnComputerUseAgentInheritsContext(t *testing.T) { ctx := chatdTestContext(t) parentChat := createParentChatWithInheritedContext(ctx, t, db, server) insertEnabledAnthropicProvider(ctx, t, db, parentChat.OwnerID) + // The direct DB insert above bypasses the pubsub event that + // production uses to invalidate the provider cache. Explicitly + // invalidate here so the background processing goroutine does + // not serve a stale provider list (OpenAI only) that was cached + // before the Anthropic provider was inserted. + server.configCache.InvalidateProviders() tools := server.subagentTools(ctx, func() database.Chat { return parentChat }, parentChat.LastModelConfigID) tool := findToolByName(tools, spawnAgentToolName)