Problem
writeTempFile in both packages/pi-code-reasoning/extensions/output.ts and packages/pi-ref-tools/extensions/helpers.ts builds tmp filenames using only Date.now() as the uniqueness key. Two truncations within the same millisecond produce the same filename, and the second writeFileSync silently overwrites the first — leaving the first tool response pointing at a path that now contains the wrong content.
This was fixed in pi-sequential-thinking by PR #103 (commit c3d60b3). The two peer packages have the identical bug.
Evidence
$ grep -n "Date.now()" packages/pi-code-reasoning/extensions/output.ts
# pi-code-reasoning-${safeName}-${Date.now()}.txt
$ grep -n "Date.now()" packages/pi-ref-tools/extensions/helpers.ts
# pi-ref-tools-${safeName}-${Date.now()}.txt
A regression test in pi-sequential-thinking/__tests__/helpers.test.ts (50 consecutive calls) demonstrated the bug: 50 calls produced only 3 unique paths before the fix.
Proposed fix
Mirror the pi-sequential-thinking fix: append randomUUID().slice(0, 8) to the filename. One-line change in each package, plus an equivalent collision-resistance test.
// before
const filename = `pi-code-reasoning-${safeName}-${Date.now()}.txt`;
// after
const filename = `pi-code-reasoning-${safeName}-${Date.now()}-${randomUUID().slice(0, 8)}.txt`;
Related
Problem
writeTempFilein bothpackages/pi-code-reasoning/extensions/output.tsandpackages/pi-ref-tools/extensions/helpers.tsbuilds tmp filenames using onlyDate.now()as the uniqueness key. Two truncations within the same millisecond produce the same filename, and the secondwriteFileSyncsilently overwrites the first — leaving the first tool response pointing at a path that now contains the wrong content.This was fixed in
pi-sequential-thinkingby PR #103 (commitc3d60b3). The two peer packages have the identical bug.Evidence
A regression test in
pi-sequential-thinking/__tests__/helpers.test.ts(50 consecutive calls) demonstrated the bug: 50 calls produced only 3 unique paths before the fix.Proposed fix
Mirror the
pi-sequential-thinkingfix: appendrandomUUID().slice(0, 8)to the filename. One-line change in each package, plus an equivalent collision-resistance test.Related
pi-sequential-thinkingwriteTempFileto a workspace-internal shared package, which would let this fix live in one place.