From 0341b4fc3d8bb2a12c7064c69ceb16e7509af7cc Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 26 Oct 2026 00:54:19 +0000 Subject: [PATCH 1/2] test(server): a finished pull request sweep must not stay reachable from cache fibers Regression for #25172. A cache lookup forked during the sweep keeps the Effect.fn stack frames of syncGroup/syncEntry, whose closures hold the sweep's groups, so every sweep's links outlive it. Co-Authored-By: Claude Opus 5.5 --- .../PullRequestSyncReactor.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts b/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts index 028e74b06a2ca..eccb107bc2516 100644 --- a/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts +++ b/apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts @@ -1,3 +1,5 @@ +import * as NodeV8 from "node:v8"; + import { SourceControlProviderKind } from "@t3tools/contracts"; import * as Stream from "effect/Stream"; import { @@ -21,10 +23,12 @@ import { type ThreadPullRequestSnapshot, } from "@t3tools/contracts"; import { assert, describe, it } from "@effect/vitest"; +import * as Cache from "effect/Cache"; import * as Clock from "effect/Clock"; import * as Crypto from "effect/Crypto"; import * as DateTime from "effect/DateTime"; import * as Deferred from "effect/Deferred"; +import * as Duration from "effect/Duration"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Queue from "effect/Queue"; @@ -496,6 +500,40 @@ const mergingSnapshot = () => makeSnapshot([makeThread(MERGING_THREAD, { pullRequests: [makeLink(7, { state: "open" })] })]); describe("PullRequestSyncReactor", () => { + it.effect("lets a finished sweep's links go while a cache keeps the fiber that read them", () => + Effect.gen(function* () { + class SweptLink { + readonly swept = true; + } + // Like PullRequestReadCache's revisions: a lookup fiber, kept for good, forked from the reader. + const kept = yield* Cache.makeWith(() => Effect.void, { + capacity: 1, + timeToLive: () => Duration.infinity, + }); + const fixture = yield* makeHarness({ + snapshot: makeSnapshot([]), + summary: (input) => Cache.get(kept, undefined).pipe(Effect.as(makeSummary(input))), + }); + yield* Ref.set( + fixture.snapshots, + makeSnapshot( + Array.from({ length: 30 }, (_, index) => + makeThread(`thread-${index}`, { + pullRequests: [Object.assign(new SweptLink(), makeLink(7))], + }), + ), + ), + ); + yield* Effect.gen(function* () { + yield* startAndSweep(fixture); + assert.strictEqual((yield* Ref.get(fixture.syncCommands)).length, 30); + yield* Ref.set(fixture.snapshots, makeSnapshot([])); + + assert.strictEqual(NodeV8.queryObjects(SweptLink, { format: "count" }), 0); + }).pipe(Effect.provide(fixture.layer)); + }), + ); + it.effect("retries a failed stack read after the summary becomes terminal", () => Effect.scoped( Effect.gen(function* () { From 15b7291404409de78da6a7f6c46f1c72bf4dfa87 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 26 Oct 2026 00:58:00 +0000 Subject: [PATCH 2/2] fix(server): finished pull request sweeps no longer stay in memory syncGroup and syncEntry were Effect.fn closures defined inside each sweep. Effect.fn's per-call stack frame closes over the call's arguments and body, and a cache lookup fiber forked during the read keeps that frame for good, so every one-minute sweep's groups and linked threads stayed reachable. Both are now fnUntraced with an Effect.withSpan pipeable, which keeps their span names without capturing the sweep in a stack-frame closure. Fixes pingdotgg/t3code#25172 Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/PullRequestSyncReactor.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts b/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts index cc3225315620f..4f70b3f63a952 100644 --- a/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts +++ b/apps/server/src/orchestration-v2/PullRequestSyncReactor.ts @@ -392,7 +392,9 @@ export const make = Effect.gen(function* () { const stacksReadThisSweep = new Map(); const persistence = yield* Semaphore.make(1); - const syncEntry = Effect.fn("PullRequestSyncReactor.syncEntry")(function* ( + // Effect.fn's stack frames close over these sweep-scoped bodies and their arguments, and a + // cache lookup forked inside keeps those frames, so a plain span leaves the sweep collectable. + const syncEntry = Effect.fnUntraced(function* ( entry: LinkEntry, fields: SnapshotFields, fetchedStack: { readonly stack: ThreadPullRequestStack | null } | null, @@ -446,12 +448,9 @@ export const make = Effect.gen(function* () { stack: nextStack, }); } - }); + }, Effect.withSpan("PullRequestSyncReactor.syncEntry")); - const syncGroup = Effect.fn("PullRequestSyncReactor.syncGroup")(function* ( - key: string, - entries: ReadonlyArray, - ) { + const syncGroup = Effect.fnUntraced(function* (key: string, entries: ReadonlyArray) { const first = entries[0]!; const ref = { projectId: first.thread.projectId, @@ -554,7 +553,7 @@ export const make = Effect.gen(function* () { ), { discard: true }, ); - }); + }, Effect.withSpan("PullRequestSyncReactor.syncGroup")); const skips = new Map(); const readGroup = (key: string, entries: ReadonlyArray, pauseKey: string) =>