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.
This commit is contained in:
iliya 2026-03-03 01:02:50 +02:00
parent b08a4d3764
commit 59c5ee3836

View file

@ -3441,14 +3441,26 @@ export class TeamProvisioningService {
cwd: string, cwd: string,
env: NodeJS.ProcessEnv env: NodeJS.ProcessEnv
): Promise<{ warning?: string }> { ): Promise<{ warning?: string }> {
// Stage 1: verify binary works // Stage 1 + Stage 2 attempt #1 in parallel.
const versionProbe = await this.spawnProbe( // 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, claudePath,
['--version'], ['--version'],
cwd, cwd,
env, env,
CLI_PREPARE_TIMEOUT_MS 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) { if (versionProbe.exitCode !== 0) {
const errorText = const errorText =
buildCombinedLogs(versionProbe.stdout, versionProbe.stderr) || buildCombinedLogs(versionProbe.stdout, versionProbe.stderr) ||
@ -3460,13 +3472,21 @@ export class TeamProvisioningService {
for (let attempt = 1; attempt <= PREFLIGHT_AUTH_MAX_RETRIES; attempt++) { for (let attempt = 1; attempt <= PREFLIGHT_AUTH_MAX_RETRIES; attempt++) {
let pingProbe: { exitCode: number | null; stdout: string; stderr: string } | null = null; let pingProbe: { exitCode: number | null; stdout: string; stderr: string } | null = null;
try { try {
pingProbe = await this.spawnProbe( pingProbe =
claudePath, attempt === 1
['-p', 'Reply with the single word PONG and nothing else', '--output-format', 'text'], ? await pingAttempt1Promise
cwd, : await this.spawnProbe(
env, claudePath,
PREFLIGHT_TIMEOUT_MS [
); '-p',
'Reply with the single word PONG and nothing else',
'--output-format',
'text',
],
cwd,
env,
PREFLIGHT_TIMEOUT_MS
);
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error); const message = error instanceof Error ? error.message : String(error);
if (attempt < PREFLIGHT_AUTH_MAX_RETRIES) { if (attempt < PREFLIGHT_AUTH_MAX_RETRIES) {