Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[Code Quality] Think tool races under parallel tool execution

Đang mở Phù hợp với người mới
#4,568 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@dlanov đang làm issue này rồi.

Từ ngày 11/10/2026.

  • #4570 của @dlanov — đang mở

Đá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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend, testing

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ả

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.

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

Mở trong Codespaces

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của docker/docker-agent

Tất cả issue của docker/docker-agent

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.