GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): a commit, push or pull request finishes when its connect… · Lazurio/t3code@3e199b8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • git
      • detachedProgressStream.test.ts
      • detachedProgressStream.ts
    • ws.ts
  • packages/client-runtime/src/state
    • vcsAction.test.ts
    • vcsAction.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/git/detachedProgressStream.test.ts‎

Copy file name to clipboard
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, expect, it } from "@effect/vitest";
2+
import * as Deferred from "effect/Deferred";
3+
import * as Effect from "effect/Effect";
4+
import * as Fiber from "effect/Fiber";
5+
import * as Stream from "effect/Stream";
6+
7+
import { detachedProgressStream } from "./detachedProgressStream.ts";
8+
9+
describe("detachedProgressStream", () => {
10+
it.effect("finishes the work after the client's stream is interrupted", () =>
11+
Effect.gen(function* () {
12+
const pushing = yield* Deferred.make<void>();
13+
const releasePush = yield* Deferred.make<void>();
14+
const outcome = yield* Deferred.make<"pull request created" | "interrupted">();
15+
16+
const consumed = yield* detachedProgressStream<string, never, never>((offer) =>
17+
offer("committed").pipe(
18+
Effect.andThen(Deferred.succeed(pushing, undefined)),
19+
Effect.andThen(Deferred.await(releasePush)),
20+
Effect.andThen(offer("pushed")),
21+
Effect.andThen(Deferred.succeed(outcome, "pull request created")),
22+
Effect.onInterrupt(() => Deferred.succeed(outcome, "interrupted")),
23+
),
24+
).pipe(Stream.runDrain, Effect.forkChild);
25+
26+
yield* Deferred.await(pushing);
27+
// The socket closes: Effect RPC interrupts the client's request fiber.
28+
yield* Fiber.interrupt(consumed);
29+
yield* Deferred.succeed(releasePush, undefined);
30+
31+
expect(yield* Deferred.await(outcome)).toBe("pull request created");
32+
}),
33+
);
34+
35+
it.effect("streams progress and ends when the work succeeds", () =>
36+
Effect.gen(function* () {
37+
const events = yield* detachedProgressStream<string, never, never>((offer) =>
38+
offer("committed").pipe(Effect.andThen(offer("pushed"))),
39+
).pipe(Stream.runCollect);
40+
41+
expect(events).toEqual(["committed", "pushed"]);
42+
}),
43+
);
44+
45+
it.effect("fails the stream with the work's own error", () =>
46+
Effect.gen(function* () {
47+
const error = yield* detachedProgressStream<string, string, never>((offer) =>
48+
offer("committed").pipe(Effect.andThen(Effect.fail("push rejected"))),
49+
).pipe(Stream.runDrain, Effect.flip);
50+
51+
expect(error).toBe("push rejected");
52+
}),
53+
);
54+
});
Collapse file

‎apps/server/src/git/detachedProgressStream.ts‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as Effect from "effect/Effect";
2+
import * as Queue from "effect/Queue";
3+
import * as Stream from "effect/Stream";
4+
5+
// Effect RPC interrupts every fiber of a client whose socket closes, so work that ran in the
6+
// stream's fiber stopped halfway: a commit without its push, a push without its pull request.
7+
// The work runs detached instead. Progress offered after the stream ends is dropped; the work
8+
// still finishes, and its result reaches the client through state it already resyncs.
9+
export const detachedProgressStream = <A, E, R>(
10+
run: (offer: (event: A) => Effect.Effect<void>) => Effect.Effect<unknown, E, R>,
11+
): Stream.Stream<A, E, R> =>
12+
Stream.callback<A, E, R>((queue) =>
13+
run((event) => Queue.offer(queue, event).pipe(Effect.ignore)).pipe(
14+
Effect.matchCauseEffect({
15+
onFailure: (cause) => Queue.failCause(queue, cause),
16+
onSuccess: () => Queue.end(queue),
17+
}),
18+
Effect.ignore,
19+
Effect.forkDetach,
20+
),
21+
);
Collapse file

