Browse Source

fix(image-hook): reset checkpoint after history compaction

When OpenCode compacts conversation history, userMsgCount can drop below
the stored lastProcessed counter, causing the guard to skip new images
without warning. Reset the checkpoint when the count falls below the
stored value.
Michael Henke 2 weeks ago
parent
commit
4726c46bb2
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/hooks/image-hook.ts

+ 6 - 1
src/hooks/image-hook.ts

@@ -202,7 +202,12 @@ export function processImageAttachments(args: {
     const sessionId = firstUserMsg?.info.sessionID ?? 'default';
     const counterKey = `${workDir}:${sessionId}`;
     const userMsgCount = messages.filter(isUserMessageWithParts).length;
-    const lastProcessed = lastProcessedUserMsgCountByDir.get(counterKey) ?? 0;
+    let lastProcessed = lastProcessedUserMsgCountByDir.get(counterKey) ?? 0;
+    // ponytail: reset after history compaction; re-checking old messages is harmless
+    if (userMsgCount < lastProcessed) {
+      lastProcessed = 0;
+      lastProcessedUserMsgCountByDir.set(counterKey, 0);
+    }
     if (userMsgCount > lastProcessed) {
       // Check only the new user messages (those we haven't seen yet)
       let userIndex = 0;