Skip to content

Commit 86039e8

Browse files
allquixoticclaude
andcommitted
fix(concurrency): namespace temp filenames to avoid cross-conversation clashes
Two parallel conversations could collide on shared temp filenames: - image-handler: temp_image_<ms> -> add a crypto.randomUUID() suffix - diagnosticsHandler: zoo-diagnostics-<taskId8>-<ms> -> use the full task id plus a random hex suffix Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b2f55f6 commit 86039e8

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/core/webview/diagnosticsHandler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "path"
22
import * as os from "os"
33
import * as fs from "fs/promises"
4+
import * as crypto from "crypto"
45
import * as vscode from "vscode"
56

67
import { getTaskDirectoryPath } from "../../utils/storage"
@@ -73,7 +74,10 @@ export async function generateErrorDiagnostics(params: GenerateDiagnosticsParams
7374
// Create a temporary diagnostics file
7475
const tmpDir = os.tmpdir()
7576
const timestamp = Date.now()
76-
const tempFileName = `zoo-diagnostics-${taskId.slice(0, 8)}-${timestamp}.json`
77+
// Use the full task id plus a short random suffix so two diagnostics dumps for
78+
// the same (or a same-8-char-prefix) task in the same millisecond can't collide
79+
// across concurrent conversations.
80+
const tempFileName = `zoo-diagnostics-${taskId}-${timestamp}-${crypto.randomBytes(4).toString("hex")}.json`
7781
const tempFilePath = path.join(tmpDir, tempFileName)
7882

7983
await fs.writeFile(tempFilePath, fullContent, "utf8")

src/integrations/misc/image-handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path"
22
import * as os from "os"
3+
import * as crypto from "crypto"
34
import * as vscode from "vscode"
45
import { getWorkspacePath } from "../../utils/path"
56
import { t } from "../../i18n"
@@ -52,7 +53,9 @@ export async function openImage(dataUriOrPath: string, options?: { values?: { ac
5253
const imageBuffer = Buffer.from(base64Data, "base64")
5354

5455
// Default behavior: open the image
55-
const tempFilePath = path.join(os.tmpdir(), `temp_image_${Date.now()}.${format}`)
56+
// Include a random suffix so concurrent conversations saving images in the same
57+
// millisecond don't collide on the temp filename.
58+
const tempFilePath = path.join(os.tmpdir(), `temp_image_${Date.now()}_${crypto.randomUUID()}.${format}`)
5659
try {
5760
await vscode.workspace.fs.writeFile(vscode.Uri.file(tempFilePath), imageBuffer)
5861
// Check if this is a copy action

0 commit comments

Comments
 (0)