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(pr): action replies are opt-in for old clients and keep post-muta… · pingdotgg/t3code@25ff493

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/pullRequest
    • PullRequestService.test.ts
    • PullRequestService.ts
  • packages
    • client-runtime/src/state
      • pullRequests.test.ts
      • pullRequests.ts
      • runtime.ts
    • contracts/src
      • pullRequest.ts
      • rpc.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/PullRequestService.test.ts
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,13 @@ it.effect("returns the host's merged reply as a summary and trusts it without an
12481248
const observedAt = Date.parse("2026-09-03T02:00:01.000Z");
12491249
yield* TestClock.setTime(observedAt);
12501250

1251-
const result = yield* service.runAction({ ...reference, action: "merge" });
1251+
// Clients that did not ask decode the success as void, so they must get nothing back.
1252+
assert.isUndefined(yield* service.runAction({ ...reference, action: "merge" }));
1253+
const result = yield* service.runAction({
1254+
...reference,
1255+
action: "merge",
1256+
replyWithSummary: true,
1257+
});
12521258

12531259
assert.deepStrictEqual(result, {
12541260
...merged,
Collapse file

‎apps/server/src/pullRequest/PullRequestService.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/pullRequest/PullRequestService.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3621,7 +3621,7 @@ export const make = Effect.gen(function* () {
36213621
});
36223622
}
36233623
}
3624-
return summary;
3624+
return input.replyWithSummary === true ? summary : undefined;
36253625
});
36263626

36273627
const credentialCached =
Collapse file

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

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/pullRequests.test.ts
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,71 @@ it.effect("keeps an action's reply when a refresh started before the action answ
12561256
),
12571257
);
12581258

