Skip to content

writeTempFile filename collision in pi-code-reasoning and pi-ref-tools #104

Description

@feniix

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions