feat: 子会话结果增加创建/结束时间戳
- SubSessionResult 新增 CreatedAt / FinishedAt 字段 - manager.Dispatch 在各路径统一设置时间戳:成功/失败/超时 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user