@@ -571,6 +571,7 @@ function apiProviderAuthMetadata( |
571 | 571 | // account info. The previous 8s budget expired mid-init, so the probe returned |
572 | 572 | // `undefined` and left the provider unverified and unselectable in the picker. |
573 | 573 | const CAPABILITIES_PROBE_TIMEOUT_MS = 25_000; |
| 574 | +const CAPABILITIES_PROBE_CONCURRENCY = 2; |
574 | 575 |
|
575 | 576 | function nonEmptyProbeString(value: string): string | undefined { |
576 | 577 | const candidate = value.trim(); |
@@ -683,18 +684,17 @@ const probeClaudeCapabilities = ( |
683 | 684 | environment?: NodeJS.ProcessEnv, |
684 | 685 | cwd?: string, |
685 | 686 | ) => { |
686 | | - const abortControllers: AbortController[] = []; |
687 | 687 | return Effect.gen(function* () { |
688 | 688 | const claudeEnvironment = yield* makeClaudeEnvironment(claudeSettings, environment); |
689 | 689 | const executablePath = yield* resolveClaudeSdkExecutablePath( |
690 | 690 | claudeSettings.binaryPath, |
691 | 691 | claudeEnvironment, |
692 | 692 | ); |
693 | | - return yield* Effect.tryPromise(async () => { |
694 | | - const initialize = (model?: string) => { |
695 | | - const abort = new AbortController(); |
696 | | - abortControllers.push(abort); |
697 | | - const q = claudeQuery({ |
| 693 | + const initialize = (model?: string) => { |
| 694 | + const abort = new AbortController(); |
| 695 | + let query: ReturnType<typeof claudeQuery> | undefined; |
| 696 | + return Effect.tryPromise(() => { |
| 697 | + query = claudeQuery({ |
698 | 698 | // Never yield — we only need initialization data, not a conversation. |
699 | 699 | // This prevents any prompt from reaching the Anthropic API. |
700 | 700 | // oxlint-disable-next-line require-yield |
@@ -713,56 +713,60 @@ const probeClaudeCapabilities = ( |
713 | 713 | stderr: () => {}, |
714 | 714 | }, |
715 | 715 | }); |
716 | | - return q.initializationResult(); |
717 | | - }; |
718 | | - const customModels = [ |
719 | | - ...new Set(claudeSettings.customModels.map((model) => model.trim())), |
720 | | - ].filter((model) => model.length > 0); |
721 | | - const initializations = []; |
722 | | - for (const model of customModels.length > 0 ? customModels : [undefined]) { |
723 | | - try { |
724 | | - initializations.push(await initialize(model)); |
725 | | - } catch { |
726 | | - // One invalid custom model must not prevent the remaining probes. |
727 | | - } |
728 | | - } |
729 | | - if (initializations.length === 0 && customModels.length > 0) { |
730 | | - initializations.push(await initialize()); |
731 | | - } |
732 | | - const init = initializations[0]!; |
733 | | - const modelsByValue = indexClaudeModels( |
734 | | - initializations.flatMap((initialization) => initialization.models), |
| 716 | + return query.initializationResult(); |
| 717 | + }).pipe( |
| 718 | + Effect.ensuring( |
| 719 | + Effect.sync(() => { |
| 720 | + if (!abort.signal.aborted) abort.abort(); |
| 721 | + query?.close(); |
| 722 | + }), |
| 723 | + ), |
| 724 | + Effect.timeoutOption(CAPABILITIES_PROBE_TIMEOUT_MS), |
| 725 | + Effect.result, |
| 726 | + Effect.map((result) => |
| 727 | + Result.isFailure(result) ? undefined : Option.getOrUndefined(result.success), |
| 728 | + ), |
735 | 729 | ); |
736 | | - const account = init.account as |
737 | | - | { |
738 | | - readonly email?: string; |
739 | | - readonly subscriptionType?: string; |
740 | | - readonly tokenSource?: string; |
741 | | - readonly apiProvider?: string; |
742 | | - } |
743 | | - | undefined; |
744 | | - return { |
745 | | - email: account?.email, |
746 | | - subscriptionType: account?.subscriptionType, |
747 | | - tokenSource: account?.tokenSource, |
748 | | - apiProvider: account?.apiProvider, |
749 | | - slashCommands: parseClaudeInitializationCommands(init.commands), |
750 | | - models: [...modelsByValue.values()], |
751 | | - } satisfies ClaudeCapabilitiesProbe; |
752 | | - }); |
753 | | - }).pipe( |
754 | | - Effect.ensuring( |
755 | | - Effect.sync(() => { |
756 | | - for (const abort of abortControllers) { |
757 | | - if (!abort.signal.aborted) abort.abort(); |
| 730 | + }; |
| 731 | + const customModels = [ |
| 732 | + ...new Set(claudeSettings.customModels.map((model) => model.trim())), |
| 733 | + ].filter((model) => model.length > 0); |
| 734 | + const initializations = (yield* Effect.forEach( |
| 735 | + customModels.length > 0 ? customModels : [undefined], |
| 736 | + initialize, |
| 737 | + { concurrency: CAPABILITIES_PROBE_CONCURRENCY }, |
| 738 | + )).filter((initialization) => initialization !== undefined); |
| 739 | + if (initializations.length === 0 && customModels.length > 0) { |
| 740 | + const fallback = yield* initialize(); |
| 741 | + if (fallback) initializations.push(fallback); |
| 742 | + } |
| 743 | + const init = initializations[0]; |
| 744 | + if (!init) return undefined; |
| 745 | + |
| 746 | + const modelsByValue = indexClaudeModels( |
| 747 | + initializations.flatMap((initialization) => initialization.models), |
| 748 | + ); |
| 749 | + const account = init.account as |
| 750 | + | { |
| 751 | + readonly email?: string; |
| 752 | + readonly subscriptionType?: string; |
| 753 | + readonly tokenSource?: string; |
| 754 | + readonly apiProvider?: string; |
758 | 755 | } |
759 | | - }), |
760 | | - ), |
761 | | - Effect.timeoutOption(CAPABILITIES_PROBE_TIMEOUT_MS), |
| 756 | + | undefined; |
| 757 | + return { |
| 758 | + email: account?.email, |
| 759 | + subscriptionType: account?.subscriptionType, |
| 760 | + tokenSource: account?.tokenSource, |
| 761 | + apiProvider: account?.apiProvider, |
| 762 | + slashCommands: parseClaudeInitializationCommands(init.commands), |
| 763 | + models: [...modelsByValue.values()], |
| 764 | + } satisfies ClaudeCapabilitiesProbe; |
| 765 | + }).pipe( |
762 | 766 | Effect.result, |
763 | 767 | Effect.map((result) => { |
764 | 768 | if (Result.isFailure(result)) return undefined; |
765 | | - return Option.isSome(result.success) ? result.success.value : undefined; |
| 769 | + return result.success; |
766 | 770 | }), |
767 | 771 | ); |
768 | 772 | }; |
|