Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Code Quality] Think tool races under parallel tool execution

クローズ 初心者向け
#4,568 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #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 プログラムで race を再現し、その後 think ツールの状態とハンドラーを調べてください。並行呼び出しで race が発生せず、すべての思考が保持される状態を完了条件とします。並行実行の回帰テストを追加し、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
平均マージ
8時間 10分
マージ済み PR(30日)
231

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

docker/docker-agent のほかの issue

docker/docker-agent の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。