Skip to content

Commit 2abc76d

Browse files
authored
fix(media): keep failure markers visible in audio-only processing (#130869)
1 parent 47882f4 commit 2abc76d

3 files changed

Lines changed: 107 additions & 82 deletions

File tree

‎docs/nodes/media-understanding.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ When `mode: "all"`, outputs are labeled `[Image 1/2]`, `[Audio 2/2]`, etc.
269269
- At most five skip markers render per message; further skipped attachments collapse into one reason-neutral `[<n> more attachments skipped]` summary so junk attachments cannot grow the prompt without bound. File and image, audio, or video markers share this five-marker budget.
270270
- If a PDF falls back to rendered page images, OpenClaw forwards those images to vision-capable reply models and keeps the placeholder `[PDF content rendered to images]` in the file block.
271271
- Image, audio, and video decisions record one closed disposition for every attachment candidate: handled, handed to native vision, not selected after the attachment limit, disabled, missing a model, denied by chat scope, or failed.
272-
- Unhandled media gets a bounded model-visible marker. Images handed to native vision and media turns owned by another harness do not add markers.
272+
- Unhandled media gets a bounded model-visible marker. Images handed to native vision do not add markers. When a native harness owns the turn and OpenClaw runs only audio preprocessing, failed or skipped audio still gets a marker; image, video, and document inputs remain owned by the harness. Too-small audio keeps its placeholder transcript without a duplicate marker.
273273

274274
## Config examples
275275

‎src/media-understanding/apply.test.ts‎

Lines changed: 98 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -613,81 +613,92 @@ describe("applyMediaUnderstanding", () => {
613613
);
614614
});
615615

