fix(coderd/x/chatd): synchronize aibridgeTestFactory recorded fields - #28031
Merged
Conversation
aibridgeTestFactory.TransportFor wrote providerName and source without synchronization. Tests that start the chat worker share one factory between concurrently running chat runners (parent and subagent), so the race detector flagged write/write races, e.g. in TestAwaitSubagentCompletion/Timeout on CI (CODAGT-917). Guard the recorded fields with a mutex and read them through a locked accessor at the three asserting call sites. Repro before the fix: concurrent TransportFor calls on one factory fail go test -race with the exact CI signature (lines 37-38).
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
ibetitsmike
marked this pull request as ready for review
August 11, 2026 18:26
DanielleMaywood
approved these changes
Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the data race in the chatd test helper
aibridgeTestFactoryreported in CODAGT-917 (test-go-race-pgflake inTestAwaitSubagentCompletion/Timeout).TransportForrecordedproviderNameandsourcewith plain field writes. Tests that start the chat worker share one factory between concurrently running chat runners (parent chat and spawned subagent), so two runners resolving models at the same time raced on those writes.The fix guards the recorded fields with a mutex and reads them through a locked
recorded()accessor at the three asserting call sites.Verified with a red-green repro: concurrent
TransportForcalls on one factory failedgo test -racewith the exact CI signature (lines 37-38) before the fix and pass after it. Also rango test -race ./coderd/x/chatd -run TestAwaitSubagentCompletion -count=10and the fullgo test -race ./coderd/x/chatdpackage, both clean.Audited every other
aibridge.TransportFactoryimplementation andaibridgeTestFactoryuse site for the same defect:chattest.MockAIBridgeTransportis already mutex-guarded,stubTransportFactory(coderd/aibridge_test.go) records via a channel,providerRoutedTransportFactory(chatd_test.go) is a stateless lookup, and the production factories keep no recorded state. No other occurrence exists.Closes CODAGT-917.