fix(adk): copy-on-write SetMessageID to avoid concurrent map panic - #1085
Merged
Conversation
ChatModel streaming fans out the same *schema.Message pointers to multiple consumers inside the model body. Stamping the eino message ID into Extra via an in-place map write then races with concurrent reads of that shared map, triggering a fatal "concurrent map read and map write" panic. Make SetMessageID copy-on-write: allocate a fresh map, copy existing entries, then set the ID. All callers already reassign the returned map, so the change is transparent. This removes the map-level panic; the field-level race on the exported Extra field is documented as a known, unfixable-by-framework limit. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
shentongmartin
approved these changes
Jun 17, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1085 +/- ##
=======================================
Coverage 83.15% 83.16%
=======================================
Files 162 162
Lines 23133 23134 +1
=======================================
+ Hits 19237 19239 +2
+ Misses 2632 2631 -1
Partials 1264 1264 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
*schema.Messagepointers to multiple consumers inside the model body. Stamping the eino message ID intoExtravia an in-place map write then races with concurrent reads of that shared map, triggering a fatalconcurrent map read and map writepanic.internal.SetMessageIDcopy-on-write: allocate a fresh map, copy existing entries, then set the ID. All callers already reassign the returned map (v.Extra = SetMessageID(...)), so the change is transparent and fixes every path at once.Extrafield cannot be eliminated by the framework whileExtrais public, and is documented as a known limit in the function doc.Test plan
go build ./...go test -race ./adk/...(all green, incl. 30s race run on the adk root package)🤖 Generated with Claude Code