Skip to content

Commit c20a855

Browse files
Gateway: skip text-only assistant media supplements
1 parent df00747 commit c20a855

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎src/gateway/server-methods/chat.directive-tags.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,48 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
715715
);
716716
});
717717

718+
it("does not persist agent media supplements when no playable media resolves", async () => {
719+
const transcriptDir = createTranscriptFixture("openclaw-chat-send-agent-stale-tts-");
720+
const staleAudioPath = path.join(transcriptDir, "stale.mp3");
721+
mockState.config = {
722+
agents: {
723+
defaults: {
724+
workspace: transcriptDir,
725+
},
726+
},
727+
};
728+
mockState.triggerAgentRunStart = true;
729+
mockState.dispatchedReplies = [
730+
{
731+
kind: "final",
732+
payload: {
733+
text: "Text-only test: one clean reply, no TTS, no media, no tool narration.",
734+
mediaUrl: staleAudioPath,
735+
mediaUrls: [staleAudioPath],
736+
trustedLocalMedia: true,
737+
},
738+
},
739+
];
740+
const respond = vi.fn();
741+
const context = createChatContext();
742+
743+
await runNonStreamingChatSend({
744+
context,
745+
respond,
746+
idempotencyKey: "idem-stale-agent-media",
747+
expectBroadcast: false,
748+
waitFor: "dedupe",
749+
});
750+
751+
const assistantUpdates = mockState.emittedTranscriptUpdates.filter(
752+
(update) =>
753+
typeof update.message === "object" &&
754+
update.message !== null &&
755+
(update.message as { role?: unknown }).role === "assistant",
756+
);
757+
expect(assistantUpdates).toEqual([]);
758+
});
759+
718760
it("keeps visible text on non-agent TTS final media because no model transcript exists", async () => {
719761
const transcriptDir = createTranscriptFixture("openclaw-chat-send-command-tts-final-");
720762
const audioPath = path.join(transcriptDir, "tts.mp3");

‎src/gateway/server-methods/chat.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,9 @@ export const chatHandlers: GatewayRequestHandlers = {
22502250
const persistedContentForAppend = hasAssistantDisplayMediaContent(persistedAssistantContent)
22512251
? persistedAssistantContent
22522252
: undefined;
2253+
if (!persistedContentForAppend?.length) {
2254+
return;
2255+
}
22532256
const transcriptReply =
22542257
mediaMessage?.transcriptText ??
22552258
extractAssistantDisplayTextFromContent(assistantContent) ??

0 commit comments

Comments
 (0)