feat: 子会话结果增加创建/结束时间戳

- SubSessionResult 新增 CreatedAt / FinishedAt 字段
- manager.Dispatch 在各路径统一设置时间戳:成功/失败/超时

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-22 20:31:48 +08:00
parent 8783cadf9b
commit 7e475bdfa6
2 changed files with 11 additions and 3 deletions
@@ -49,7 +49,9 @@ type SubSessionResult struct {
Confidence float64 `json:"confidence"` // 置信度 0-1 Confidence float64 `json:"confidence"` // 置信度 0-1
Progress float64 `json:"progress"` // 执行进度 0.0 ~ 1.0 Progress float64 `json:"progress"` // 执行进度 0.0 ~ 1.0
Error string `json:"error,omitempty"` 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 工具调用记录 // ToolCallRecord 工具调用记录
@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"git.yeij.top/AskaEth/Cyrene/pkg/logger" "git.yeij.top/AskaEth/Cyrene/pkg/logger"
"sync" "sync"
"time"
"git.yeij.top/AskaEth/Cyrene/ai-core/internal/bus" "git.yeij.top/AskaEth/Cyrene/ai-core/internal/bus"
"git.yeij.top/AskaEth/Cyrene/ai-core/internal/llm" "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{ m.getBus().Publish(bus.BusEvent{
Type: bus.EventSubSessionStarted, Type: bus.EventSubSessionStarted,
Payload: bus.SubSessionPayload{SubType: p.Type(), Status: "started"}, Payload: bus.SubSessionPayload{SubType: p.Type(), Status: "started"},
@@ -125,7 +127,8 @@ func (m *Manager) Dispatch(
if err != nil { if err != nil {
result.Error = fmt.Sprintf("创建上下文失败: %v", err) result.Error = fmt.Sprintf("创建上下文失败: %v", err)
logger.Printf("[subsession] %s 创建上下文失败: %v", p.Type(), err) logger.Printf("[subsession] %s 创建上下文失败: %v", p.Type(), err)
resultCh <- result result.FinishedAt = time.Now()
resultCh <- result
return return
} }
@@ -134,6 +137,7 @@ func (m *Manager) Dispatch(
// 执行子会话 // 执行子会话
subResult, execErr := p.Execute(subCtx, llmMessages) subResult, execErr := p.Execute(subCtx, llmMessages)
if execErr != nil { if execErr != nil {
result.FinishedAt = time.Now()
result.Error = fmt.Sprintf("执行失败: %v", execErr) result.Error = fmt.Sprintf("执行失败: %v", execErr)
logger.Printf("[subsession] %s 执行失败: %v", p.Type(), execErr) logger.Printf("[subsession] %s 执行失败: %v", p.Type(), execErr)
resultCh <- result resultCh <- result
@@ -143,12 +147,14 @@ func (m *Manager) Dispatch(
// 检查超时 // 检查超时
select { select {
case <-subCtx.Done(): case <-subCtx.Done():
result.FinishedAt = time.Now()
result.Error = "子会话超时" result.Error = "子会话超时"
logger.Printf("[subsession] %s 超时 (limit=%v)", p.Type(), p.Timeout()) logger.Printf("[subsession] %s 超时 (limit=%v)", p.Type(), p.Timeout())
default: default:
if subResult != nil { if subResult != nil {
result = *subResult result = *subResult
result.Type = p.Type() result.Type = p.Type()
result.CreatedAt = createdAt
logger.Printf("[subsession] %s 完成: 摘要=%s", p.Type(), truncate(result.Summary, 50)) logger.Printf("[subsession] %s 完成: 摘要=%s", p.Type(), truncate(result.Summary, 50))
} }
} }