fix(prs): queue fast actions and close batches by dragging (#15851)

Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
mariaandmaria-rcks authored and GitHub committed 2026-10-05 09:12:34 -03:00
1 parent 7812230572
commit 7ffa2184a7
13 files changed
+550 -67

No files matched your search

@@ -2,9 +2,11 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
import * as KeyValueStore from "effect/unstable/persistence/KeyValueStore";
import { assert, it } from "@effect/vitest";
import * as Cause from "effect/Cause";
import * as Clock from "effect/Clock";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
@@ -3348,6 +3350,72 @@ it.effect("answers a repeated listing from cache, and concurrent readers share o
}),
);
it.effect.each(["list", "listStats"] as const)(
"retries a replacement %s read that joins a canceled lookup",
(operation) =>
Effect.gen(function* () {
const started = yield* Deferred.make<void>();
const stopping = yield* Deferred.make<void>();
const finishShutdown = yield* Deferred.make<void>();
let hostCalls = 0;
const lookup = Effect.gen(function* () {
if (++hostCalls !== 1) return;
yield* Deferred.succeed(started, undefined);
return yield* Effect.never.pipe(
Effect.onInterrupt(() =>
Deferred.succeed(stopping, undefined).pipe(
Effect.andThen(Deferred.await(finishShutdown)),
),
),
);
});
const service = yield* makeService({
projects: [
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
],
providers: [
fakeProvider("github", {
listChangeRequests: () =>
lookup.pipe(
Effect.as({
items: [changeRequest(1, "2026-07-02T00:00:00Z")],
truncated: false,
continues: false,
}),
),
listChangeRequestStats: () =>
lookup.pipe(
Effect.as([{ repository: "acme/web", number: 1, additions: 3, deletions: 1 }]),
),
}),
],
});
const read =
operation === "list"
? service
.list({ state: "open" })
.pipe(Effect.map((result) => result.entries.map((entry) => entry.number)))
: service
.listStats({
refs: [{ projectId: "p1" as ProjectId, repository: "acme/web", number: 1 }],
})
.pipe(Effect.map((result) => result.stats.map((stat) => stat.number)));
const original = yield* Effect.forkScoped(read);
yield* Deferred.await(started);
const cancellation = yield* Effect.forkScoped(Fiber.interrupt(original));
yield* Deferred.await(stopping);
// Join the old entry while its lookup is still finishing cancellation.
const replacement = yield* Effect.forkScoped(read, { startImmediately: true });
yield* Deferred.succeed(finishShutdown, undefined);
yield* Fiber.join(cancellation);
const canceled = yield* Fiber.await(original);
assert.isTrue(Exit.isFailure(canceled));
if (Exit.isFailure(canceled)) assert.isTrue(Cause.hasInterruptsOnly(canceled.cause));
assert.deepStrictEqual(yield* Fiber.join(replacement), [1]);
assert.strictEqual(hostCalls, 2);
}),
);
it.effect("shares one cold viewer lookup across distinct concurrent lists", () =>
Effect.gen(function* () {
let viewerCalls = 0;
@@ -5,6 +5,7 @@ import {
} from "@t3tools/shared/sourceControl";
import { normalizeGitRemoteUrl } from "@t3tools/shared/git";
import * as Cache from "effect/Cache";
import * as Cause from "effect/Cause";
import * as Clock from "effect/Clock";
import * as Context from "effect/Context";
import * as DateTime from "effect/DateTime";
@@ -2887,7 +2888,12 @@ export const make = Effect.gen(function* () {
? null
: Object.entries(input.cursors).toSorted(([left], [right]) => left.localeCompare(right)),
]);
return Cache.get(listCache, key);
// A replacement reader can join a lookup still finishing its previous reader's cancellation.
return Cache.get(listCache, key).pipe(
Effect.catchCause((cause) =>
Cause.hasInterruptsOnly(cause) ? Cache.get(listCache, key) : Effect.failCause(cause),
),
);
};
const checksCache = yield* Cache.makeWith(
@@ -3134,7 +3140,11 @@ export const make = Effect.gen(function* () {
}
if (missing.size === 0) return { stats: held };
const key = statsBatchKey(missing.values());
const { result, at } = yield* Cache.get(listStatsCache, key);
const { result, at } = yield* Cache.get(listStatsCache, key).pipe(
Effect.catchCause((cause) =>
Cause.hasInterruptsOnly(cause) ? Cache.get(listStatsCache, key) : Effect.failCause(cause),
),
);
for (const [key, ref] of missing) {
const stat = result.stats.find(
(stat) =>