The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 12:00 UTC
perf(server): source control discovery no longer stalls up to 10s on Bitbucket (#27102)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 29, 2026 at 13:17 UTC
3898c3298617e8a12177dbc8cd1ad681c96e3fac
4 files changed
+85
-41
apps/server/src/sourceControl/SourceControlProviderRegistry.test.ts
+31
-1
@@ -118,7 +118,12 @@ function makeRegistry(input: {
118
kind: provider.kind,
119
label: provider.kind,
120
installHint: "unused",
121
- probeAuth: Effect.die("unused"),
121
+ probeAuth: Effect.succeed({
122
+ status: "unknown",
123
+ account: Option.none(),
124
+ host: Option.none(),
125
+ detail: Option.none(),
126
+ }),
127
},
128
})),
129
).pipe(
@@ -440,3 +445,28 @@ it.effect("asks again once Settings change", () =>
445
assert.strictEqual((yield* resolveUnknown(registry, "c")).provider.kind, "github");
446
}),
447
);
448
+
449
+it.effect("answers discovery without waiting on a hosting API that stalls", () =>
450
+ Effect.gen(function* () {
451
+ const registry = yield* makeRegistry({
452
+ remotes: [],
453
+ discovery: [
454
+ claimingCli("gitlab"),
455
+ {
456
+ type: "api",
457
+ kind: kind("bitbucket"),
458
+ label: "Bitbucket",
459
+ installHint: "unused",
460
+ probeAuth: Effect.never,
461
+ },
462
+ ],
463
+ });
464
+ const discovering = yield* registry.discover.pipe(Effect.forkChild);
465
+ yield* TestClock.adjust("3 seconds");
466
+ const items = yield* Fiber.join(discovering);
467
+ const bitbucket = items.find((item) => item.kind === "bitbucket");
468
+ assert.strictEqual(bitbucket?.status, "available");
469
+ assert.strictEqual(bitbucket?.auth.status, "unknown");
470
+ assert.strictEqual(items.find((item) => item.kind === "gitlab")?.status, "available");
471
+ }),
472
+);
packages/source-control-bitbucket/src/server/BitbucketApi.test.ts
+2
-1
@@ -513,7 +513,7 @@ it.effect("never puts a saved token that is unsafe for an HTTP header on the wir
513
});
514
515
it.effect("reports saved credentials as configured when Bitbucket cannot confirm them", () => {
516
- const { layer } = makeLayer({
516
+ const { execute, layer } = makeLayer({
517
response: () => new Response(null, { status: 401 }),
518
env: { T3CODE_BITBUCKET_API_BASE_URL: "https://api.test.local/2.0" },
519
});
@@ -523,6 +523,7 @@ it.effect("reports saved credentials as configured when Bitbucket cannot confirm
523
const settings = yield* TestSourceControlHost.TestSourceControlHostSettings;
524
525
assert.strictEqual((yield* bitbucket.probeAuth).status, "unauthenticated");
526
+ assert.strictEqual(execute.mock.calls.length, 0);
527
528
yield* settings.update({
529
sourceControlHosts: { bitbucket: { accessToken: "saved-access-token" } },
packages/source-control-bitbucket/src/server/BitbucketApi.ts
+19
-12
@@ -986,18 +986,25 @@ export const make = Effect.gen(function* () {
986
987
return BitbucketApi.of({
988
request,
989
- probeAuth: executeJson(
990
- "probeAuth",
991
- HttpClientRequest.get(apiUrl("/user")),
992
- BitbucketUserSchema,
993
- ).pipe(
994
- Effect.map((user) => ({
995
- status: "authenticated" as const,
996
- account: nonEmpty(user.username ?? user.display_name ?? user.account_id),
997
- host: Option.some("bitbucket.org"),
998
- detail: Option.none<string>(),
999
- })),
1000
- Effect.catch(() => currentCredential.pipe(Effect.map(authFromCredential))),
989
+ // Bitbucket answers anonymous /user with 401, so without a credential there is nothing to ask.
990
+ probeAuth: currentCredential.pipe(
991
+ Effect.flatMap((credential) =>
992
+ credential === null
993
+ ? Effect.succeed(authFromCredential(null))
994
+ : executeJson(
995
+ "probeAuth",
996
+ HttpClientRequest.get(apiUrl("/user")),
997
+ BitbucketUserSchema,
998
+ ).pipe(
999
+ Effect.map((user) => ({
1000
+ status: "authenticated" as const,
1001
+ account: nonEmpty(user.username ?? user.display_name ?? user.account_id),
1002
+ host: Option.some("bitbucket.org"),
1003
+ detail: Option.none<string>(),
1004
+ })),
1005
+ Effect.catch(() => currentCredential.pipe(Effect.map(authFromCredential))),
1006
+ ),
1007
+ ),
1008
),
1009
listPullRequests: Effect.fn("BitbucketApi.listPullRequests")(function (input) {
1010
return resolveRepository(input).pipe(
packages/source-control-core/src/server/discovery.ts
+33
-27
@@ -75,6 +75,8 @@ type SourceControlCliRemoteRefinementSpec = SourceControlCliDiscoverySpec & {
75
};
76
77
const DEFAULT_PROBE_TIMEOUT_MS = 5_000;
78
+/** An API host that stalls must not hold the whole discovery answer behind it. */
79
+const API_PROBE_TIMEOUT = "3 seconds";
80
81
function probeTimeoutMs(spec: SourceControlCliDiscoverySpec): number {
82
return spec.probeTimeoutMs ?? DEFAULT_PROBE_TIMEOUT_MS;
@@ -236,6 +238,12 @@ export function probeSourceControlProvider(input: {
238
if (input.spec.type === "managed-cli") return input.spec.probe(input.cwd);
239
if (input.spec.type === "api") {
240
return input.spec.probeAuth.pipe(
241
+ Effect.timeoutOption(API_PROBE_TIMEOUT),
242
+ Effect.map(
243
+ Option.getOrElse(() =>
244
+ unknownAuth("The hosting service did not answer in time. Refresh to try again."),
245
+ ),
246
+ ),
247
Effect.map(
248
(auth) =>
249
({
@@ -253,20 +261,15 @@ export function probeSourceControlProvider(input: {
261
262
const spec = input.spec;
263
256
- return probeCli({
257
- spec,
258
- process: input.process,
259
- cwd: input.cwd,
260
- }).pipe(
261
- Effect.flatMap((item) => {
262
- if (item.status !== "available") {
263
- return Effect.succeed({
264
- ...item,
265
- auth: unknownAuth("Hosting integration command was not found on the server PATH."),
266
- } satisfies SourceControlProviderDiscoveryItem);
267
- }
268
-
269
- return input.process
264
+ // The auth check does not depend on the version output, so both spawn at once.
265
+ return Effect.all(
266
+ [
267
+ probeCli({
268
+ spec,
269
+ process: input.process,
270
+ cwd: input.cwd,
271
+ }),
272
+ input.process
273
.run({
274
operation: "source-control.discovery.auth",
275
command: spec.executable,
@@ -278,21 +281,24 @@ export function probeSourceControlProvider(input: {
281
appendTruncationMarker: true,
282
})
283
.pipe(
281
- Effect.map(
282
- (result) =>
283
- ({
284
- ...item,
285
- auth: spec.parseAuth(result),
286
- }) satisfies SourceControlProviderDiscoveryItem,
287
- ),
284
+ Effect.map(spec.parseAuth),
285
Effect.catch((cause) =>
289
- Effect.succeed({
290
- ...item,
291
- auth: unknownAuth(Option.getOrUndefined(detailFromCause(cause))),
292
- } satisfies SourceControlProviderDiscoveryItem),
286
+ Effect.succeed(unknownAuth(Option.getOrUndefined(detailFromCause(cause)))),
287
),
294
- );
295
- }),
288
+ ),
289
+ ],
290
+ { concurrency: "unbounded" },
291
+ ).pipe(
292
+ Effect.map(
293
+ ([item, auth]) =>
294
+ ({
295
+ ...item,
296
+ auth:
297
+ item.status === "available"
298
+ ? auth
299
+ : unknownAuth("Hosting integration command was not found on the server PATH."),
300
+ }) satisfies SourceControlProviderDiscoveryItem,
301
+ ),
302
);
303
}
304