Skip to content

fix(coderd/x/chatd): synchronize aibridgeTestFactory recorded fields - #28031

Merged
ibetitsmike merged 2 commits into
mainfrom
mike/codagt-917-fix-aibridgetestfactory-race
Aug 11, 2026
Merged

fix(coderd/x/chatd): synchronize aibridgeTestFactory recorded fields#28031
ibetitsmike merged 2 commits into
mainfrom
mike/codagt-917-fix-aibridgetestfactory-race

Conversation

@ibetitsmike

Copy link
Copy Markdown
Collaborator

Fixes the data race in the chatd test helper aibridgeTestFactory reported in CODAGT-917 (test-go-race-pg flake in TestAwaitSubagentCompletion/Timeout).

TransportFor recorded providerName and source with 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 TransportFor calls on one factory failed go test -race with the exact CI signature (lines 37-38) before the fix and pass after it. Also ran go test -race ./coderd/x/chatd -run TestAwaitSubagentCompletion -count=10 and the full go test -race ./coderd/x/chatd package, both clean.

Audited every other aibridge.TransportFactory implementation and aibridgeTestFactory use site for the same defect: chattest.MockAIBridgeTransport is 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.

Mux acted on Mike's behalf to create this PR.

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).
@linear-code

linear-code Bot commented Aug 11, 2026

Copy link
Copy Markdown

CODAGT-917

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: c5db120a4f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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
ibetitsmike marked this pull request as ready for review August 11, 2026 18:26
Comment thread coderd/x/chatd/model_routing_internal_test.go Outdated
@ibetitsmike
ibetitsmike merged commit bde38e9 into main Aug 11, 2026
28 checks passed
@ibetitsmike
ibetitsmike deleted the mike/codagt-917-fix-aibridgetestfactory-race branch August 11, 2026 21:51
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants