Skip to content

Commit a63cfce

Browse files
authored
fix(reply): stop advertising unavailable media messaging tools (#129944)
* fix(reply): stop advertising unavailable media messaging tools * test(agents): wait for complete process-tree readiness payload
1 parent 36560c6 commit a63cfce

3 files changed

Lines changed: 16 additions & 20 deletions

File tree

‎src/agents/sessions/exec.real.test.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawnSync } from "node:child_process";
2-
import { existsSync, readFileSync } from "node:fs";
2+
import { readFileSync } from "node:fs";
33
import { join } from "node:path";
44
import { afterEach, describe, expect, it, vi } from "vitest";
55
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
@@ -62,14 +62,14 @@ describe("execCommand process-tree cleanup", () => {
6262
const resultPromise = execCommand(process.execPath, ["-e", parentScript], process.cwd(), {
6363
timeout: 1_000,
6464
});
65-
await vi.waitFor(() => expect(existsSync(readyPath)).toBe(true), {
66-
timeout: 3_000,
67-
interval: 25,
68-
});
69-
const { parentPid, childPid } = JSON.parse(readFileSync(readyPath, "utf8")) as {
70-
parentPid: number;
71-
childPid: number;
72-
};
65+
const { parentPid, childPid } = await vi.waitFor(
66+
() =>
67+
JSON.parse(readFileSync(readyPath, "utf8")) as {
68+
parentPid: number;
69+
childPid: number;
70+
},
71+
{ timeout: 3_000, interval: 25 },
72+
);
7373
cleanupPids.add(parentPid);
7474
cleanupPids.add(childPid);
7575

‎src/auto-reply/reply.media-note.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe("getReplyFromConfig media note plumbing", () => {
2222
isBareSessionReset: false,
2323
startupAction: "new",
2424
prefixedBody: sessionCtx.BodyForAgent,
25+
sourceReplyDeliveryMode: "automatic",
2526
});
2627
const prompt = envelope.prefixedCommandBody;
2728

@@ -30,11 +31,11 @@ describe("getReplyFromConfig media note plumbing", () => {
3031
"[media attached 1/2: /tmp/a.png (application/octet-stream)]",
3132
"[media attached 2/2: /tmp/b.png (application/octet-stream)]",
3233
].join("\n");
33-
const replyHint =
34-
"To send an image back, use the message tool with structured media fields such as media, mediaUrl, path, or filePath. Keep caption in the text body.";
35-
expect(prompt).toBe(`${mediaNote}\n${replyHint}\nhello`);
36-
expect(envelope.queuedBody).toBe(`${mediaNote}\n${replyHint}\nhello`);
34+
expect(prompt).toBe(`${mediaNote}\nhello`);
35+
expect(envelope.queuedBody).toBe(`${mediaNote}\nhello`);
3736
expect(envelope.transcriptCommandBody).toBe(`${mediaNote}\nhello`);
37+
expect(prompt).not.toContain("message tool");
38+
expect(envelope.queuedBody).not.toContain("message tool");
3839
expect(envelope.media?.map(({ path }) => path)).toEqual(["/tmp/a.png", "/tmp/b.png"]);
3940
const idxA = prompt.indexOf("[media attached 1/2: /tmp/a.png");
4041
const idxB = prompt.indexOf("[media attached 2/2: /tmp/b.png");

‎src/auto-reply/reply/prompt-prelude.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import { buildInboundMediaNoteProjection } from "../media-note.js";
1212
import type { MsgContext, TemplateContext } from "../templating.js";
1313
import { appendChannelPromptContext } from "./channel-prompt-context.js";
1414

15-
const REPLY_MEDIA_HINT =
16-
"To send an image back, use the message tool with structured media fields such as media, mediaUrl, path, or filePath. Keep caption in the text body.";
1715
const ROOM_EVENT_PROMPT = "[OpenClaw room event]";
1816
const RESUMABLE_ROOM_CONTEXT_OMITTED_PREFIXES = [
1917
"Conversation context (chronological, selected for current message):",
@@ -34,7 +32,6 @@ function buildReplyPromptBodies(params: {
3432
media?: readonly MediaFact[];
3533
}): {
3634
mediaNote?: string;
37-
mediaReplyHint?: string;
3835
media?: MediaFact[];
3936
prefixedCommandBody: string;
4037
queuedBody: string;
@@ -56,12 +53,11 @@ function buildReplyPromptBodies(params: {
5653
const generatedMedia = buildInboundMediaNoteProjection(params.ctx);
5754
const mediaNote = generatedMedia.text;
5855
const media = [...generatedMedia.media, ...normalizeMediaFacts(params.media)];
59-
const mediaReplyHint = mediaNote ? REPLY_MEDIA_HINT : undefined;
6056
const queuedBodyRaw = mediaNote
61-
? [mediaNote, mediaReplyHint, queueBodyBase].filter(Boolean).join("\n").trim()
57+
? [mediaNote, queueBodyBase].filter(Boolean).join("\n").trim()
6258
: queueBodyBase;
6359
const prefixedCommandBodyRaw = mediaNote
64-
? [mediaNote, mediaReplyHint, prefixedBody].filter(Boolean).join("\n").trim()
60+
? [mediaNote, prefixedBody].filter(Boolean).join("\n").trim()
6561
: prefixedBody;
6662
const transcriptBody = params.transcriptBody ?? params.effectiveBaseBody;
6763
const includeMediaTranscript = mediaNote && params.inboundEventKind !== "room_event";
@@ -74,7 +70,6 @@ function buildReplyPromptBodies(params: {
7470
: "";
7571
return {
7672
mediaNote,
77-
mediaReplyHint,
7873
...(media.length > 0 ? { media } : {}),
7974
prefixedCommandBody: annotateInterSessionPromptText(
8075
prefixedCommandBodyRaw,

0 commit comments

Comments
 (0)