Fix race condition in session file initialization by chaining file operations

Co-authored-by: pavelfeldman <883973+pavelfeldman@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-07-21 02:14:40 +00:00
parent 9588845cc3
commit bb9de30ef9

View File

@ -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<void> | 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:',