GeezerVison is showing github.com — fix(server): stalled clones say "Stalled" instead of a frozen speed (… · Pipyakas/t3code@7e347f2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/ProjectCloneTracker.test.ts +40Lines changed: 40 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { describe, expect, it } from "@effect/vitest"; | 3 | 3 | import { | 4 | 4 | OrchestrationDispatchCommandError, | 5 | 5 | ProjectId, | | 6 | + projectCloneProgressSummary, | 6 | 7 | SourceControlRepositoryError, | 7 | 8 | } from "@t3tools/contracts"; | 8 | 9 | import * as Deferred from "effect/Deferred"; | @@ -105,6 +106,45 @@ describe("ProjectCloneTracker", () => { | 105 | 106 | }).pipe(Effect.provide(harness.layer)); | 106 | 107 | }); | 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 | + | 108 | 148 | it.effect("keeps a failed clone with git's own explanation and retries it", () => { | 109 | 149 | let attempts = 0; | 110 | 150 | const harness = makeHarness({ | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/ProjectCloneTracker.ts +58-20Lines changed: 58 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,7 @@ import * as Effect from "effect/Effect"; | 20 | 20 | import * as Exit from "effect/Exit"; | 21 | 21 | import * as Fiber from "effect/Fiber"; | 22 | 22 | import * as Layer from "effect/Layer"; | | 23 | +import * as Option from "effect/Option"; | 23 | 24 | import * as PubSub from "effect/PubSub"; | 24 | 25 | import * as Queue from "effect/Queue"; | 25 | 26 | import * as Ref from "effect/Ref"; | @@ -67,6 +68,10 @@ export interface ProjectCloneHooks { | 67 | 68 | } | 68 | 69 |
| 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"; | 70 | 75 |
| 71 | 76 | function clampText(text: string, maxLength: number): string { | 72 | 77 | return text.length <= maxLength ? text : `${text.slice(0, maxLength - 1)}…`; | @@ -165,9 +170,28 @@ export const make = Effect.gen(function* () { | 165 | 170 | percent: update.percent, | 166 | 171 | detail: | 167 | 172 | update.detail === null ? null : clampText(update.detail, PROJECT_CLONE_DETAIL_MAX_LENGTH), | | 173 | + stalled: false, | 168 | 174 | }, | 169 | 175 | })).pipe(Effect.asVoid); | 170 | 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 | + | 171 | 195 | const finish = Effect.fn("ProjectCloneTracker.finish")(function* ( | 172 | 196 | projectId: ProjectId, | 173 | 197 | phase: "done" | "failed" | "cancelled", | @@ -182,12 +206,29 @@ export const make = Effect.gen(function* () { | 182 | 206 | phase, | 183 | 207 | endedAt, | 184 | 208 | percent: phase === "done" ? 100 : tracked.snapshot.percent, | | 209 | + stalled: false, | 185 | 210 | error: error === null ? null : clampText(error, PROJECT_CLONE_ERROR_MAX_LENGTH), | 186 | 211 | }, | 187 | 212 | })); | 188 | 213 | if (phase === "done") yield* scheduleRemoval(projectId); | 189 | 214 | }); | 190 | 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 | + | 191 | 232 | /** | 192 | 233 | * Runs in its own fiber; the tracker records the outcome through `onExit`, | 193 | 234 | * which still runs when the fiber is interrupted (a `matchCause` handler | @@ -196,26 +237,21 @@ export const make = Effect.gen(function* () { | 196 | 237 | * checkout. | 197 | 238 | */ | 198 | 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 | + ); | 219 | 255 |
| 220 | 256 | const launch = Effect.fn("ProjectCloneTracker.launch")(function* (projectId: ProjectId) { | 221 | 257 | const current = yield* Ref.get(clones); | @@ -244,6 +280,7 @@ export const make = Effect.gen(function* () { | 244 | 280 | stage: "connecting", | 245 | 281 | percent: null, | 246 | 282 | detail: null, | | 283 | + stalled: false, | 247 | 284 | error: null, | 248 | 285 | startedAt, | 249 | 286 | endedAt: null, | @@ -346,6 +383,7 @@ export const make = Effect.gen(function* () { | 346 | 383 | stage: "connecting", | 347 | 384 | percent: null, | 348 | 385 | detail: null, | | 386 | + stalled: false, | 349 | 387 | error: null, | 350 | 388 | startedAt, | 351 | 389 | endedAt: null, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ProjectCloneToastCoordinator.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -45,7 +45,7 @@ interface TrackedToast { | 45 | 45 | } | 46 | 46 |
| 47 | 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 | 49 | } | 50 | 50 |
| 51 | 51 | async function runCloneAction( | |
Collapse file Copy file name to clipboardExpand all lines: packages/contracts/src/projectClone.ts +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,6 +31,8 @@ export const ProjectCloneSnapshot = Schema.Struct({ | 31 | 31 | stage: ProjectCloneStage, | 32 | 32 | percent: Schema.NullOr(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 100 }))), | 33 | 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), | 34 | 36 | error: Schema.NullOr(Schema.String.check(Schema.isMaxLength(PROJECT_CLONE_ERROR_MAX_LENGTH))), | 35 | 37 | startedAt: IsoDateTime, | 36 | 38 | endedAt: Schema.NullOr(IsoDateTime), | @@ -98,10 +100,12 @@ export function projectCloneDisplayName( | 98 | 100 | } | 99 | 101 |
| 100 | 102 | export function projectCloneProgressSummary( | 101 | | - snapshot: Pick<ProjectCloneSnapshot, "stage" | "percent" | "detail">, | | 103 | + snapshot: Pick<ProjectCloneSnapshot, "stage" | "percent" | "detail" | "stalled">, | 102 | 104 | ): string { | 103 | 105 | const parts = [projectCloneStageLabel(snapshot.stage)]; | 104 | 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); | 106 | 110 | return parts.join(" · "); | 107 | 111 | } |
|