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, 20:45 UTC
fix(server): stalled clones say "Stalled" instead of a frozen speed (#22780)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 21, 2026 at 02:40 UTC
8fe4206decd202f951a270741cd3d1c8b32dd455
4 files changed
+105
-23
apps/server/src/project/ProjectCloneTracker.test.ts
+40
@@ -3,6 +3,7 @@ import { describe, expect, it } from "@effect/vitest";
3
import {
4
OrchestrationDispatchCommandError,
5
ProjectId,
6
+ projectCloneProgressSummary,
7
SourceControlRepositoryError,
8
} from "@t3tools/contracts";
9
import * as Deferred from "effect/Deferred";
@@ -105,6 +106,45 @@ describe("ProjectCloneTracker", () => {
106
}).pipe(Effect.provide(harness.layer));
107
});
108
109
+ it.effect("flags a clone stalled when git goes quiet and clears it when git speaks", () => {
110
+ const release = Deferred.makeUnsafe<void>();
111
+ const resumed = Deferred.makeUnsafe<void>();
112
+ const harness = makeHarness({
113
+ clone: (input, options) =>
114
+ Effect.gen(function* () {
115
+ const report = options?.onProgress ?? (() => Effect.void);
116
+ yield* report({ stage: "receiving", percent: 24, detail: "168.80 MiB | 20.69 MiB/s" });
117
+ yield* Deferred.await(resumed);
118
+ yield* report({ stage: "receiving", percent: 25, detail: "170.00 MiB | 1.00 MiB/s" });
119
+ yield* Deferred.await(release);
120
+ return { cwd: input.destinationPath, remoteUrl: input.remoteUrl ?? "", repository: null };
121
+ }),
122
+ });
123
+ return Effect.gen(function* () {
124
+ const tracker = yield* ProjectCloneTracker.ProjectCloneTracker;
125
+ yield* tracker.start(startInput, harness.hooks);
126
+ yield* Effect.yieldNow;
127
+ expect((yield* tracker.get(projectId))?.stalled).toBe(false);
128
+
129
+ yield* TestClock.adjust("19 seconds");
130
+ expect((yield* tracker.get(projectId))?.stalled).toBe(false);
131
+ yield* TestClock.adjust("1 second");
132
+ const stalled = yield* tracker.get(projectId);
133
+ expect(stalled).toMatchObject({ stalled: true, percent: 24 });
134
+ expect(projectCloneProgressSummary(stalled!)).toBe("Receiving objects · 24% · Stalled");
135
+
136
+ yield* Deferred.succeed(resumed, undefined);
137
+ yield* Effect.yieldNow;
138
+ expect(yield* tracker.get(projectId)).toMatchObject({ stalled: false, percent: 25 });
139
+
140
+ yield* TestClock.adjust("20 seconds");
141
+ expect((yield* tracker.get(projectId))?.stalled).toBe(true);
142
+ yield* Deferred.succeed(release, undefined);
143
+ yield* Effect.yieldNow;
144
+ expect(yield* tracker.get(projectId)).toMatchObject({ phase: "done", stalled: false });
145
+ }).pipe(Effect.provide(harness.layer));
146
+ });
147
+
148
it.effect("keeps a failed clone with git's own explanation and retries it", () => {
149
let attempts = 0;
150
const harness = makeHarness({
apps/server/src/project/ProjectCloneTracker.ts
+58
-20
@@ -20,6 +20,7 @@ import * as Effect from "effect/Effect";
20
import * as Exit from "effect/Exit";
21
import * as Fiber from "effect/Fiber";
22
import * as Layer from "effect/Layer";
23
+import * as Option from "effect/Option";
24
import * as PubSub from "effect/PubSub";
25
import * as Queue from "effect/Queue";
26
import * as Ref from "effect/Ref";
@@ -67,6 +68,10 @@ export interface ProjectCloneHooks {
68
}
69
70
const DONE_RETENTION = "30 seconds";
71
+// Git prints nothing while a transfer waits on the network, and the kernel can
72
+// take 15+ minutes to give up on a dead connection. Without this the banner
73
+// keeps showing the last transfer speed as if data were still arriving.
74
+const STALL_AFTER = "20 seconds";
75
76
function clampText(text: string, maxLength: number): string {
77
return text.length <= maxLength ? text : `${text.slice(0, maxLength - 1)}…`;
@@ -165,9 +170,28 @@ export const make = Effect.gen(function* () {
170
percent: update.percent,
171
detail:
172
update.detail === null ? null : clampText(update.detail, PROJECT_CLONE_DETAIL_MAX_LENGTH),
173
+ stalled: false,
174
},
175
})).pipe(Effect.asVoid);
176
177
+ const markStalled = (projectId: ProjectId) =>
178
+ modify(projectId, (tracked) => ({
179
+ ...tracked,
180
+ snapshot: { ...tracked.snapshot, stalled: true },
181
+ })).pipe(Effect.asVoid);
182
+
183
+ /** Marks the clone stalled once, then waits for git to speak again. */
184
+ const watchForStall = (projectId: ProjectId, pulses: Queue.Dequeue<void>) =>
185
+ Queue.take(pulses).pipe(
186
+ Effect.timeoutOption(STALL_AFTER),
187
+ Effect.flatMap((pulse) =>
188
+ Option.isSome(pulse)
189
+ ? Effect.void
190
+ : markStalled(projectId).pipe(Effect.andThen(Queue.take(pulses))),
191
+ ),
192
+ Effect.forever,
193
+ );
194
+
195
const finish = Effect.fn("ProjectCloneTracker.finish")(function* (
196
projectId: ProjectId,
197
phase: "done" | "failed" | "cancelled",
@@ -182,12 +206,29 @@ export const make = Effect.gen(function* () {
206
phase,
207
endedAt,
208
percent: phase === "done" ? 100 : tracked.snapshot.percent,
209
+ stalled: false,
210
error: error === null ? null : clampText(error, PROJECT_CLONE_ERROR_MAX_LENGTH),
211
},
212
}));
213
if (phase === "done") yield* scheduleRemoval(projectId);
214
});
215
216
+ const cloneWatchingForStall = Effect.fn("ProjectCloneTracker.cloneWatchingForStall")(function* (
217
+ projectId: ProjectId,
218
+ tracked: TrackedClone,
219
+ ) {
220
+ const pulses = yield* Queue.sliding<void>(1);
221
+ yield* watchForStall(projectId, pulses).pipe(Effect.forkScoped);
222
+ return yield* repositories.cloneRepository(
223
+ { remoteUrl: tracked.input.cloneUrl, destinationPath: tracked.input.destinationPath },
224
+ {
225
+ onProgress: (update) =>
226
+ Queue.offer(pulses, undefined).pipe(Effect.andThen(progress(projectId, update))),
227
+ timeoutMs: null,
228
+ },
229
+ );
230
+ }, Effect.scoped);
231
+
232
/**
233
* Runs in its own fiber; the tracker records the outcome through `onExit`,
234
* which still runs when the fiber is interrupted (a `matchCause` handler
@@ -196,26 +237,21 @@ export const make = Effect.gen(function* () {
237
* checkout.
238
*/
239
const runClone = (projectId: ProjectId, tracked: TrackedClone) =>
199
- repositories
200
- .cloneRepository(
201
- { remoteUrl: tracked.input.cloneUrl, destinationPath: tracked.input.destinationPath },
202
- { onProgress: (update) => progress(projectId, update), timeoutMs: null },
203
- )
204
- .pipe(
205
- Effect.onExit((exit) =>
206
- Exit.isSuccess(exit)
207
- ? finish(projectId, "done", null)
208
- : Cause.hasInterruptsOnly(exit.cause)
209
- ? finish(projectId, "cancelled", null)
210
- : finish(projectId, "failed", describeCloneFailure(exit.cause)),
211
- ),
212
- Effect.flatMap(() =>
213
- tracked.hooks
214
- .onCloned({ projectId, workspaceRoot: tracked.input.destinationPath })
215
- .pipe(Effect.ignoreCause({ log: true })),
216
- ),
217
- Effect.ignoreCause(),
218
- );
240
+ cloneWatchingForStall(projectId, tracked).pipe(
241
+ Effect.onExit((exit) =>
242
+ Exit.isSuccess(exit)
243
+ ? finish(projectId, "done", null)
244
+ : Cause.hasInterruptsOnly(exit.cause)
245
+ ? finish(projectId, "cancelled", null)
246
+ : finish(projectId, "failed", describeCloneFailure(exit.cause)),
247
+ ),
248
+ Effect.flatMap(() =>
249
+ tracked.hooks
250
+ .onCloned({ projectId, workspaceRoot: tracked.input.destinationPath })
251
+ .pipe(Effect.ignoreCause({ log: true })),
252
+ ),
253
+ Effect.ignoreCause(),
254
+ );
255
256
const launch = Effect.fn("ProjectCloneTracker.launch")(function* (projectId: ProjectId) {
257
const current = yield* Ref.get(clones);
@@ -244,6 +280,7 @@ export const make = Effect.gen(function* () {
280
stage: "connecting",
281
percent: null,
282
detail: null,
283
+ stalled: false,
284
error: null,
285
startedAt,
286
endedAt: null,
@@ -346,6 +383,7 @@ export const make = Effect.gen(function* () {
383
stage: "connecting",
384
percent: null,
385
detail: null,
386
+ stalled: false,
387
error: null,
388
startedAt,
389
endedAt: null,
apps/web/src/components/ProjectCloneToastCoordinator.tsx
+1
-1
@@ -45,7 +45,7 @@ interface TrackedToast {
45
}
46
47
function renderKey(clone: ProjectCloneSnapshot): string {
48
- return `${clone.phase}:${clone.stage}:${clone.percent ?? ""}:${clone.detail ?? ""}:${clone.error ?? ""}`;
48
+ return `${clone.phase}:${clone.stage}:${clone.percent ?? ""}:${clone.detail ?? ""}:${clone.stalled === true}:${clone.error ?? ""}`;
49
}
50
51
async function runCloneAction(
packages/contracts/src/projectClone.ts
+6
-2
@@ -31,6 +31,8 @@ export const ProjectCloneSnapshot = Schema.Struct({
31
stage: ProjectCloneStage,
32
percent: Schema.NullOr(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 100 }))),
33
detail: Schema.NullOr(Schema.String.check(Schema.isMaxLength(PROJECT_CLONE_DETAIL_MAX_LENGTH))),
34
+ /** Git has printed nothing for a while; `detail` is no longer current. Older servers omit it. */
35
+ stalled: Schema.optionalKey(Schema.Boolean),
36
error: Schema.NullOr(Schema.String.check(Schema.isMaxLength(PROJECT_CLONE_ERROR_MAX_LENGTH))),
37
startedAt: IsoDateTime,
38
endedAt: Schema.NullOr(IsoDateTime),
@@ -98,10 +100,12 @@ export function projectCloneDisplayName(
100
}
101
102
export function projectCloneProgressSummary(
101
- snapshot: Pick<ProjectCloneSnapshot, "stage" | "percent" | "detail">,
103
+ snapshot: Pick<ProjectCloneSnapshot, "stage" | "percent" | "detail" | "stalled">,
104
): string {
105
const parts = [projectCloneStageLabel(snapshot.stage)];
106
if (snapshot.percent !== null) parts.push(`${snapshot.percent}%`);
105
- if (snapshot.detail) parts.push(snapshot.detail);
107
+ // The detail carries git's last transfer speed, which a stall makes a lie.
108
+ if (snapshot.stalled) parts.push("Stalled");
109
+ else if (snapshot.detail) parts.push(snapshot.detail);
110
return parts.join(" · ");
111
}