fix(parallel): 修复并行执行启动横幅重复打印问题

修复 GitHub Actions 失败的测试 TestRunParallelStartupLogsPrinted。

问题根源:
- 在 main.go 中有重复的启动横幅和日志路径打印逻辑
- executeConcurrent 内部也添加了相同的打印逻辑
- 导致横幅和任务日志被打印两次

修复内容:
1. 删除 main.go 中 --parallel 处理中的重复打印代码(行 184-194)
2. 保留 executeConcurrent 中的 printTaskStart 函数,实现:
   - 在任务启动时立即打印日志路径
   - 使用 mutex 保护并发打印,确保横幅只打印一次
   - 按实际执行顺序打印任务信息

测试结果:
- TestRunParallelStartupLogsPrinted: PASS
- TestRunNonParallelOutputsIncludeLogPathsIntegration: PASS
- TestRunStartupCleanupRemovesOrphansEndToEnd: PASS

影响范围:
- 修复了 --parallel 模式下的日志输出格式
- 不影响非并行模式的执行

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
swe-agent[bot]
2025-12-09 17:02:59 +08:00
parent 132df6cb28
commit c6cd20d2fd
6 changed files with 267 additions and 74 deletions

View File

@@ -50,6 +50,10 @@ func parseJSONStreamWithWarn(r io.Reader, warnFn func(string)) (message, threadI
}
func parseJSONStreamWithLog(r io.Reader, warnFn func(string), infoFn func(string)) (message, threadID string) {
return parseJSONStreamInternal(r, warnFn, infoFn, nil)
}
func parseJSONStreamInternal(r io.Reader, warnFn func(string), infoFn func(string), onMessage func()) (message, threadID string) {
scanner := bufio.NewScanner(r)
scanner.Buffer(make([]byte, 64*1024), 10*1024*1024)
@@ -60,6 +64,12 @@ func parseJSONStreamWithLog(r io.Reader, warnFn func(string), infoFn func(string
infoFn = func(string) {}
}
notifyMessage := func() {
if onMessage != nil {
onMessage()
}
}
totalEvents := 0
var (
@@ -133,6 +143,7 @@ func parseJSONStreamWithLog(r io.Reader, warnFn func(string), infoFn func(string
infoFn(fmt.Sprintf("item.completed event item_type=%s message_len=%d", itemType, len(normalized)))
if event.Item != nil && event.Item.Type == "agent_message" && normalized != "" {
codexMessage = normalized
notifyMessage()
}
}
@@ -151,6 +162,7 @@ func parseJSONStreamWithLog(r io.Reader, warnFn func(string), infoFn func(string
if event.Result != "" {
claudeMessage = event.Result
notifyMessage()
}
case hasKey(raw, "role") || hasKey(raw, "delta"):
@@ -166,6 +178,7 @@ func parseJSONStreamWithLog(r io.Reader, warnFn func(string), infoFn func(string
if event.Content != "" {
geminiBuffer.WriteString(event.Content)
notifyMessage()
}
infoFn(fmt.Sprintf("Parsed Gemini event #%d type=%s role=%s delta=%t status=%s content_len=%d", totalEvents, event.Type, event.Role, event.Delta, event.Status, len(event.Content)))