fix(tasks): retain failure notices and distinguish prior attempts
This commit is contained in:
parent
e1c4551b64
commit
51e4acacfe
|
|
@ -236,6 +236,13 @@ func (r *longTaskRuntime) Run(ctx context.Context, t *taskflow.Task, step taskfl
|
|||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
notice := "目标任务步骤未完成: " + err.Error()
|
||||
_ = h.appendAssistantMessageNotice(assistant.ID, notice)
|
||||
_ = h.db.AddProcessDetail(assistant.ID, conv.ID, "error", notice, nil)
|
||||
}
|
||||
}()
|
||||
ctx = authctx.WithPrincipal(ctx, p)
|
||||
runCtx, cancel := context.WithCancelCause(ctx)
|
||||
defer cancel(nil)
|
||||
|
|
@ -484,6 +491,9 @@ func (r *longTaskRuntime) trace(id string, args map[string]any) (agentruntime.To
|
|||
for _, c := range s.Conversations {
|
||||
if c == conversation {
|
||||
sourceID, sourceStatus = s.ID, s.Status
|
||||
if conversation != s.ConversationID {
|
||||
sourceStatus = "previous_attempt"
|
||||
}
|
||||
allowed = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,6 +150,14 @@ func TestLongTaskMemoryKeepsTaskBoundaryAndPriorAttempts(t *testing.T) {
|
|||
if !strings.Contains(result.Content, "attempt-one") || !strings.Contains(result.Content, "attempt-two") || strings.Contains(result.Content, "foreign") {
|
||||
t.Fatal(result.Content)
|
||||
}
|
||||
var oldRef string
|
||||
if err = h.db.QueryRow(`SELECT id FROM process_details WHERE conversation_id=? LIMIT 1`, ids[0]).Scan(&oldRef); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prior, err := h.longTaskRuntime.trace(task.ID, map[string]any{"trace_id": oldRef})
|
||||
if err != nil || !strings.Contains(prior.Content, `"step_status":"previous_attempt"`) {
|
||||
t.Fatalf("old attempt was promoted: %s %v", prior.Content, err)
|
||||
}
|
||||
result, err = h.longTaskRuntime.memory(task.ID, map[string]any{"query": "needle", "step_id": "not-in-task"})
|
||||
if err != nil || strings.Contains(result.Content, "attempt-one") {
|
||||
t.Fatal(result, err)
|
||||
|
|
@ -264,6 +272,10 @@ func testLongTaskNativePiLifecycle(t *testing.T, denied bool) {
|
|||
if got.Status != "blocked" || toolRuns.Load() != 0 || len(got.Steps) != 1 || got.Steps[0].Status != "failed" || !strings.Contains(got.Steps[0].Summary, "没有成功工具结果") {
|
||||
t.Fatalf("false completion was not rejected: %+v steps=%+v", got, got.Steps)
|
||||
}
|
||||
messages, err := h.db.GetMessages(got.Steps[0].ConversationID)
|
||||
if err != nil || len(messages) < 2 || !strings.Contains(messages[len(messages)-1].Content, "目标任务步骤未完成") {
|
||||
t.Fatalf("failed conversation left without failure notice: %+v %v", messages, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if got.Status != "completed" || toolRuns.Load() != 1 || len(got.Steps) != 1 || got.Steps[0].ConversationID == "" {
|
||||
|
|
|
|||
Loading…
Reference in New Issue