1259+
it.effect("keeps a list read the server's refresh started before the action replied", () =>
1260+
Effect.scoped(
1261+
Effect.gen(function* () {
1262+
const refreshEvents = yield* PubSub.unbounded<number>();
1263+
let state: "open" | "merged" = "open";
1264+
let reads = 0;
1265+
const actionInputs: unknown[] = [];
1266+
const listWaiting = Latch.makeUnsafe();
1267+
const release = yield* Deferred.make<void>();
1268+
const client = actionReplyClient({
1269+
[WS_METHODS.pullRequestsSubscribeRefreshes]: () => Stream.fromPubSub(refreshEvents),
1270+
[WS_METHODS.pullRequestsList]: () =>
1271+
Effect.gen(function* () {
1272+
reads++;
1273+
const entries = [
1274+
{ ...actionReference, state, isDraft: false, updatedAt: actionReply.updatedAt },
1275+
];
1276+
if (reads === 2) yield* Deferred.await(release);
1277+
return {
1278+
entries,
1279+
viewers: {},
1280+
providers: [],
1281+
errors: [],
1282+
truncated: false,
1283+
nextCursors: {},
1284+
};
1285+
}),
1286+
[WS_METHODS.pullRequestsRunAction]: (input: unknown) =>
1287+
Effect.gen(function* () {
1288+
actionInputs.push(input);
1289+
state = "merged";
1290+
// The server announces its refresh before it replies.
1291+
yield* PubSub.publish(refreshEvents, 1);
1292+
yield* listWaiting.await;
1293+
return actionReply;
1294+
}),
1295+
});
1296+
const { atoms, registry } = yield* makeTestRuntime(client);
1297+
const target = { environmentId: TARGET.environmentId, input: actionReference };
1298+
const list = atoms.list({ environmentId: target.environmentId, input: { state: "all" } });
1299+
const unmount = registry.mount(list);
1300+
yield* Effect.addFinalizer(() => Effect.sync(unmount));
1301+
yield* Effect.promise(() => executeAtomQuery(registry, list));
1302+
const stop = registry.subscribe(list, (result) => {
1303+
if (result.waiting) listWaiting.openUnsafe();
1304+
});
1305+
yield* Effect.addFinalizer(() => Effect.sync(stop));
1306+
1307+
yield* Effect.promise(() =>
1308+
atoms.runAction.run(registry, {
1309+
...target,
1310+
input: { ...actionReference, action: "merge" },
1311+
}),
1312+
);
1313+
yield* Deferred.succeed(release, undefined);
1314+
1315+
expect(
1316+
(yield* AtomRegistry.getResult(registry, list, { suspendOnWaiting: true })).entries,
1317+
).toMatchObject([{ state: "merged" }]);
1318+
expect(reads).toBe(2);
1319+
expect(actionInputs).toEqual([expect.objectContaining({ replyWithSummary: true })]);
1320+
}),
1321+
),
1322+
);
1323+
12591324
it.effect("shows a reopen reply at once and re-reads the fields it lacks", () =>
12601325
Effect.scoped(
12611326
Effect.gen(function* () {
Collapse file

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

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/pullRequests.ts
+74-41Lines changed: 74 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,17 @@ function updateCached<A, E>(
127127
registry.update(atom, AsyncResult.map(update));
128128
}
129129

130-
type ActionReplyPatch = (
131-
registry: AtomRegistry.AtomRegistry,
132-
environmentId: EnvironmentId,
133-
reference: PullRequestRef,
134-
reply: PullRequestSummary | undefined,
135-
) => Effect.Effect<void>;
130+
interface ActionReplyPatch {
131+
/** The read this reader is waiting on, if any. */
132+
readonly pendingRead: (registry: AtomRegistry.AtomRegistry) => object | undefined;
133+
readonly apply: (
134+
registry: AtomRegistry.AtomRegistry,
135+
environmentId: EnvironmentId,
136+
reference: PullRequestRef,
137+
reply: PullRequestSummary | undefined,
138+
readsBeforeSend: ReadonlySet<object>,
139+
) => Effect.Effect<void>;
140+
}
136141

137142
// Module-wide so readers built by separate factories, such as linked summaries, are patched too.
138143
const actionReplyPatches = new WeakMap<object, ActionReplyPatch>();
@@ -252,38 +257,54 @@ function actionPatchedQuery<Input, A, E>(
252257
writableQuery(atom, options.idleTtlMs),
253258
);
254259
return (target: { readonly environmentId: EnvironmentId; readonly input: Input }) => {
255-
const atom = writable(source(target));
260+
const query = source(target);
261+
const atom = writable(query);
256262
if (actionReplyPatches.has(atom)) return atom;
257-
actionReplyPatches.set(
258-
atom,
259-
Effect.fnUntraced(function* (registry, environmentId, reference, reply) {
260-
if (environmentId !== target.environmentId || !options.concerns(target.input, reference))
261-
return;
262-
if (reply === undefined) {
263-
return options.rereadWithoutReply === true ? registry.refresh(atom) : undefined;
264-
}
265-
const shown = Option.flatMap(
266-
registry.getNodes().get(atom)?.valueOption() ?? Option.none(),
267-
(current: AsyncResult.AsyncResult<A, E>) => AsyncResult.value(current),
268-
);
269-
// A read with nothing to show began before the action; restart it rather than guess.
270-
if (Option.isNone(shown)) return registry.refresh(atom);
271-
const patched = options.patch(target.input, shown.value, reference, reply);
272-
if (patched === "refresh") return registry.refresh(atom);
273-
const reread = options.rereads?.(shown.value, reply) === true;
274-
const next = reuseUnchanged(shown.value, patched);
275-
if (next === shown.value) return reread ? registry.refresh(atom) : undefined;
276-
yield* options.onAnswer?.(target, next, registry) ?? Effect.void;
277-
updateCached(registry, atom, () => next, reread);
278-
if (options.persistence !== undefined) {
279-
yield* options.persistence.save(
280-
environmentId,
281-
queryPersistenceKey(options.label, target.input),
282-
next,
263+
const pendingRead = (registry: AtomRegistry.AtomRegistry) => {
264+
const result = Option.getOrUndefined(
265+
registry.getNodes().get(query)?.valueOption() ?? Option.none(),
266+
) as AsyncResult.AsyncResult<A, E> | undefined;
267+
return result?.waiting === true ? result : undefined;
268+
};
269+
actionReplyPatches.set(atom, {
270+
pendingRead,
271+
apply: Effect.fnUntraced(
272+
function* (registry, environmentId, reference, reply, readsBeforeSend) {
273+
if (environmentId !== target.environmentId || !options.concerns(target.input, reference))
274+
return;
275+
const pending = pendingRead(registry);
276+
// A read sent after the action already sees its result; one sent before may not.
277+
const freshRead = pending !== undefined && !readsBeforeSend.has(pending);
278+
const reread = () => (freshRead ? undefined : registry.refresh(atom));
279+
if (reply === undefined) {
280+
return options.rereadWithoutReply === true ? reread() : undefined;
281+
}
282+
const shown = Option.flatMap(
283+
registry.getNodes().get(atom)?.valueOption() ?? Option.none(),
284+
(current: AsyncResult.AsyncResult<A, E>) => AsyncResult.value(current),
283285
);
284-
}
285-
}),
286-
);
286+
if (Option.isNone(shown)) return reread();
287+
const patched = options.patch(target.input, shown.value, reference, reply);
288+
if (patched === "refresh") return reread();
289+
const lacking = options.rereads?.(shown.value, reply) === true;
290+
const next = reuseUnchanged(shown.value, patched);
291+
if (next === shown.value) return lacking ? reread() : undefined;
292+
yield* options.onAnswer?.(target, next, registry) ?? Effect.void;
293+
if (lacking || (pending !== undefined && !freshRead)) registry.refresh(atom);
294+
registry.update(
295+
atom,
296+
AsyncResult.map(() => next),
297+
);
298+
if (options.persistence !== undefined) {
299+
yield* options.persistence.save(
300+
environmentId,
301+
queryPersistenceKey(options.label, target.input),
302+
next,
303+
);
304+
}
305+
},
306+
),
307+
});
287308
return atom;
288309
};
289310
}
@@ -590,17 +611,27 @@ export function createPullRequestEnvironmentAtoms<R, E>(
590611
});
591612
preparedInput = { ...actionInput, mergeMethod };
592613
}
593-
return yield* routedRequest(WS_METHODS.pullRequestsRunAction, preparedInput);
614+
return yield* routedRequest(WS_METHODS.pullRequestsRunAction, {
615+
...preparedInput,
616+
replyWithSummary: true,
617+
});
594618
});
619+
const actionReplyReaders = (registry: AtomRegistry.AtomRegistry) =>
620+
Array.from(registry.getNodes().keys()).flatMap((atom) => {
621+
const patch = typeof atom === "string" ? undefined : actionReplyPatches.get(atom);
622+
return patch === undefined ? [] : [patch];
623+
});
624+
const readsInFlight = (registry: AtomRegistry.AtomRegistry): ReadonlySet<object> =>
625+
new Set(actionReplyReaders(registry).flatMap((reader) => reader.pendingRead(registry) ?? []));
595626
const applyActionReply = Effect.fn("PullRequests.applyActionReply")(function* (
596627
registry: AtomRegistry.AtomRegistry,
597628
environmentId: EnvironmentId,
598629
reference: PullRequestRef,
599630
reply: PullRequestSummary | undefined,
631+
readsBeforeSend: ReadonlySet<object>,
600632
) {
601-
for (const atom of registry.getNodes().keys()) {
602-
const patch = typeof atom === "string" ? undefined : actionReplyPatches.get(atom);
603-
if (patch !== undefined) yield* patch(registry, environmentId, reference, reply);
633+
for (const reader of actionReplyReaders(registry)) {
634+
yield* reader.apply(registry, environmentId, reference, reply, readsBeforeSend);
604635
}
605636
if (reply !== undefined && reference.expectedAccountId === undefined) {
606637
yield* (
@@ -761,8 +792,9 @@ export function createPullRequestEnvironmentAtoms<R, E>(
761792
// Preparation belongs to the write's lane. Refreshable queries would restart it after
762793
// every preceding action, and preparing outside the lane could reorder the clicks.
763794
execute: runAction,
795+
onStart: (_target, registry) => readsInFlight(registry),
764796
// Loaded readers show the reply, or re-read when the host's reply lacked the pull request.
765-
onSuccess: ({ environmentId, input }, registry, reply) => {
797+
onSuccess: ({ environmentId, input }, registry, reply, readsBeforeSend) => {
766798
const { projectId, host, repository, number, expectedAccountId } = input;
767799
return applyActionReply(
768800
registry,
@@ -775,6 +807,7 @@ export function createPullRequestEnvironmentAtoms<R, E>(
775807
...(expectedAccountId === undefined ? {} : { expectedAccountId }),
776808
},
777809
reply,
810+
readsBeforeSend ?? new Set(),
778811
);
779812
},
780813
scheduler: commandScheduler,
Collapse file

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

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/runtime.ts
+18-2Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,11 +950,20 @@ export function createEnvironmentRpcCommand<
950950
ER,
951951
TTag extends EnvironmentUnaryRpcTag,
952952
Input extends EnvironmentRpcInput<TTag> = EnvironmentRpcInput<TTag>,
953+
Started = undefined,
953954
>(
954955
runtime: Atom.AtomRuntime<EnvironmentRegistry.EnvironmentRegistry | R, ER>,
955956
options: {
956957
readonly label: string;
957958
readonly tag: TTag;
959+
/** Runs once authorized, as the request starts; what it returns reaches `onSuccess`. */
960+
readonly onStart?: (
961+
target: {
962+
readonly environmentId: EnvironmentIdType;
963+
readonly input: NoInfer<Input>;
964+
},
965+
registry: AtomRegistry.AtomRegistry,
966+
) => Started;
958967
readonly execute?: (
959968
input: Input,
960969
) => Effect.Effect<
@@ -974,6 +983,7 @@ export function createEnvironmentRpcCommand<
974983
},
975984
registry: AtomRegistry.AtomRegistry,
976985
result: EnvironmentRpcSuccess<TTag>,
986+
started: Started | undefined,
977987
) => Effect.Effect<void, never, R>;
978988
readonly onSettled?: (
979989
target: {
@@ -994,15 +1004,21 @@ export function createEnvironmentRpcCommand<
9941004
environmentId,
9951005
input,
9961006
};
1007+
let started: Started | undefined;
9971008
// Routing requires consent on the origin as well as the actual destination.
9981009
// The transport check below deliberately checks the destination again.
9991010
return permissions.authorize(registry, environmentId, input).pipe(
1000-
Effect.andThen(() => options.execute?.(input) ?? requestGuarded(options.tag, input)),
1011+
Effect.andThen(() => {
1012+
started = options.onStart?.(target, registry);
1013+
return options.execute?.(input) ?? requestGuarded(options.tag, input);
1014+
}),
10011015
Effect.provideService(RpcPermissionGuard, {
10021016
authorize: (id, method, payload) =>
10031017
createCommandPermissions(runtime, method).authorize(registry, id, payload),
10041018
}),
1005-
Effect.tap((result) => options.onSuccess?.(target, registry, result) ?? Effect.void),
1019+
Effect.tap(
1020+
(result) => options.onSuccess?.(target, registry, result, started) ?? Effect.void,
1021+
),
10061022
Effect.ensuring(options.onSettled?.(target, registry) ?? Effect.void),
10071023
);
10081024
},
Collapse file

‎packages/contracts/src/pullRequest.ts‎

Copy file name to clipboardExpand all lines: packages/contracts/src/pullRequest.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ export const PullRequestActionInput = Schema.Struct({
739739
action: PullRequestAction,
740740
mergeMethod: Schema.optional(PullRequestMergeMethod),
741741
updateMethod: Schema.optional(PullRequestUpdateMethod),
742+
/** Opt-in, because older clients decode the action's success as void and reject a summary. */
743+
replyWithSummary: Schema.optional(Schema.Literal(true)),
742744
});
743745
export type PullRequestActionInput = typeof PullRequestActionInput.Type;
744746

Collapse file

‎packages/contracts/src/rpc.ts‎

Copy file name to clipboardExpand all lines: packages/contracts/src/rpc.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ const WsPullRequestsSetFilesViewedRpc = Rpc.make(WS_METHODS.pullRequestsSetFiles
11161116

11171117
const WsPullRequestsRunActionRpc = Rpc.make(WS_METHODS.pullRequestsRunAction, {
11181118
payload: PullRequestActionInput,
1119-
// Undefined when the host's reply did not carry the change request; clients then re-read.
1119+
// Undefined unless asked for with replyWithSummary, or when the host's reply lacked it.
11201120
success: Schema.UndefinedOr(PullRequestSummary),
11211121
error: PullRequestRpcError,
11221122
});

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.