Skip to content

A local plugin for image-heavy chats in Codex, Claude Code and other agents: earlier images stop going out with every message, and the model fetches the one it needs by its ID, also after compaction.

fix(children): retry recording after a failed write

lin-coco33713a892fe7
diff --git a/plugin/src/children.ts b/plugin/src/children.ts
index c75ecc1..abef3e4 100644
--- a/plugin/src/children.ts
+++ b/plugin/src/children.ts
@@ -24,13 +24,13 @@ export function readChildren(taskId: string, dir = childrenDirOf()): Record<stri
export function recordChild(taskId: string, childId: string, child: Child, dir = childrenDirOf()): boolean {
const key = `${dir}\0${taskId}\0${childId}`;
if (known.has(key) || !THREAD_ID.test(taskId) || !THREAD_ID.test(childId)) return false;
- known.add(key);
const children = readChildren(taskId, dir);
- if (children[childId]) return false;
+ if (children[childId]) { known.add(key); return false; }
mkdirSync(dir, { recursive: true });
const file = join(dir, `${taskId}.json`);
writeFileSync(`${file}.tmp`, JSON.stringify({ ...children, [childId]: child }, null, 2));
renameSync(`${file}.tmp`, file);
+ known.add(key);
return true;
}
diff --git a/spike/src/children.test.ts b/spike/src/children.test.ts
index 5e581bc..4ad1f92 100644
--- a/spike/src/children.test.ts
+++ b/spike/src/children.test.ts
@@ -3,7 +3,7 @@
// Input: synthetic rollouts and temporary folders; output: Node test assertions only.
import assert from "node:assert/strict";
-import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
@@ -59,3 +59,16 @@ test("each child is recorded once under its task; later requests leave the recor
assert.equal(recordChild("../escape", SIDE, { kind: "side", from: MAIN, at: "x" }, dir), false);
assert.deepEqual(readChildren("../escape", dir), {});
});
+
+// A transient write failure must not poison the engine's process-local deduplication cache.
+test("a child can be recorded again after its first write fails", () => {
+ const { root } = sessions();
+ const dir = join(root, "blocked-children");
+ const child = { kind: "side" as const, from: MAIN, at: "2026-10-15T10:00:00Z" };
+ writeFileSync(dir, "temporarily blocks mkdir");
+ assert.throws(() => recordChild(MAIN, SIDE, child, dir));
+ rmSync(dir);
+ assert.equal(recordChild(MAIN, SIDE, child, dir), true, "retry after recovery must persist the child");
+ assert.deepEqual(readChildren(MAIN, dir), { [SIDE]: child });
+ assert.equal(recordChild(MAIN, SIDE, child, dir), false, "successful writes are still deduplicated");
+});