fix(adk): avoid racing on shared react config when concurrent Run reuses one ChatModelAgent - #1218
Open
GerardGao wants to merge 1 commit into
Open
Conversation
…ses one ChatModelAgent
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.
What
buildMessageReActRunFuncandbuildAgenticReActRunFuncbuild the react config(
reactConfig/agenticReactConfig) once per agent and then write the per-runcancel scope into it on every
Run:When one long-lived
ChatModelAgentis reused across concurrentRuncalls(e.g. a multi-tenant gateway), these writes race with
newReact/newAgenticReactreading the same fields, and two runs can observe each other'scancel pointer — so a plain run can be cancelled by another run's cancel scope.
Fixes #1177.
How
Inside the run closure, shallow-copy the once-built config before assigning the
cancel fields and hand the copy to
newReact/newAgenticReact:All other fields are read-only after construction, and
buildModelWrapperssnapshots the wrapper config fields at build time, so a struct copy is
sufficient. The per-run cancel injection points (ReAct cancel safe-points, model
wrapper stack, graph interrupt wiring) are preserved unchanged.
Tests
TestConcurrentRunSharedAgentWithTools_Race: 4 concurrent runs on oneshared agent with a start barrier. Fails reliably under
go test -racebefore this change and passes after.
go test -race ./adk/passes;golangci-lint run ./adk/...reports 0 issues.