@devries-cameron20 / t3code-1 / commits / 0318eadc32
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): agent clones are no longer cut off after 2 minutes (#27588)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 11, 2026 at 12:02 UTC 0318eadc3202c64f3da9aad08ea5aa868a2f0d7c
4 files changed +159 -4
apps/server/src/mcp/toolkits/project/handlers.test.ts
+73
@@ -2,6 +2,7 @@ import * as ProviderRegistry from "../../../provider/ProviderRegistry.ts";
2 import { expect, it } from "@effect/vitest";
3 import {
4 EnvironmentId,
5 + GitCommandError,
6 ProjectId,
7 ProviderInstanceId,
8 ProviderDriverKind,
@@ -15,13 +16,17 @@ import {
16 import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
17 import * as NodeServices from "@effect/platform-node/NodeServices";
18 import * as Cause from "effect/Cause";
19 +import * as Deferred from "effect/Deferred";
20 import * as Effect from "effect/Effect";
21 import * as Exit from "effect/Exit";
22 +import * as Fiber from "effect/Fiber";
23 import * as FileSystem from "effect/FileSystem";
24 import * as Path from "effect/Path";
25 import * as Layer from "effect/Layer";
26 import * as Option from "effect/Option";
27 import * as Stream from "effect/Stream";
28 +import { ChildProcessSpawner } from "effect/process";
29 +import * as TestClock from "effect/testing/TestClock";
30
31 import * as DocumentText from "../../../provider/DocumentText.ts";
32 import { OrchestratorRuntimeModeAboveCeilingError } from "../../../orchestration-v2/Orchestrator.ts";
@@ -33,6 +38,8 @@ import * as Project from "../../../project/ProjectService.ts";
38 import * as ProjectCloneTracker from "../../../project/ProjectCloneTracker.ts";
39 import * as ManagedProjectFolders from "../../../project/ManagedProjectFolders.ts";
40 import * as PeerForwarding from "../../../peer/PeerForwarding.ts";
41 +import * as SourceControlProviderRegistry from "../../../sourceControl/SourceControlProviderRegistry.ts";
42 +import * as Repositories from "../../../sourceControl/SourceControlRepositoryService.ts";
43 import * as GitVcsDriver from "../../../vcs/GitVcsDriver.ts";
44 import * as VcsProcess from "../../../vcs/VcsProcess.ts";
45 import * as McpInvocationContext from "../../McpInvocationContext.ts";
@@ -689,6 +696,72 @@ it.effect("a client launches with the fallback for an exhausted default", () =>
696 }),
697 );
698
699 +it.effect("an agent's clone is not cut off while git is still transferring", () =>
700 + Effect.gen(function* () {
701 + const fs = yield* FileSystem.FileSystem;
702 + const path = yield* Path.Path;
703 + const parent = yield* fs.makeTempDirectoryScoped({ prefix: "t3-mcp-clone-" });
704 + const destinationPath = path.join(parent, "repo");
705 + const started = yield* Deferred.make<void>();
706 + const transferred = yield* Deferred.make<void>();
707 + const { dependencies } = clientLaunchHarness({
708 + runtimeModeCeiling: "full-access",
709 + launched: [],
710 + });
711 + const repositories = Repositories.layer.pipe(
712 + Layer.provide(
713 + Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
714 + resolveLink: () => undefined,
715 + }),
716 + ),
717 + Layer.provide(
718 + Layer.mock(GitVcsDriver.GitVcsDriver)({
719 + // Like the real driver, the clone fails once it outlives the deadline it was given.
720 + execute: (input) =>
721 + Deferred.succeed(started, undefined).pipe(
722 + Effect.andThen(Deferred.await(transferred)),
723 + Effect.as({
724 + exitCode: ChildProcessSpawner.ExitCode(0),
725 + stdout: "",
726 + stderr: "",
727 + stdoutTruncated: false,
728 + stderrTruncated: false,
729 + }),
730 + Effect.timeoutOrElse({
731 + duration: input.timeoutMs ?? Infinity,
732 + orElse: () =>
733 + Effect.fail(
734 + new GitCommandError({
735 + operation: input.operation,
736 + command: "git",
737 + cwd: input.cwd,
738 + detail: "Git command timed out.",
739 + }),
740 + ),
741 + }),
742 + ),
743 + }),
744 + ),
745 + Layer.provideMerge(dependencies),
746 + );
747 + const toolkit = yield* ProjectToolkit.pipe(
748 + Effect.provide(
749 + McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(repositories)),
750 + ),
751 + );
752 +
753 + const clone = yield* toolkit
754 + .handle("t3_project_clone", { remoteUrl: "https://example.test/repo.git", destinationPath })
755 + .pipe(Stream.unwrap, Stream.runCollect, Effect.provide(repositories), Effect.forkChild);
756 + yield* Deferred.await(started);
757 + // A large repository over a slow link; agents' MCP calls get a far longer budget.
758 + yield* TestClock.adjust("10 minutes");
759 + yield* Deferred.succeed(transferred, undefined);
760 +
761 + expect((yield* Fiber.join(clone)).at(-1)?.result).toMatchObject({ cwd: destinationPath });
762 + }).pipe(Effect.provide(NodeServices.layer)),
763 +);
764 +
765 it.effect("deleting a project through MCP also discards its clone record", () =>
766 Effect.gen(function* () {
767 const discarded: Array<ProjectId> = [];
apps/server/src/mcp/toolkits/project/handlers.ts
+2 -1
@@ -387,7 +387,8 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
387 (input) =>
388 Effect.gen(function* () {
389 const repositories = yield* Repositories.SourceControlRepositoryService;
390 - return yield* repositories.cloneRepository(input).pipe(
390 + // Agents' MCP calls have their own long budget, and an aborted call interrupts git.
391 + return yield* repositories.cloneRepository(input, { timeoutMs: null }).pipe(
392 Effect.mapError(
393 (error) =>
394 new OrchestratorMcpFailure({
apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
+62
@@ -3,12 +3,15 @@ import * as NodePath from "@effect/platform-node/NodePath";
3 import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
4 import * as NodeServices from "@effect/platform-node/NodeServices";
5 import { assert, it } from "@effect/vitest";
6 +import * as Deferred from "effect/Deferred";
7 import * as Effect from "effect/Effect";
8 +import * as Fiber from "effect/Fiber";
9 import * as FileSystem from "effect/FileSystem";
10 import * as Path from "effect/Path";
11 import * as Layer from "effect/Layer";
12 import * as PlatformError from "effect/PlatformError";
13 import { ChildProcessSpawner } from "effect/process";
14 +import * as TestClock from "effect/testing/TestClock";
15
16 import {
17 GitCommandError,
@@ -292,6 +295,65 @@ it.effect("reports clone progress from git's stderr and keeps its error text on
295 }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
296 );
297
298 +it.effect("says a clone that ran out of time timed out, not git's last remote line", () =>
299 + Effect.gen(function* () {
300 + const fs = yield* FileSystem.FileSystem;
301 + const path = yield* Path.Path;
302 + const parent = yield* fs.makeTempDirectoryScoped({
303 + prefix: "t3-source-control-clone-timeout-",
304 + });
305 + const started = yield* Deferred.make<void>();
306 + const clone = yield* Effect.gen(function* () {
307 + const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
308 + return yield* Effect.flip(
309 + service.cloneRepository({
310 + remoteUrl: CLONE_URLS.url,
311 + destinationPath: path.join(parent, "t3code"),
312 + }),
313 + );
314 + }).pipe(
315 + Effect.provide(
316 + layer({
317 + git: {
318 + // Like the real driver: the transfer outlives its deadline and git's last line is
319 + // a remote summary.
320 + execute: (input) =>
321 + Effect.gen(function* () {
322 + yield* (
323 + input.progress?.onStderrLine?.(
324 + "remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0",
325 + ) ?? Effect.void
326 + );
327 + yield* Deferred.succeed(started, undefined);
328 + return yield* Effect.never;
329 + }).pipe(
330 + Effect.timeoutOrElse({
331 + duration: input.timeoutMs ?? Infinity,
332 + orElse: () =>
333 + Effect.fail(
334 + new GitCommandError({
335 + operation: input.operation,
336 + command: "git",
337 + cwd: input.cwd,
338 + detail: "Git command timed out.",
339 + }),
340 + ),
341 + }),
342 + ),
343 + },
344 + }),
345 + ),
346 + Effect.forkChild,
347 + );
348 +
349 + yield* Deferred.await(started);
350 + yield* TestClock.adjust("2 minutes");
351 + const error = yield* Fiber.join(clone);
352 +
353 + assert.match(error.detail, /timed out/i);
354 + }).pipe(Effect.provide(NodeServices.layer)),
355 +);
356 +
357 function rejectingSsh(
358 urls: Array<string>,
359 httpsFails: boolean,
apps/server/src/sourceControl/SourceControlRepositoryService.ts
+22 -3
@@ -1,4 +1,5 @@
1 import * as Context from "effect/Context";
2 +import * as Duration from "effect/Duration";
3 import * as Effect from "effect/Effect";
4 import * as FileSystem from "effect/FileSystem";
5 import * as Layer from "effect/Layer";
@@ -349,12 +350,15 @@ export const make = Effect.gen(function* () {
350 };
351 // Git misreads @ in a pathless URL's query as userinfo and echoes its suffix as the host.
352 const normalizedCloneUrl = cloneUrl.replace(/^([a-z][a-z0-9+.-]*:\/\/[^/?#]+)\?/i, "$1/?");
352 - yield* git
353 + const provider = input.provider ?? SourceControlProviderKind.make("unknown");
354 + const timeoutMs = options?.timeoutMs === undefined ? CLONE_TIMEOUT_MS : options.timeoutMs;
355 + const clone = git
356 .execute({
357 operation: "SourceControlRepositoryService.cloneRepository",
358 cwd: path.dirname(destinationPath),
359 args: ["clone", "--progress", "--", normalizedCloneUrl, path.basename(destinationPath)],
357 - timeoutMs: options?.timeoutMs === undefined ? CLONE_TIMEOUT_MS : options.timeoutMs,
360 + // The deadline is applied below so a timeout is reported as one, not as git's last line.
361 + timeoutMs: null,
362 // Buffered output is unused and progress can be huge; cap it while retaining line callbacks.
363 maxOutputBytes: 256 * 1024,
364 appendTruncationMarker: true,
@@ -367,7 +371,7 @@ export const make = Effect.gen(function* () {
371 (cause) =>
372 new SourceControlRepositoryError({
373 operation: "cloneRepository",
370 - provider: input.provider ?? SourceControlProviderKind.make("unknown"),
374 + provider,
375 detail:
376 stderrTail.length > 0
377 ? stderrTail.join(" ")
@@ -376,6 +380,21 @@ export const make = Effect.gen(function* () {
380 }),
381 ),
382 );
383 + if (timeoutMs === null) return yield* clone;
384 + // Interrupting the clone closes the scope that owns git, which kills it.
385 + return yield* clone.pipe(
386 + Effect.timeoutOrElse({
387 + duration: timeoutMs,
388 + orElse: () =>
389 + Effect.fail(
390 + new SourceControlRepositoryError({
391 + operation: "cloneRepository",
392 + provider,
393 + detail: `The clone timed out after ${Duration.format(Duration.millis(timeoutMs))}.`,
394 + }),
395 + ),
396 + }),
397 + );
398 });
399
400 const cloneRepository = Effect.fn("SourceControlRepositoryService.cloneRepository")(function* (