[Code Quality] Think tool races under parallel tool execution
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Bắt đầu với pkg/tools/builtin/think/think.go:25–27 và đường xử lý dispatch song song trong pkg/runtime/toolexec/dispatcher.go:251–273. Tái hiện race bằng chương trình Go được cung cấp, sau đó kiểm tra trạng thái và handler của công cụ think. Hoàn thành khi các lời gọi đồng thời không còn race và vẫn giữ lại mọi suy nghĩ; thêm kiểm thử hồi quy đồng thời và chạy kiểm thử đó bằng go test -race.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Severity: medium · Type: code-quality
Location
Reviewed commit: cd65d7c776dda80d554735ee20572d09cfe2d791.
pkg/tools/builtin/think/think.go:25–27: appends tot.thoughtsand joins the shared slice without synchronization.pkg/runtime/toolexec/dispatcher.go:251–273: dispatches calls from the same model batch concurrently.
Issue details
Two think calls on the same toolset can execute concurrently. The handler writes the slice header/backing array and reads it through strings.Join without a mutex. The same toolset instance can also be reused by concurrent runs of the same agent.
This is reproducible without credentials or a model request. Save the following as /tmp/think-race.go, then run go run -race /tmp/think-race.go from the repository root:
package main
import (
"context"
"sync"
"github.com/docker/docker-agent/pkg/tools"
"github.com/docker/docker-agent/pkg/tools/builtin/think"
)
func main() {
ctx := context.Background()
set := think.New()
available, _ := set.Tools(ctx)
tool := available[0]
start := make(chan struct{})
var wg sync.WaitGroup
for range 2 {
wg.Go(func() {
<-start
for range 100 {
_, _ = tool.Handler(ctx, tools.ToolCall{Function: tools.FunctionCall{Name: "think", Arguments: `{"thought":"parallel thought"}`}}, tools.NopRuntime{})
}
})
}
close(start)
wg.Wait()
}
On darwin/arm64 with the repository's Go 1.27.2 toolchain, this reports WARNING: DATA RACE at think.go:26 and think.go:27, ending with Found 5 data race(s) and exit status 66.
Impact
Concurrent scratchpad calls may lose appended thoughts or return inconsistent output. The race violates the dispatcher's parallel-execution contract; a read-only annotation does not make the tool's internal state immutable.
Recommended fix
Protect the append and output snapshot with a mutex (or serialize execution explicitly). If joining outside the lock, copy the slice while holding the lock first. Add a regression test that invokes the same tool concurrently and verifies all thoughts are retained, and run it under go test -race.
Separately decide whether the scratchpad should be scoped to a conversation rather than a long-lived toolset; locking alone does not establish conversation isolation.
- Ngôn ngữ chính
- Go
- Star
- 4.4k
- Fork
- 508
- Merge trung bình
- 5 giờ 46 phút
- Pull request đã merge (30 ngày)
- 269
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của docker/docker-agent
-
area/config area/providers/docker-model-runner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
docker/docker-agent#4522 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
pkg/hooks tests fail with a misleading assertion when jq is not installedCó thể đã có người làm @dwin-gharibi đã nhận 49 ngày trước. Đang mởarea/testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
docker/docker-agent#4052 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`remove_directory` and `create_directory` hide work they already did when a later path failsCó thể đã có người làm @dwin-gharibi đã nhận 68 ngày trước. Đang mởarea/tools
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
docker/docker-agent#3933 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`edit_file` silently edits the first match when `oldText` occurs more than onceCó thể đã có người làm @dwin-gharibi đã nhận 68 ngày trước. Đang mởarea/tools
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
docker/docker-agent#3929 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
a2a toolset cannot call agents served by 'serve a2a' since v1.129 (A2A 1.0 card vs v0.3 client)Có thể đã có người làm @smashingtags đã nhận 1 ngày trước. Đang mởarea/a2a area/tools
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 56/100
docker/docker-agent#4571 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của docker/docker-agent
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
agent-review-finding bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
jordansmall/spindrift#5281 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Integer parameters equal to 2^63 pass the range check in toInt and wrap to a negative numberĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
github/github-mcp-server#3489 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
L: java:gradle L: java:maven L: ruby:bundler T: bug 🐞
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
dependabot/dependabot-core#16547 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docs/examples still create key ranges in ascending order, which fails in 3.1.0 (follow-up to #1754)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
pg-sharding/spqr#3083 ·
Maintainer thường phản hồi trong vòng 1 ngày