[Code Quality] Think tool races under parallel tool execution
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #4570 来自 @dlanov —— 已合并
评估
调研方向
从 pkg/tools/builtin/think/think.go:25–27 和 pkg/runtime/toolexec/dispatcher.go:251–273 中的并行分发路径入手。使用提供的 Go 程序复现竞态,然后检查 think 工具的状态和处理程序。完成标准是并发调用没有竞态,并且保留所有思考;添加并发回归测试,并使用 go test -race 运行。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Go
- 星标
- 4.4k
- 派生
- 508
- 平均合并
- 7 小时 2 分钟
- 30 天内合并 PR
- 233
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker/docker-agent 的其他 Issue
-
DMR provider ignores integer `provider_opts.context_size` (YAML integers decode as uint64), so the model starts at its maximum context可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭area/config area/providers/docker-model-runner
难度 2/5 1-3 小时 新手友好度 82/100
docker/docker-agent#4522 · 3 条评论 ·
维护者通常 1 天内回复
-
pkg/hooks tests fail with a misleading assertion when jq is not installed可能已有人在做 @dwin-gharibi 于 51 天前认领。 未关闭area/testing
难度 2/5 1-3 小时 新手友好度 86/100
docker/docker-agent#4052 ·
维护者通常 1 天内回复
-
`remove_directory` and `create_directory` hide work they already did when a later path fails可能已有人在做 @dwin-gharibi 于 69 天前认领。 未关闭area/tools
难度 2/5 1-3 小时 新手友好度 85/100
docker/docker-agent#3933 ·
维护者通常 1 天内回复
-
`edit_file` silently edits the first match when `oldText` occurs more than once可能已有人在做 @dwin-gharibi 于 69 天前认领。 未关闭area/tools
难度 2/5 1-3 小时 新手友好度 78/100
docker/docker-agent#3929 · 2 条评论 ·
维护者通常 1 天内回复
-
area/providers/openai
难度 3/5 1-2 天 新手友好度 55/100
docker/docker-agent#4594 ·
维护者通常 1 天内回复
查看 docker/docker-agent 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
SAP/crossplane-provider-btp#1118 ·
维护者通常 1 天内回复
-
benchmark: `make setup` fails because audit-exporter builds with Go 1.25.0 while go.mod requires 1.26.0可能已有人在做 @xsvm 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 84/100
volcano-sh/volcano#6097 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复