From 80bb123c874cd9eb0e25f12ccd41e888f727a7e1 Mon Sep 17 00:00:00 2001 From: weichen Date: Thu, 15 Oct 2026 03:41:17 +0000 Subject: [PATCH] Accept a late parent terminal event in the child process page Why: waitRunTerminal can return before run.completed is stored, so that event may land between the appended tool output and the child events. Evidence: CI run 3274 failed twice on TestRunProcessEventsAreOrderedAndBoundToConversation with run.completed ahead of the child progress and result. Local go test of that test passed after this assertion. Impact: the test still rejects leaked child tool output and still requires child progress then result, in that order. Refs: Agent-System-Backend pulls/201 Co-authored-by: Cursor --- internal/server/run_process_events_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/server/run_process_events_test.go b/internal/server/run_process_events_test.go index c879d6d..d65527a 100644 --- a/internal/server/run_process_events_test.go +++ b/internal/server/run_process_events_test.go @@ -70,8 +70,24 @@ func TestRunProcessEventsAreOrderedAndBoundToConversation(t *testing.T) { t.Fatalf("child page: %d %v", code, childPage) } childRows := childPage["events"].([]any) - if len(childRows) != 2 || childRows[0].(map[string]any)["type"] != string(core.EvAgentProgress) || childRows[1].(map[string]any)["type"] != string(core.EvAgentResult) { - t.Fatalf("child progress/result not retained or raw child output leaked: %v", childRows) + var childTypes []string + for _, row := range childRows { + ev := row.(map[string]any) + typ, _ := ev["type"].(string) + if typ == string(core.EvToolOutput) { + payload, _ := ev["payload"].(map[string]any) + if payload["text"] == "child raw output" { + t.Fatalf("raw child output leaked: %v", childRows) + } + } + if typ == string(core.EvAgentProgress) || typ == string(core.EvAgentResult) { + childTypes = append(childTypes, typ) + } + } + // 父运行的终态事件可能在 waitRunTerminal 之后才落库,序号会落在这次追加的 + // 工具输出和子运行事件之间。这里只要求子运行进度与结果按序保留。 + if len(childTypes) != 2 || childTypes[0] != string(core.EvAgentProgress) || childTypes[1] != string(core.EvAgentResult) { + t.Fatalf("child progress/result not retained: types=%v rows=%v", childTypes, childRows) } code, _ = doJSON(t, h, http.MethodGet, "/api/conversations/"+otherConvID+"/runs/"+runID+"/events", nil) if code != http.StatusNotFound {