From bb9de30ef9a1dc054e6c3d0512cdfeea2fb205ff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 21 Jul 2025 02:14:40 +0000 Subject: [PATCH] Fix race condition in session file initialization by chaining file operations Co-authored-by: pavelfeldman <883973+pavelfeldman@users.noreply.github.com> --- src/context.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/context.ts b/src/context.ts index edea1c2..c60d40e 100644 --- a/src/context.ts +++ b/src/context.ts @@ -45,6 +45,7 @@ export class Context { private _pendingAction: PendingAction | undefined; private _downloads: { download: playwright.Download, finished: boolean, outputFile: string }[] = []; private _sessionFile: string | undefined; + private _sessionFileInitialized: Promise | undefined; clientVersion: { name: string; version: string; } | undefined; constructor(tools: Tool[], config: FullConfig, browserContextFactory: BrowserContextFactory) { @@ -53,7 +54,7 @@ export class Context { this._browserContextFactory = browserContextFactory; testDebug('create context'); if (this.config.saveSession) - void this._initializeSessionFile(); + this._sessionFileInitialized = this._initializeSessionFile(); } clientSupportsImages(): boolean { @@ -150,6 +151,10 @@ export class Context { if (!this.config.saveSession || !this._sessionFile) return; + // Ensure session file is initialized before proceeding + if (this._sessionFileInitialized) + await this._sessionFileInitialized; + const entry = [ `- ${toolName}:`, ' params:',