Skip to content

Commit 4526b44

Browse files
committed
fix: preserve generated media completion attachments
1 parent 15b0d43 commit 4526b44

4 files changed

Lines changed: 77 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Docs: https://docs.openclaw.ai
1717

1818
### Fixes
1919

20+
- Agents/media: accept generated media attachments on internal completion events and report delivery-loss failures as errors, so completed background music/video tasks do not disappear after provider success.
2021
- Matrix/approvals: release in-flight reaction bindings when the channel approval handler stops mid-delivery, preventing stale approval targets after restart. Fixes #82485. (#82482) Thanks @Feelw00.
2122
- Matrix/E2EE: stop requesting MSC4222 `state_after` sync responses so homeservers with incomplete state-after data do not leave fresh encrypted rooms without outbound room encryptors. Fixes #82515. Thanks @nickdecooman.
2223
- TUI: update the displayed model in real time when an auto-fallback resolution swaps in a different model mid-turn, so the status line reflects the actual model handling the run. Fixes #82296. Thanks @giodl73-repo.

‎src/agents/tools/media-generate-background-shared.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ async function wakeMediaGenerationTaskCompletion(params: {
323323
directIdempotencyKey: announceId,
324324
});
325325
if (!delivery.delivered && delivery.error) {
326-
log.warn("Media generation completion wake failed", {
326+
log.error("Media generation completion wake failed; generated media may not be delivered", {
327327
taskId: params.handle.taskId,
328328
runId: params.handle.runId,
329329
toolName: params.toolName,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Value } from "typebox/value";
2+
import { describe, expect, it } from "vitest";
3+
import type { AgentInternalEvent } from "../../../agents/internal-events.js";
4+
import { AgentParamsSchema } from "./agent.js";
5+
6+
function makeAgentParamsWithInternalEvent(event: AgentInternalEvent) {
7+
return {
8+
message: "A music generation task finished. Process the completion update now.",
9+
sessionKey: "agent:main:discord:channel:1456744319972282449",
10+
internalEvents: [event],
11+
idempotencyKey: "music_generate:task-123:ok",
12+
};
13+
}
14+
15+
const musicCompletionEvent: AgentInternalEvent = {
16+
type: "task_completion",
17+
source: "music_generation",
18+
childSessionKey: "music_generate:task-123",
19+
childSessionId: "task-123",
20+
announceType: "music generation task",
21+
taskLabel: "OpenClaw release anthem",
22+
status: "ok",
23+
statusLabel: "completed successfully",
24+
result: "Generated 1 track.",
25+
attachments: [
26+
{
27+
type: "audio",
28+
path: "/tmp/openclaw/generated-release-anthem.mp3",
29+
mimeType: "audio/mpeg",
30+
name: "generated-release-anthem.mp3",
31+
},
32+
],
33+
mediaUrls: ["/tmp/openclaw/generated-release-anthem.mp3"],
34+
replyInstruction: "Deliver the generated music.",
35+
};
36+
37+
describe("AgentParamsSchema", () => {
38+
it("accepts generated music attachments on internal completion events", () => {
39+
const params = makeAgentParamsWithInternalEvent(musicCompletionEvent);
40+
41+
expect(Value.Check(AgentParamsSchema, params)).toBe(true);
42+
});
43+
44+
it("keeps task completion internal events strict", () => {
45+
const params = makeAgentParamsWithInternalEvent({
46+
...musicCompletionEvent,
47+
unexpected: true,
48+
} as AgentInternalEvent);
49+
50+
expect(Value.Check(AgentParamsSchema, params)).toBe(false);
51+
});
52+
53+
it("rejects malformed generated attachment entries on internal events", () => {
54+
const params = makeAgentParamsWithInternalEvent({
55+
...musicCompletionEvent,
56+
attachments: [null],
57+
} as unknown as AgentInternalEvent);
58+
59+
expect(Value.Check(AgentParamsSchema, params)).toBe(false);
60+
});
61+
});

‎src/gateway/protocol/schema/agent.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ import {
66
} from "../../../agents/internal-event-contract.js";
77
import { InputProvenanceSchema, NonEmptyString, SessionLabelString } from "./primitives.js";
88

9+
export const AgentGeneratedAttachmentSchema = Type.Object(
10+
{
11+
type: Type.Optional(Type.String({ enum: ["image", "audio", "video", "file"] })),
12+
path: Type.Optional(Type.String()),
13+
url: Type.Optional(Type.String()),
14+
mediaUrl: Type.Optional(Type.String()),
15+
filePath: Type.Optional(Type.String()),
16+
mimeType: Type.Optional(Type.String()),
17+
name: Type.Optional(Type.String()),
18+
},
19+
{ additionalProperties: false },
20+
);
21+
922
export const AgentInternalEventSchema = Type.Object(
1023
{
1124
type: Type.Literal(AGENT_INTERNAL_EVENT_TYPE_TASK_COMPLETION),
@@ -17,6 +30,7 @@ export const AgentInternalEventSchema = Type.Object(
1730
status: Type.String({ enum: [...AGENT_INTERNAL_EVENT_STATUSES] }),
1831
statusLabel: Type.String(),
1932
result: Type.String(),
33+
attachments: Type.Optional(Type.Array(AgentGeneratedAttachmentSchema)),
2034
mediaUrls: Type.Optional(Type.Array(Type.String())),
2135
statsLine: Type.Optional(Type.String()),
2236
replyInstruction: Type.String(),

0 commit comments

Comments
 (0)