From 063c06ca5feb4b968e83af76d7f17e8050796876 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Mon, 11 May 2026 17:48:27 +1000 Subject: [PATCH] test: prevent expired contexts in chatd parallel subtests (#25107) Parallel subtests in `coderd/x/chatd` reused a parent test context with a `testutil.WaitLong` deadline, so the context could expire before a subtest was scheduled under load. That made the subagent lifecycle tools return plain-text context errors instead of the expected JSON payload, causing flaky JSON unmarshal failures. Create fresh `chatdTestContext` values inside the affected parallel subtests and add `chatdTestContext` to the `paralleltestctx` custom function list so this pattern is caught by `make lint`. Closes https://github.com/coder/internal/issues/1494 --- Makefile | 2 +- coderd/x/chatd/subagent_internal_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ebcb1e84a8..617bfc9efe 100644 --- a/Makefile +++ b/Makefile @@ -749,7 +749,7 @@ lint/go: ./scripts/check_codersdk_imports.sh linter_ver=$$(grep -oE 'GOLANGCI_LINT_VERSION=\S+' dogfood/coder/ubuntu-26.04/Dockerfile | cut -d '=' -f 2) go run github.com/golangci/golangci-lint/cmd/golangci-lint@v$$linter_ver run - go tool github.com/coder/paralleltestctx/cmd/paralleltestctx -custom-funcs="testutil.Context" ./... + go tool github.com/coder/paralleltestctx/cmd/paralleltestctx -custom-funcs="testutil.Context,chatdTestContext" ./... go run ./scripts/intxcheck ./... .PHONY: lint/go diff --git a/coderd/x/chatd/subagent_internal_test.go b/coderd/x/chatd/subagent_internal_test.go index 1112864689..427c6a2a82 100644 --- a/coderd/x/chatd/subagent_internal_test.go +++ b/coderd/x/chatd/subagent_internal_test.go @@ -1510,6 +1510,7 @@ func TestResolveExploreToolSnapshot(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() + ctx := chatdTestContext(t) gotMCPServerIDs, err := server.resolveExploreToolSnapshot( ctx, tt.parent, @@ -2076,6 +2077,7 @@ func TestSpawnAgent_BlankTypeReturnsValidOptions(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() + ctx := chatdTestContext(t) resp := runSpawnAgentTool(ctx, t, server, parentChat, spawnAgentArgs{ Type: tt.subagentType, Prompt: "delegate work", @@ -2294,6 +2296,7 @@ func TestSubagentLifecycleToolErrorsIncludePersistedSubagentType(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() + ctx := chatdTestContext(t) result := requireToolResponseMap(t, runSubagentTool( ctx, t,