‎apps/server/src/ws.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/ws.ts
+25-32Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ import * as VcsProvisioningService from "./vcs/VcsProvisioningService.ts";
218218
import * as GitWorkflowService from "./git/GitWorkflowService.ts";
219219
import { refreshPushedPullRequests } from "./git/refreshPushedPullRequests.ts";
220220
import { linkCreatedPullRequest } from "./git/linkCreatedPullRequest.ts";
221+
import { detachedProgressStream } from "./git/detachedProgressStream.ts";
221222
import * as ReviewService from "./review/ReviewService.ts";
222223
import * as ProjectEnrichmentService from "./project/ProjectEnrichmentService.ts";
223224
import * as ProjectService from "./project/ProjectService.ts";
@@ -3141,45 +3142,37 @@ export const layerWsRpc = (
31413142
}),
31423143
),
31433144
[WS_METHODS.gitRunStackedAction]: (input) =>
3144-
Stream.callback<GitActionProgressEvent, GitManagerServiceError>((queue) =>
3145+
detachedProgressStream<GitActionProgressEvent, GitManagerServiceError, never>((offer) =>
31453146
gitWorkflow
31463147
.runStackedAction(input, {
31473148
actionId: input.actionId,
3148-
progressReporter: {
3149-
publish: (event) => Queue.offer(queue, event).pipe(Effect.asVoid),
3150-
},
3149+
progressReporter: { publish: offer },
31513150
})
31523151
.pipe(
3153-
Effect.matchCauseEffect({
3154-
// Earlier steps (branch, commit) may have landed before the failing one.
3155-
onFailure: (cause) =>
3156-
refreshGitStatus(input.cwd).pipe(Effect.andThen(Queue.failCause(queue, cause))),
3157-
onSuccess: (result) =>
3158-
(input.threadId === undefined
3159-
? Effect.void
3160-
: linkCreatedPullRequest({
3161-
threadId: input.threadId,
3162-
result,
3163-
commandId: serverCommandId("pr-created-link"),
3164-
}).pipe(
3165-
Effect.provideService(Orchestrator.OrchestratorV2, orchestrationEngine),
3166-
Effect.provideService(ProjectService.ProjectService, projectService),
3167-
)
3168-
).pipe(
3169-
Effect.andThen(
3170-
refreshPushedPullRequests(input, result).pipe(
3171-
Effect.provideService(Orchestrator.OrchestratorV2, orchestrationEngine),
3172-
Effect.provideService(ProjectStore.ProjectStoreV2, projectStore),
3173-
Effect.provideService(
3174-
PullRequestService.PullRequestService,
3175-
pullRequests,
3176-
),
3177-
),
3152+
// Earlier steps (branch, commit) may have landed before the failing one.
3153+
Effect.tapCause(() => refreshGitStatus(input.cwd)),
3154+
Effect.flatMap((result) =>
3155+
(input.threadId === undefined
3156+
? Effect.void
3157+
: linkCreatedPullRequest({
3158+
threadId: input.threadId,
3159+
result,
3160+
commandId: serverCommandId("pr-created-link"),
3161+
}).pipe(
3162+
Effect.provideService(Orchestrator.OrchestratorV2, orchestrationEngine),
3163+
Effect.provideService(ProjectService.ProjectService, projectService),
3164+
)
3165+
).pipe(
3166+
Effect.andThen(
3167+
refreshPushedPullRequests(input, result).pipe(
3168+
Effect.provideService(Orchestrator.OrchestratorV2, orchestrationEngine),
3169+
Effect.provideService(ProjectStore.ProjectStoreV2, projectStore),
3170+
Effect.provideService(PullRequestService.PullRequestService, pullRequests),
31783171
),
3179-
Effect.andThen(refreshGitStatus(input.cwd)),
3180-
Effect.andThen(Queue.end(queue).pipe(Effect.asVoid)),
31813172
),
3182-
}),
3173+
Effect.andThen(refreshGitStatus(input.cwd)),
3174+
),
3175+
),
31833176
),
31843177
),
31853178
[WS_METHODS.gitResolvePullRequest]: (input) => gitWorkflow.resolvePullRequest(input),
Collapse file

‎packages/client-runtime/src/state/vcsAction.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcsAction.test.ts
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import * as Layer from "effect/Layer";
1717
import * as Option from "effect/Option";
1818
import * as Stream from "effect/Stream";
1919
import * as SubscriptionRef from "effect/SubscriptionRef";
20+
import { RpcClientError } from "effect/rpc";
21+
import * as Socket from "effect/socket/Socket";
2022
import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
2123

2224
import {
@@ -40,6 +42,7 @@ import {
4042
EMPTY_VCS_ACTION_STATE,
4143
normalizeVcsActionProgressEvent,
4244
parseVcsActionTargetKey,
45+
VcsActionConnectionLostError,
4346
VcsActionMissingTerminalEventError,
4447
VcsActionRemoteFailureError,
4548
VcsActionTargetKeyParseError,
@@ -378,6 +381,43 @@ describe("vcsActionState", () => {
378381
}),
379382
);
380383

384+
it.effect("reports a dropped connection as lost, not as a failed action", () =>
385+
Effect.gen(function* () {
386+
const target = { environmentId, cwd };
387+
const transportActionId = createVcsActionTransportId(target, actionId);
388+
const error = yield* consumeVcsActionProgress(
389+
Stream.fromIterable<GitActionProgressEvent>([
390+
{
391+
actionId: transportActionId,
392+
action,
393+
cwd,
394+
kind: "phase_started",
395+
phase: "push",
396+
label: "Pushing...",
397+
},
398+
]).pipe(
399+
Stream.concat(
400+
Stream.fail(
401+
new RpcClientError.RpcClientError({
402+
reason: new Socket.SocketCloseError({ code: 1006 }),
403+
}),
404+
),
405+
),
406+
),
407+
{
408+
target,
409+
transportActionId,
410+
actionId,
411+
action,
412+
onProgress: () => Effect.void,
413+
},
414+
).pipe(Effect.flip);
415+
416+
expect(error).toBeInstanceOf(VcsActionConnectionLostError);
417+
expect(error).toMatchObject({ actionId, transportActionId, action, environmentId, cwd });
418+
}),
419+
);
420+
381421
it("tracks finite mutations without letting an older completion clear newer state", async () => {
382422
const runtime = Atom.runtime(Layer.empty) as unknown as Atom.AtomRuntime<
383423
EnvironmentRegistry.EnvironmentRegistry | Persistence.EnvironmentCacheStore,
Collapse file

‎packages/client-runtime/src/state/vcsAction.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcsAction.ts
+32-1Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity";
1919

2020
import type { EnvironmentRegistry } from "../connection/registry.ts";
2121
import * as Persistence from "../platform/persistence.ts";
22-
import { runStreamGuarded, RpcPermissionGuard } from "../rpc/client.ts";
22+
import { isRpcClientError, runStreamGuarded, RpcPermissionGuard } from "../rpc/client.ts";
2323
import {
2424
createRuntimeCommand,
2525
runStreamInEnvironment,
@@ -130,6 +130,21 @@ export class VcsActionMissingTerminalEventError extends Schema.TaggedError<VcsAc
130130
}
131131
}
132132

133+
export class VcsActionConnectionLostError extends Schema.TaggedError<VcsActionConnectionLostError>()(
134+
"VcsActionConnectionLostError",
135+
{
136+
actionId: Schema.String,
137+
transportActionId: Schema.String,
138+
action: GitStackedAction,
139+
environmentId: EnvironmentId,
140+
cwd: Schema.String,
141+
},
142+
) {
143+
override get message(): string {
144+
return `Lost the connection to the server during '${this.action}'. The action can still finish there; the status updates once the connection returns.`;
145+
}
146+
}
147+
133148
export class VcsActionTargetKeyParseError extends Schema.TaggedError<VcsActionTargetKeyParseError>()(
134149
"VcsActionTargetKeyParseError",
135150
{
@@ -145,6 +160,7 @@ export class VcsActionTargetKeyParseError extends Schema.TaggedError<VcsActionTa
145160
export const VcsActionExecutionError = Schema.Union([
146161
VcsActionRemoteFailureError,
147162
VcsActionMissingTerminalEventError,
163+
VcsActionConnectionLostError,
148164
]);
149165
export type VcsActionExecutionError = typeof VcsActionExecutionError.Type;
150166

@@ -313,6 +329,21 @@ export function consumeVcsActionProgress<E, R>(
313329
}),
314330
);
315331
}),
332+
// The server runs the action detached from the socket, so losing the transport says
333+
// nothing about whether the action failed.
334+
Effect.catchIf(
335+
(error) => isRpcClientError(error) && error.reason._tag !== "RpcClientDefect",
336+
() =>
337+
Effect.fail<VcsActionExecutionError>(
338+
new VcsActionConnectionLostError({
339+
actionId: input.actionId,
340+
transportActionId: input.transportActionId,
341+
action: input.action,
342+
environmentId: input.target.environmentId,
343+
cwd: input.target.cwd,
344+
}),
345+
),
346+
),
316347
);
317348
});
318349
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.