From 59c5ee383664feff06fa7245a8feec9fc17c04cf Mon Sep 17 00:00:00 2001 From: iliya Date: Tue, 3 Mar 2026 01:02:50 +0200 Subject: [PATCH] feat: optimize binary verification and preflight checks in TeamProvisioningService - Implemented parallel execution of version verification and initial ping attempts to reduce overall wait time during team provisioning. - Enhanced error handling by prioritizing the version check for clearer error messages while maintaining the integrity of subsequent ping attempts. - Streamlined the logic for retrying ping attempts, improving the efficiency of the preflight authentication process. --- .../services/team/TeamProvisioningService.ts | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/services/team/TeamProvisioningService.ts b/src/main/services/team/TeamProvisioningService.ts index da806286..22c670d0 100644 --- a/src/main/services/team/TeamProvisioningService.ts +++ b/src/main/services/team/TeamProvisioningService.ts @@ -3441,14 +3441,26 @@ export class TeamProvisioningService { cwd: string, env: NodeJS.ProcessEnv ): Promise<{ warning?: string }> { - // Stage 1: verify binary works - const versionProbe = await this.spawnProbe( + // Stage 1 + Stage 2 attempt #1 in parallel. + // Rationale: both are independent process spawns and the combined wall time + // is dominated by startup/IO. We still prioritize the stage-1 error message. + const versionProbePromise = this.spawnProbe( claudePath, ['--version'], cwd, env, CLI_PREPARE_TIMEOUT_MS ); + const pingAttempt1Promise = this.spawnProbe( + claudePath, + ['-p', 'Reply with the single word PONG and nothing else', '--output-format', 'text'], + cwd, + env, + PREFLIGHT_TIMEOUT_MS + ); + + // Stage 1: verify binary works (awaited first for clearer errors) + const versionProbe = await versionProbePromise; if (versionProbe.exitCode !== 0) { const errorText = buildCombinedLogs(versionProbe.stdout, versionProbe.stderr) || @@ -3460,13 +3472,21 @@ export class TeamProvisioningService { for (let attempt = 1; attempt <= PREFLIGHT_AUTH_MAX_RETRIES; attempt++) { let pingProbe: { exitCode: number | null; stdout: string; stderr: string } | null = null; try { - pingProbe = await this.spawnProbe( - claudePath, - ['-p', 'Reply with the single word PONG and nothing else', '--output-format', 'text'], - cwd, - env, - PREFLIGHT_TIMEOUT_MS - ); + pingProbe = + attempt === 1 + ? await pingAttempt1Promise + : await this.spawnProbe( + claudePath, + [ + '-p', + 'Reply with the single word PONG and nothing else', + '--output-format', + 'text', + ], + cwd, + env, + PREFLIGHT_TIMEOUT_MS + ); } catch (error) { const message = error instanceof Error ? error.message : String(error); if (attempt < PREFLIGHT_AUTH_MAX_RETRIES) {