Skip to content

Conversation

@mtojek
Copy link
Member

@mtojek mtojek commented Dec 15, 2025

Fixes #59

Fixes data race in bridge_integration_test.go where test code was directly accessing mockRecorderClient fields (tokenUsages, userPrompts, toolUsages, interceptions) without holding the mutex, while the Record* methods were modifying these fields under the mutex.

Changes

Added four new accessor methods that return copies of the recorded data under mutex protection:

  • RecordedTokenUsages()
  • RecordedPromptUsages()
  • RecordedToolUsages()
  • RecordedInterceptions()

All direct field accesses in tests have been replaced with calls to these new thread-safe accessor methods.

Testing

All tests pass with -race flag enabled:

go test -race ./...
ok  	github.com/coder/aibridge	1.335s
ok  	github.com/coder/aibridge/buildinfo	1.014s
ok  	github.com/coder/aibridge/mcp	1.037s
ok  	github.com/coder/aibridge/utils	1.016s

Non-agent testing

while true; do go test -timeout 600s -run ^TestAnthropicInjectedTools$ github.com/coder/aibridge -count=500 -race -parallel=8; done

Fixes data race in bridge_integration_test.go where test code was
directly accessing mockRecorderClient fields (tokenUsages, userPrompts,
toolUsages, interceptions) without holding the mutex, while the Record*
methods were modifying these fields under the mutex.

Added four new accessor methods that return copies of the recorded data
under mutex protection:
- RecordedTokenUsages()
- RecordedPromptUsages()
- RecordedToolUsages()
- RecordedInterceptions()

Resolves #59
@mtojek mtojek marked this pull request as draft December 15, 2025 14:17
@mtojek mtojek self-assigned this Dec 15, 2025
@mtojek mtojek marked this pull request as ready for review December 15, 2025 14:19
@mtojek mtojek requested a review from dannykopping December 15, 2025 14:19
Copy link
Collaborator

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a note about safety

@mtojek mtojek merged commit 2f9dd49 into main Dec 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data race in TestOpenAIInjectedTools test mock

2 participants