From cf4f1ed03aa6ded9fafba16ee9205ef715649e94 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 21 Jan 2026 18:17:10 +0000 Subject: [PATCH] fix: persist history image injections --- CHANGELOG.md | 1 + src/agents/pi-embedded-runner/run/attempt.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05909cdf3..68a3d120d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Docs: https://docs.clawd.bot - CLI: move gateway service commands under `clawdbot gateway` and add `gateway probe` for reachability. ### Fixes +- Embedded runner: persist injected history images so attachments aren’t reloaded each turn. (#1374) Thanks @Nicell. - Nodes tool: include agent/node/gateway context in tool failure logs to speed approval debugging. - macOS: exec approvals now respect wildcard agent allowlists (`*`). - macOS: allow SSH agent auth when no identity file is set. (#1384) Thanks @ameno-. diff --git a/src/agents/pi-embedded-runner/run/attempt.ts b/src/agents/pi-embedded-runner/run/attempt.ts index 6aa62cd39..b54ff4087 100644 --- a/src/agents/pi-embedded-runner/run/attempt.ts +++ b/src/agents/pi-embedded-runner/run/attempt.ts @@ -627,6 +627,7 @@ export async function runEmbeddedAttempt( // Inject history images into their original message positions. // This ensures the model sees images in context (e.g., "compare to the first image"). if (imageResult.historyImagesByIndex.size > 0) { + let didMutate = false; for (const [msgIndex, images] of imageResult.historyImagesByIndex) { // Bounds check: ensure index is valid before accessing if (msgIndex < 0 || msgIndex >= activeSession.messages.length) continue; @@ -635,6 +636,7 @@ export async function runEmbeddedAttempt( // Convert string content to array format if needed if (typeof msg.content === "string") { msg.content = [{ type: "text", text: msg.content }]; + didMutate = true; } if (Array.isArray(msg.content)) { // Check for existing image content to avoid duplicates across turns @@ -653,11 +655,16 @@ export async function runEmbeddedAttempt( // Only add if this image isn't already in the message if (!existingImageData.has(img.data)) { msg.content.push(img); + didMutate = true; } } } } } + if (didMutate) { + // Persist message mutations (e.g., injected history images) so we don't re-scan/reload. + activeSession.agent.replaceMessages(activeSession.messages); + } } cacheTrace?.recordStage("prompt:images", {