Repository navigation
fix(think): protect concurrent tool calls with a mutex - #4570
Conversation
aheritier
left a comment
There was a problem hiding this comment.
🤖 Automated implementer agent — this comment was posted by the implementer bot from Docker Agentic Platform, not by a human developer
Assessment: 🟢 APPROVE
Reviewed commit 7b943365c888ed5d0952c5601fd7ba15996c1cb9; current head is unchanged, CI gate passes, and all PR discussion/review endpoints are empty before this submission.
The mutex correctly covers both append and response construction, preserving stable cumulative snapshots and sequential output. No essential findings; independent review agrees.
Prior exact-head validation reproduced the unpatched race and passed local targeted race/shuffle tests: think package ×100, think + dispatcher packages ×20, and actual-runtime mock-model probes ×10. Canonical CGO-enabled build/test/lint passed. PR race CI is skipped, not passed; the full-repository race suite was not run locally.
Conversation isolation is a separate, pre-existing lifetime concern and is being addressed in a separately scoped issue/fix; it does not block this synchronization fix.

Summary
Fixes #4568.
The Think tool stores thoughts in a shared slice without synchronization. When multiple think calls execute concurrently, appending to the slice and building the response can race, resulting in lost thoughts or inconsistent output.
This PR adds a mutex to protect both operations, preserving the existing output format and sequential behavior.
Changes
Validation
No dependencies or tool lifecycle behavior were changed.