Skip to content

Commit 664cb71

Browse files
committed
fix(reply): keep current-turn image suppression on the recorder for plugin harnesses
Plugin-owned harness preparation hydrates the current turn from the persisted user-turn record. Carry the unresolved fact indexes on the transcript recorder as a prompt-only view so that path still skips the unreadable attachment without the flag reaching the durable transcript.
1 parent 48a6b2a commit 664cb71

6 files changed

Lines changed: 71 additions & 0 deletions

File tree

‎src/agents/embedded-agent-runner/run/attempt-prompt-submit.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ export async function prepareEmbeddedAttemptPromptExecution(input: {
339339
attempt.userTurnTranscriptRecorder?.message ??
340340
(await attempt.userTurnTranscriptRecorder?.resolveMessage());
341341
const persistedMedia = persistedMessage ? (readPersistedMediaFacts(persistedMessage) ?? []) : [];
342+
for (const factIndex of attempt.userTurnTranscriptRecorder?.promptSuppressedFactIndexes ?? []) {
343+
const fact = persistedMedia[factIndex];
344+
if (fact) {
345+
persistedMedia[factIndex] = { ...fact, hydrationSuppressed: true };
346+
}
347+
}
342348

343349
const result = await detectAndLoadPromptImages({
344350
prompt: input.prompt,

‎src/agents/embedded-agent-runner/run/run-attempt-dispatch.media.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,64 @@ describe("plugin harness prompt media", () => {
370370
}
371371
});
372372

373+
it("skips a recorder fact suppressed for this prompt while keeping the persisted record clean", async () => {
374+
const workspaceDir = await fs.mkdtemp(
375+
path.join(os.tmpdir(), "openclaw-harness-prompt-suppressed-"),
376+
);
377+
const imagePath = path.join(workspaceDir, "present.png");
378+
await fs.writeFile(imagePath, Buffer.from(TINY_PNG_BASE64, "base64"));
379+
const media = [
380+
{ path: imagePath, contentType: "image/png" },
381+
{ path: path.join(workspaceDir, "missing.png"), contentType: "image/png" },
382+
];
383+
const message = {
384+
role: "user",
385+
content: "compare these",
386+
__openclaw: {
387+
media,
388+
mediaImageLayout: {
389+
slots: [
390+
{ kind: "inline", factIndex: 0 },
391+
{ kind: "offloaded", factIndex: 1 },
392+
],
393+
},
394+
},
395+
};
396+
const buildInput = (promptSuppressedFactIndexes?: number[]) =>
397+
({
398+
runParams: {
399+
agentId: "main",
400+
config: { agents: { defaults: { sandbox: { mode: "off" } } } },
401+
images: [{ type: "image", data: TINY_PNG_BASE64, mimeType: "image/png" }],
402+
imageOrder: ["inline"],
403+
media,
404+
sessionId: "session-prompt-suppressed",
405+
userTurnTranscriptRecorder: { message, promptSuppressedFactIndexes },
406+
},
407+
runtime: {
408+
model: { input: ["text", "image"] },
409+
sessionId: "session-prompt-suppressed",
410+
workspaceDir,
411+
},
412+
pluginHarnessOwnsTransport: true,
413+
}) as unknown as Parameters<typeof preparePluginHarnessPromptImages>[0];
414+
try {
415+
await expect(preparePluginHarnessPromptImages(buildInput())).rejects.toThrow(
416+
/failed to hydrate 1 structured image attachment/,
417+
);
418+
419+
const result = await preparePluginHarnessPromptImages(buildInput([1]));
420+
421+
expect(result.images).toEqual([
422+
{ type: "image", data: TINY_PNG_BASE64, mimeType: "image/png" },
423+
]);
424+
expect(result.imageOrder).toEqual(["inline"]);
425+
expect(media[1]).not.toHaveProperty("hydrationSuppressed");
426+
} finally {
427+
await fs.rm(workspaceDir, { recursive: true, force: true });
428+
}
429+
});
430+
373431
it("surfaces an unsuppressed identity-less inline fact with no image block", async () => {
374432
await expect(
375433
preparePluginHarnessPromptImages({

‎src/auto-reply/reply/get-reply-run-execute.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ export async function executePreparedReplyRun(state: PreparedReplyRunAdmission)
314314
(userTurnInput
315315
? createUserTurnTranscriptRecorder({
316316
input: userTurnInput,
317+
...(unresolvedSourceIndexes.size > 0
318+
? { promptSuppressedFactIndexes: [...unresolvedSourceIndexes] }
319+
: {}),
317320
target: () => ({
318321
sessionId: preparedSessionState.sessionId,
319322
sessionKey: sessionKey ?? preparedSessionState.sessionId,

‎src/auto-reply/reply/get-reply-run.media-only.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ describe("runPreparedReply media-only handling", () => {
11321132
{ path: "/tmp/unreadable.png", contentType: "image/png", kind: "image" },
11331133
]);
11341134
expect(persisted.mediaImageLayout).toEqual({ slots: [{ kind: "offloaded", factIndex: 0 }] });
1135+
expect(call.followupRun.userTurnTranscriptRecorder?.promptSuppressedFactIndexes).toEqual([0]);
11351136
});
11361137

11371138
it.each([

‎src/sessions/user-turn-transcript.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ export function createUserTurnTranscriptRecorder(
595595
get message() {
596596
return message;
597597
},
598+
promptSuppressedFactIndexes: params.promptSuppressedFactIndexes,
598599
resolveMessage: resolveMessageForPersistence,
599600
replaceTextBeforePersistence: (text) => {
600601
if (persisted || runtimePersisted || sentToProvider) {

‎src/sessions/user-turn-transcript.types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ export type CreateUserTurnTranscriptRecorderParams = {
151151
onMessagePersisted?: (message: PersistedUserTurnMessage) => void | Promise<void>;
152152
expectedSessionState?: SessionTranscriptTurnExpectedState;
153153
sessionLifecyclePatch?: SessionTranscriptTurnLifecyclePatch;
154+
promptSuppressedFactIndexes?: readonly number[];
154155
};
155156

156157
export type UserTurnTranscriptRecorder = {
157158
readonly message: PersistedUserTurnMessage | undefined;
159+
readonly promptSuppressedFactIndexes?: readonly number[];
158160
resolveMessage: () => Promise<PersistedUserTurnMessage | undefined>;
159161
/** Replaces generated current-turn text before runtime persistence/provider submission. */
160162
replaceTextBeforePersistence?: (text: string) => void;

0 commit comments

Comments
 (0)