From 51e4acacfe21ec341273e1abfabdd00e834e8cfb Mon Sep 17 00:00:00 2001 From: Sycun <165354365+Sycun@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:21:21 +0800 Subject: [PATCH] fix(tasks): retain failure notices and distinguish prior attempts --- internal/handler/long_task_runtime.go | 10 ++++++++++ internal/handler/long_task_test.go | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/internal/handler/long_task_runtime.go b/internal/handler/long_task_runtime.go index d525c3cc..f8673b92 100644 --- a/internal/handler/long_task_runtime.go +++ b/internal/handler/long_task_runtime.go @@ -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 } } diff --git a/internal/handler/long_task_test.go b/internal/handler/long_task_test.go index 287c9cdc..cf3fd02d 100644 --- a/internal/handler/long_task_test.go +++ b/internal/handler/long_task_test.go @@ -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 == "" {