Skip to content

Commit 125b619

Browse files
fix(server): release completed pull request sweep data (pingdotgg#25177)
1 parent 5211acf commit 125b619

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as NodeV8 from "node:v8";
2+
13
import { SourceControlProviderKind } from "@t3tools/contracts";
24
import * as Stream from "effect/Stream";
35
import {
@@ -21,10 +23,12 @@ import {
2123
type ThreadPullRequestSnapshot,
2224
} from "@t3tools/contracts";
2325
import { assert, describe, it } from "@effect/vitest";
26+
import * as Cache from "effect/Cache";
2427
import * as Clock from "effect/Clock";
2528
import * as Crypto from "effect/Crypto";
2629
import * as DateTime from "effect/DateTime";
2730
import * as Deferred from "effect/Deferred";
31+
import * as Duration from "effect/Duration";
2832
import * as Effect from "effect/Effect";
2933
import * as Layer from "effect/Layer";
3034
import * as Queue from "effect/Queue";
@@ -496,6 +500,40 @@ const mergingSnapshot = () =>
496500
makeSnapshot([makeThread(MERGING_THREAD, { pullRequests: [makeLink(7, { state: "open" })] })]);
497501

498502
describe("PullRequestSyncReactor", () => {
503+
it.effect("lets a finished sweep's links go while a cache keeps the fiber that read them", () =>
504+
Effect.gen(function* () {
505+
class SweptLink {
506+
readonly swept = true;
507+
}
508+
// Like PullRequestReadCache's revisions: a lookup fiber, kept for good, forked from the reader.
509+
const kept = yield* Cache.makeWith(() => Effect.void, {
510+
capacity: 1,
511+
timeToLive: () => Duration.infinity,
512+
});
513+
const fixture = yield* makeHarness({
514+
snapshot: makeSnapshot([]),
515+
summary: (input) => Cache.get(kept, undefined).pipe(Effect.as(makeSummary(input))),
516+
});
517+
yield* Ref.set(
518+
fixture.snapshots,
519+
makeSnapshot(
520+
Array.from({ length: 30 }, (_, index) =>
521+
makeThread(`thread-${index}`, {
522+
pullRequests: [Object.assign(new SweptLink(), makeLink(7))],
523+
}),
524+
),
525+
),
526+
);
527+
yield* Effect.gen(function* () {
528+
yield* startAndSweep(fixture);
529+
assert.strictEqual((yield* Ref.get(fixture.syncCommands)).length, 30);
530+
yield* Ref.set(fixture.snapshots, makeSnapshot([]));
531+
532+
assert.strictEqual(NodeV8.queryObjects(SweptLink, { format: "count" }), 0);
533+
}).pipe(Effect.provide(fixture.layer));
534+
}),
535+
);
536+
499537
it.effect("retries a failed stack read after the summary becomes terminal", () =>
500538
Effect.scoped(
501539
Effect.gen(function* () {

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ export const make = Effect.gen(function* () {
392392
const stacksReadThisSweep = new Map<string, ThreadPullRequestStack | null>();
393393
const persistence = yield* Semaphore.make(1);
394394

395-
const syncEntry = Effect.fn("PullRequestSyncReactor.syncEntry")(function* (
395+
// Effect.fn's stack frames close over these sweep-scoped bodies and their arguments, and a
396+
// cache lookup forked inside keeps those frames, so a plain span leaves the sweep collectable.
397+
const syncEntry = Effect.fnUntraced(function* (
396398
entry: LinkEntry,
397399
fields: SnapshotFields,
398400
fetchedStack: { readonly stack: ThreadPullRequestStack | null } | null,
@@ -446,12 +448,9 @@ export const make = Effect.gen(function* () {
446448
stack: nextStack,
447449
});
448450
}
449-
});
451+
}, Effect.withSpan("PullRequestSyncReactor.syncEntry"));
450452

451-
const syncGroup = Effect.fn("PullRequestSyncReactor.syncGroup")(function* (
452-
key: string,
453-
entries: ReadonlyArray<LinkEntry>,
454-
) {
453+
const syncGroup = Effect.fnUntraced(function* (key: string, entries: ReadonlyArray<LinkEntry>) {
455454
const first = entries[0]!;
456455
const ref = {
457456
projectId: first.thread.projectId,
@@ -554,7 +553,7 @@ export const make = Effect.gen(function* () {
554553
),
555554
{ discard: true },
556555
);
557-
});
556+
}, Effect.withSpan("PullRequestSyncReactor.syncGroup"));
558557

559558
const skips = new Map<string, { count: number; readonly key: string }>();
560559
const readGroup = (key: string, entries: ReadonlyArray<LinkEntry>, pauseKey: string) =>

0 commit comments

Comments
 (0)