Skip to content

Commit 40e475e

Browse files
donjorrsi-pr-agent
authored andcommitted
refactor(upstream-fixes): fork WS RPCs get their own handler layer under TypeScript's instantiation limit
Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: no
1 parent f053d33 commit 40e475e

5 files changed

Lines changed: 69 additions & 22 deletions

File tree

‎apps/server/src/git/CheckoutMoveService.fork.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,22 @@ const make = Effect.gen(function* () {
425425
);
426426

427427
return CheckoutMoveServiceFork.of({
428-
request: (input) =>
429-
requests.withLock(input.threadId, request(input).pipe(Effect.provide(services))),
430-
recoverRemovedWorktree: (thread) =>
431-
newUuid.pipe(
432-
Effect.flatMap((uuid) =>
433-
recoverRemovedWorktree(thread, {
434-
recoveryId: `server:worktree-checkout-recovery:${uuid}`,
435-
duringRun: false,
436-
}),
437-
),
438-
Effect.map((recovered) => recovered.thread),
439-
),
428+
request: Effect.fn("CheckoutMoveServiceFork.request")(function (input) {
429+
return requests.withLock(input.threadId, request(input).pipe(Effect.provide(services)));
430+
}),
431+
recoverRemovedWorktree: Effect.fn("CheckoutMoveServiceFork.recoverRemovedWorktree")(
432+
function (thread) {
433+
return newUuid.pipe(
434+
Effect.flatMap((uuid) =>
435+
recoverRemovedWorktree(thread, {
436+
recoveryId: `server:worktree-checkout-recovery:${uuid}`,
437+
duringRun: false,
438+
}),
439+
),
440+
Effect.map((recovered) => recovered.thread),
441+
);
442+
},
443+
),
440444
drain: worker.drain,
441445
});
442446
});
@@ -453,7 +457,7 @@ export const checkoutMoveServiceLiveFork = checkoutMoveServiceLayerFork.pipe(
453457
Layer.provide(layerEventSink),
454458
);
455459

