(workspaceId: string)
| 394 | } |
| 395 | |
| 396 | private async ensureLoaded(workspaceId: string): Promise<void> { |
| 397 | const data = this.getOrCreateWorkspaceData(workspaceId); |
| 398 | if (data.loaded) { |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | // Serialize concurrent loads for the same workspace: if another call is already |
| 403 | // loading this workspace, await its promise instead of starting a second load. |
| 404 | // This prevents duplicate disk reads and — critically — prevents stale-step |
| 405 | // finalization from running while a concurrent request has a legitimate |
| 406 | // in-progress step. |
| 407 | const existingPromise = this.loadingPromises.get(workspaceId); |
| 408 | if (existingPromise) { |
| 409 | await existingPromise; |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | const loadPromise = this.loadFromDisk(workspaceId, data); |
| 414 | this.loadingPromises.set(workspaceId, loadPromise); |
| 415 | try { |
| 416 | await loadPromise; |
| 417 | } finally { |
| 418 | this.loadingPromises.delete(workspaceId); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | private async loadFromDisk(workspaceId: string, data: WorkspaceData): Promise<void> { |
| 423 | const filePath = this.getSessionFilePath(workspaceId); |
no test coverage detected