Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/agentengine/video_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func (c *conversations) generateVideo(ctx context.Context, turn *activeTurn, sin
}
result, err := c.engine.generateVideo(videoCtx, task.Model, task.Prompt, options)
if err != nil {
timedOut := errors.Is(videoCtx.Err(), context.DeadlineExceeded) || errors.Is(err, context.DeadlineExceeded)
cancel()
task.State, task.Error = "failed", "video_generation_failed"
if err.Error() == "video_model_not_configured" || err.Error() == "video_model_unavailable" {
Expand All @@ -321,8 +322,10 @@ func (c *conversations) generateVideo(ctx context.Context, turn *activeTurn, sin
task.Error = "video_generation_blocked"
}
}
if ctx.Err() != nil {
if errors.Is(ctx.Err(), context.Canceled) {
task.Error = "video_generation_canceled"
} else if timedOut {
task.Error = "video_generation_timeout"
}
cleanupCtx, cleanupCancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
defer cleanupCancel()
Expand Down
21 changes: 21 additions & 0 deletions internal/agentengine/video_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"io"
"slices"
"strings"
Expand Down Expand Up @@ -90,6 +91,26 @@ func TestVideoDeliveryFailureReplacesDownloadingStatus(t *testing.T) {
}
}

func TestVideoGenerationDeadlineEmitsTimeoutStatus(t *testing.T) {
engine := &Engine{generateVideo: func(context.Context, *modelprovider.VideoGenerationConfig, string, modelprovider.VideoGenerationOptions) (modelprovider.GeneratedVideo, error) {
return modelprovider.GeneratedVideo{}, fmt.Errorf("poll video: %w", context.DeadlineExceeded)
}}
conversation := &conversations{engine: engine, agentID: "agent-video"}
turn := &activeTurn{agentID: "agent-video", request: TurnRequest{ID: "turn-video", ConversationKey: "room-video"}}
var task contract.VideoGenerationTask
sink := contract.MediaGenerationSink{EventSink: EventSinkFunc(func(_ context.Context, event TurnEvent) error {
task = event.Output.Payload.(contract.VideoGenerationTask)
return nil
})}
err := conversation.generateVideo(context.Background(), turn, sink, contract.VideoGenerationTask{ID: "video-call", Prompt: "kitten"}, nil)
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("error = %v, want deadline exceeded", err)
}
if task.State != "failed" || task.Error != "video_generation_timeout" {
t.Fatalf("failed task = %#v", task)
}
}

func TestRecoverVideoGenerationDoesNotOccupyConversationAdmission(t *testing.T) {
started := make(chan struct{})
release := make(chan struct{})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { render, screen } from "@testing-library/react";
import { createTranslator } from "@/shared/i18n";
import { VideoGenerationStatus } from "./VideoGenerationStatus";

it.each([
["zh", "failed", "invalid_video_seconds", "视频生成失败"],
["en", "failed", "invalid_parameter", "Video generation failed"],
["zh", "delivery_failed", "video_delivery_failed", "视频已生成,但发送失败"],
] as const)("shows only the failure status in %s for %s / %s", (locale, state, code, label) => {
render(
<VideoGenerationStatus
message={{
content: "Original video prompt",
metadata: {
video_generation: {
state,
error: code,
error_details: {
code,
message: 'The parameter duration is not valid; received: "2" Request id: private-123',
},
},
},
}}
t={createTranslator(locale)}
/>,
);

expect(screen.getByText(label)).toBeVisible();
expect(
screen.queryByText(/parameter duration|private-123|invalid_video_seconds|invalid_parameter/),
).not.toBeInTheDocument();
expect(screen.queryByText(/重试|try again/i)).not.toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ export function VideoGenerationStatus({
in_progress: t("videoGenerating"),
downloading: t("videoDownloading"),
};
const errorDetails =
task.error_details && typeof task.error_details === "object" && !Array.isArray(task.error_details)
? (task.error_details as Record<string, unknown>)
: null;
const errorMessage = String(errorDetails?.message ?? "").trim();
return (
<MediaGeneration
kind="video"
Expand All @@ -49,7 +44,6 @@ export function VideoGenerationStatus({
result={result}
promptDisclosureLabel={t("videoViewPrompt")}
prompt={String(task.prompt ?? message.content ?? "")}
failureMessage={errorMessage}
/>
);
}
Loading