456-
/** Spread into the WebSocket handler table through `zmux-estate/ws-checkout-move-handlers`. */
460+
/** Spread into the fork WS handler table in `wsRpcHandlers.fork.ts`. */
457461
export const checkoutMoveRpcHandlersFork = (checkoutMoves: CheckoutMoveServiceFork["Service"]) => ({
458462
"thread.checkoutMove.request": (input: ThreadCheckoutMoveRequestInput) =>
459463
checkoutMoves.request(input),

‎apps/server/src/ws.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,9 @@ import { listLinkedPullRequestThreads } from "./pullRequest/linkedThreads.ts";
246246
import { pullRequestSyncKey } from "./pullRequest/pullRequestSyncKey.ts";
247247
import * as SqlClient from "effect/sql/SqlClient";
248248
import * as PullRequestSyncReactor from "./orchestration-v2/PullRequestSyncReactor.ts";
249-
import { gitHubIssueRpcHandlersFork } from "./githubIssue/githubIssueWiring.fork.ts"; // fork-hook: github-issues/ws-wiring-import
250249
import * as GitHubIssueService from "./githubIssue/GitHubIssueService.ts"; // fork-hook: github-issues/ws-service-import
250+
import { wsRpcHandlersLayerFork, wsRpcTagsFork } from "./wsRpcHandlers.fork.ts"; // fork-hook: upstream-fixes/ws-rpc-handlers-import
251251
import { sharedCheckoutWsLayerFork } from "./git/sharedCheckoutGuard.fork.ts"; // fork-hook: zmux-estate/ws-shared-checkout-import
252-
import * as CheckoutMoveFork from "./git/CheckoutMoveService.fork.ts"; // fork-hook: zmux-estate/ws-checkout-move-import
253252
import * as SourceControlDiscovery from "./sourceControl/SourceControlDiscovery.ts";
254253
import * as OtlpEndpointCheck from "./observability/OtlpEndpointCheck.ts";
255254
import * as SourceControlRepositoryService from "./sourceControl/SourceControlRepositoryService.ts";
@@ -1235,12 +1234,14 @@ export const subscribeOrchestrationV2Shell = Effect.fn("ws.orchestrationV2.subsc
12351234
},
12361235
);
12371236

1237+
const ServerWsRpcHandlerGroupFork = ServerWsRpcGroup.omit(...wsRpcTagsFork); // fork-hook: upstream-fixes/ws-rpc-handler-group-omit
12381238
export const layerWsRpc = (
12391239
currentSession: EnvironmentAuth.AuthenticatedSession,
12401240
clientOrigin: OrchestrationClientOrigin,
12411241
clientAnalyticsProps: Readonly<Record<string, unknown>>,
12421242
previewAutomationBroker: PreviewAutomationBroker.PreviewAutomationBroker["Service"],
12431243
serverBrowser: ServerBrowser.ServerBrowser["Service"],
1244+
ServerWsRpcGroup = ServerWsRpcHandlerGroupFork, // fork-hook: upstream-fixes/ws-rpc-handler-group
12441245
) =>
12451246
Layer.effectContext(
12461247
Effect.gen(function* () {
@@ -1377,8 +1378,6 @@ export const layerWsRpc = (
13771378
const sourceControlRepositories =
13781379
yield* SourceControlRepositoryService.SourceControlRepositoryService;
13791380
const withPullRequestViewer = pullRequests.withRoutingCredential;
1380-
const githubIssues = yield* GitHubIssueService.GitHubIssueService; // fork-hook: github-issues/ws-service-yield
1381-
const checkoutMoves = yield* CheckoutMoveFork.CheckoutMoveServiceFork; // fork-hook: zmux-estate/ws-checkout-move-yield
13821381
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
13831382
const sessions = yield* SessionStore.SessionStore;
13841383
const processDiagnostics = yield* ProcessDiagnostics.ProcessDiagnostics;
@@ -2683,9 +2682,6 @@ export const layerWsRpc = (
26832682
),
26842683
[WS_METHODS.pullRequestsUpdate]: (input) =>
26852684
withPullRequestViewer(input, pullRequests.update(input)),
2686-
[WS_METHODS.pullRequestsCreateAttachmentUploadUrl]: (input) =>
2687-
pullRequests.createAttachmentUploadUrl(input),
2688-
[WS_METHODS.pullRequestsUploadAttachment]: (input) => pullRequests.uploadAttachment(input),
26892685
[WS_METHODS.pullRequestsComment]: (input) =>
26902686
withPullRequestViewer(input, pullRequests.comment(input)),
26912687
[WS_METHODS.pullRequestsUpdateComment]: (input) =>
@@ -2722,8 +2718,6 @@ export const layerWsRpc = (
27222718
withPullRequestViewer(input, pullRequests.labelCandidates(input)),
27232719
[WS_METHODS.pullRequestsSetLabels]: (input) =>
27242720
withPullRequestViewer(input, pullRequests.setLabels(input)),
2725-
...gitHubIssueRpcHandlersFork(githubIssues, sql), // fork-hook: github-issues/ws-rpc-handlers
2726-
...CheckoutMoveFork.checkoutMoveRpcHandlersFork(checkoutMoves), // fork-hook: zmux-estate/ws-checkout-move-handlers
27272721
[WS_METHODS.sourceControlLookupRepository]: (input) =>
27282722
sourceControlRepositories.lookupRepository(input),
27292723
[WS_METHODS.sourceControlCloneRepository]: (input) =>
@@ -3404,6 +3398,7 @@ export const layer = Layer.unwrap(
34043398
previewAutomationBroker,
34053399
serverBrowser,
34063400
).pipe(
3401+
Layer.merge(wsRpcHandlersLayerFork), // fork-hook: upstream-fixes/ws-rpc-handlers-layer
34073402
Layer.provideMerge(RpcSerialization.layerJson),
34083403
// Handler-context reporters see only request defects, not server-wide defects.
34093404
Layer.provide(DefectReporter.layer),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Fork-only: every fork WS RPC is served from this handler layer, not upstream's handler table in
2+
// `ws.ts`. One table holding upstream's and the fork's handlers exceeds TypeScript's type
3+
// instantiation limit (TS2589), which silently turns the WS layer's requirements into `any`.
4+
// `ws.ts` omits these tags from its table (`upstream-fixes/ws-rpc-handler-group-omit`), shadows
5+
// its group with that one inside the table's layer (`upstream-fixes/ws-rpc-handler-group`), and
6+
// merges this layer beside it (`upstream-fixes/ws-rpc-handlers-layer`).
7+
import * as Effect from "effect/Effect";
8+
import { RpcGroup } from "effect/rpc";
9+
import * as SqlClient from "effect/sql/SqlClient";
10+
import { RpcScopeAuthorization, wsRpcsFork } from "@t3tools/contracts";
11+
12+
import * as CheckoutMoveFork from "./git/CheckoutMoveService.fork.ts";
13+
import * as GitHubIssueService from "./githubIssue/GitHubIssueService.ts";
14+
import { gitHubIssueRpcHandlersFork } from "./githubIssue/githubIssueWiring.fork.ts";
15+
import { RpcInstrumentation } from "./observability/RpcInstrumentation.ts";
16+
import * as PullRequestService from "./pullRequest/PullRequestService.ts";
17+
18+
export const wsRpcTagsFork = wsRpcsFork.map((rpc) => rpc._tag);
19+
20+
// The middleware only types the handlers; `RpcServer.make` runs upstream's full group, whose
21+
// middleware wraps these RPCs too.
22+
const WsRpcGroupFork = RpcGroup.make(...wsRpcsFork)
23+
.middleware(RpcScopeAuthorization)
24+
.middleware(RpcInstrumentation);
25+
26+
export const wsRpcHandlersLayerFork = WsRpcGroupFork.toLayer(
27+
Effect.gen(function* () {
28+
const sql = yield* SqlClient.SqlClient;
29+
const githubIssues = yield* GitHubIssueService.GitHubIssueService;
30+
const checkoutMoves = yield* CheckoutMoveFork.CheckoutMoveServiceFork;
31+
const pullRequests = yield* PullRequestService.PullRequestService;
32+
return WsRpcGroupFork.of({
33+
...gitHubIssueRpcHandlersFork(githubIssues, sql),
34+
...CheckoutMoveFork.checkoutMoveRpcHandlersFork(checkoutMoves),
35+
"pullRequests.createAttachmentUploadUrl": (input) =>
36+
pullRequests.createAttachmentUploadUrl(input),
37+
"pullRequests.uploadAttachment": (input) => pullRequests.uploadAttachment(input),
38+
});
39+
}),
40+
);

‎packages/contracts/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export * from "./scheduledTask.ts";
7474
export * from "./worktreeMcp.ts";
7575
export * from "./resourceTelemetry.ts";
7676
export * from "./rpc.ts";
77+
export { wsRpcsFork } from "./rpc.fork.ts"; // fork-hook: upstream-fixes/ws-rpcs-fork-export
7778
export * from "./worktreeSetup.ts";
7879
export * from "./secretRequest.ts";
7980
export * from "./clientRpcPermissions.ts";

‎packages/contracts/src/rpc.fork.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,10 @@ export const checkoutMoveRpcFork = {
152152
} as const,
153153
rpcs: [WsThreadCheckoutMoveRequestRpcFork] as const,
154154
};
155+
156+
/** Every fork WS RPC; the server serves them from a handler layer of their own. */
157+
export const wsRpcsFork = [
158+
...pullRequestAttachmentRpcFork.rpcs,
159+
...githubIssuesRpcFork.rpcs,
160+
...checkoutMoveRpcFork.rpcs,
161+
] as const;

0 commit comments

Comments
 (0)