Skip to content

Conversation

@eric642
Copy link
Contributor

@eric642 eric642 commented Nov 21, 2025

When multiple goroutines concurrently called Execute() or Render() on the same Prompt instance, they would mutate shared Message objects, causing race conditions and incorrect rendering results.

The bug was in renderMessages() function which directly modified the Content field of Message objects returned from MessagesFn. This caused concurrent renders to interfere with each other.

Fixed by creating new Message copies during rendering instead of mutating the originals. This ensures each concurrent render operation gets its own independent Message objects.

When multiple goroutines concurrently called Execute() or Render() on the
same Prompt instance, they would mutate shared Message objects, causing
race conditions and incorrect rendering results.

The bug was in renderMessages() function which directly modified the
Content field of Message objects returned from MessagesFn. This caused
concurrent renders to interfere with each other.

Fixed by creating new Message copies during rendering instead of mutating
the originals. This ensures each concurrent render operation gets its own
independent Message objects.
@eric642
Copy link
Contributor Author

eric642 commented Nov 21, 2025

@hugoaguirre Fix the concurrency issue caused by #3780

@eric642
Copy link
Contributor Author

eric642 commented Nov 24, 2025

@hugoaguirre @apascal07 pls review it.

@apascal07 apascal07 requested review from apascal07 and removed request for rutujaD1999 November 24, 2025 03:49
Co-authored-by: Alex Pascal <apascal07@gmail.com>
@apascal07
Copy link
Collaborator

Go files are not formatted. Please run 'go fmt ./...' and commit the changes:
ai/prompt.go

Please run.

@eric642
Copy link
Contributor Author

eric642 commented Nov 26, 2025

@apascal07 Thank you for the reminder. I have formatted the code

@hugoaguirre hugoaguirre enabled auto-merge (squash) November 26, 2025 04:24
@hugoaguirre hugoaguirre changed the title fix(ai): fix race condition in concurrent prompt rendering fix(go/ai): fix race condition in concurrent prompt rendering Nov 26, 2025
@hugoaguirre hugoaguirre merged commit 354951d into firebase:main Nov 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants