Skip to content

Commit 37d27a2

Browse files
t3dotggclaude
andcommitted
fix(server): clone progress shows "Stalled" when git goes quiet
A dead network connection leaves git silent while the kernel retries for 15+ minutes, so the clone banner kept showing the last transfer speed as if data were still arriving. The tracker now flags a clone as stalled after 20 seconds without git output, and the shared progress summary shows "Stalled" in place of the stale speed on web, toasts, and mobile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 21da306 commit 37d27a2

4 files changed

Lines changed: 105 additions & 23 deletions

File tree

‎apps/server/src/project/ProjectCloneTracker.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it } from "@effect/vitest";
33
import {
44
OrchestrationDispatchCommandError,
55
ProjectId,
6+
projectCloneProgressSummary,
67
SourceControlRepositoryError,
78
} from "@t3tools/contracts";
89
import * as Deferred from "effect/Deferred";
@@ -105,6 +106,45 @@ describe("ProjectCloneTracker", () => {
105106
}).pipe(Effect.provide(harness.layer));
106107
});
107108

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+
108148
it.effect("keeps a failed clone with git's own explanation and retries it", () => {
109149
let attempts = 0;
110150
const harness = makeHarness({

‎apps/server/src/project/ProjectCloneTracker.ts‎

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as Effect from "effect/Effect";
2020
import * as Exit from "effect/Exit";
2121
import * as Fiber from "effect/Fiber";
2222
import * as Layer from "effect/Layer";
23+
import * as Option from "effect/Option";
2324
import * as PubSub from "effect/PubSub";
2425
import * as Queue from "effect/Queue";
2526
import * as Ref from "effect/Ref";
@@ -67,6 +68,10 @@ export interface ProjectCloneHooks {
6768
}
6869

6970
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";
7075

7176
function clampText(text: string, maxLength: number): string {
7277
return text.length <= maxLength ? text : `${text.slice(0, maxLength - 1)}…`;
@@ -165,9 +170,28 @@ export const make = Effect.gen(function* () {
165170
percent: update.percent,
166171
detail:
167172
update.detail === null ? null : clampText(update.detail, PROJECT_CLONE_DETAIL_MAX_LENGTH),
173+
stalled: false,
168174
},
169175
})).pipe(Effect.asVoid);
170176

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+
171195
const finish = Effect.fn("ProjectCloneTracker.finish")(function* (
172196
projectId: ProjectId,
173197
phase: "done" | "failed" | "cancelled",
@@ -182,12 +206,29 @@ export const make = Effect.gen(function* () {
182206
phase,
183207
endedAt,
184208
percent: phase === "done" ? 100 : tracked.snapshot.percent,
209+
stalled: false,
185210
error: error === null ? null : clampText(error, PROJECT_CLONE_ERROR_MAX_LENGTH),
186211
},
187212
}));
188213
if (phase === "done") yield* scheduleRemoval(projectId);
189214
});
190215

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+
191232
/**
192233
* Runs in its own fiber; the tracker records the outcome through `onExit`,
193234
* which still runs when the fiber is interrupted (a `matchCause` handler
@@ -196,26 +237,21 @@ export const make = Effect.gen(function* () {
196237
* checkout.
197238
*/
198239
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+
);
219255

220256
const launch = Effect.fn("ProjectCloneTracker.launch")(function* (projectId: ProjectId) {
221257
const current = yield* Ref.get(clones);
@@ -244,6 +280,7 @@ export const make = Effect.gen(function* () {
244280
stage: "connecting",
245281
percent: null,
246282
detail: null,
283+
stalled: false,
247284
error: null,
248285
startedAt,
249286
endedAt: null,
@@ -346,6 +383,7 @@ export const make = Effect.gen(function* () {
346383
stage: "connecting",
347384
percent: null,
348385
detail: null,
386+
stalled: false,
349387
error: null,
350388
startedAt,
351389
endedAt: null,

‎apps/web/src/components/ProjectCloneToastCoordinator.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ interface TrackedToast {
4545
}
4646

4747
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 ?? ""}`;
4949
}
5050

5151
async function runCloneAction(

‎packages/contracts/src/projectClone.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const ProjectCloneSnapshot = Schema.Struct({
3131
stage: ProjectCloneStage,
3232
percent: Schema.NullOr(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 100 }))),
3333
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),
3436
error: Schema.NullOr(Schema.String.check(Schema.isMaxLength(PROJECT_CLONE_ERROR_MAX_LENGTH))),
3537
startedAt: IsoDateTime,
3638
endedAt: Schema.NullOr(IsoDateTime),
@@ -98,10 +100,12 @@ export function projectCloneDisplayName(
98100
}
99101

100102
export function projectCloneProgressSummary(
101-
snapshot: Pick<ProjectCloneSnapshot, "stage" | "percent" | "detail">,
103+
snapshot: Pick<ProjectCloneSnapshot, "stage" | "percent" | "detail" | "stalled">,
102104
): string {
103105
const parts = [projectCloneStageLabel(snapshot.stage)];
104106
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);
106110
return parts.join(" · ");
107111
}

0 commit comments

Comments
 (0)