From 7e475bdfa6dfe1fb266ace3415af3ab0e5723d14 Mon Sep 17 00:00:00 2001 From: AskaEth Date: Mon, 22 Jun 2026 20:31:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AD=90=E4=BC=9A=E8=AF=9D=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=A2=9E=E5=8A=A0=E5=88=9B=E5=BB=BA/=E7=BB=93?= =?UTF-8?q?=E6=9D=9F=E6=97=B6=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SubSessionResult 新增 CreatedAt / FinishedAt 字段 - manager.Dispatch 在各路径统一设置时间戳:成功/失败/超时 Co-Authored-By: Claude --- backend/ai-core/internal/model/sub_session.go | 4 +++- backend/ai-core/internal/subsession/manager.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/ai-core/internal/model/sub_session.go b/backend/ai-core/internal/model/sub_session.go index 60d513f..4222611 100644 --- a/backend/ai-core/internal/model/sub_session.go +++ b/backend/ai-core/internal/model/sub_session.go @@ -49,7 +49,9 @@ type SubSessionResult struct { Confidence float64 `json:"confidence"` // 置信度 0-1 Progress float64 `json:"progress"` // 执行进度 0.0 ~ 1.0 Error string `json:"error,omitempty"` - Metadata map[string]any `json:"metadata"` // 类型特定的元数据 + Metadata map[string]any `json:"metadata"` // 类型特定的元数据 + CreatedAt time.Time `json:"created_at"` // 任务创建时间 + FinishedAt time.Time `json:"finished_at"` // 任务结束时间 } // ToolCallRecord 工具调用记录 diff --git a/backend/ai-core/internal/subsession/manager.go b/backend/ai-core/internal/subsession/manager.go index 0f5de25..1c11eba 100644 --- a/backend/ai-core/internal/subsession/manager.go +++ b/backend/ai-core/internal/subsession/manager.go @@ -6,6 +6,7 @@ import ( "fmt" "git.yeij.top/AskaEth/Cyrene/pkg/logger" "sync" + "time" "git.yeij.top/AskaEth/Cyrene/ai-core/internal/bus" "git.yeij.top/AskaEth/Cyrene/ai-core/internal/llm" @@ -109,7 +110,8 @@ func (m *Manager) Dispatch( } }() - result := model.SubSessionResult{Type: p.Type()} + createdAt := time.Now() + result := model.SubSessionResult{Type: p.Type(), CreatedAt: createdAt} m.getBus().Publish(bus.BusEvent{ Type: bus.EventSubSessionStarted, Payload: bus.SubSessionPayload{SubType: p.Type(), Status: "started"}, @@ -125,7 +127,8 @@ func (m *Manager) Dispatch( if err != nil { result.Error = fmt.Sprintf("创建上下文失败: %v", err) logger.Printf("[subsession] %s 创建上下文失败: %v", p.Type(), err) - resultCh <- result + result.FinishedAt = time.Now() + resultCh <- result return } @@ -134,6 +137,7 @@ func (m *Manager) Dispatch( // 执行子会话 subResult, execErr := p.Execute(subCtx, llmMessages) if execErr != nil { + result.FinishedAt = time.Now() result.Error = fmt.Sprintf("执行失败: %v", execErr) logger.Printf("[subsession] %s 执行失败: %v", p.Type(), execErr) resultCh <- result @@ -143,12 +147,14 @@ func (m *Manager) Dispatch( // 检查超时 select { case <-subCtx.Done(): + result.FinishedAt = time.Now() result.Error = "子会话超时" logger.Printf("[subsession] %s 超时 (limit=%v)", p.Type(), p.Timeout()) default: if subResult != nil { result = *subResult result.Type = p.Type() + result.CreatedAt = createdAt logger.Printf("[subsession] %s 完成: 摘要=%s", p.Type(), truncate(result.Summary, 50)) } }