From 68df669576f2f10352794f67dc4a5eefe5d1cf34 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Tue, 12 May 2026 15:12:31 +0800 Subject: [PATCH] Fix OpenClaw terminal artifact states --- internal/acp/orchestrator.go | 3 +++ internal/acp/routing_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/internal/acp/orchestrator.go b/internal/acp/orchestrator.go index 904e200..2b32679 100644 --- a/internal/acp/orchestrator.go +++ b/internal/acp/orchestrator.go @@ -805,6 +805,8 @@ func guardOpenClawArtifactResult(result map[string]any, artifactDeliveryRequired message := "未检测到 OpenClaw 本轮导出的实际文件。已阻止口头下载声明进入 artifacts 面板;请重新执行并要求 OpenClaw 在 workspace 中真实生成文件。" result["success"] = false result["status"] = "artifact_missing" + result["code"] = "OPENCLAW_ARTIFACT_MISSING" + result["error"] = "OpenClaw artifact export returned no files for this run." result["output"] = message result["message"] = message result["summary"] = message @@ -824,6 +826,7 @@ func guardOpenClawNoDisplayableResult(result map[string]any, noDisplayableOutput } result["success"] = false result["status"] = "failed" + result["code"] = "OPENCLAW_NO_DISPLAYABLE_OUTPUT" result["error"] = "openclaw returned no displayable output" result["message"] = openClawNoDisplayableText result["output"] = openClawNoDisplayableText diff --git a/internal/acp/routing_test.go b/internal/acp/routing_test.go index a6cff9d..503aa9b 100644 --- a/internal/acp/routing_test.go +++ b/internal/acp/routing_test.go @@ -557,6 +557,9 @@ func TestExecuteSessionTaskGatewayNoDisplayableOutputFails(t *testing.T) { if got := response["status"]; got != "failed" { t.Fatalf("expected failed status for no-output gateway response, got %#v", response) } + if got := response["code"]; got != "OPENCLAW_NO_DISPLAYABLE_OUTPUT" { + t.Fatalf("expected structured no-displayable code, got %#v", response) + } if got := response["output"]; got != openClawNoDisplayableText { t.Fatalf("expected no-displayable output message, got %#v", response) } @@ -883,6 +886,12 @@ func TestExecuteSessionTaskGatewayDoesNotExportStaleWorkspaceArtifactsWhenScoped if got := response["status"]; got != "artifact_missing" { t.Fatalf("expected artifact_missing status, got %#v", response) } + if got := response["code"]; got != "OPENCLAW_ARTIFACT_MISSING" { + t.Fatalf("expected structured artifact missing code, got %#v", response) + } + if _, ok := response["artifacts"]; ok { + t.Fatalf("expected no stale artifacts when scoped directory is empty, got %#v", response["artifacts"]) + } exportParams := gateway.LastArtifactExportParams() if got := strings.TrimSpace(shared.StringArg(exportParams, "artifactScope", "")); !strings.HasPrefix(got, "tasks/thread-openclaw-latest-artifact/") { t.Fatalf("expected scoped artifact export params, got %#v", exportParams) @@ -934,6 +943,9 @@ func TestExecuteSessionMessageGatewayRejectsClaimedArtifactsWithoutScopedFiles(t if got := response["status"]; got != "artifact_missing" { t.Fatalf("expected artifact_missing status, got %#v", response) } + if got := response["code"]; got != "OPENCLAW_ARTIFACT_MISSING" { + t.Fatalf("expected structured artifact missing code, got %#v", response) + } if gateway.ArtifactExportCount() != 0 { t.Fatalf("expected no artifact export for unprepared claimed output, got %d", gateway.ArtifactExportCount()) } @@ -1599,6 +1611,12 @@ func TestExecuteSessionTaskGatewayRejectsMissingOpenClawFilesForDeliveryRequest( if success, _ := response["success"].(bool); success { t.Fatalf("expected missing artifact delivery to be marked unsuccessful, got %#v", response) } + if got := response["status"]; got != "artifact_missing" { + t.Fatalf("expected artifact_missing status, got %#v", response) + } + if got := response["code"]; got != "OPENCLAW_ARTIFACT_MISSING" { + t.Fatalf("expected structured artifact missing code, got %#v", response) + } output := strings.TrimSpace(shared.StringArg(response, "output", "")) if strings.Contains(output, "点击直接下载") || strings.Contains(output, "文件已就绪") { t.Fatalf("expected hallucinated download text to be replaced, got %q", output)