Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Code Quality] Think tool races under parallel tool execution

已关闭 适合新手
#4,568 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #4570 来自 @dlanov —— 已合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
backend, testing

调研方向

从 pkg/tools/builtin/think/think.go:25–27 和 pkg/runtime/toolexec/dispatcher.go:251–273 中的并行分发路径入手。使用提供的 Go 程序复现竞态,然后检查 think 工具的状态和处理程序。完成标准是并发调用没有竞态,并且保留所有思考;添加并发回归测试,并使用 go test -race 运行。

由索引模型根据 Issue 内容生成。

描述

area/runtime area/tools

Severity: medium · Type: code-quality

Location

Reviewed commit: cd65d7c776dda80d554735ee20572d09cfe2d791.

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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

docker/docker-agent 的其他 Issue

查看 docker/docker-agent 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。