616-
it("injects a placeholder transcript when local-path audio is too small", async () => {
617-
const ctx = await createAudioCtx({
618-
fileName: "tiny.ogg",
619-
mediaType: "audio/ogg",
620-
content: Buffer.alloc(100),
621-
});
622-
const transcribeAudio = vi.fn(async () => ({ text: "should-not-run" }));
623-
const cfg: OpenClawConfig = {
624-
tools: {
625-
media: {
626-
models: [{ provider: "groq", capabilities: ["audio"] }],
627-
audio: {
628-
enabled: true,
629-
maxBytes: 1024 * 1024,
616+
it.each([undefined, "audio-only"] as const)(
617+
"injects one placeholder for too-small local audio in %s mode",
618+
async (processingMode) => {
619+
const ctx = await createAudioCtx({
620+
fileName: "tiny.ogg",
621+
mediaType: "audio/ogg",
622+
content: Buffer.alloc(100),
623+
});
624+
const transcribeAudio = vi.fn(async () => ({ text: "should-not-run" }));
625+
const cfg: OpenClawConfig = {
626+
tools: {
627+
media: {
628+
models: [{ provider: "groq", capabilities: ["audio"] }],
629+
audio: {
630+
enabled: true,
631+
maxBytes: 1024 * 1024,
632+
},
630633
},
631634
},
632-
},
633-
};
635+
};
634636

635-
const result = await applyMediaUnderstanding({
636-
ctx,
637-
cfg,
638-
providers: {
639-
groq: { id: "groq", transcribeAudio },
640-
},
641-
});
637+
const result = await applyMediaUnderstanding({
638+
ctx,
639+
cfg,
640+
processingMode,
641+
providers: {
642+
groq: { id: "groq", transcribeAudio },
643+
},
644+
});
642645

643-
expect(transcribeAudio).not.toHaveBeenCalled();
644-
expect(result.appliedAudio).toBe(true);
645-
expect(result.outputs).toEqual([
646-
{
647-
kind: "audio.transcription",
648-
attachmentIndex: 0,
649-
text: "[Voice note could not be transcribed because the audio attachment was too small]",
650-
provider: "openclaw",
651-
model: "synthetic-empty-audio",
652-
},
653-
]);
654-
expect(ctx.Transcript).toBe(
655-
"[Voice note could not be transcribed because the audio attachment was too small]",
656-
);
657-
expect(ctx.Body).toBe(
658-
"[Audio]\nTranscript:\n[Voice note could not be transcribed because the audio attachment was too small]",
659-
);
660-
});
646+
expect(transcribeAudio).not.toHaveBeenCalled();
647+
expect(result.appliedAudio).toBe(true);
648+
expect(result.outputs).toEqual([
649+
{
650+
kind: "audio.transcription",
651+
attachmentIndex: 0,
652+
text: "[Voice note could not be transcribed because the audio attachment was too small]",
653+
provider: "openclaw",
654+
model: "synthetic-empty-audio",
655+
},
656+
]);
657+
expect(ctx.Transcript).toBe(
658+
"[Voice note could not be transcribed because the audio attachment was too small]",
659+
);
660+
expect(ctx.Body).toBe(
661+
"[Audio]\nTranscript:\n[Voice note could not be transcribed because the audio attachment was too small]",
662+
);
663+
},
664+
);
661665

662-
it("skips audio transcription when attachment exceeds maxBytes", async () => {
663-
const ctx = await createAudioCtx({
664-
fileName: "large.wav",
665-
mediaType: "audio/wav",
666-
content: Buffer.from([0, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
667-
});
668-
const transcribeAudio = vi.fn(async () => ({ text: "should-not-run" }));
669-
const cfg: OpenClawConfig = {
670-
tools: {
671-
media: {
672-
models: [{ provider: "groq", capabilities: ["audio"] }],
673-
audio: {
674-
enabled: true,
675-
maxBytes: 4,
666+
it.each([undefined, "audio-only"] as const)(
667+
"marks audio exceeding maxBytes in %s mode",
668+
async (processingMode) => {
669+
const ctx = await createAudioCtx({
670+
fileName: "large.wav",
671+
mediaType: "audio/wav",
672+
content: Buffer.from([0, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
673+
});
674+
const transcribeAudio = vi.fn(async () => ({ text: "should-not-run" }));
675+
const cfg: OpenClawConfig = {
676+
tools: {
677+
media: {
678+
models: [{ provider: "groq", capabilities: ["audio"] }],
679+
audio: {
680+
enabled: true,
681+
maxBytes: 4,
682+
},
676683
},
677684
},
678-
},
679-
};
685+
};
680686

681-
const result = await applyMediaUnderstanding({
682-
ctx,
683-
cfg,
684-
providers: { groq: { id: "groq", transcribeAudio } },
685-
});
687+
const result = await applyMediaUnderstanding({
688+
ctx,
689+
cfg,
690+
processingMode,
691+
providers: { groq: { id: "groq", transcribeAudio } },
692+
});
686693

687-
expect(result.appliedAudio).toBe(false);
688-
expect(transcribeAudio).not.toHaveBeenCalled();
689-
expect(ctx.Body).toBe("[Audio attachment could not be analyzed]");
690-
});
694+
expect(result.appliedAudio).toBe(false);
695+
expect(result.outputs).toEqual([]);
696+
expect(ctx.Transcript).toBeUndefined();
697+
expect(transcribeAudio).not.toHaveBeenCalled();
698+
expect(ctx.Body).toBe("[Audio attachment could not be analyzed]");
699+
expect(ctx.BodyForAgent).toBe(ctx.Body);
700+
},
701+
);
691702

692703
it("falls back to CLI model when provider fails", async () => {
693704
const ctx = await createAudioCtx();
@@ -1676,7 +1687,11 @@ describe("applyMediaUnderstanding", () => {
16761687
expect(ctx.BodyForCommands).toBe("audio ok");
16771688
});
16781689

1679-
it("limits native-harness preprocessing to audio", async () => {
1690+
it.each([
1691+
{ outcome: "success", body: "[Audio]\nTranscript:\naudio ok" },
1692+
{ outcome: "failure", body: "[Audio attachment could not be analyzed]" },
1693+
{ outcome: "scope-denied", body: "[Audio attachment not analyzed in this chat]" },
1694+
])("limits native-harness preprocessing to audio on STT $outcome", async ({ outcome, body }) => {
16801695
const dir = await createTempMediaDir();
16811696
const imagePath = path.join(dir, "photo.jpg");
16821697
const audioPath = path.join(dir, "note.ogg");
@@ -1686,11 +1701,17 @@ describe("applyMediaUnderstanding", () => {
16861701
await fs.writeFile(filePath, "file text");
16871702

16881703
const describeImage = vi.fn(async () => ({ text: "image ok" }));
1689-
const transcribeAudio = vi.fn(async () => ({ text: "audio ok" }));
1704+
const transcribeAudio = vi.fn(async () => {
1705+
if (outcome === "failure") {
1706+
throw new Error("transcription provider unavailable");
1707+
}
1708+
return { text: "audio ok" };
1709+
});
16901710
const ctx: MsgContext = {
16911711
Body: "",
16921712
media: [
16931713
{ path: imagePath, contentType: "image/jpeg" },
1714+
{ url: "https://example.test/clip.mp4", contentType: "video/mp4" },
16941715
{ path: audioPath, contentType: "audio/ogg" },
16951716
{ path: filePath, contentType: "text/plain" },
16961717
],
@@ -1703,7 +1724,10 @@ describe("applyMediaUnderstanding", () => {
17031724
{ provider: "groq", capabilities: ["audio"] },
17041725
],
17051726
image: { enabled: true },
1706-
audio: { enabled: true },
1727+
audio: {
1728+
enabled: true,
1729+
scope: { default: outcome === "scope-denied" ? "deny" : "allow" },
1730+
},
17071731
},
17081732
},
17091733
};
@@ -1719,17 +1743,19 @@ describe("applyMediaUnderstanding", () => {
17191743
});
17201744

17211745
expect(describeImage).not.toHaveBeenCalled();
1722-
expect(transcribeAudio).toHaveBeenCalledOnce();
1746+
expect(transcribeAudio).toHaveBeenCalledTimes(outcome === "scope-denied" ? 0 : 1);
17231747
expect(result).toEqual(
17241748
expect.objectContaining({
17251749
appliedImage: false,
1726-
appliedAudio: true,
1750+
appliedAudio: outcome === "success",
17271751
appliedVideo: false,
17281752
appliedFile: false,
17291753
extractedFileImages: [],
17301754
}),
17311755
);
1732-
expect(ctx.Body).toBe("[Audio]\nTranscript:\naudio ok");
1756+
expect(ctx.Body).toBe(body);
1757+
expect(ctx.BodyForAgent).toBe(body);
1758+
expect(ctx.Transcript).toBe(outcome === "success" ? "audio ok" : undefined);
17331759
});
17341760

17351761
it("orders synthetic too-small audio output between image and video", async () => {

‎src/media-understanding/apply.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,14 @@ export async function applyMediaUnderstanding(params: {
611611
// placement, suppress — a wrong path is worse than the plain marker (#122411).
612612
selfServePathsEnabled: params.selfServeLocalPaths === true,
613613
});
614-
const mediaMarkers =
615-
params.processingMode === "audio-only"
616-
? []
617-
: renderMediaAttachmentMarkers({
618-
attachments,
619-
decisions,
620-
outputs,
621-
deliveredImageIndexes: params.deliveredImageIndexes,
622-
});
614+
// Only processed capabilities have decisions, so audio-only runs cannot
615+
// add markers for image/video inputs still owned by the native harness.
616+
const mediaMarkers = renderMediaAttachmentMarkers({
617+
attachments,
618+
decisions,
619+
outputs,
620+
deliveredImageIndexes: params.deliveredImageIndexes,
621+
});
623622
const contextBlocks = applyAttachmentMarkerBudget([...fileContext.blocks, ...mediaMarkers]);
624623
if (contextBlocks.length > 0) {
625624
ctx.Body = appendFileBlocks(ctx.Body, contextBlocks);

0 commit comments

Comments
 (0)