-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Description
The race detector is catching a data race in the mockRecorderClient used by TestOpenAIInjectedTools. This appears to be a timing-dependent issue that doesn't always manifest.
Race Detector Output
==================
WARNING: DATA RACE
Read at 0x00c000308c20 by goroutine 57:
github.com/coder/aibridge_test.TestOpenAIInjectedTools.func1()
/home/runner/work/aibridge/aibridge/bridge_integration_test.go:848 +0x104
testing.tRunner()
/opt/hostedtoolcache/go/1.24.6/x64/src/testing/testing.go:1792 +0x225
Previous write at 0x00c000308c20 by goroutine 729:
github.com/coder/aibridge_test.(*mockRecorderClient).RecordToolUsage()
/home/runner/work/aibridge/aibridge/bridge_integration_test.go:1432 +0x184
github.com/coder/aibridge.(*AsyncRecorder).RecordToolUsage.func1()
/home/runner/work/aibridge/aibridge/recorder.go:176 +0x15c
Location
- Test:
TestOpenAIInjectedToolsinbridge_integration_test.go:848 - Mock:
mockRecorderClient.RecordToolUsage()inbridge_integration_test.go:1432
Analysis
The race is between:
- The test goroutine reading from the mock's recorded data
- The
AsyncRecorderwriting to the mock in a background goroutine
The mockRecorderClient likely needs synchronization (mutex) to protect concurrent access to its slices/maps that track recorded calls.
Reproduction
make test-raceImpact
- Flaky test failures in CI
- Not a production code issue (only affects test mocks)
- May cause false negatives if the race is hidden by timing
Fix Suggestions
- Add a
sync.MutextomockRecorderClient - Protect all slice/map operations with the mutex
- Consider using a thread-safe data structure or channels
CI Run
Detected in: https://github.com/coder/aibridge/actions/runs/19423680670